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
This commit is contained in:
Henry Weller
2016-08-24 19:34:00 +01:00
parent fc44390db3
commit e476f80e7a
6 changed files with 169 additions and 143 deletions

View File

@ -72,12 +72,12 @@ void Foam::functionObjects::fieldValues::fieldValueDelta::writeFileHeader
const wordList& fields2 = region2Ptr_->fields(); const wordList& fields2 = region2Ptr_->fields();
DynamicList<word> commonFields(fields1.size()); 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) if (index != -1)
{ {
commonFields.append(fields1[i]); commonFields.append(fields1[fieldi]);
} }
} }

View File

@ -554,11 +554,11 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::writeFileHeader
file() << tab << "Area"; file() << tab << "Area";
} }
forAll(fields_, i) forAll(fields_, fieldi)
{ {
file() file()
<< tab << operationTypeNames_[operation_] << tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")"; << "(" << fields_[fieldi] << ")";
} }
file() << endl; file() << endl;

View File

@ -96,11 +96,11 @@ void Foam::functionObjects::fieldValues::volFieldValue::writeFileHeader
writeCommented(file(), "Time"); writeCommented(file(), "Time");
forAll(fields_, i) forAll(fields_, fieldi)
{ {
file() file()
<< tab << operationTypeNames_[operation_] << tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")"; << "(" << fields_[fieldi] << ")";
} }
file() << endl; file() << endl;

View File

@ -42,7 +42,9 @@ namespace functionObjects
void Foam::functionObjects::forceCoeffs::writeFileHeader(const label i) void Foam::functionObjects::forceCoeffs::writeFileHeader(const label i)
{ {
if (i == 0) switch (fileID(i))
{
case MAIN_FILE:
{ {
// force coeff data // force coeff data
@ -60,8 +62,10 @@ void Foam::functionObjects::forceCoeffs::writeFileHeader(const label i)
writeTabbed(file(i), "Cl"); writeTabbed(file(i), "Cl");
writeTabbed(file(i), "Cl(f)"); writeTabbed(file(i), "Cl(f)");
writeTabbed(file(i), "Cl(r)"); writeTabbed(file(i), "Cl(r)");
break;
} }
else if (i == 1) case BINS_FILE:
{ {
// bin coeff data // bin coeff data
@ -103,13 +107,16 @@ void Foam::functionObjects::forceCoeffs::writeFileHeader(const label i)
writeTabbed(file(i), "Cd" + jn); writeTabbed(file(i), "Cd" + jn);
writeTabbed(file(i), "Cl" + jn); writeTabbed(file(i), "Cl" + jn);
} }
break;
} }
else default:
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Unhandled file index: " << i << "Unhandled file index: " << i
<< abort(FatalError); << abort(FatalError);
} }
}
file(i)<< endl; file(i)<< endl;
} }
@ -200,8 +207,8 @@ bool Foam::functionObjects::forceCoeffs::write()
scalar Clf = Cl/2.0 + Cm; scalar Clf = Cl/2.0 + Cm;
scalar Clr = Cl/2.0 - Cm; scalar Clr = Cl/2.0 - Cm;
writeTime(file(0)); writeTime(file(MAIN_FILE));
file(0) file(MAIN_FILE)
<< tab << Cm << tab << Cd << tab << Cm << tab << Cd
<< tab << Cl << tab << Clf << tab << Clr << endl; << 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) forAll(coeffs[0], i)
{ {
file(1) file(BINS_FILE)
<< tab << coeffs[2][i] << tab << coeffs[2][i]
<< tab << coeffs[1][i] << tab << coeffs[1][i]
<< tab << coeffs[0][i]; << tab << coeffs[0][i];
} }
file(1) << endl; file(BINS_FILE) << endl;
} }
Log << endl; Log << endl;

View File

