ENH: functionObjects - updated writing to file

This commit is contained in:
andy
2013-11-25 10:52:20 +00:00
parent 18ae63051b
commit 636215a0ea
14 changed files with 267 additions and 145 deletions

View File

@ -31,9 +31,18 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::word Foam::functionObjectFile::outputPrefix = "postProcessing"; const Foam::word Foam::functionObjectFile::outputPrefix = "postProcessing";
Foam::label Foam::functionObjectFile::addChars = 7;
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjectFile::initStream(Ostream& os) const
{
os.setf(ios_base::scientific, ios_base::floatfield);
// os.precision(IOstream::defaultPrecision());
os.width(charWidth());
}
Foam::fileName Foam::functionObjectFile::baseFileDir() const Foam::fileName Foam::functionObjectFile::baseFileDir() const
{ {
fileName baseDir = obr_.time().path(); fileName baseDir = obr_.time().path();
@ -96,6 +105,8 @@ void Foam::functionObjectFile::createFiles()
filePtrs_.set(i, new OFstream(outputDir/(fName + ".dat"))); filePtrs_.set(i, new OFstream(outputDir/(fName + ".dat")));
initStream(filePtrs_[i]);
writeFileHeader(i); writeFileHeader(i);
i++; i++;
@ -149,7 +160,7 @@ void Foam::functionObjectFile::resetName(const word& name)
Foam::Omanip<int> Foam::functionObjectFile::valueWidth(const label offset) const Foam::Omanip<int> Foam::functionObjectFile::valueWidth(const label offset) const
{ {
return setw(IOstream::defaultPrecision() + 7 + offset); return setw(IOstream::defaultPrecision() + addChars + offset);
} }
@ -295,4 +306,42 @@ Foam::OFstream& Foam::functionObjectFile::file(const label i)
} }
Foam::label Foam::functionObjectFile::charWidth() const
{
return IOstream::defaultPrecision() + addChars;
}
void Foam::functionObjectFile::writeCommented
(
Ostream& os,
const string& str
) const
{
os << setw(1) << "#" << setw(1) << ' '
<< setw(charWidth() - 2) << str.c_str();
}
void Foam::functionObjectFile::writeTabbed
(
Ostream& os,
const string& str
) const
{
os << tab << setw(charWidth()) << str.c_str();
}
void Foam::functionObjectFile::writeHeader
(
Ostream& os,
const string& str
) const
{
os << setw(1) << "#" << setw(1) << ' '
<< setf(ios_base::left) << setw(charWidth() - 2) << str.c_str() << nl;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -78,6 +78,9 @@ protected:
// Protected Member Functions // Protected Member Functions
//- Initialise the output stream for writing
virtual void initStream(Ostream& os) const;
//- Return the base directory for output //- Return the base directory for output
virtual fileName baseFileDir() const; virtual fileName baseFileDir() const;
@ -114,6 +117,9 @@ public:
//- Folder prefix //- Folder prefix
static const word outputPrefix; static const word outputPrefix;
//- Additional characters for writing
static label addChars;
// Constructors // Constructors
//- Construct null //- Construct null
@ -154,13 +160,38 @@ public:
//- Return file 'i' //- Return file 'i'
OFstream& file(const label i); OFstream& file(const label i);
//- Write a formatted value to stream //- Write a commented string to stream
template<class Type> void writeCommented
const char* writeValue
( (
const Type& value, Ostream& os,
const label offset = 0 const string& str
) const; ) const;
//- Write a tabbed string to stream
void writeTabbed
(
Ostream& os,
const string& str
) const;
//- Write a commented header to stream
void writeHeader
(
Ostream& os,
const string& str
) const;
//- Write a (commented) header property and value pair
template<class Type>
void writeHeaderValue
(
Ostream& os,
const string& property,
const Type& value
) const;
//- Return width of character stream output
label charWidth() const;
}; };

View File

@ -39,7 +39,10 @@ defineTypeNameAndDebug(cloudInfo, 0);
void Foam::cloudInfo::writeFileHeader(const label i) void Foam::cloudInfo::writeFileHeader(const label i)
{ {
file(i) << "# Time" << tab << "nParcels" << tab << "mass" << endl; writeHeader(file(), "Cloud information");
writeCommented(file(), "Time");
writeTabbed(file(), "nParcels");
writeTabbed(file(), "mass");
} }

View File

