functionObjects::writeLocalObjects: Provides support for controlled writing of field

defined by functionObjects, e.g. wallHeatFlux, wallShearStress and yPlus.

Patch contributed by Bruno Santos
Resolves bug-report http://bugs.openfoam.org/view.php?id=2353
This commit is contained in:
Henry Weller
2016-12-09 21:54:13 +00:00
parent 3140cfa906
commit 249c09933e
13 changed files with 731 additions and 123 deletions

View File

@ -104,6 +104,7 @@ Foam::functionObjects::wallHeatFlux::wallHeatFlux
:
fvMeshFunctionObject(name, runTime, dict),
logFiles(obr_, name),
writeLocalObjects(obr_, log),
patchSet_()
{
volScalarField* wallHeatFluxPtr
@ -127,6 +128,7 @@ Foam::functionObjects::wallHeatFlux::wallHeatFlux
read(dict);
resetName(typeName);
resetLocalObjectName(typeName);
}
@ -141,6 +143,7 @@ Foam::functionObjects::wallHeatFlux::~wallHeatFlux()
bool Foam::functionObjects::wallHeatFlux::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
writeLocalObjects::read(dict);
const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
@ -229,16 +232,15 @@ bool Foam::functionObjects::wallHeatFlux::execute()
bool Foam::functionObjects::wallHeatFlux::write()
{
Log << type() << " " << name() << " write:" << nl;
writeLocalObjects::write();
logFiles::write();
const volScalarField& wallHeatFlux =
obr_.lookupObject<volScalarField>(type());
Log << type() << " " << name() << " write:" << nl
<< " writing field " << wallHeatFlux.name() << endl;
wallHeatFlux.write();
const fvPatchList& patches = mesh_.boundary();
const surfaceScalarField::Boundary& magSf =
@ -249,8 +251,7 @@ bool Foam::functionObjects::wallHeatFlux::write()
label patchi = iter.key();
const fvPatch& pp = patches[patchi];
const scalarField& hfp =
wallHeatFlux.boundaryField()[patchi];
const scalarField& hfp = wallHeatFlux.boundaryField()[patchi];
const scalar minHfp = gMin(hfp);
const scalar maxHfp = gMax(hfp);
@ -267,10 +268,12 @@ bool Foam::functionObjects::wallHeatFlux::write()
<< endl;
}
Log << " min/max(" << pp.name() << ") = "
Log << " min/max/integ(" << pp.name() << ") = "
<< minHfp << ", " << maxHfp << ", " << integralHfp << endl;
}
Log << endl;
return true;
}

View File

@ -52,10 +52,15 @@ Usage
patches | list of patches to process | no | all wall patches
\endtable
Note
Writing field 'wallHeatFlux' is done by default, but it can be overridden by
defining an empty \c objects list. For details see writeLocalObjects.
See also
Foam::functionObject
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::logFiles
Foam::functionObjects::writeLocalObjects
Foam::functionObjects::pressureTools
Foam::functionObjects::timeControl
@ -69,6 +74,7 @@ SourceFiles
#include "fvMeshFunctionObject.H"
#include "logFiles.H"
#include "writeLocalObjects.H"
#include "volFieldsFwd.H"
#include "surfaceFieldsFwd.H"
#include "HashSet.H"
@ -88,7 +94,8 @@ namespace functionObjects
class wallHeatFlux
:
public fvMeshFunctionObject,
public logFiles
public logFiles,
public writeLocalObjects
{
protected:

View File

@ -90,6 +90,7 @@ Foam::functionObjects::wallShearStress::wallShearStress
:
fvMeshFunctionObject(name, runTime, dict),
logFiles(obr_, name),
writeLocalObjects(obr_, log),
patchSet_()
{
volVectorField* wallShearStressPtr
@ -118,6 +119,7 @@ Foam::functionObjects::wallShearStress::wallShearStress
read(dict);
resetName(typeName);
resetLocalObjectName(typeName);
}
@ -132,6 +134,7 @@ Foam::functionObjects::wallShearStress::~wallShearStress()
bool Foam::functionObjects::wallShearStress::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
writeLocalObjects::read(dict);
const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
@ -225,16 +228,15 @@ bool Foam::functionObjects::wallShearStress::execute()
bool Foam::functionObjects::wallShearStress::write()
{
Log << type() << " " << name() << " write:" << nl;
writeLocalObjects::write();
logFiles::write();
const volVectorField& wallShearStress =
obr_.lookupObject<volVectorField>(type());
Log << type() << " " << name() << " write:" << nl
<< " writing field " << wallShearStress.name() << endl;
wallShearStress.write();
const fvPatchList& patches = mesh_.boundary();
forAllConstIter(labelHashSet, patchSet_, iter)
@ -260,6 +262,8 @@ bool Foam::functionObjects::wallShearStress::write()
<< minSsp << ", " << maxSsp << endl;
}
Log << endl;
return true;
}

