Commit 1de91282 authored by Henry Weller's avatar Henry Weller
Browse files

regionFunctionObject: Moved the field/object maintenance functions from...

regionFunctionObject: Moved the field/object maintenance functions from fvMeshFunctionObject into regionFunctionObject
parent 0e3f6558
...@@ -38,6 +38,59 @@ namespace functionObjects ...@@ -38,6 +38,59 @@ namespace functionObjects
} }
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
bool Foam::functionObjects::regionFunctionObject::writeObject
(
const word& fieldName
)
{
if (obr_.foundObject<regIOobject>(fieldName))
{
const regIOobject& field = obr_.lookupObject<regIOobject>(fieldName);
if (log_)
{
Info<< "functionObjects::" << type() << " " << name()
<< " writing field: " << field.name() << endl;
}
field.write();
return true;
}
else
{
return false;
}
}
bool Foam::functionObjects::regionFunctionObject::clearObject
(
const word& fieldName
)
{
if (foundObject<regIOobject>(fieldName))
{
const regIOobject& resultObject = lookupObject<regIOobject>(fieldName);
if (resultObject.ownedByRegistry())
{
return const_cast<regIOobject&>(resultObject).checkOut();
}
else
{
return false;
}
}
else
{
return true;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::regionFunctionObject::regionFunctionObject Foam::functionObjects::regionFunctionObject::regionFunctionObject
......
...@@ -76,6 +76,32 @@ protected: ...@@ -76,6 +76,32 @@ protected:
Switch log_; Switch log_;
// Protected member functions
//- Find field in the objectRegistry
template<class ObjectType>
bool foundObject(const word& fieldName) const;
//- Lookup field from the objectRegistry
template<class ObjectType>
const ObjectType& lookupObject(const word& fieldName) const;
//- Store the given field in the objectRegistry under the given name
template<class ObjectType>
bool store
(
word& fieldName,
const tmp<ObjectType>& tfield,
bool cacheable = false
);
//- Write field if present in objectRegistry
bool writeObject(const word& fieldName);
//- Clear field from the objectRegistry if present
bool clearObject(const word& fieldName);
private: private:
// Private Member Functions // Private Member Functions
...@@ -132,6 +158,12 @@ public: ...@@ -132,6 +158,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "regionFunctionObjectTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //
...@@ -23,36 +23,36 @@ License ...@@ -23,36 +23,36 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "fvMeshFunctionObject.H" #include "regionFunctionObject.H"
#include "volFields.H" #include "objectRegistry.H"
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
template<class FieldType> template<class ObjectType>
bool Foam::functionObjects::fvMeshFunctionObject::foundField bool Foam::functionObjects::regionFunctionObject::foundObject
( (
const word& fieldName const word& fieldName
) const ) const
{ {
return mesh_.foundObject<FieldType>(fieldName); return obr_.foundObject<ObjectType>(fieldName);
} }
template<class FieldType> template<class ObjectType>
const FieldType& Foam::functionObjects::fvMeshFunctionObject::lookupField const ObjectType& Foam::functionObjects::regionFunctionObject::lookupObject
( (
const word& fieldName const word& fieldName
) const ) const
{ {
return mesh_.lookupObject<FieldType>(fieldName); return obr_.lookupObject<ObjectType>(fieldName);
} }
template<class FieldType> template<class ObjectType>
bool Foam::functionObjects::fvMeshFunctionObject::store bool Foam::functionObjects::regionFunctionObject::store
( (
word& fieldName, word& fieldName,
const tmp<FieldType>& tfield, const tmp<ObjectType>& tfield,
bool cacheable bool cacheable
) )
{ {
...@@ -71,12 +71,12 @@ bool Foam::functionObjects::fvMeshFunctionObject::store ...@@ -71,12 +71,12 @@ bool Foam::functionObjects::fvMeshFunctionObject::store
if if
( (
fieldName.size() fieldName.size()
&& mesh_.foundObject<FieldType>(fieldName) && obr_.foundObject<ObjectType>(fieldName)
) )
{ {
const FieldType& field = const ObjectType& field =
( (
mesh_.lookupObject<FieldType>(fieldName) obr_.lookupObject<ObjectType>(fieldName)
); );
// If there is a result field already registered assign to the new // If there is a result field already registered assign to the new
...@@ -84,11 +84,11 @@ bool Foam::functionObjects::fvMeshFunctionObject::store ...@@ -84,11 +84,11 @@ bool Foam::functionObjects::fvMeshFunctionObject::store
// the object registry // the object registry
if (&field != &tfield()) if (&field != &tfield())
{ {
const_cast<FieldType&>(field) = tfield; const_cast<ObjectType&>(field) = tfield;
} }
else else
{ {
mesh_.objectRegistry::store(tfield.ptr()); obr_.objectRegistry::store(tfield.ptr());
} }
} }
else else
...@@ -102,7 +102,7 @@ bool Foam::functionObjects::fvMeshFunctionObject::store ...@@ -102,7 +102,7 @@ bool Foam::functionObjects::fvMeshFunctionObject::store
fieldName = tfield().name(); fieldName = tfield().name();
} }
mesh_.objectRegistry::store(tfield.ptr()); obr_.objectRegistry::store(tfield.ptr());
} }
return true; return true;
......
...@@ -37,6 +37,7 @@ SourceFiles ...@@ -37,6 +37,7 @@ SourceFiles
#ifndef fvcSurfaceIntegrate_H #ifndef fvcSurfaceIntegrate_H
#define fvcSurfaceIntegrate_H #define fvcSurfaceIntegrate_H
#include "primitiveFieldsFwd.H"
#include "volFieldsFwd.H" #include "volFieldsFwd.H"
#include "surfaceFieldsFwd.H" #include "surfaceFieldsFwd.H"
......
...@@ -38,59 +38,6 @@ namespace functionObjects ...@@ -38,59 +38,6 @@ namespace functionObjects
} }
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
bool Foam::functionObjects::fvMeshFunctionObject::writeField
(
const word& fieldName
)
{
if (mesh_.foundObject<regIOobject>(fieldName))
{
const regIOobject& field = mesh_.lookupObject<regIOobject>(fieldName);
if (log_)
{
Info<< "functionObjects::" << type() << " " << name()
<< " writing field: " << field.name() << endl;
}
field.write();
return true;
}
else
{
return false;
}
}
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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fvMeshFunctionObject::fvMeshFunctionObject Foam::functionObjects::fvMeshFunctionObject::fvMeshFunctionObject
......
...@@ -73,32 +73,6 @@ protected: ...@@ -73,32 +73,6 @@ protected:
const fvMesh& mesh_; const fvMesh& mesh_;
// Protected member functions
//- Find field in the objectRegistry
template<class FieldType>
bool foundField(const word& fieldName) const;
//- Lookup field from the objectRegistry
template<class FieldType>
const FieldType& lookupField(const word& fieldName) const;
//- Store the given field in the objectRegistry under the given name
template<class FieldType>
bool store
(
word& fieldName,
const tmp<FieldType>& tfield,
bool cacheable = false
);
//- Write field if present in objectRegistry
bool writeField(const word& fieldName);
//- Clear field from the objectRegistry if present
bool clearField(const word& fieldName);
private: private:
// Private Member Functions // Private Member Functions
...@@ -139,12 +113,6 @@ public: ...@@ -139,12 +113,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fvMeshFunctionObjectTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //
...@@ -68,10 +68,10 @@ Foam::functionObjects::CourantNo::byRho ...@@ -68,10 +68,10 @@ Foam::functionObjects::CourantNo::byRho
bool Foam::functionObjects::CourantNo::calc() bool Foam::functionObjects::CourantNo::calc()
{ {
if (foundField<surfaceScalarField>(phiName_)) if (foundObject<surfaceScalarField>(phiName_))
{ {
const surfaceScalarField& phi = const surfaceScalarField& phi =
lookupField<surfaceScalarField>(phiName_); lookupObject<surfaceScalarField>(phiName_);
tmp<volScalarField::Internal> Coi tmp<volScalarField::Internal> Coi
( (
...@@ -83,13 +83,13 @@ bool Foam::functionObjects::CourantNo::calc() ...@@ -83,13 +83,13 @@ bool Foam::functionObjects::CourantNo::calc()
) )
); );
if (foundField<volScalarField>(resultName_)) if (foundObject<volScalarField>(resultName_))
{ {
volScalarField& Co volScalarField& Co
( (
const_cast<volScalarField&> const_cast<volScalarField&>
( (
lookupField<volScalarField>(resultName_) lookupObject<volScalarField>(resultName_)
) )
); );
......
...@@ -49,9 +49,9 @@ namespace functionObjects ...@@ -49,9 +49,9 @@ namespace functionObjects
bool Foam::functionObjects::Lambda2::calc() bool Foam::functionObjects::Lambda2::calc()
{ {
if (foundField<volVectorField>(fieldName_)) if (foundObject<volVectorField>(fieldName_))
{ {
const volVectorField& U = lookupField<volVectorField>(fieldName_); const volVectorField& U = lookupObject<volVectorField>(fieldName_);
const tmp<volTensorField> tgradU(fvc::grad(U)); const tmp<volTensorField> tgradU(fvc::grad(U));
const volTensorField& gradU = tgradU(); const volTensorField& gradU = tgradU();
......
...@@ -51,14 +51,14 @@ bool Foam::functionObjects::MachNo::calc() ...@@ -51,14 +51,14 @@ bool Foam::functionObjects::MachNo::calc()
{ {
if if
( (
foundField<volVectorField>(fieldName_) foundObject<volVectorField>(fieldName_)
&& mesh_.foundObject<fluidThermo>(fluidThermo::dictName) && mesh_.foundObject<fluidThermo>(fluidThermo::dictName)
) )
{ {
const fluidThermo& thermo = const fluidThermo& thermo =
mesh_.lookupObject<fluidThermo>(fluidThermo::dictName); mesh_.lookupObject<fluidThermo>(fluidThermo::dictName);
const volVectorField& U = lookupField<volVectorField>(fieldName_); const volVectorField& U = lookupObject<volVectorField>(fieldName_);
return store return store
( (
......
...@@ -50,7 +50,7 @@ namespace functionObjects ...@@ -50,7 +50,7 @@ namespace functionObjects
bool Foam::functionObjects::PecletNo::calc() bool Foam::functionObjects::PecletNo::calc()
{ {
if (foundField<surfaceScalarField>(phiName_)) if (foundObject<surfaceScalarField>(phiName_))
{ {
tmp<volScalarField> nuEff tmp<volScalarField> nuEff
( (
......
...@@ -49,9 +49,9 @@ namespace functionObjects ...@@ -49,9 +49,9 @@ namespace functionObjects
bool Foam::functionObjects::Q::calc() bool Foam::functionObjects::Q::calc()
{ {
if (foundField<volVectorField>(fieldName_)) if (foundObject<volVectorField>(fieldName_))
{ {
const volVectorField& U = lookupField<volVectorField>(fieldName_); const volVectorField& U = lookupObject<volVectorField>(fieldName_);
const tmp<volTensorField> tgradU(fvc::grad(U)); const tmp<volTensorField> tgradU(fvc::grad(U));
const volTensorField& gradU = tgradU(); const volTensorField& gradU = tgradU();
......
...@@ -34,17 +34,17 @@ bool Foam::functionObjects::blendingFactor::calcBF() ...@@ -34,17 +34,17 @@ bool Foam::functionObjects::blendingFactor::calcBF()
{ {
typedef GeometricField<Type, fvPatchField, volMesh> FieldType; typedef GeometricField<Type, fvPatchField, volMesh> FieldType;
if (!foundField<FieldType>(fieldName_)) if (!foundObject<FieldType>(fieldName_))
{ {
return false; return false;
} }
const FieldType& field = lookupField<FieldType>(fieldName_); const FieldType& field = lookupObject<FieldType>(fieldName_);
const word divScheme("div(" + phiName_ + ',' + fieldName_ + ')'); const word divScheme("div(" + phiName_ + ',' + fieldName_ + ')');
ITstream& its = mesh_.divScheme(divScheme); ITstream& its = mesh_.divScheme(divScheme);
const surfaceScalarField& phi = lookupField<surfaceScalarField>(phiName_); const surfaceScalarField& phi = lookupObject<surfaceScalarField>(phiName_);
tmp<fv::convectionScheme<Type>> cs = tmp<fv::convectionScheme<Type>> cs =
fv::convectionScheme<Type>::New(mesh_, phi, its); fv::convectionScheme<Type>::New(mesh_, phi, its);
......
...@@ -30,12 +30,12 @@ License ...@@ -30,12 +30,12 @@ License
template<class FieldType> template<class FieldType>
bool Foam::functionObjects::div::calcDiv() bool Foam::functionObjects::div::calcDiv()
{ {
if (foundField<FieldType>(fieldName_)) if (foundObject<FieldType>(fieldName_))
{ {
return store return store
( (
resultName_, resultName_,
fvc::div(lookupField<FieldType>(fieldName_)) fvc::div(lookupObject<FieldType>(fieldName_))
); );
} }
else else
......
...@@ -49,12 +49,12 @@ namespace functionObjects ...@@ -49,12 +49,12 @@ namespace functionObjects
bool Foam::functionObjects::enstrophy::calc() bool Foam::functionObjects::enstrophy::calc()
{ {
if (foundField<volVectorField>(fieldName_)) if (foundObject<volVectorField>(fieldName_))
{ {
return store return store
( (
resultName_, resultName_,
0.5*magSqr(fvc::curl(lookupField<volVectorField>(fieldName_))) 0.5*magSqr(fvc::curl(lookupObject<volVectorField>(fieldName_)))
); );
} }
else else
......
...@@ -124,7 +124,7 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::write ...@@ -124,7 +124,7 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::write
{ {
forAll(fieldSet_, fieldi) forAll(fieldSet_, fieldi)
{ {
fvMeshFunctionObject::writeField(transformFieldName(fieldSet_[fieldi])); writeObject(transformFieldName(fieldSet_[fieldi]));