functionObjects: Simplified and reorganised using the fieldExpression base-class

This commit is contained in:
Henry Weller
2016-05-21 20:10:47 +01:00
parent 3009367a88
commit 546159a86c
14 changed files with 50 additions and 101 deletions

View File

@ -111,8 +111,8 @@ Foam::functionObjects::CourantNo::~CourantNo()
bool Foam::functionObjects::CourantNo::read(const dictionary& dict) bool Foam::functionObjects::CourantNo::read(const dictionary& dict)
{ {
phiName_ = dict.lookupOrDefault<word>("phiName", "phi"); phiName_ = dict.lookupOrDefault<word>("phi", "phi");
rhoName_ = dict.lookupOrDefault<word>("rhoName", "rho"); rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
return true; return true;
} }

View File

@ -91,7 +91,7 @@ Foam::functionObjects::Lambda2::~Lambda2()
bool Foam::functionObjects::Lambda2::read(const dictionary& dict) bool Foam::functionObjects::Lambda2::read(const dictionary& dict)
{ {
UName_ = dict.lookupOrDefault<word>("UName", "U"); UName_ = dict.lookupOrDefault<word>("U", "U");
return true; return true;
} }

View File

@ -36,5 +36,9 @@ fieldExpression/fieldExpression.C
div/div.C div/div.C
grad/grad.C grad/grad.C
mag/mag.C mag/mag.C
vorticity/vorticity.C
Q/Q.C
Lambda2/Lambda2.C
CourantNo/CourantNo.C
LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects

View File

@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "Q.H" #include "Q.H"
#include "volFields.H"
#include "fvcGrad.H" #include "fvcGrad.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
@ -55,29 +54,8 @@ Foam::functionObjects::Q::Q
const dictionary& dict const dictionary& dict
) )
: :
fvMeshFunctionObject(name, runTime, dict) fieldExpression(name, runTime, dict, "U", "Q")
{ {}
read(dict);
volScalarField* QPtr
(
new volScalarField
(
IOobject
(
type(),
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", dimless/sqr(dimTime), 0.0)
)
);
mesh_.objectRegistry::store(QPtr);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
@ -88,45 +66,24 @@ Foam::functionObjects::Q::~Q()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::Q::read(const dictionary& dict)
{
UName_ = dict.lookupOrDefault<word>("UName", "U");
return true;
}
bool Foam::functionObjects::Q::execute(const bool postProcess) bool Foam::functionObjects::Q::execute(const bool postProcess)
{ {
const volVectorField& U = if (foundField<volVectorField>(fieldName_))
mesh_.lookupObject<volVectorField>(UName_); {
const volVectorField& U = lookupField<volVectorField>(fieldName_);
const tmp<volTensorField> tgradU(fvc::grad(U));
const volTensorField& gradU = tgradU();
const volTensorField gradU(fvc::grad(U)); return store
volScalarField& Q =
const_cast<volScalarField&>
( (
mesh_.lookupObject<volScalarField>(type()) resultName_,
0.5*(sqr(tr(gradU)) - tr(((gradU) & (gradU))))
); );
}
Q = 0.5*(sqr(tr(gradU)) - tr(((gradU) & (gradU)))); else
{
return true; return false;
} }
bool Foam::functionObjects::Q::write(const bool postProcess)
{
const volScalarField& Q =
mesh_.lookupObject<volScalarField>(type());
Info<< type() << " " << name() << " output:" << nl
<< " writing field " << Q.name() << nl
<< endl;
Q.write();
return true;
} }

View File

@ -36,6 +36,7 @@ Description
\f] \f]
SeeAlso SeeAlso
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject Foam::functionObjects::fvMeshFunctionObject
SourceFiles SourceFiles
@ -46,8 +47,7 @@ SourceFiles
#ifndef functionObjects_Q_H #ifndef functionObjects_Q_H
#define functionObjects_Q_H #define functionObjects_Q_H
#include "fvMeshFunctionObject.H" #include "fieldExpression.H"
#include "volFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -62,22 +62,8 @@ namespace functionObjects
class Q class Q
: :
public fvMeshFunctionObject public fieldExpression
{ {
// Private data
//- Name of velocity field, default is "U"
word UName_;
// Private Member Functions
//- Disallow default bitwise copy construct
Q(const Q&);
//- Disallow default bitwise assignment
void operator=(const Q&);
public: public:
@ -102,14 +88,8 @@ public:
// Member Functions // Member Functions
//- Read the Q data
virtual bool read(const dictionary&);
//- Calculate the Q-field //- Calculate the Q-field
virtual bool execute(const bool postProcess = false); virtual bool execute(const bool postProcess = false);
//- Write the Q-field
virtual bool write(const bool postProcess = false);
}; };