@ -112,20 +112,23 @@ void Foam::fieldMinMax::read(const dictionary& dict)
void Foam::fieldMinMax::writeFileHeader(const label i) void Foam::fieldMinMax::writeFileHeader(const label i)
{ {
file() writeHeader(file(), "Field minima and maxima");
<< "# Time" << token::TAB << "field" << token::TAB writeCommented(file(), "Time");
<< "min" << token::TAB << "position(min)"; writeTabbed(file(), "field");
writeTabbed(file(), "min");
writeTabbed(file(), "position(min)");
if (Pstream::parRun()) if (Pstream::parRun())
{ {
file() << token::TAB << "proc"; writeTabbed(file(), "processor");
} }
file() << token::TAB << "max" << token::TAB << "position(max)"; writeTabbed(file(), "max");
writeTabbed(file(), "position(max)");
if (Pstream::parRun()) if (Pstream::parRun())
{ {
file() << token::TAB << "proc"; writeTabbed(file(), "processor");
} }
file() << endl; file() << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -111,21 +111,25 @@ void Foam::fieldMinMax::calcMinMaxFields
scalar maxValue = maxVs[maxI]; scalar maxValue = maxVs[maxI];
const vector& maxC = maxCs[maxI]; const vector& maxC = maxCs[maxI];
file()<< obr_.time().value();
writeTabbed(file(), fieldName);
file() file()
<< obr_.time().value() << token::TAB << token::TAB << minValue
<< fieldName << token::TAB << token::TAB << minC;
<< minValue << token::TAB << minC;
if (Pstream::parRun()) if (Pstream::parRun())
{ {
file() << token::TAB << minI; file()<< token::TAB << minI;
} }
file() << token::TAB << maxValue << token::TAB << maxC; file()
<< token::TAB << maxValue
<< token::TAB << maxC;
if (Pstream::parRun()) if (Pstream::parRun())
{ {
file() << token::TAB << maxI; file()<< token::TAB << maxI;
} }
file() << endl; file() << endl;
@ -212,21 +216,25 @@ void Foam::fieldMinMax::calcMinMaxFields
Type maxValue = maxVs[maxI]; Type maxValue = maxVs[maxI];
const vector& maxC = maxCs[maxI]; const vector& maxC = maxCs[maxI];
file()<< obr_.time().value();
writeTabbed(file(), fieldName);
file() file()
<< obr_.time().value() << token::TAB << token::TAB << minValue
<< fieldName << token::TAB << token::TAB << minC;
<< minValue << token::TAB << minC;
if (Pstream::parRun()) if (Pstream::parRun())
{ {
file() << token::TAB << minI; file()<< token::TAB << minI;
} }
file() << token::TAB << maxValue << token::TAB << maxC; file()
<< token::TAB << maxValue
<< token::TAB << maxC;
if (Pstream::parRun()) if (Pstream::parRun())
{ {
file() << token::TAB << maxI; file()<< token::TAB << maxI;
} }
file() << endl; file() << endl;

View File

@ -94,11 +94,10 @@ void Foam::fieldValues::fieldValueDelta::writeFileHeader(const label i)
Ostream& os = file(); Ostream& os = file();
os << "# Source1 : " << source1Ptr_->name() << nl writeHeaderValue(os, "Source1", source1Ptr_->name());
<< "# Source2 : " << source2Ptr_->name() << nl writeHeaderValue(os, "Source2", source2Ptr_->name());
<< "# Operation : " << operationTypeNames_[operation_] << nl; writeHeaderValue(os, "Operation", operationTypeNames_[operation_]);
writeCommented(os, "Time");
os << "# Time";
forAll(commonFields, i) forAll(commonFields, i)
{ {
@ -156,7 +155,7 @@ void Foam::fieldValues::fieldValueDelta::write()
if (Pstream::master()) if (Pstream::master())
{ {
file()<< obr_.time().timeName(); file()<< obr_.time().value();
} }
if (log_) if (log_)

View File

@ -45,34 +45,41 @@ void Foam::forceCoeffs::writeFileHeader(const label i)
{ {
// force coeff data // 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)");
file(i) file(i)
<< "# liftDir : " << liftDir_ << nl << tab << "Cm" << tab << "Cd" << tab << "Cl" << tab << "Cl(f)"
<< "# dragDir : " << dragDir_ << nl << tab << "Cl(r)";
<< "# pitchAxis : " << pitchAxis_ << nl
<< "# magUInf : " << magUInf_ << nl
<< "# lRef : " << lRef_ << nl
<< "# Aref : " << Aref_ << nl
<< "# CofR : " << coordSys_.origin() << nl
<< "# Time" << tab << "Cm" << tab << "Cd" << tab << "Cl" << tab
<< "Cl(f)" << tab << "Cl(r)";
} }
else if (i == 1) else if (i == 1)
{ {
// bin coeff data // bin coeff data
file(i) writeHeader(file(i), "Force coefficient bins");
<< "# bins : " << nBin_ << nl writeHeaderValue(file(i), "bins", nBin_);
<< "# start : " << binMin_ << nl writeHeaderValue(file(i), "start", binMin_);
<< "# delta : " << binDx_ << nl writeHeaderValue(file(i), "delta", binDx_);
<< "# direction : " << binDir_ << nl writeHeaderValue(file(i), "direction", binDir_);
<< "# Time"; writeCommented(file(i), "Time");
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) + ']');
writeTabbed(file(i), "Cm" + jn);
file(i) writeTabbed(file(i), "Cd" + jn);
<< tab << "Cm" << jn << tab << "Cd" << jn << tab << "Cl" << jn; writeTabbed(file(i), "Cl" + jn);
} }
} }
else else
@ -193,9 +200,8 @@ void Foam::forceCoeffs::write()
scalar Clr = Cl/2.0 - Cm; scalar Clr = Cl/2.0 - Cm;
file(0) file(0)
<< obr_.time().value() << tab << obr_.time().value() << tab << Cm << tab << Cd
<< Cm << tab << Cd << tab << Cl << tab << Clf << tab << Clr << tab << Cl << tab << Clf << tab << Clr << endl;
<< endl;
if (log_) if (log_)
{ {

View File

@ -73,11 +73,13 @@ void Foam::forces::writeFileHeader(const label i)
{ {
// force data // force data
writeHeader(file(i), "Forces");
writeHeaderValue(file(i), "CofR", coordSys_.origin());
writeCommented(file(i), "Time");
file(i) file(i)
<< "# CofR : " << coordSys_.origin() << nl << "forces[pressure,viscous,porous] "
<< "# Time" << tab << "moment[pressure,viscous,porous]";
<< "forces(pressure,viscous,porous) "
<< "moment(pressure,viscous,porous)";
if (localSystem_) if (localSystem_)
{ {
@ -91,32 +93,30 @@ void Foam::forces::writeFileHeader(const label i)
{ {
// bin data // bin data
file(i) writeHeader(file(i), "Force bins");
<< "# bins : " << nBin_ << nl writeHeaderValue(file(i), "bins", nBin_);
<< "# start : " << binMin_ << nl writeHeaderValue(file(i), "start", binMin_);
<< "# delta : " << binDx_ << nl writeHeaderValue(file(i), "delta", binDx_);
<< "# direction : " << binDir_ << nl writeHeaderValue(file(i), "direction", binDir_);
<< "# Time"; writeCommented(file(i), "Time");
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 m("moments" + jn + "[pressure,viscous,porous]");
file(i) file(i)<< tab << f << tab << m;
<< tab
<< "forces" << jn << "(pressure,viscous,porous) "
<< "moment" << jn << "(pressure,viscous,porous)";
} }
if (localSystem_) if (localSystem_)
{ {
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 m("localMoments" + jn + "[pressure,viscous,porous]");
file(i) file(i)<< tab << f << tab << m;
<< tab
<< "localForces" << jn << "(pressure,viscous,porous) "
<< "localMoments" << jn << "(pressure,viscous,porous)";
} }
} }
} }
@ -370,28 +370,24 @@ void Foam::forces::writeForces()
if (log_) if (log_)
{ {
Info<< type() << " " << name_ << " output:" << nl Info<< type() << " " << name_ << " output:" << nl
<< " forces(pressure,viscous,porous) = (" << " sum of forces:" << nl
<< sum(force_[0]) << "," << " pressure : " << sum(force_[0]) << nl
<< sum(force_[1]) << "," << " viscous : " << sum(force_[1]) << nl
<< sum(force_[2]) << ")" << nl << " porous : " << sum(force_[2]) << nl
<< " moment(pressure,viscous,porous) = (" << " sum of moments:" << nl
<< sum(moment_[0]) << "," << " pressure : " << sum(moment_[0]) << nl
<< sum(moment_[1]) << "," << " viscous : " << sum(moment_[1]) << nl
<< sum(moment_[2]) << ")" << " porous : " << sum(moment_[2])
<< nl; << endl;
} }
file(0) << obr_.time().value() << tab file(0) << obr_.time().value() << tab << setw(1) << '['
<< "(" << sum(force_[0]) << setw(1) << ','
<< sum(force_[0]) << "," << sum(force_[1]) << setw(1) << ","
<< sum(force_[1]) << "," << sum(force_[2]) << setw(3) << "] ["
<< sum(force_[2]) << sum(moment_[0]) << setw(1) << ","
<< ") " << sum(moment_[1]) << setw(1) << ","
<< "(" << sum(moment_[2]) << setw(1) << "]"
<< sum(moment_[0]) << ","
<< sum(moment_[1]) << ","
<< sum(moment_[2])
<< ")"
<< endl; << endl;
if (localSystem_) if (localSystem_)
@ -403,17 +399,13 @@ void Foam::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]));
file(0) << obr_.time().value() << tab file(0) << obr_.time().value() << tab << setw(1) << "["
<< "(" << sum(localForceN) << setw(1) << ","
<< sum(localForceN) << "," << sum(localForceT) << setw(1) << ","
<< sum(localForceT) << "," << sum(localForceP) << setw(3) << "] ["
<< sum(localForceP) << sum(localMomentN) << setw(1) << ","
<< ") " << sum(localMomentT) << setw(1) << ","
<< "(" << sum(localMomentP) << setw(1) << "]"
<< sum(localMomentN) << ","
<< sum(localMomentT) << ","
<< sum(localMomentP)
<< ")"
<< endl; << endl;
} }
} }
@ -448,9 +440,13 @@ void Foam::forces::writeBins()
forAll(f[0], i) forAll(f[0], i)
{ {
file(1) file(1)
<< tab << tab << setw(1) << "["
<< "(" << f[0][i] << "," << f[1][i] << "," << f[2][i] << ") " << f[0][i] << setw(1) << ","
<< "(" << m[0][i] << "," << m[1][i] << "," << m[2][i] << ")"; << f[1][i] << setw(1) << ","
<< f[2][i] << setw(3) << "] ["
<< m[0][i] << setw(1) << ","
<< m[1][i] << setw(1) << ","
<< m[2][i] << setw(1) << "]";
} }
if (localSystem_) if (localSystem_)
@ -480,9 +476,13 @@ void Foam::forces::writeBins()
forAll(lf[0], i) forAll(lf[0], i)
{ {
file(1) file(1)
<< tab << tab << setw(1) << "["
<< "(" << lf[0][i] << "," << lf[1][i] << "," << lf[2][i] << ") " << lf[0][i] << setw(1) << ","
<< "(" << lm[0][i] << "," << lm[1][i] << "," << lm[2][i] << ")"; << lf[1][i] << setw(1) << ","
<< lf[2][i] << setw(3) << "] ["
<< lm[0][i] << setw(1) << ","
<< lm[1][i] << setw(1) << ","
<< lm[2][i] << setw(1) << "]";
} }
} }

