faceSource: Writing the total area of the faceSource (sum(magSf)) for each time is now optional

Previous behavior which may be useful for moving-mesh cases can be
selected using the optional entry:
    writeTotalArea  yes;

The initial total area is written in the log and data file header e.g.:

 #   Source : faceZone f0
 #   Faces  : 8
 #   Area   : 1.063860e-02
This commit is contained in:
Henry
2015-04-26 16:32:19 +01:00
parent 2e9a3903cd
commit db4ac98fd8
8 changed files with 56 additions and 28 deletions

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) 2012-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -38,7 +38,7 @@ Foam::label Foam::functionObjectFile::addChars = 7;
void Foam::functionObjectFile::initStream(Ostream& os) const void Foam::functionObjectFile::initStream(Ostream& os) const
{ {
os.setf(ios_base::scientific, ios_base::floatfield); os.setf(ios_base::scientific, ios_base::floatfield);
// os.precision(IOstream::defaultPrecision()); // os.precision(IOstream::defaultPrecision());
os.width(charWidth()); os.width(charWidth());
} }

View File

@ -107,13 +107,13 @@ Foam::fv::optionList::optionList(const fvMesh& mesh)
void Foam::fv::optionList::reset(const dictionary& dict) void Foam::fv::optionList::reset(const dictionary& dict)
{ {
// Count number of active fvOptions
label count = 0; label count = 0;
forAllConstIter(dictionary, dict, iter) forAllConstIter(dictionary, dict, iter)
{ {
// safety:
if (iter().isDict()) if (iter().isDict())
{ {
count ++; count++;
} }
} }

View File

@ -378,6 +378,23 @@ void Foam::fieldValues::faceSource::combineSurfaceGeometry
} }
Foam::scalar Foam::fieldValues::faceSource::totalArea() const
{
scalar totalArea;
if (surfacePtr_.valid())
{
totalArea = gSum(surfacePtr_().magSf());
}
else
{
totalArea = gSum(filterField(mesh().magSf(), false));
}
return totalArea;
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fieldValues::faceSource::initialise(const dictionary& dict) void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
@ -423,22 +440,15 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
return; return;
} }
scalar totalArea;
if (surfacePtr_.valid()) if (surfacePtr_.valid())
{ {
surfacePtr_().update(); surfacePtr_().update();
totalArea = gSum(surfacePtr_().magSf());
}
else
{
totalArea = gSum(filterField(mesh().magSf(), false));
} }
Info<< type() << " " << name_ << ":" << nl Info<< type() << " " << name_ << ":" << nl
<< " total faces = " << nFaces_ << " total faces = " << nFaces_
<< nl << nl
<< " total area = " << totalArea << " total area = " << totalArea()
<< nl; << nl;
if (dict.readIfPresent("weightField", weightFieldName_)) if (dict.readIfPresent("weightField", weightFieldName_))
@ -517,10 +527,18 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
void Foam::fieldValues::faceSource::writeFileHeader(const label i) void Foam::fieldValues::faceSource::writeFileHeader(const label i)
{ {
file() writeCommented(file(), "Source : ");
<< "# Source : " << sourceTypeNames_[source_] << " " file() << sourceTypeNames_[source_] << " " << sourceName_ << endl;
<< sourceName_ << nl << "# Faces : " << nFaces_ << nl writeCommented(file(), "Faces : ");
<< "# Time" << tab << "sum(magSf)"; file() << nFaces_ << endl;
writeCommented(file(), "Area : ");
file() << totalArea() << endl;
writeCommented(file(), "Time");
if (writeTotalArea_)
{
file() << tab << "Area";
}
forAll(fields_, i) forAll(fields_, i)
{ {
@ -621,6 +639,7 @@ Foam::fieldValues::faceSource::faceSource
: :
fieldValue(name, obr, dict, typeName, loadFromFiles), fieldValue(name, obr, dict, typeName, loadFromFiles),
surfaceWriterPtr_(NULL), surfaceWriterPtr_(NULL),
writeTotalArea_(dict.lookupOrDefault("writeTotalArea", false)),
source_(sourceTypeNames_.read(dict.lookup("source"))), source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))), operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("none"), weightFieldName_("none"),
@ -661,21 +680,22 @@ void Foam::fieldValues::faceSource::write()
if (active_) if (active_)
{ {
scalar totalArea;
if (surfacePtr_.valid()) if (surfacePtr_.valid())
{ {
surfacePtr_().update(); surfacePtr_().update();
totalArea = gSum(surfacePtr_().magSf());
}
else
{
totalArea = gSum(filterField(mesh().magSf(), false));
} }
if (Pstream::master()) if (Pstream::master())
{ {
file() << obr_.time().value() << tab << totalArea; file() << obr_.time().value();
}
if (writeTotalArea_)
{
if (Pstream::master())
{
file() << tab << totalArea();
}
} }
// construct weight field. Note: zero size means weight = 1 // construct weight field. Note: zero size means weight = 1

View File

@ -228,6 +228,9 @@ private:
pointField& points pointField& points
) const; ) const;
//- Calculate and return total area of the faceSource: sum(magSf)
scalar totalArea() const;
protected: protected:
@ -236,6 +239,9 @@ protected:
//- Surface writer //- Surface writer
autoPtr<surfaceWriter> surfaceWriterPtr_; autoPtr<surfaceWriter> surfaceWriterPtr_;
//- Optionally write the totalArea
bool writeTotalArea_;
//- Source type //- Source type
sourceType source_; sourceType source_;

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
awk '{print $1 " " $4}' postProcessing/poolHeight/0/faceSource.dat > poolHeight_vs_time awk '{print $1 " " $3}' postProcessing/poolHeight/0/faceSource.dat > poolHeight_vs_time

View File

@ -75,6 +75,7 @@ functions
outputControl timeStep; outputControl timeStep;
outputInterval 1; outputInterval 1;
log yes; log yes;
writeTotalArea no;
valueOutput no; valueOutput no;
source faceZone; source faceZone;
sourceName f0; sourceName f0;

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
awk '{print $1 " " $4}' postProcessing/poolHeight/0/faceSource.dat > poolHeight_vs_time awk '{print $1 " " $3}' postProcessing/poolHeight/0/faceSource.dat > poolHeight_vs_time

View File

@ -75,6 +75,7 @@ functions
outputControl timeStep; outputControl timeStep;
outputInterval 1; outputInterval 1;
log yes; log yes;
writeTotalArea no;
valueOutput no; valueOutput no;
source faceZone; source faceZone;
sourceName f0; sourceName f0;