View File

@ -33,6 +33,7 @@ Description
volScalarField. volScalarField.
SeeAlso SeeAlso
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject Foam::functionObjects::fvMeshFunctionObject
SourceFiles SourceFiles

View File

@ -42,10 +42,14 @@ Foam::functionObjects::fieldExpression::fieldExpression
( (
const word& name, const word& name,
const Time& runTime, const Time& runTime,
const dictionary& dict const dictionary& dict,
const word& fieldName,
const word& resultName
) )
: :
fvMeshFunctionObject(name, runTime, dict) fvMeshFunctionObject(name, runTime, dict),
fieldName_(fieldName),
resultName_(resultName)
{ {
read(dict); read(dict);
} }
@ -61,7 +65,10 @@ Foam::functionObjects::fieldExpression::~fieldExpression()
bool Foam::functionObjects::fieldExpression::read(const dictionary& dict) bool Foam::functionObjects::fieldExpression::read(const dictionary& dict)
{ {
dict.lookup("field") >> fieldName_; if (fieldName_ == word::null || dict.found("field"))
{
dict.lookup("field") >> fieldName_;
}
if (dict.found("result")) if (dict.found("result"))
{ {

View File

@ -93,7 +93,9 @@ public:
( (
const word& name, const word& name,
const Time& runTime, const Time& runTime,
const dictionary& dict const dictionary& dict,
const word& fieldName = word::null,
const word& resultName = word::null
); );

View File

@ -91,7 +91,7 @@ Foam::functionObjects::vorticity::~vorticity()
bool Foam::functionObjects::vorticity::read(const dictionary& dict) bool Foam::functionObjects::vorticity::read(const dictionary& dict)
{ {
UName_ = dict.lookupOrDefault<word>("UName", "U"); UName_ = dict.lookupOrDefault<word>("U", "U");
if (UName_ != "U") if (UName_ != "U")
{ {
outputName_ = typeName + "(" + UName_ + ")"; outputName_ = typeName + "(" + UName_ + ")";

View File

@ -1,16 +1,6 @@
codedFunctionObject/codedFunctionObject.C codedFunctionObject/codedFunctionObject.C
CourantNo/CourantNo.C
Lambda2/Lambda2.C
Peclet/Peclet.C
Q/Q.C
blendingFactor/blendingFactor.C
dsmcFields/dsmcFields.C
residuals/residuals.C residuals/residuals.C
scalarTransport/scalarTransport.C
timeActivatedFileUpdate/timeActivatedFileUpdate.C timeActivatedFileUpdate/timeActivatedFileUpdate.C
turbulenceFields/turbulenceFields.C
vorticity/vorticity.C
yPlus/yPlus.C
setTimeStep/setTimeStepFunctionObject.C setTimeStep/setTimeStepFunctionObject.C
systemCall/systemCall.C systemCall/systemCall.C
abort/abort.C abort/abort.C
@ -18,4 +8,12 @@ removeRegisteredObject/removeRegisteredObject.C
writeDictionary/writeDictionary.C writeDictionary/writeDictionary.C
writeRegisteredObject/writeRegisteredObject.C writeRegisteredObject/writeRegisteredObject.C
scalarTransport/scalarTransport.C
blendingFactor/blendingFactor.C
dsmcFields/dsmcFields.C
turbulenceFields/turbulenceFields.C
Peclet/Peclet.C
yPlus/yPlus.C
LIB = $(FOAM_LIBBIN)/libutilityFunctionObjects LIB = $(FOAM_LIBBIN)/libutilityFunctionObjects

View File

@ -94,8 +94,8 @@ Foam::functionObjects::Peclet::~Peclet()
bool Foam::functionObjects::Peclet::read(const dictionary& dict) bool Foam::functionObjects::Peclet::read(const dictionary& dict)
{ {
phiName_ = dict.lookupOrDefault<word>("phiName", "phi"); phiName_ = dict.lookupOrDefault<word>("phi", "phi");
rhoName_ = dict.lookupOrDefault<word>("rhoName", "rho"); rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
return true; return true;
} }