View File

@ -42,9 +42,11 @@ defineTypeNameAndDebug(DESModelRegions, 0);
void Foam::DESModelRegions::writeFileHeader(const label i) void Foam::DESModelRegions::writeFileHeader(const label i)
{ {
file() << "# DES model region coverage (% volume)" << nl writeHeader(file(), "DES model region coverage (% volume)");
<< "# time " << token::TAB << "LES" << token::TAB << "RAS"
<< endl; writeCommented(file(), "Time");
writeTabbed(file(), "LES");
writeTabbed(file(), "RAS");
} }
@ -206,8 +208,10 @@ void Foam::DESModelRegions::write()
if (Pstream::master() && log_) if (Pstream::master() && log_)
{ {
file() << obr_.time().timeName() << token::TAB file() << obr_.time().value()
<< prc << token::TAB << 100.0 - prc << endl; << token::TAB << prc
<< token::TAB << 100.0 - prc
<< endl;
} }
if (log_) if (log_)

View File

@ -43,9 +43,11 @@ defineTypeNameAndDebug(wallShearStress, 0);
void Foam::wallShearStress::writeFileHeader(const label i) void Foam::wallShearStress::writeFileHeader(const label i)
{ {
// Add headers to output data // Add headers to output data
file() << "# Wall shear stress" << nl writeHeader(file(), "Wall shear stress");
<< "# time " << token::TAB << "patch" << token::TAB writeCommented(file(), "Time");
<< "min" << token::TAB << "max" << endl; writeTabbed(file(), "patch");
writeTabbed(file(), "min");
writeTabbed(file(), "max");
} }
@ -73,9 +75,11 @@ void Foam::wallShearStress::calcShearStress
if (Pstream::master()) if (Pstream::master())
{ {
file() << mesh.time().timeName() << token::TAB file() << mesh.time().value()
<< pp.name() << token::TAB << minSsp << token::TAB << pp.name()
<< token::TAB << maxSsp << endl; << token::TAB << minSsp
<< token::TAB << maxSsp
<< endl;
} }
if (log_) if (log_)

