Commit e476f80e authored by Henry Weller's avatar Henry Weller
Browse files

functionObjects: Improved handling of multi-file indexing and code style

Patch contributed by Bruno Santos
Resolves bug-report http://bugs.openfoam.org/view.php?id=2216
parent fc44390d
......@@ -72,12 +72,12 @@ void Foam::functionObjects::fieldValues::fieldValueDelta::writeFileHeader
const wordList& fields2 = region2Ptr_->fields();
DynamicList<word> commonFields(fields1.size());
forAll(fields1, i)
forAll(fields1, fieldi)
{
label index = findIndex(fields2, fields1[i]);
label index = findIndex(fields2, fields1[fieldi]);
if (index != -1)
{
commonFields.append(fields1[i]);
commonFields.append(fields1[fieldi]);
}
}
......
......@@ -554,11 +554,11 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::writeFileHeader
file() << tab << "Area";
}
forAll(fields_, i)
forAll(fields_, fieldi)
{
file()
<< tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
<< "(" << fields_[fieldi] << ")";
}
file() << endl;
......
......@@ -96,11 +96,11 @@ void Foam::functionObjects::fieldValues::volFieldValue::writeFileHeader
writeCommented(file(), "Time");
forAll(fields_, i)
forAll(fields_, fieldi)
{
file()
<< tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
<< "(" << fields_[fieldi] << ")";
}
file() << endl;
......
......@@ -42,74 +42,81 @@ namespace functionObjects
void Foam::functionObjects::forceCoeffs::writeFileHeader(const label i)
{
if (i == 0)
switch (fileID(i))
{
// force coeff data
writeHeader(file(i), "Force coefficients");
writeHeaderValue(file(i), "liftDir", liftDir_);
writeHeaderValue(file(i), "dragDir", dragDir_);
writeHeaderValue(file(i), "pitchAxis", pitchAxis_);
writeHeaderValue(file(i), "magUInf", magUInf_);
writeHeaderValue(file(i), "lRef", lRef_);
writeHeaderValue(file(i), "Aref", Aref_);
writeHeaderValue(file(i), "CofR", coordSys_.origin());
writeCommented(file(i), "Time");
writeTabbed(file(i), "Cm");
writeTabbed(file(i), "Cd");
writeTabbed(file(i), "Cl");
writeTabbed(file(i), "Cl(f)");
writeTabbed(file(i), "Cl(r)");
}
else if (i == 1)
{
// bin coeff data
writeHeader(file(i), "Force coefficient bins");
writeHeaderValue(file(i), "bins", nBin_);
writeHeaderValue(file(i), "start", binMin_);
writeHeaderValue(file(i), "delta", binDx_);
writeHeaderValue(file(i), "direction", binDir_);
vectorField binPoints(nBin_);
writeCommented(file(i), "x co-ords :");
forAll(binPoints, pointi)
case MAIN_FILE:
{
binPoints[pointi] = (binMin_ + (pointi + 1)*binDx_)*binDir_;
file(i) << tab << binPoints[pointi].x();
// force coeff data
writeHeader(file(i), "Force coefficients");
writeHeaderValue(file(i), "liftDir", liftDir_);
writeHeaderValue(file(i), "dragDir", dragDir_);
writeHeaderValue(file(i), "pitchAxis", pitchAxis_);
writeHeaderValue(file(i), "magUInf", magUInf_);
writeHeaderValue(file(i), "lRef", lRef_);
writeHeaderValue(file(i), "Aref", Aref_);
writeHeaderValue(file(i), "CofR", coordSys_.origin());
writeCommented(file(i), "Time");
writeTabbed(file(i), "Cm");
writeTabbed(file(i), "Cd");
writeTabbed(file(i), "Cl");
writeTabbed(file(i), "Cl(f)");
writeTabbed(file(i), "Cl(r)");
break;
}
file(i) << nl;
writeCommented(file(i), "y co-ords :");
forAll(binPoints, pointi)
case BINS_FILE:
{
file(i) << tab << binPoints[pointi].y();
}
file(i) << nl;
// bin coeff data
writeCommented(file(i), "z co-ords :");
forAll(binPoints, pointi)
{
file(i) << tab << binPoints[pointi].z();
}
file(i) << nl;
writeHeader(file(i), "Force coefficient bins");
writeHeaderValue(file(i), "bins", nBin_);
writeHeaderValue(file(i), "start", binMin_);
writeHeaderValue(file(i), "delta", binDx_);
writeHeaderValue(file(i), "direction", binDir_);
writeCommented(file(i), "Time");
vectorField binPoints(nBin_);
writeCommented(file(i), "x co-ords :");
forAll(binPoints, pointi)
{
binPoints[pointi] = (binMin_ + (pointi + 1)*binDx_)*binDir_;
file(i) << tab << binPoints[pointi].x();
}
file(i) << nl;
for (label j = 0; j < nBin_; j++)
writeCommented(file(i), "y co-ords :");
forAll(binPoints, pointi)
{
file(i) << tab << binPoints[pointi].y();
}
file(i) << nl;
writeCommented(file(i), "z co-ords :");
forAll(binPoints, pointi)
{
file(i) << tab << binPoints[pointi].z();
}
file(i) << nl;
writeCommented(file(i), "Time");
for (label j = 0; j < nBin_; j++)
{
const word jn('(' + Foam::name(j) + ')');
writeTabbed(file(i), "Cm" + jn);
writeTabbed(file(i), "Cd" + jn);
writeTabbed(file(i), "Cl" + jn);
}
break;
}
default:
{
const word jn('(' + Foam::name(j) + ')');
writeTabbed(file(i), "Cm" + jn);
writeTabbed(file(i), "Cd" + jn);
writeTabbed(file(i), "Cl" + jn);
FatalErrorInFunction
<< "Unhandled file index: " << i
<< abort(FatalError);
}
}
else
{
FatalErrorInFunction
<< "Unhandled file index: " << i
<< abort(FatalError);
}
file(i)<< endl;
}
......@@ -200,8 +207,8 @@ bool Foam::functionObjects::forceCoeffs::write()
scalar Clf = Cl/2.0 + Cm;
scalar Clr = Cl/2.0 - Cm;
writeTime(file(0));
file(0)
writeTime(file(MAIN_FILE));
file(MAIN_FILE)
<< tab << Cm << tab << Cd
<< tab << Cl << tab << Clf << tab << Clr << endl;
......@@ -224,17 +231,17 @@ bool Foam::functionObjects::forceCoeffs::write()
}
}
writeTime(file(1));
writeTime(file(BINS_FILE));
forAll(coeffs[0], i)
{
file(1)
file(BINS_FILE)
<< tab << coeffs[2][i]
<< tab << coeffs[1][i]
<< tab << coeffs[0][i];
}
file(1) << endl;
file(BINS_FILE) << endl;
}
Log << endl;
......
......@@ -53,6 +53,8 @@ Foam::wordList Foam::functionObjects::forces::createFileNames
DynamicList<word> names(1);
const word forceType(dict.lookup("type"));
// Name for file(MAIN_FILE=0)
names.append(forceType);
if (dict.found("binData"))
......@@ -61,6 +63,7 @@ Foam::wordList Foam::functionObjects::forces::createFileNames
label nb = readLabel(binDict.lookup("nBin"));
if (nb > 0)
{
// Name for file(BINS_FILE=1)
names.append(forceType + "_bins");
}
}
......@@ -71,86 +74,95 @@ Foam::wordList Foam::functionObjects::forces::createFileNames
void Foam::functionObjects::forces::writeFileHeader(const label i)
{
if (i == 0)
switch (fileID(i))
{
// force data
writeHeader(file(i), "Forces");
writeHeaderValue(file(i), "CofR", coordSys_.origin());
writeCommented(file(i), "Time");
case MAIN_FILE:
{
// force data
file(i)
<< "forces(pressure viscous porous) "
<< "moment(pressure viscous porous)";
writeHeader(file(i), "Forces");
writeHeaderValue(file(i), "CofR", coordSys_.origin());
writeCommented(file(i), "Time");
if (localSystem_)
{
const word forceTypes("(pressure viscous porous)");
file(i)
<< tab
<< "localForces(pressure,viscous,porous) "
<< "localMoments(pressure,viscous,porous)";
}
}
else if (i == 1)
{
// bin data
<< "forces" << forceTypes << tab
<< "moments" << forceTypes;
writeHeader(file(i), "Force bins");
writeHeaderValue(file(i), "bins", nBin_);
writeHeaderValue(file(i), "start", binMin_);
writeHeaderValue(file(i), "delta", binDx_);
writeHeaderValue(file(i), "direction", binDir_);
if (localSystem_)
{
file(i)
<< tab
<< "localForces" << forceTypes << tab
<< "localMoments" << forceTypes;
}
vectorField binPoints(nBin_);
writeCommented(file(i), "x co-ords :");
forAll(binPoints, pointi)
{
binPoints[pointi] = (binMin_ + (pointi + 1)*binDx_)*binDir_;
file(i) << tab << binPoints[pointi].x();
break;
}
file(i) << nl;
writeCommented(file(i), "y co-ords :");
forAll(binPoints, pointi)
case BINS_FILE:
{
file(i) << tab << binPoints[pointi].y();
}
file(i) << nl;
// bin data
writeCommented(file(i), "z co-ords :");
forAll(binPoints, pointi)
{
file(i) << tab << binPoints[pointi].z();
}
file(i) << nl;
writeHeader(file(i), "Force bins");
writeHeaderValue(file(i), "bins", nBin_);
writeHeaderValue(file(i), "start", binMin_);
writeHeaderValue(file(i), "delta", binDx_);
writeHeaderValue(file(i), "direction", binDir_);
writeCommented(file(i), "Time");
vectorField binPoints(nBin_);
writeCommented(file(i), "x co-ords :");
forAll(binPoints, pointi)
{
binPoints[pointi] = (binMin_ + (pointi + 1)*binDx_)*binDir_;
file(i) << tab << binPoints[pointi].x();
}
file(i) << nl;
for (label j = 0; j < nBin_; j++)
{
const word jn('(' + Foam::name(j) + ')');
const word f("forces" + jn + "[pressure,viscous,porous]");
const word m("moments" + jn + "[pressure,viscous,porous]");
writeCommented(file(i), "y co-ords :");
forAll(binPoints, pointi)
{
file(i) << tab << binPoints[pointi].y();
}
file(i) << nl;
file(i)<< tab << f << tab << m;
}
if (localSystem_)
{
writeCommented(file(i), "z co-ords :");
forAll(binPoints, pointi)
{
file(i) << tab << binPoints[pointi].z();
}
file(i) << nl;
writeCommented(file(i), "Time");
const word binForceTypes("[pressure,viscous,porous]");
for (label j = 0; j < nBin_; j++)
{
const word jn('(' + Foam::name(j) + ')');
const word f("localForces" + jn + "[pressure,viscous,porous]");
const word m("localMoments" + jn + "[pressure,viscous,porous]");
const word f("forces" + jn + binForceTypes);
const word m("moments" + jn + binForceTypes);
file(i)<< tab << f << tab << m;
}
if (localSystem_)
{
for (label j = 0; j < nBin_; j++)
{
const word jn('(' + Foam::name(j) + ')');
const word f("localForces" + jn + binForceTypes);
const word m("localMoments" + jn + binForceTypes);
file(i)<< tab << f << tab << m;
}
}
break;
}
default:
{
FatalErrorInFunction
<< "Unhandled file index: " << i
<< abort(FatalError);
}
}
else
{
FatalErrorInFunction
<< "Unhandled file index: " << i
<< abort(FatalError);
}
file(i)<< endl;
......@@ -406,8 +418,8 @@ void Foam::functionObjects::forces::writeForces()
<< " porous : " << sum(moment_[2])
<< endl;
writeTime(file(0));
file(0) << tab << setw(1) << '('
writeTime(file(MAIN_FILE));
file(MAIN_FILE) << tab << setw(1) << '('
<< sum(force_[0]) << setw(1) << ' '
<< sum(force_[1]) << setw(1) << ' '
<< sum(force_[2]) << setw(3) << ") ("
......@@ -425,8 +437,8 @@ void Foam::functionObjects::forces::writeForces()
vectorField localMomentT(coordSys_.localVector(moment_[1]));
vectorField localMomentP(coordSys_.localVector(moment_[2]));
writeTime(file(0));
file(0) << tab << setw(1) << '('
writeTime(file(MAIN_FILE));
file(MAIN_FILE) << tab << setw(1) << '('
<< sum(localForceN) << setw(1) << ' '
<< sum(localForceT) << setw(1) << ' '
<< sum(localForceP) << setw(3) << ") ("
......@@ -462,11 +474,11 @@ void Foam::functionObjects::forces::writeBins()
}
}
writeTime(file(1));
writeTime(file(BINS_FILE));
forAll(f[0], i)
{
file(1)
file(BINS_FILE)
<< tab << setw(1) << '('
<< f[0][i] << setw(1) << ' '
<< f[1][i] << setw(1) << ' '
......@@ -502,7 +514,7 @@ void Foam::functionObjects::forces::writeBins()
forAll(lf[0], i)
{
file(1)
file(BINS_FILE)
<< tab << setw(1) << '('
<< lf[0][i] << setw(1) << ' '
<< lf[1][i] << setw(1) << ' '
......@@ -513,7 +525,7 @@ void Foam::functionObjects::forces::writeBins()
}
}
file(1) << endl;
file(BINS_FILE) << endl;
}
......
......@@ -141,6 +141,13 @@ protected:
// Protected data
//- Enumeration for ensuring the right file is accessed
enum fileID
{
MAIN_FILE = 0,
BINS_FILE = 1
};
//- Pressure, viscous and porous force per bin
List<Field<vector>> force_;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment