From 1a6b662b411df29620c774640abd8cc077e2f4db Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Fri, 8 Oct 2021 08:53:55 +0100 Subject: [PATCH] surfaceInterpolate: Made consistent with other function objects The surfaceInterpolate function object is now a field expression. This means it works in the same way as mag, grad, etc... It also now has a packaged configuration and has been included into the postProcessing test case. It can be used in the following ways. On the command line: postProcess -func "surfaceInterpolate(rho, result=rhof)" rhoPimpleFoam -postProcess -func "surfaceInterpolate(thermo:rho, result=rhof)" In the controlDict: functions { #includeFunc surfaceInterpolate(rho, result=rhof) } By running: foamGet surfaceInterpolate Then editing the resulting system/surfaceInterpolate file and then running postProcess or adding an #includeFunc entry without arguments. --- .../postProcessing/fields/surfaceInterpolate | 21 ++++ .../surfaceInterpolate/surfaceInterpolate.C | 105 ++++-------------- .../surfaceInterpolate/surfaceInterpolate.H | 98 +++------------- .../surfaceInterpolateTemplates.C | 56 ++-------- .../postProcessing/channel/system/controlDict | 2 + 5 files changed, 73 insertions(+), 209 deletions(-) create mode 100644 etc/caseDicts/postProcessing/fields/surfaceInterpolate diff --git a/etc/caseDicts/postProcessing/fields/surfaceInterpolate b/etc/caseDicts/postProcessing/fields/surfaceInterpolate new file mode 100644 index 0000000000..02c7ce59ae --- /dev/null +++ b/etc/caseDicts/postProcessing/fields/surfaceInterpolate @@ -0,0 +1,21 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + Calculates the surface interpolation of a field. + +\*---------------------------------------------------------------------------*/ + +type surfaceInterpolate; +libs ("libfieldFunctionObjects.so"); + +field ; + +executeControl writeTime; +writeControl writeTime; + +// ************************************************************************* // diff --git a/src/functionObjects/field/surfaceInterpolate/surfaceInterpolate.C b/src/functionObjects/field/surfaceInterpolate/surfaceInterpolate.C index e53283f98c..8a2a797088 100644 --- a/src/functionObjects/field/surfaceInterpolate/surfaceInterpolate.C +++ b/src/functionObjects/field/surfaceInterpolate/surfaceInterpolate.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,7 +24,6 @@ License \*---------------------------------------------------------------------------*/ #include "surfaceInterpolate.H" -#include "surfaceFields.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -34,17 +33,30 @@ namespace Foam namespace functionObjects { defineTypeNameAndDebug(surfaceInterpolate, 0); - - addToRunTimeSelectionTable - ( - functionObject, - surfaceInterpolate, - dictionary - ); + addToRunTimeSelectionTable(functionObject, surfaceInterpolate, dictionary); } } +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::functionObjects::surfaceInterpolate::calc() +{ + bool processed = false; + + #define processType(fieldType, none) \ + processed = processed || calcSurfaceInterpolate(); + FOR_ALL_FIELD_TYPES(processType) + + if (!processed) + { + cannotFindObject(fieldName_); + } + + return processed; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::surfaceInterpolate::surfaceInterpolate @@ -54,11 +66,8 @@ Foam::functionObjects::surfaceInterpolate::surfaceInterpolate const dictionary& dict ) : - fvMeshFunctionObject(name, runTime, dict), - fieldSet_() -{ - read(dict); -} + fieldExpression(name, runTime, dict, typeName) +{} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // @@ -67,72 +76,4 @@ Foam::functionObjects::surfaceInterpolate::~surfaceInterpolate() {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -bool Foam::functionObjects::surfaceInterpolate::read -( - const dictionary& dict -) -{ - dict.lookup("fields") >> fieldSet_; - - return true; -} - - -bool Foam::functionObjects::surfaceInterpolate::execute() -{ - Info<< type() << " " << name() << " write:" << nl; - - // Clear out any previously loaded fields - ssf_.clear(); - svf_.clear(); - sSpheretf_.clear(); - sSymmtf_.clear(); - stf_.clear(); - - interpolateFields(ssf_); - interpolateFields(svf_); - interpolateFields(sSpheretf_); - interpolateFields(sSymmtf_); - interpolateFields(stf_); - - Info<< endl; - - return true; -} - - -bool Foam::functionObjects::surfaceInterpolate::write() -{ - Info<< type() << " " << name() << " write:" << nl; - - Info<< " Writing interpolated surface fields to " - << obr_.time().timeName() << endl; - - forAll(ssf_, i) - { - ssf_[i].write(); - } - forAll(svf_, i) - { - svf_[i].write(); - } - forAll(sSpheretf_, i) - { - sSpheretf_[i].write(); - } - forAll(sSymmtf_, i) - { - sSymmtf_[i].write(); - } - forAll(stf_, i) - { - stf_[i].write(); - } - - return true; -} - - // ************************************************************************* // diff --git a/src/functionObjects/field/surfaceInterpolate/surfaceInterpolate.H b/src/functionObjects/field/surfaceInterpolate/surfaceInterpolate.H index 0548bd9bdd..cf0740dd8d 100644 --- a/src/functionObjects/field/surfaceInterpolate/surfaceInterpolate.H +++ b/src/functionObjects/field/surfaceInterpolate/surfaceInterpolate.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,37 +25,13 @@ Class Foam::functionObjects::surfaceInterpolate Description - Linearly interpolates volume fields to generate surface fields. + Calculates the surface interpolation of a field. - Fields are stored - - every time step the field is updated with new values - - at output it writes the fields - - This functionObject can either be used - - to calculate a new field as a post-processing step or - - since the fields are registered, used in another functionObject - - Example of function object specification: - \verbatim - surfaceInterpolate1 - { - type surfaceInterpolate; - libs ("libfieldFunctionObjects.so"); - ... - fields ((p pInterp)(U UInterp)); - } - \endverbatim - -Usage - \table - Property | Description | Required | Default value - type | type name: surfaceInterpolate | yes | - fields | list of fields with corresponding output field names | yes | - \endtable + The operation can be applied to any volume field and will generate a + surface field. See also Foam::functionObjects::fvMeshFunctionObject - Foam::functionObjects::timeControl SourceFiles surfaceInterpolate.C @@ -65,53 +41,33 @@ SourceFiles #ifndef functionObjects_surfaceInterpolate_H #define functionObjects_surfaceInterpolate_H -#include "fvMeshFunctionObject.H" -#include "surfaceFieldsFwd.H" -#include "Tuple2.H" +#include "fieldExpression.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { - -// Forward declaration of classes -class objectRegistry; -class dictionary; -class mapPolyMesh; - namespace functionObjects { /*---------------------------------------------------------------------------*\ - Class surfaceInterpolate Declaration + Class surfaceInterpolate Declaration \*---------------------------------------------------------------------------*/ class surfaceInterpolate : - public fvMeshFunctionObject + public fieldExpression { -protected: - - // Protected data - - //- Fields to process - List> fieldSet_; - - //- Locally constructed fields - PtrList ssf_; - PtrList svf_; - PtrList sSpheretf_; - PtrList sSymmtf_; - PtrList stf_; - - - // Protected Member Functions + // Private Member Functions + //- Calculate the surface interpolation of the field and register the + // result template - void interpolateFields - ( - PtrList>& - ) const; + bool calcSurfaceInterpolate(); + + //- Calculate the surface interpolation of the field and return true if + // successful + virtual bool calc(); public: @@ -122,8 +78,7 @@ public: // Constructors - //- Construct for given objectRegistry and dictionary. - // Allow the possibility to load fields from files + //- Construct from Time and dictionary surfaceInterpolate ( const word& name, @@ -131,30 +86,9 @@ public: const dictionary& dict ); - //- Disallow default bitwise copy construction - surfaceInterpolate(const surfaceInterpolate&) = delete; - //- Destructor virtual ~surfaceInterpolate(); - - - // Member Functions - - //- Read the controls - virtual bool read(const dictionary&); - - //- Calculate the interpolated fields - virtual bool execute(); - - //- Write the interpolated fields - virtual bool write(); - - - // Member Operators - - //- Disallow default bitwise assignment - void operator=(const surfaceInterpolate&) = delete; }; diff --git a/src/functionObjects/field/surfaceInterpolate/surfaceInterpolateTemplates.C b/src/functionObjects/field/surfaceInterpolate/surfaceInterpolateTemplates.C index 0864f76b96..c210cbe3ec 100644 --- a/src/functionObjects/field/surfaceInterpolate/surfaceInterpolateTemplates.C +++ b/src/functionObjects/field/surfaceInterpolate/surfaceInterpolateTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,58 +24,24 @@ License \*---------------------------------------------------------------------------*/ #include "surfaceInterpolate.H" -#include "volFields.H" #include "linear.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template -void Foam::functionObjects::surfaceInterpolate::interpolateFields -( - PtrList>& sflds -) const +bool Foam::functionObjects::surfaceInterpolate::calcSurfaceInterpolate() { - typedef GeometricField VolFieldType; - typedef GeometricField SurfaceFieldType; - - // Convert field to map - HashTable fieldMap(2*fieldSet_.size()); - forAll(fieldSet_, i) + if (foundObject>(fieldName_)) { - fieldMap.insert(fieldSet_[i].first(), fieldSet_[i].second()); + return store + ( + resultName_, + linearInterpolate(lookupObject>(fieldName_)) + ); } - - - HashTable flds(obr_.lookupClass()); - - forAllConstIter(typename HashTable, flds, iter) + else { - const VolFieldType& fld = *iter(); - - if (fieldMap.found(fld.name())) - { - // const word sName = "interpolate(" + fld.name() + ')'; - const word& sName = fieldMap[fld.name()]; - - if (obr_.found(sName)) - { - Info<< " surface field " << sName << " already exists" - << endl; - } - else - { - label sz = sflds.size(); - sflds.setSize(sz+1); - sflds.set - ( - sz, - new SurfaceFieldType(sName, linearInterpolate(fld)) - ); - - Info<< " interpolated " << fld.name() << " to create " - << sflds[sz].name() << endl; - } - } + return false; } } diff --git a/test/postProcessing/channel/system/controlDict b/test/postProcessing/channel/system/controlDict index 813a1acee6..a4bd4cd5c1 100644 --- a/test/postProcessing/channel/system/controlDict +++ b/test/postProcessing/channel/system/controlDict @@ -124,6 +124,8 @@ fieldsFunctions #includeFunc streamFunction + #includeFunc surfaceInterpolate(rho, result=rhof) + #includeFunc totalEnthalpy #includeFunc turbulenceFields(nuEff, R, devTau)