View File

@ -44,10 +44,13 @@ defineTypeNameAndDebug(yPlusLES, 0);
void Foam::yPlusLES::writeFileHeader(const label i) void Foam::yPlusLES::writeFileHeader(const label i)
{ {
file() << "# y+ (LES)" << nl writeHeader(file(), "y+ (LES)");
<< "# time " << token::TAB << "patch" << token::TAB
<< "min" << token::TAB << "max" << token::TAB << "average" writeCommented(file(), "Time");
<< endl; writeTabbed(file(), "patch");
writeTabbed(file(), "min");
writeTabbed(file(), "max");
writeTabbed(file(), "average");
} }
@ -100,10 +103,12 @@ void Foam::yPlusLES::calcIncompressibleYPlus
if (Pstream::master()) if (Pstream::master())
{ {
file() << obr_.time().value() << token::TAB file() << obr_.time().value()
<< currPatch.name() << token::TAB << token::TAB << currPatch.name()
<< minYp << token::TAB << maxYp << token::TAB << token::TAB << minYp
<< avgYp << endl; << token::TAB << maxYp
<< token::TAB << avgYp
<< endl;
} }
} }
} }
@ -166,10 +171,12 @@ void Foam::yPlusLES::calcCompressibleYPlus
if (Pstream::master()) if (Pstream::master())
{ {
file() << obr_.time().value() << token::TAB file() << obr_.time().value()
<< currPatch.name() << token::TAB << token::TAB << currPatch.name()
<< minYp << token::TAB << maxYp << token::TAB << token::TAB << minYp
<< avgYp << endl; << token::TAB << maxYp
<< token::TAB << avgYp
<< endl;
} }
} }
} }

