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 * * * * * * * * * * * * * //
const Foam::word Foam::functionObjectFile::outputPrefix = "postProcessing";
Foam::label Foam::functionObjectFile::addChars = 7;
// * * * * * * * * * * * * 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
{
fileName baseDir = obr_.time().path();
@ -96,6 +105,8 @@ void Foam::functionObjectFile::createFiles()
filePtrs_.set(i, new OFstream(outputDir/(fName + ".dat")));
initStream(filePtrs_[i]);
writeFileHeader(i);
i++;
@ -149,7 +160,7 @@ void Foam::functionObjectFile::resetName(const word& name)
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
//- Initialise the output stream for writing
virtual void initStream(Ostream& os) const;
//- Return the base directory for output
virtual fileName baseFileDir() const;
@ -114,6 +117,9 @@ public:
//- Folder prefix
static const word outputPrefix;
//- Additional characters for writing
static label addChars;
// Constructors
//- Construct null
@ -154,13 +160,38 @@ public:
//- Return file 'i'
OFstream& file(const label i);
//- Write a formatted value to stream
template<class Type>
const char* writeValue
//- Write a commented string to stream
void writeCommented
(
const Type& value,
const label offset = 0
Ostream& os,
const string& str
) 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)
{
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)
{
file()
<< "# Time" << token::TAB << "field" << token::TAB
<< "min" << token::TAB << "position(min)";
writeHeader(file(), "Field minima and maxima");
writeCommented(file(), "Time");
writeTabbed(file(), "field");
writeTabbed(file(), "min");
writeTabbed(file(), "position(min)");
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())
{
file() << token::TAB << "proc";
writeTabbed(file(), "processor");
}
file() << endl;

View File

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

View File

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

View File

@ -45,34 +45,41 @@ void Foam::forceCoeffs::writeFileHeader(const label 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)");
file(i)
<< "# liftDir : " << liftDir_ << nl
<< "# dragDir : " << dragDir_ << nl
<< "# 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)";
<< tab << "Cm" << tab << "Cd" << tab << "Cl" << tab << "Cl(f)"
<< tab << "Cl(r)";
}
else if (i == 1)
{
// bin coeff data
file(i)
<< "# bins : " << nBin_ << nl
<< "# start : " << binMin_ << nl
<< "# delta : " << binDx_ << nl
<< "# direction : " << binDir_ << nl
<< "# Time";
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");
for (label j = 0; j < nBin_; j++)
{
const word jn('[' + Foam::name(j) + ']');
file(i)
<< tab << "Cm" << jn << tab << "Cd" << jn << tab << "Cl" << jn;
writeTabbed(file(i), "Cm" + jn);
writeTabbed(file(i), "Cd" + jn);
writeTabbed(file(i), "Cl" + jn);
}
}
else
@ -193,9 +200,8 @@ void Foam::forceCoeffs::write()
scalar Clr = Cl/2.0 - Cm;
file(0)
<< obr_.time().value() << tab
<< Cm << tab << Cd << tab << Cl << tab << Clf << tab << Clr
<< endl;
<< obr_.time().value() << tab << Cm << tab << Cd
<< tab << Cl << tab << Clf << tab << Clr << endl;
if (log_)
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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