From 1de91282cdf8e8d296e3276191e8ada3d8c10f1d Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Wed, 25 May 2016 16:26:57 +0100 Subject: [PATCH] regionFunctionObject: Moved the field/object maintenance functions from fvMeshFunctionObject into regionFunctionObject --- .../regionFunctionObject.C | 53 +++++++++++++++++++ .../regionFunctionObject.H | 32 +++++++++++ .../regionFunctionObjectTemplates.C} | 34 ++++++------ .../finiteVolume/fvc/fvcSurfaceIntegrate.H | 1 + .../fvMeshFunctionObject.C | 53 ------------------- .../fvMeshFunctionObject.H | 32 ----------- .../field/CourantNo/CourantNo.C | 8 +-- .../functionObjects/field/Lambda2/Lambda2.C | 4 +- .../functionObjects/field/MachNo/MachNo.C | 4 +- .../functionObjects/field/PecletNo/PecletNo.C | 2 +- .../functionObjects/field/Q/Q.C | 4 +- .../blendingFactor/blendingFactorTemplates.C | 6 +-- .../functionObjects/field/div/divTemplates.C | 4 +- .../field/enstrophy/enstrophy.C | 4 +- .../fieldCoordinateSystemTransform.C | 2 +- .../field/fieldExpression/fieldExpression.C | 5 +- .../functionObjects/field/flowType/flowType.C | 4 +- .../field/grad/gradTemplates.C | 8 +-- .../functionObjects/field/mag/magTemplates.C | 8 +-- .../functionObjects/field/pressure/pressure.C | 8 +-- .../field/vorticity/vorticity.C | 4 +- 21 files changed, 141 insertions(+), 139 deletions(-) rename src/{finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObjectTemplates.C => OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C} (75%) diff --git a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C index 54fed15f56..47b26420b4 100644 --- a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C @@ -38,6 +38,59 @@ namespace functionObjects } +// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // + +bool Foam::functionObjects::regionFunctionObject::writeObject +( + const word& fieldName +) +{ + if (obr_.foundObject(fieldName)) + { + const regIOobject& field = obr_.lookupObject(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(fieldName)) + { + const regIOobject& resultObject = lookupObject(fieldName); + + if (resultObject.ownedByRegistry()) + { + return const_cast(resultObject).checkOut(); + } + else + { + return false; + } + } + else + { + return true; + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::regionFunctionObject::regionFunctionObject diff --git a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H index c5ec22eb43..427aaa84d4 100644 --- a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H @@ -76,6 +76,32 @@ protected: Switch log_; + // Protected member functions + + //- Find field in the objectRegistry + template + bool foundObject(const word& fieldName) const; + + //- Lookup field from the objectRegistry + template + const ObjectType& lookupObject(const word& fieldName) const; + + //- Store the given field in the objectRegistry under the given name + template + bool store + ( + word& fieldName, + const tmp& 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 Member Functions @@ -132,6 +158,12 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#ifdef NoRepository + #include "regionFunctionObjectTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObjectTemplates.C b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C similarity index 75% rename from src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObjectTemplates.C rename to src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C index b3e07b2513..d85bc46a2c 100644 --- a/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObjectTemplates.C +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C @@ -23,36 +23,36 @@ License \*---------------------------------------------------------------------------*/ -#include "fvMeshFunctionObject.H" -#include "volFields.H" +#include "regionFunctionObject.H" +#include "objectRegistry.H" // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // -template -bool Foam::functionObjects::fvMeshFunctionObject::foundField +template +bool Foam::functionObjects::regionFunctionObject::foundObject ( const word& fieldName ) const { - return mesh_.foundObject(fieldName); + return obr_.foundObject(fieldName); } -template -const FieldType& Foam::functionObjects::fvMeshFunctionObject::lookupField +template +const ObjectType& Foam::functionObjects::regionFunctionObject::lookupObject ( const word& fieldName ) const { - return mesh_.lookupObject(fieldName); + return obr_.lookupObject(fieldName); } -template -bool Foam::functionObjects::fvMeshFunctionObject::store +template +bool Foam::functionObjects::regionFunctionObject::store ( word& fieldName, - const tmp& tfield, + const tmp& tfield, bool cacheable ) { @@ -71,12 +71,12 @@ bool Foam::functionObjects::fvMeshFunctionObject::store if ( fieldName.size() - && mesh_.foundObject(fieldName) + && obr_.foundObject(fieldName) ) { - const FieldType& field = + const ObjectType& field = ( - mesh_.lookupObject(fieldName) + obr_.lookupObject(fieldName) ); // If there is a result field already registered assign to the new @@ -84,11 +84,11 @@ bool Foam::functionObjects::fvMeshFunctionObject::store // the object registry if (&field != &tfield()) { - const_cast(field) = tfield; + const_cast(field) = tfield; } else { - mesh_.objectRegistry::store(tfield.ptr()); + obr_.objectRegistry::store(tfield.ptr()); } } else @@ -102,7 +102,7 @@ bool Foam::functionObjects::fvMeshFunctionObject::store fieldName = tfield().name(); } - mesh_.objectRegistry::store(tfield.ptr()); + obr_.objectRegistry::store(tfield.ptr()); } return true; diff --git a/src/finiteVolume/finiteVolume/fvc/fvcSurfaceIntegrate.H b/src/finiteVolume/finiteVolume/fvc/fvcSurfaceIntegrate.H index c3efda91c5..72a398cc21 100644 --- a/src/finiteVolume/finiteVolume/fvc/fvcSurfaceIntegrate.H +++ b/src/finiteVolume/finiteVolume/fvc/fvcSurfaceIntegrate.H @@ -37,6 +37,7 @@ SourceFiles #ifndef fvcSurfaceIntegrate_H #define fvcSurfaceIntegrate_H +#include "primitiveFieldsFwd.H" #include "volFieldsFwd.H" #include "surfaceFieldsFwd.H" diff --git a/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.C b/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.C index 57945b0246..f5e0b45852 100644 --- a/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.C +++ b/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.C @@ -38,59 +38,6 @@ namespace functionObjects } -// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // - -bool Foam::functionObjects::fvMeshFunctionObject::writeField -( - const word& fieldName -) -{ - if (mesh_.foundObject(fieldName)) - { - const regIOobject& field = mesh_.lookupObject(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(fieldName)) - { - const regIOobject& resultField = lookupField(fieldName); - - if (resultField.ownedByRegistry()) - { - return const_cast(resultField).checkOut(); - } - else - { - return false; - } - } - else - { - return true; - } -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::fvMeshFunctionObject::fvMeshFunctionObject diff --git a/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.H b/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.H index 78c259f0f7..6e2477fc47 100644 --- a/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.H +++ b/src/finiteVolume/fvMesh/fvMeshFunctionObject/fvMeshFunctionObject.H @@ -73,32 +73,6 @@ protected: const fvMesh& mesh_; - // Protected member functions - - //- Find field in the objectRegistry - template - bool foundField(const word& fieldName) const; - - //- Lookup field from the objectRegistry - template - const FieldType& lookupField(const word& fieldName) const; - - //- Store the given field in the objectRegistry under the given name - template - bool store - ( - word& fieldName, - const tmp& 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 Member Functions @@ -139,12 +113,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository - #include "fvMeshFunctionObjectTemplates.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/CourantNo/CourantNo.C b/src/postProcessing/functionObjects/field/CourantNo/CourantNo.C index 53cd86a606..31fa4f1916 100644 --- a/src/postProcessing/functionObjects/field/CourantNo/CourantNo.C +++ b/src/postProcessing/functionObjects/field/CourantNo/CourantNo.C @@ -68,10 +68,10 @@ Foam::functionObjects::CourantNo::byRho bool Foam::functionObjects::CourantNo::calc() { - if (foundField(phiName_)) + if (foundObject(phiName_)) { const surfaceScalarField& phi = - lookupField(phiName_); + lookupObject(phiName_); tmp Coi ( @@ -83,13 +83,13 @@ bool Foam::functionObjects::CourantNo::calc() ) ); - if (foundField(resultName_)) + if (foundObject(resultName_)) { volScalarField& Co ( const_cast ( - lookupField(resultName_) + lookupObject(resultName_) ) ); diff --git a/src/postProcessing/functionObjects/field/Lambda2/Lambda2.C b/src/postProcessing/functionObjects/field/Lambda2/Lambda2.C index 0023147876..0587d7be42 100644 --- a/src/postProcessing/functionObjects/field/Lambda2/Lambda2.C +++ b/src/postProcessing/functionObjects/field/Lambda2/Lambda2.C @@ -49,9 +49,9 @@ namespace functionObjects bool Foam::functionObjects::Lambda2::calc() { - if (foundField(fieldName_)) + if (foundObject(fieldName_)) { - const volVectorField& U = lookupField(fieldName_); + const volVectorField& U = lookupObject(fieldName_); const tmp tgradU(fvc::grad(U)); const volTensorField& gradU = tgradU(); diff --git a/src/postProcessing/functionObjects/field/MachNo/MachNo.C b/src/postProcessing/functionObjects/field/MachNo/MachNo.C index 1d08a64025..a362e508f1 100644 --- a/src/postProcessing/functionObjects/field/MachNo/MachNo.C +++ b/src/postProcessing/functionObjects/field/MachNo/MachNo.C @@ -51,14 +51,14 @@ bool Foam::functionObjects::MachNo::calc() { if ( - foundField(fieldName_) + foundObject(fieldName_) && mesh_.foundObject(fluidThermo::dictName) ) { const fluidThermo& thermo = mesh_.lookupObject(fluidThermo::dictName); - const volVectorField& U = lookupField(fieldName_); + const volVectorField& U = lookupObject(fieldName_); return store ( diff --git a/src/postProcessing/functionObjects/field/PecletNo/PecletNo.C b/src/postProcessing/functionObjects/field/PecletNo/PecletNo.C index 5e11a10ee4..69c4ee48ae 100644 --- a/src/postProcessing/functionObjects/field/PecletNo/PecletNo.C +++ b/src/postProcessing/functionObjects/field/PecletNo/PecletNo.C @@ -50,7 +50,7 @@ namespace functionObjects bool Foam::functionObjects::PecletNo::calc() { - if (foundField(phiName_)) + if (foundObject(phiName_)) { tmp nuEff ( diff --git a/src/postProcessing/functionObjects/field/Q/Q.C b/src/postProcessing/functionObjects/field/Q/Q.C index 043550caa6..b4fd7e48b1 100644 --- a/src/postProcessing/functionObjects/field/Q/Q.C +++ b/src/postProcessing/functionObjects/field/Q/Q.C @@ -49,9 +49,9 @@ namespace functionObjects bool Foam::functionObjects::Q::calc() { - if (foundField(fieldName_)) + if (foundObject(fieldName_)) { - const volVectorField& U = lookupField(fieldName_); + const volVectorField& U = lookupObject(fieldName_); const tmp tgradU(fvc::grad(U)); const volTensorField& gradU = tgradU(); diff --git a/src/postProcessing/functionObjects/field/blendingFactor/blendingFactorTemplates.C b/src/postProcessing/functionObjects/field/blendingFactor/blendingFactorTemplates.C index 6c51490edb..64f8df386b 100644 --- a/src/postProcessing/functionObjects/field/blendingFactor/blendingFactorTemplates.C +++ b/src/postProcessing/functionObjects/field/blendingFactor/blendingFactorTemplates.C @@ -34,17 +34,17 @@ bool Foam::functionObjects::blendingFactor::calcBF() { typedef GeometricField FieldType; - if (!foundField(fieldName_)) + if (!foundObject(fieldName_)) { return false; } - const FieldType& field = lookupField(fieldName_); + const FieldType& field = lookupObject(fieldName_); const word divScheme("div(" + phiName_ + ',' + fieldName_ + ')'); ITstream& its = mesh_.divScheme(divScheme); - const surfaceScalarField& phi = lookupField(phiName_); + const surfaceScalarField& phi = lookupObject(phiName_); tmp> cs = fv::convectionScheme::New(mesh_, phi, its); diff --git a/src/postProcessing/functionObjects/field/div/divTemplates.C b/src/postProcessing/functionObjects/field/div/divTemplates.C index fb204a4569..08d78e198f 100644 --- a/src/postProcessing/functionObjects/field/div/divTemplates.C +++ b/src/postProcessing/functionObjects/field/div/divTemplates.C @@ -30,12 +30,12 @@ License template bool Foam::functionObjects::div::calcDiv() { - if (foundField(fieldName_)) + if (foundObject(fieldName_)) { return store ( resultName_, - fvc::div(lookupField(fieldName_)) + fvc::div(lookupObject(fieldName_)) ); } else diff --git a/src/postProcessing/functionObjects/field/enstrophy/enstrophy.C b/src/postProcessing/functionObjects/field/enstrophy/enstrophy.C index 9370c668c9..6c62c7294a 100644 --- a/src/postProcessing/functionObjects/field/enstrophy/enstrophy.C +++ b/src/postProcessing/functionObjects/field/enstrophy/enstrophy.C @@ -49,12 +49,12 @@ namespace functionObjects bool Foam::functionObjects::enstrophy::calc() { - if (foundField(fieldName_)) + if (foundObject(fieldName_)) { return store ( resultName_, - 0.5*magSqr(fvc::curl(lookupField(fieldName_))) + 0.5*magSqr(fvc::curl(lookupObject(fieldName_))) ); } else diff --git a/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C b/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C index fef631eae1..1a529262a5 100644 --- a/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C +++ b/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C @@ -124,7 +124,7 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::write { forAll(fieldSet_, fieldi) { - fvMeshFunctionObject::writeField(transformFieldName(fieldSet_[fieldi])); + writeObject(transformFieldName(fieldSet_[fieldi])); } return true; diff --git a/src/postProcessing/functionObjects/field/fieldExpression/fieldExpression.C b/src/postProcessing/functionObjects/field/fieldExpression/fieldExpression.C index 868e0d78f5..61bc2c3417 100644 --- a/src/postProcessing/functionObjects/field/fieldExpression/fieldExpression.C +++ b/src/postProcessing/functionObjects/field/fieldExpression/fieldExpression.C @@ -24,6 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "fieldExpression.H" +#include "dictionary.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -112,13 +113,13 @@ bool Foam::functionObjects::fieldExpression::execute(const bool postProcess) bool Foam::functionObjects::fieldExpression::write(const bool postProcess) { - return writeField(resultName_); + return writeObject(resultName_); } bool Foam::functionObjects::fieldExpression::clear() { - return clearField(resultName_); + return clearObject(resultName_); } diff --git a/src/postProcessing/functionObjects/field/flowType/flowType.C b/src/postProcessing/functionObjects/field/flowType/flowType.C index 5193f3736c..a867c850fa 100644 --- a/src/postProcessing/functionObjects/field/flowType/flowType.C +++ b/src/postProcessing/functionObjects/field/flowType/flowType.C @@ -49,9 +49,9 @@ namespace functionObjects bool Foam::functionObjects::flowType::calc() { - if (foundField(fieldName_)) + if (foundObject(fieldName_)) { - const volVectorField& U = lookupField(fieldName_); + const volVectorField& U = lookupObject(fieldName_); const tmp tgradU(fvc::grad(U)); const volTensorField& gradU = tgradU(); diff --git a/src/postProcessing/functionObjects/field/grad/gradTemplates.C b/src/postProcessing/functionObjects/field/grad/gradTemplates.C index 1eeae18466..fb505bb8b6 100644 --- a/src/postProcessing/functionObjects/field/grad/gradTemplates.C +++ b/src/postProcessing/functionObjects/field/grad/gradTemplates.C @@ -33,21 +33,21 @@ bool Foam::functionObjects::grad::calcGrad() typedef GeometricField VolFieldType; typedef GeometricField SurfaceFieldType; - if (foundField(fieldName_)) + if (foundObject(fieldName_)) { return store ( resultName_, - fvc::grad(lookupField(fieldName_)), + fvc::grad(lookupObject(fieldName_)), true ); } - else if (foundField(fieldName_)) + else if (foundObject(fieldName_)) { return store ( resultName_, - fvc::grad(lookupField(fieldName_)), + fvc::grad(lookupObject(fieldName_)), true ); } diff --git a/src/postProcessing/functionObjects/field/mag/magTemplates.C b/src/postProcessing/functionObjects/field/mag/magTemplates.C index 8cb4debaa6..0b6035f0a0 100644 --- a/src/postProcessing/functionObjects/field/mag/magTemplates.C +++ b/src/postProcessing/functionObjects/field/mag/magTemplates.C @@ -34,20 +34,20 @@ bool Foam::functionObjects::mag::calcMag() typedef GeometricField VolFieldType; typedef GeometricField SurfaceFieldType; - if (foundField(fieldName_)) + if (foundObject(fieldName_)) { return store ( resultName_, - Foam::mag(lookupField(fieldName_)) + Foam::mag(lookupObject(fieldName_)) ); } - else if (foundField(fieldName_)) + else if (foundObject(fieldName_)) { return store ( resultName_, - Foam::mag(lookupField(fieldName_)) + Foam::mag(lookupObject(fieldName_)) ); } else diff --git a/src/postProcessing/functionObjects/field/pressure/pressure.C b/src/postProcessing/functionObjects/field/pressure/pressure.C index d2f854f181..ba33b99b49 100644 --- a/src/postProcessing/functionObjects/field/pressure/pressure.C +++ b/src/postProcessing/functionObjects/field/pressure/pressure.C @@ -87,7 +87,7 @@ Foam::tmp Foam::functionObjects::pressure::rhoScale { if (p.dimensions() == dimPressure) { - return lookupField(rhoName_)*tsf; + return lookupObject(rhoName_)*tsf; } else { @@ -122,7 +122,7 @@ Foam::tmp Foam::functionObjects::pressure::pDyn { return tp - + rhoScale(p, 0.5*magSqr(lookupField(UName_))); + + rhoScale(p, 0.5*magSqr(lookupObject(UName_))); } else { @@ -163,9 +163,9 @@ Foam::functionObjects::pressure::coeff bool Foam::functionObjects::pressure::calc() { - if (foundField(fieldName_)) + if (foundObject(fieldName_)) { - const volScalarField& p = lookupField(fieldName_); + const volScalarField& p = lookupObject(fieldName_); return store ( diff --git a/src/postProcessing/functionObjects/field/vorticity/vorticity.C b/src/postProcessing/functionObjects/field/vorticity/vorticity.C index b6c462e50f..6e0c1f6526 100644 --- a/src/postProcessing/functionObjects/field/vorticity/vorticity.C +++ b/src/postProcessing/functionObjects/field/vorticity/vorticity.C @@ -49,12 +49,12 @@ namespace functionObjects bool Foam::functionObjects::vorticity::calc() { - if (foundField(fieldName_)) + if (foundObject(fieldName_)) { return store ( resultName_, - fvc::curl(lookupField(fieldName_)) + fvc::curl(lookupObject(fieldName_)) ); } else