Commit 0e3f6558 authored by Henry Weller's avatar Henry Weller
Browse files

functionObjects: Clear the result field from the objectRegistry if the...

functionObjects: Clear the result field from the objectRegistry if the argument fields are not available
This is needed to handle the processing of many time directories, some
of which may have the required fields and some not.
parent bae74211
......@@ -66,6 +66,31 @@ bool Foam::functionObjects::fvMeshFunctionObject::writeField
}
bool Foam::functionObjects::fvMeshFunctionObject::clearField
(
const word& fieldName
)
{
if (foundField<regIOobject>(fieldName))
{
const regIOobject& resultField = lookupField<regIOobject>(fieldName);
if (resultField.ownedByRegistry())
{
return const_cast<regIOobject&>(resultField).checkOut();
}
else
{
return false;
}
}
else
{
return true;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fvMeshFunctionObject::fvMeshFunctionObject
......
......@@ -95,6 +95,9 @@ protected:
//- Write field if present in objectRegistry
bool writeField(const word& fieldName);
//- Clear field from the objectRegistry if present
bool clearField(const word& fieldName);
private:
......
......@@ -74,10 +74,22 @@ bool Foam::functionObjects::fvMeshFunctionObject::store
&& mesh_.foundObject<FieldType>(fieldName)
)
{
const_cast<FieldType&>
const FieldType& field =
(
mesh_.lookupObject<FieldType>(fieldName)
) = tfield;
);
// If there is a result field already registered assign to the new
// result field otherwise transfer ownership of the new result field to
// the object registry
if (&field != &tfield())
{
const_cast<FieldType&>(field) = tfield;
}
else
{
mesh_.objectRegistry::store(tfield.ptr());
}
}
else
{
......
......@@ -66,41 +66,7 @@ Foam::functionObjects::CourantNo::byRho
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::CourantNo::CourantNo
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "phi", "Co")
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::CourantNo::~CourantNo()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::CourantNo::read(const dictionary& dict)
{
fieldExpression::read(dict);
phiName_ = dict.lookupOrDefault<word>("phi", "phi");
rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
return true;
}
bool Foam::functionObjects::CourantNo::execute(const bool postProcess)
bool Foam::functionObjects::CourantNo::calc()
{
if (foundField<surfaceScalarField>(phiName_))
{
......@@ -163,4 +129,38 @@ bool Foam::functionObjects::CourantNo::execute(const bool postProcess)
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::CourantNo::CourantNo
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "phi", "Co")
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::CourantNo::~CourantNo()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::CourantNo::read(const dictionary& dict)
{
fieldExpression::read(dict);
phiName_ = dict.lookupOrDefault<word>("phi", "phi");
rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
return true;
}
// ************************************************************************* //
......@@ -73,12 +73,15 @@ class CourantNo
// Private Member Functions
//- Divide Co by rho if required
//- Divide the Courant number by rho if required
tmp<volScalarField::Internal> byRho
(
const tmp<volScalarField::Internal>& Co
) const;
//- Calculate the Courant number field and return true if successful
virtual bool calc();
public:
......@@ -105,9 +108,6 @@ public:
//- Read the CourantNo data
virtual bool read(const dictionary&);
//- Calculate the Courant number
virtual bool execute(const bool postProcess = false);
};
......
......@@ -45,28 +45,9 @@ namespace functionObjects
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::Lambda2::Lambda2
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "U", "Lambda2")
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::Lambda2::~Lambda2()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::Lambda2::execute(const bool postProcess)
bool Foam::functionObjects::Lambda2::calc()
{
if (foundField<volVectorField>(fieldName_))
{
......@@ -93,4 +74,23 @@ bool Foam::functionObjects::Lambda2::execute(const bool postProcess)
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::Lambda2::Lambda2
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "U", "Lambda2")
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::Lambda2::~Lambda2()
{}
// ************************************************************************* //
......@@ -61,6 +61,11 @@ class Lambda2
:
public fieldExpression
{
// Private Member Functions
//- Calculate the Lambda2 field and return true if successful
virtual bool calc();
public:
......@@ -81,12 +86,6 @@ public:
//- Destructor
virtual ~Lambda2();
// Member Functions
//- Calculate the Lambda2 field
virtual bool execute(const bool postProcess = false);
};
......
......@@ -45,28 +45,9 @@ namespace functionObjects
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::MachNo::MachNo
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "U", "Ma")
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::MachNo::~MachNo()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::MachNo::execute(const bool postProcess)
bool Foam::functionObjects::MachNo::calc()
{
if
(
......@@ -92,4 +73,23 @@ bool Foam::functionObjects::MachNo::execute(const bool postProcess)
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::MachNo::MachNo
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "U", "Ma")
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::MachNo::~MachNo()
{}
// ************************************************************************* //
......@@ -60,6 +60,11 @@ class MachNo
:
public fieldExpression
{
// Private Member Functions
//- Calculate the Mach number field and return true if successful
virtual bool calc();
public:
......@@ -81,12 +86,6 @@ public:
//- Destructor
virtual ~MachNo();
// Member Functions
//- Calculate the Mach number field
virtual bool execute(const bool postProcess = false);
};
......
......@@ -46,40 +46,9 @@ namespace functionObjects
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::functionObjects::PecletNo::PecletNo
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "phi", "Pe")
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::PecletNo::~PecletNo()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::PecletNo::read(const dictionary& dict)
{
fieldExpression::read(dict);
phiName_ = dict.lookupOrDefault<word>("phi", "phi");
return true;
}
bool Foam::functionObjects::PecletNo::execute(const bool postProcess)
bool Foam::functionObjects::PecletNo::calc()
{
if (foundField<surfaceScalarField>(phiName_))
{
......@@ -112,4 +81,37 @@ bool Foam::functionObjects::PecletNo::execute(const bool postProcess)
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::PecletNo::PecletNo
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "phi", "Pe")
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::PecletNo::~PecletNo()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::PecletNo::read(const dictionary& dict)
{
fieldExpression::read(dict);
phiName_ = dict.lookupOrDefault<word>("phi", "phi");
return true;
}
// ************************************************************************* //
......@@ -66,6 +66,12 @@ class PecletNo
word phiName_;
// Private Member Functions
//- Calculate the Peclet number field and return true if successful
virtual bool calc();
public:
//- Runtime type information
......@@ -92,9 +98,6 @@ public:
//- Read the PecletNo data
virtual bool read(const dictionary&);
//- Calculate the Peclet number field
virtual bool execute(const bool postProcess = false);
};
......
......@@ -45,28 +45,9 @@ namespace functionObjects
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::Q::Q
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "U", "Q")
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::Q::~Q()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::Q::execute(const bool postProcess)
bool Foam::functionObjects::Q::calc()
{
if (foundField<volVectorField>(fieldName_))
{
......@@ -87,4 +68,23 @@ bool Foam::functionObjects::Q::execute(const bool postProcess)
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::Q::Q
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "U", "Q")
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::Q::~Q()
{}
// ************************************************************************* //
......@@ -64,6 +64,11 @@ class Q
:
public fieldExpression
{
// Private Member Functions
//- Calculate the Q field and return true if successful
virtual bool calc();
public:
......@@ -84,12 +89,6 @@ public:
//- Destructor
virtual ~Q();
// Member Functions
//- Calculate the Q field
virtual bool execute(const bool postProcess = false);
};
......
......@@ -38,6 +38,25 @@ namespace functionObjects
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::blendingFactor::calc()
{
bool processed = false;
processed = processed || calcBF<scalar>();
processed = processed || calcBF<vector>();
if (!processed)
{
WarningInFunction
<< "Unprocessed field " << fieldName_ << endl;
}
return processed;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::blendingFactor::blendingFactor
......@@ -73,21 +92,4 @@ bool Foam::functionObjects::blendingFactor::read(const dictionary& dict)
}
bool Foam::functionObjects::blendingFactor::execute(const bool postProcess)
{
bool processed = false;
processed = processed || calc<scalar>();
processed = processed || calc<vector>();
if (!processed)
{
WarningInFunction
<< "Unprocessed field " << fieldName_ << endl;
}
return processed;
}
// ************************************************************************* //
......@@ -69,9 +69,12 @@ class blendingFactor
// Private Member Functions
//- Calculate the blending factor
//- Calculate the blending factor field
template<class Type>
bool calc();
bool calcBF();
//- Calculate the blending factor field and return true if successful
virtual bool calc();
public:
......@@ -99,9 +102,6 @@ public:
//- Read the blendingFactor data
virtual bool read(const dictionary&);
//- Calculate the blending-factor
virtual bool execute(const bool postProcess = false);
};
......
......@@ -30,7 +30,7 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::blendingFactor::calc()
bool Foam::functionObjects::blendingFactor::calcBF()
{
typedef GeometricField<Type, fvPatchField, volMesh> FieldType;
......
......@@ -40,6 +40,19 @@ namespace functionObjects
}