View File

@ -63,10 +63,15 @@ Usage
patches | list of patches to process | no | all wall patches
\endtable
Note
Writing field 'wallShearStress' is done by default, but it can be overridden
by defining an empty \c objects list. For details see writeLocalObjects.
See also
Foam::functionObject
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::logFiles
Foam::functionObjects::writeLocalObjects
Foam::functionObjects::pressureTools
Foam::functionObjects::timeControl
@ -80,6 +85,7 @@ SourceFiles
#include "fvMeshFunctionObject.H"
#include "logFiles.H"
#include "writeLocalObjects.H"
#include "volFieldsFwd.H"
#include "HashSet.H"
@ -97,7 +103,8 @@ namespace functionObjects
class wallShearStress
:
public fvMeshFunctionObject,
public logFiles
public logFiles,
public writeLocalObjects
{
protected:

View File

@ -121,7 +121,8 @@ Foam::functionObjects::yPlus::yPlus
)
:
fvMeshFunctionObject(name, runTime, dict),
logFiles(obr_, name)
logFiles(obr_, name),
writeLocalObjects(obr_, log)
{
volScalarField* yPlusPtr
(
@ -144,6 +145,7 @@ Foam::functionObjects::yPlus::yPlus
read(dict);
resetName(typeName);
resetLocalObjectName(typeName);
}
@ -158,6 +160,7 @@ Foam::functionObjects::yPlus::~yPlus()
bool Foam::functionObjects::yPlus::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
writeLocalObjects::read(dict);
return true;
}
@ -193,16 +196,15 @@ bool Foam::functionObjects::yPlus::execute()
bool Foam::functionObjects::yPlus::write()
{
const volScalarField& yPlus =
obr_.lookupObject<volScalarField>(type());
Log << type() << " " << name() << " write:" << nl;
Log << type() << " " << name() << " write:" << nl
<< " writing field " << yPlus.name() << endl;
yPlus.write();
writeLocalObjects::write();
logFiles::write();
const volScalarField& yPlus =
mesh_.lookupObject<volScalarField>(type());
const volScalarField::Boundary& yPlusBf = yPlus.boundaryField();
const fvPatchList& patches = mesh_.boundary();
@ -235,6 +237,8 @@ bool Foam::functionObjects::yPlus::write()
}
}
Log << endl;
return true;
}

View File

