Commit 8f68a493 authored by Henry Weller's avatar Henry Weller
Browse files

functionObjects: Cleanup, reorganize and simplify

parent 8e040421
......@@ -88,7 +88,7 @@ protected:
bool store
(
word& fieldName,
tmp<FieldType> tfield,
const tmp<FieldType>& tfield,
bool cacheable = false
);
......
......@@ -52,7 +52,7 @@ template<class FieldType>
bool Foam::functionObjects::fvMeshFunctionObject::store
(
word& fieldName,
tmp<FieldType> tfield,
const tmp<FieldType>& tfield,
bool cacheable
)
{
......
......@@ -75,29 +75,9 @@ Foam::functionObjects::CourantNo::CourantNo
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict)
fieldExpression(name, runTime, dict, "phi", "Co")
{
read(dict);
volScalarField* CourantNoPtr
(
new volScalarField
(
IOobject
(
type(),
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", dimless, 0.0),
zeroGradientFvPatchScalarField::typeName
)
);
mesh_.objectRegistry::store(CourantNoPtr);
}
......@@ -111,6 +91,8 @@ Foam::functionObjects::CourantNo::~CourantNo()
bool Foam::functionObjects::CourantNo::read(const dictionary& dict)
{
fieldExpression::read(dict);
phiName_ = dict.lookupOrDefault<word>("phi", "phi");
rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
......@@ -120,38 +102,64 @@ bool Foam::functionObjects::CourantNo::read(const dictionary& dict)
bool Foam::functionObjects::CourantNo::execute(const bool postProcess)
{
const surfaceScalarField& phi =
mesh_.lookupObject<surfaceScalarField>(phiName_);
volScalarField& Co = const_cast<volScalarField&>
(
mesh_.lookupObject<volScalarField>(type())
);
Co.ref() = byRho
(
(0.5*mesh_.time().deltaT())
*fvc::surfaceSum(mag(phi))()()
/mesh_.V()
);
Co.correctBoundaryConditions();
return true;
}
bool Foam::functionObjects::CourantNo::write(const bool postProcess)
{
const volScalarField& CourantNo =
obr_.lookupObject<volScalarField>(type());
Info<< type() << " " << name() << " output:" << nl
<< " writing field " << CourantNo.name() << nl
<< endl;
CourantNo.write();
if (foundField<surfaceScalarField>(phiName_))
{
const surfaceScalarField& phi =
lookupField<surfaceScalarField>(phiName_);
return true;
tmp<volScalarField::Internal> Coi
(
byRho
(
(0.5*mesh_.time().deltaT())
*fvc::surfaceSum(mag(phi))()()
/mesh_.V()
)
);
if (foundField<volScalarField>(resultName_))
{
volScalarField& Co
(
const_cast<volScalarField&>
(
lookupField<volScalarField>(resultName_)
)
);
Co.ref() = Coi();
Co.correctBoundaryConditions();
}
else
{
tmp<volScalarField> tCo
(
new volScalarField
(
IOobject
(
resultName_,
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", dimless, 0.0),
zeroGradientFvPatchScalarField::typeName
)
);
tCo.ref().ref() = Coi();
tCo.ref().correctBoundaryConditions();
mesh_.objectRegistry::store(tCo.ptr());
}
return true;
}
else
{
return false;
}
}
......
......@@ -33,6 +33,7 @@ Description
be retrieved and used for other applications.
SeeAlso
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
......@@ -43,7 +44,7 @@ SourceFiles
#ifndef functionObjects_CourantNo_H
#define functionObjects_CourantNo_H
#include "fvMeshFunctionObject.H"
#include "fieldExpression.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -59,7 +60,7 @@ namespace functionObjects
class CourantNo
:
public fvMeshFunctionObject
public fieldExpression
{
// Private data
......@@ -78,12 +79,6 @@ class CourantNo
const tmp<volScalarField::Internal>& Co
) const;
//- Disallow default bitwise copy construct
CourantNo(const CourantNo&);
//- Disallow default bitwise assignment
void operator=(const CourantNo&);
public:
......@@ -113,9 +108,6 @@ public:
//- Execute, currently does nothing
virtual bool execute(const bool postProcess = false);
//- Calculate the CourantNo and write
virtual bool write(const bool postProcess = false);
};
......
......@@ -24,8 +24,6 @@ License
\*---------------------------------------------------------------------------*/
#include "Lambda2.H"
#include "volFields.H"
#include "zeroGradientFvPatchFields.H"
#include "fvcGrad.H"
#include "addToRunTimeSelectionTable.H"
......@@ -56,29 +54,8 @@ Foam::functionObjects::Lambda2::Lambda2
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict)
{
read(dict);
volScalarField* Lambda2Ptr
(
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(Lambda2Ptr);
}
fieldExpression(name, runTime, dict, "U", "Lambda2")
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
......@@ -89,51 +66,30 @@ Foam::functionObjects::Lambda2::~Lambda2()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::Lambda2::read(const dictionary& dict)
{
UName_ = dict.lookupOrDefault<word>("U", "U");
return true;
}
bool Foam::functionObjects::Lambda2::execute(const bool postProcess)
{
const volVectorField& U =
mesh_.lookupObject<volVectorField>(UName_);
const volTensorField gradU(fvc::grad(U));
if (foundField<volVectorField>(fieldName_))
{
const volVectorField& U = lookupField<volVectorField>(fieldName_);
const tmp<volTensorField> tgradU(fvc::grad(U));
const volTensorField& gradU = tgradU();
const volTensorField SSplusWW
(
(symm(gradU) & symm(gradU))
+ (skew(gradU) & skew(gradU))
);
volScalarField& Lambda2 =
const_cast<volScalarField&>
const volTensorField SSplusWW
(
mesh_.lookupObject<volScalarField>(type())
(symm(gradU) & symm(gradU))
+ (skew(gradU) & skew(gradU))
);
Lambda2 = -eigenValues(SSplusWW)().component(vector::Y);
return true;
}
bool Foam::functionObjects::Lambda2::write(const bool postProcess)
{
const volScalarField& Lambda2 =
obr_.lookupObject<volScalarField>(type());
Info<< type() << " " << name() << " output:" << nl
<< " writing field " << Lambda2.name() << nl
<< endl;
Lambda2.write();
return true;
return store
(
resultName_,
-eigenValues(SSplusWW)().component(vector::Y)
);
}
else
{
return false;
}
}
......
......@@ -33,6 +33,7 @@ Description
the velocity gradient tensor.
SeeAlso
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
......@@ -43,8 +44,7 @@ SourceFiles
#ifndef functionObjects_Lambda2_H
#define functionObjects_Lambda2_H
#include "fvMeshFunctionObject.H"
#include "volFieldsFwd.H"
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -59,22 +59,8 @@ namespace functionObjects
class Lambda2
:
public fvMeshFunctionObject
public fieldExpression
{
// Private data
//- Name of velocity field, default is "U"
word UName_;
// Private Member Functions
//- Disallow default bitwise copy construct
Lambda2(const Lambda2&);
//- Disallow default bitwise assignment
void operator=(const Lambda2&);
public:
......@@ -99,14 +85,8 @@ public:
// Member Functions
//- Read the Lambda2 data
virtual bool read(const dictionary&);
//- Calculate Lambda2
//- Calculate the Lambda2 field
virtual bool execute(const bool postProcess = false);
//- Write Lambda2
virtual bool write(const bool postProcess = false);
};
......
......@@ -40,5 +40,6 @@ vorticity/vorticity.C
Q/Q.C
Lambda2/Lambda2.C
CourantNo/CourantNo.C
Peclet/Peclet.C
LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects
......@@ -4,7 +4,8 @@ EXE_INC = \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude
-I$(LIB_SRC)/surfMesh/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude
LIB_LIBS = \
-lfiniteVolume \
......
......@@ -24,11 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "Peclet.H"
#include "volFields.H"
#include "dictionary.H"
#include "surfaceFields.H"
#include "turbulentTransportModel.H"
#include "turbulentFluidThermoModel.H"
#include "turbulenceModel.H"
#include "surfaceInterpolate.H"
#include "addToRunTimeSelectionTable.H"
......@@ -59,28 +55,9 @@ Foam::functionObjects::Peclet::Peclet
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict)
fieldExpression(name, runTime, dict, "phi", "Pe")
{
read(dict);
surfaceScalarField* PecletPtr
(
new surfaceScalarField
(
IOobject
(
type(),
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", dimless, 0.0)
)
);
mesh_.objectRegistry::store(PecletPtr);
}
......@@ -94,8 +71,9 @@ Foam::functionObjects::Peclet::~Peclet()
bool Foam::functionObjects::Peclet::read(const dictionary& dict)
{
fieldExpression::read(dict);
phiName_ = dict.lookupOrDefault<word>("phi", "phi");
rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
return true;
}
......@@ -103,99 +81,34 @@ bool Foam::functionObjects::Peclet::read(const dictionary& dict)
bool Foam::functionObjects::Peclet::execute(const bool postProcess)
{
typedef compressible::turbulenceModel cmpTurbModel;
typedef incompressible::turbulenceModel icoTurbModel;
tmp<volScalarField> nuEff;
if (mesh_.foundObject<cmpTurbModel>(turbulenceModel::propertiesName))
if (foundField<surfaceScalarField>(phiName_))
{
const cmpTurbModel& model =
mesh_.lookupObject<cmpTurbModel>
(
turbulenceModel::propertiesName
);
const volScalarField& rho =
mesh_.lookupObject<volScalarField>(rhoName_);
nuEff = model.muEff()/rho;
}
else if
(
mesh_.foundObject<icoTurbModel>(turbulenceModel::propertiesName)
)
{
const icoTurbModel& model =
mesh_.lookupObject<icoTurbModel>
tmp<volScalarField> nuEff
(
mesh_.lookupObject<turbulenceModel>
(
turbulenceModel::propertiesName
);
).nuEff()
);
nuEff = model.nuEff();
}
else if (mesh_.foundObject<dictionary>("transportProperties"))
{
const dictionary& model =
mesh_.lookupObject<dictionary>("transportProperties");
const surfaceScalarField& phi =
mesh_.lookupObject<surfaceScalarField>(phiName_);
nuEff =
tmp<volScalarField>
(
new volScalarField
(
IOobject
(
"nuEff",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar(model.lookup("nu"))
)
);
return store
(
resultName_,
mag(phi)
/(
mesh_.magSf()
*mesh_.surfaceInterpolation::deltaCoeffs()
*fvc::interpolate(nuEff)
)
);
}
else
{
FatalErrorInFunction
<< "Unable to determine the viscosity"
<< exit(FatalError);
return false;
}
const surfaceScalarField& phi =
mesh_.lookupObject<surfaceScalarField>(phiName_);
surfaceScalarField& Peclet =
const_cast<surfaceScalarField&>
(
mesh_.lookupObject<surfaceScalarField>(type())
);
Peclet =
mag(phi)
/(
mesh_.magSf()
*mesh_.surfaceInterpolation::deltaCoeffs()
*fvc::interpolate(nuEff)
);
return true;
}
bool Foam::functionObjects::Peclet::write(const bool postProcess)
{
const surfaceScalarField& Peclet =
mesh_.lookupObject<surfaceScalarField>(type());
Info<< type() << " " << name() << " output:" << nl
<< " writing field " << Peclet.name() << nl
<< endl;
Peclet.write();
return true;
}
......
......@@ -32,6 +32,7 @@ Description
surfaceScalarField.
SeeAlso
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
......@@ -42,8 +43,7 @@ SourceFiles
#ifndef functionObjects_Peclet_H
#define functionObjects_Peclet_H
#include "fvMeshFunctionObject.H"
#include "volFieldsFwd.H"
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -58,25 +58,13 @@ namespace functionObjects
class Peclet
:
public fvMeshFunctionObject
public fieldExpression
{
// Private data
//- Name of flux field, default is "phi"
word phiName_;
//- Name of density field (compressible cases only), default is "rho"
word rhoName_;
// Private Member Functions
//- Disallow default bitwise copy construct
Peclet(const Peclet&);
//- Disallow default bitwise assignment
void operator=(const Peclet&);
public:
......@@ -107,9 +95,6 @@ public:
//- Calculate the Peclet number field
virtual bool execute(const bool postProcess = false);
//- Write the Peclet number field