View File

@ -46,10 +46,13 @@ defineTypeNameAndDebug(yPlusRAS, 0);
void Foam::yPlusRAS::writeFileHeader(const label i) void Foam::yPlusRAS::writeFileHeader(const label i)
{ {
file() << "# y+ (RAS)" << nl writeHeader(file(), "y+ (RAS)");
<< "# time " << token::TAB << "patch" << token::TAB
<< "min" << token::TAB << "max" << token::TAB << "average" writeCommented(file(), "Time");
<< endl; writeTabbed(file(), "patch");
writeTabbed(file(), "min");
writeTabbed(file(), "max");
writeTabbed(file(), "average");
} }
@ -95,10 +98,12 @@ void Foam::yPlusRAS::calcIncompressibleYPlus
if (Pstream::master()) if (Pstream::master())
{ {
file() << obr_.time().value() << token::TAB file() << obr_.time().value()
<< nutPw.patch().name() << token::TAB << token::TAB << nutPw.patch().name()
<< minYp << token::TAB << maxYp << token::TAB << token::TAB << minYp
<< avgYp << endl; << token::TAB << maxYp
<< token::TAB << avgYp
<< endl;
} }
} }
} }
@ -153,10 +158,12 @@ void Foam::yPlusRAS::calcCompressibleYPlus
if (Pstream::master()) if (Pstream::master())
{ {
file() << obr_.time().value() << token::TAB file() << obr_.time().value()
<< mutPw.patch().name() << token::TAB << token::TAB << mutPw.patch().name()
<< minYp << token::TAB << maxYp << token::TAB << token::TAB << minYp
<< avgYp << endl; << token::TAB << maxYp
<< token::TAB << avgYp
<< endl;
} }
} }
} }

View File

@ -23,7 +23,7 @@ libs
application simpleFoam; application simpleFoam;
startFrom latestTime; startFrom startTime; // latestTime;
startTime 0; startTime 0;

View File

@ -8,7 +8,8 @@
forceCoeffs1 forceCoeffs1
{ {
type forceCoeffs; // type forceCoeffs;
type forces;
functionObjectLibs ( "libforces.so" ); functionObjectLibs ( "libforces.so" );