@ -28,13 +28,34 @@ Group
grpFieldFunctionObjects
Description
Evaluates and outputs turbulence y+ for models. Values written to
time directories as field 'yPlus'
Evaluates and outputs turbulence y+ for models. Values written to
time directories as field 'yPlus'.
Example of function object specification:
\verbatim
yPlus1
{
type yPlus;
libs ("libfieldFunctionObjects.so");
...
}
\endverbatim
Usage
\table
Property | Description | Required | Default value
type | type name: yPlus | yes |
\endtable
Note
Writing field 'yPlus' is done by default, but it can be overridden by
defining an empty \c objects list. For details see writeLocalObjects.
See also
Foam::functionObject
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::logFiles
Foam::functionObjects::writeLocalObjects
Foam::functionObjects::timeControl
SourceFiles
@ -47,6 +68,7 @@ SourceFiles
#include "fvMeshFunctionObject.H"
#include "logFiles.H"
#include "writeLocalObjects.H"
#include "volFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -67,7 +89,8 @@ namespace functionObjects
class yPlus
:
public fvMeshFunctionObject,
public logFiles
public logFiles,
public writeLocalObjects
{
// Private Member Functions

View File

@ -64,6 +64,62 @@ const Foam::NamedEnum
> Foam::functionObjects::writeObjects::writeOptionNames_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::writeObjects::writeObject
(
const regIOobject& obj
)
{
switch (writeOption_)
{
case AUTO_WRITE:
{
if(obj.writeOpt() != IOobject::AUTO_WRITE)
{
return;
}
break;
}
case NO_WRITE:
{
if(obj.writeOpt() != IOobject::NO_WRITE)
{
return;
}
break;
}
case ANY_WRITE:
{
break;
}
default:
{
FatalErrorInFunction
<< "Unknown writeOption "
<< writeOptionNames_[writeOption_]
<< ". Valid writeOption types are" << writeOptionNames_
<< exit(FatalError);
}
}
if
(
obj.writeOpt() == IOobject::AUTO_WRITE
&& writeObr_.time().writeTime()
)
{
Log << " automatically written object " << obj.name() << endl;
}
else
{
writeObjectsBase::writeObject(obj);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::writeObjects::writeObjects
@ -74,15 +130,15 @@ Foam::functionObjects::writeObjects::writeObjects
)
:
functionObject(name),
obr_
writeObjectsBase
(
runTime.lookupObject<objectRegistry>
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
log
),
writeOption_(ANY_WRITE),
objectNames_()
writeOption_(ANY_WRITE)
{
read(dict);
}
@ -100,16 +156,16 @@ bool Foam::functionObjects::writeObjects::read(const dictionary& dict)
{
if (dict.found("field"))
{
objectNames_.setSize(1);
dict.lookup("field") >> objectNames_[0];
writeObjectNames_.setSize(1);
dict.lookup("field") >> writeObjectNames_[0];
}
else if (dict.found("fields"))
{
dict.lookup("fields") >> objectNames_;
dict.lookup("fields") >> writeObjectNames_;
}
else
{
dict.lookup("objects") >> objectNames_;
writeObjectsBase::read(dict);
}
if (dict.found("writeOption"))
@ -121,7 +177,7 @@ bool Foam::functionObjects::writeObjects::read(const dictionary& dict)
writeOption_ = ANY_WRITE;
}
return true;
return functionObject::read(dict);
}
@ -135,85 +191,9 @@ bool Foam::functionObjects::writeObjects::write()
{
Info<< type() << " " << name() << " write:" << nl;
if (!obr_.time().writeTime())
{
obr_.time().writeTimeDict();
}
writeObjectsBase::write();
DynamicList<word> allNames(obr_.toc().size());
forAll(objectNames_, i)
{
wordList names(obr_.names<regIOobject>(objectNames_[i]));
if (names.size())
{
allNames.append(names);
}
else
{
WarningInFunction
<< "Object " << objectNames_[i] << " not found in "
<< "database. Available objects:" << nl << obr_.sortedToc()
<< endl;
}
}
forAll(allNames, i)
{
regIOobject& obj = const_cast<regIOobject&>
(
obr_.lookupObject<regIOobject>(allNames[i])
);
switch (writeOption_)
{
case AUTO_WRITE:
{
if(obj.writeOpt() != IOobject::AUTO_WRITE)
{
continue;
}
break;
}
case NO_WRITE:
{
if(obj.writeOpt() != IOobject::NO_WRITE)
{
continue;
}
break;
}
case ANY_WRITE:
{
break;
}
default:
{
FatalErrorInFunction
<< "Unknown writeOption "
<< writeOptionNames_[writeOption_]
<< ". Valid writeOption types are" << writeOptionNames_
<< exit(FatalError);
}
}
if
(
obj.writeOpt() == IOobject::AUTO_WRITE
&& obr_.time().writeTime()
)
{
Info<< " automatically written object " << obj.name() << endl;
}
else
{
Info<< " writing object " << obj.name() << endl;
obj.write();
}
}
Log << endl;
return true;
}

View File

@ -72,6 +72,7 @@ Usage
See also
Foam::functionObject
Foam::functionObjects::writeObjectsBase
Foam::functionObjects::timeControl
SourceFiles
@ -83,7 +84,7 @@ SourceFiles
#define functionObjects_writeObjects_H
#include "functionObject.H"
#include "wordReList.H"
#include "writeObjectsBase.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -91,9 +92,6 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
class objectRegistry;
namespace functionObjects
{
@ -103,7 +101,8 @@ namespace functionObjects
class writeObjects
:
public functionObject
public functionObject,
public writeObjectsBase
{
public:
@ -124,18 +123,15 @@ private:
// Private data
//- Reference to Db
const objectRegistry& obr_;
//- To only write objects of defined writeOption
writeOption writeOption_;
//- Names of objects to control
wordReList objectNames_;
// Private Member Functions
//- Write the requested registered IO object
virtual void writeObject(const regIOobject& obj);
//- Disallow default bitwise copy construct
writeObjects(const writeObjects&);