@ -53,6 +53,8 @@ Foam::wordList Foam::functionObjects::forces::createFileNames
DynamicList<word> names(1); DynamicList<word> names(1);
const word forceType(dict.lookup("type")); const word forceType(dict.lookup("type"));
// Name for file(MAIN_FILE=0)
names.append(forceType); names.append(forceType);
if (dict.found("binData")) if (dict.found("binData"))
@ -61,6 +63,7 @@ Foam::wordList Foam::functionObjects::forces::createFileNames
label nb = readLabel(binDict.lookup("nBin")); label nb = readLabel(binDict.lookup("nBin"));
if (nb > 0) if (nb > 0)
{ {
// Name for file(BINS_FILE=1)
names.append(forceType + "_bins"); names.append(forceType + "_bins");
} }
} }
@ -71,7 +74,9 @@ Foam::wordList Foam::functionObjects::forces::createFileNames
void Foam::functionObjects::forces::writeFileHeader(const label i) void Foam::functionObjects::forces::writeFileHeader(const label i)
{ {
if (i == 0) switch (fileID(i))
{
case MAIN_FILE:
{ {
// force data // force data
@ -79,19 +84,22 @@ void Foam::functionObjects::forces::writeFileHeader(const label i)
writeHeaderValue(file(i), "CofR", coordSys_.origin()); writeHeaderValue(file(i), "CofR", coordSys_.origin());
writeCommented(file(i), "Time"); writeCommented(file(i), "Time");
const word forceTypes("(pressure viscous porous)");
file(i) file(i)
<< "forces(pressure viscous porous) " << "forces" << forceTypes << tab
<< "moment(pressure viscous porous)"; << "moments" << forceTypes;
if (localSystem_) if (localSystem_)
{ {
file(i) file(i)
<< tab << tab
<< "localForces(pressure,viscous,porous) " << "localForces" << forceTypes << tab
<< "localMoments(pressure,viscous,porous)"; << "localMoments" << forceTypes;
} }
break;
} }
else if (i == 1) case BINS_FILE:
{ {
// bin data // bin data
@ -126,11 +134,12 @@ void Foam::functionObjects::forces::writeFileHeader(const label i)
writeCommented(file(i), "Time"); writeCommented(file(i), "Time");
const word binForceTypes("[pressure,viscous,porous]");
for (label j = 0; j < nBin_; j++) for (label j = 0; j < nBin_; j++)
{ {
const word jn('(' + Foam::name(j) + ')'); const word jn('(' + Foam::name(j) + ')');
const word f("forces" + jn + "[pressure,viscous,porous]"); const word f("forces" + jn + binForceTypes);
const word m("moments" + jn + "[pressure,viscous,porous]"); const word m("moments" + jn + binForceTypes);
file(i)<< tab << f << tab << m; file(i)<< tab << f << tab << m;
} }
@ -139,19 +148,22 @@ void Foam::functionObjects::forces::writeFileHeader(const label i)
for (label j = 0; j < nBin_; j++) for (label j = 0; j < nBin_; j++)
{ {
const word jn('(' + Foam::name(j) + ')'); const word jn('(' + Foam::name(j) + ')');
const word f("localForces" + jn + "[pressure,viscous,porous]"); const word f("localForces" + jn + binForceTypes);
const word m("localMoments" + jn + "[pressure,viscous,porous]"); const word m("localMoments" + jn + binForceTypes);
file(i)<< tab << f << tab << m; file(i)<< tab << f << tab << m;
} }
} }
break;
} }
else default:
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Unhandled file index: " << i << "Unhandled file index: " << i
<< abort(FatalError); << abort(FatalError);
} }
}
file(i)<< endl; file(i)<< endl;
} }
@ -406,8 +418,8 @@ void Foam::functionObjects::forces::writeForces()
<< " porous : " << sum(moment_[2]) << " porous : " << sum(moment_[2])
<< endl; << endl;
writeTime(file(0)); writeTime(file(MAIN_FILE));
file(0) << tab << setw(1) << '(' file(MAIN_FILE) << tab << setw(1) << '('
<< sum(force_[0]) << setw(1) << ' ' << sum(force_[0]) << setw(1) << ' '
<< sum(force_[1]) << setw(1) << ' ' << sum(force_[1]) << setw(1) << ' '
<< sum(force_[2]) << setw(3) << ") (" << sum(force_[2]) << setw(3) << ") ("
@ -425,8 +437,8 @@ void Foam::functionObjects::forces::writeForces()
vectorField localMomentT(coordSys_.localVector(moment_[1])); vectorField localMomentT(coordSys_.localVector(moment_[1]));
vectorField localMomentP(coordSys_.localVector(moment_[2])); vectorField localMomentP(coordSys_.localVector(moment_[2]));
writeTime(file(0)); writeTime(file(MAIN_FILE));
file(0) << tab << setw(1) << '(' file(MAIN_FILE) << tab << setw(1) << '('
<< sum(localForceN) << setw(1) << ' ' << sum(localForceN) << setw(1) << ' '
<< sum(localForceT) << setw(1) << ' ' << sum(localForceT) << setw(1) << ' '
<< sum(localForceP) << setw(3) << ") (" << sum(localForceP) << setw(3) << ") ("
@ -462,11 +474,11 @@ void Foam::functionObjects::forces::writeBins()
} }
} }
writeTime(file(1)); writeTime(file(BINS_FILE));
forAll(f[0], i) forAll(f[0], i)
{ {
file(1) file(BINS_FILE)
<< tab << setw(1) << '(' << tab << setw(1) << '('
<< f[0][i] << setw(1) << ' ' << f[0][i] << setw(1) << ' '
<< f[1][i] << setw(1) << ' ' << f[1][i] << setw(1) << ' '
@ -502,7 +514,7 @@ void Foam::functionObjects::forces::writeBins()
forAll(lf[0], i) forAll(lf[0], i)
{ {
file(1) file(BINS_FILE)
<< tab << setw(1) << '(' << tab << setw(1) << '('
<< lf[0][i] << setw(1) << ' ' << lf[0][i] << setw(1) << ' '
<< lf[1][i] << setw(1) << ' ' << lf[1][i] << setw(1) << ' '
@ -513,7 +525,7 @@ void Foam::functionObjects::forces::writeBins()
} }
} }
file(1) << endl; file(BINS_FILE) << endl;
} }

View File

@ -141,6 +141,13 @@ protected:
// Protected data // 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 //- Pressure, viscous and porous force per bin
List<Field<vector>> force_; List<Field<vector>> force_;