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.
This commit is contained in:
Will Bainbridge
2021-10-08 08:53:55 +01:00
parent 3a1897d0d8
commit 1a6b662b41
5 changed files with 73 additions and 209 deletions

View File

@ -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<fieldType>();
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<scalar>(ssf_);
interpolateFields<vector>(svf_);
interpolateFields<sphericalTensor>(sSpheretf_);
interpolateFields<symmTensor>(sSymmtf_);
interpolateFields<tensor>(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;
}
// ************************************************************************* //

View File

@ -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<Tuple2<word, word>> fieldSet_;
//- Locally constructed fields
PtrList<surfaceScalarField> ssf_;
PtrList<surfaceVectorField> svf_;
PtrList<surfaceSphericalTensorField> sSpheretf_;
PtrList<surfaceSymmTensorField> sSymmtf_;
PtrList<surfaceTensorField> stf_;
// Protected Member Functions
// Private Member Functions
//- Calculate the surface interpolation of the field and register the
// result
template<class Type>
void interpolateFields
(
PtrList<GeometricField<Type, fvsPatchField, surfaceMesh>>&
) 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;
};

View File

@ -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<class Type>
void Foam::functionObjects::surfaceInterpolate::interpolateFields
(
PtrList<GeometricField<Type, fvsPatchField, surfaceMesh>>& sflds
) const
bool Foam::functionObjects::surfaceInterpolate::calcSurfaceInterpolate()
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
// Convert field to map
HashTable<word> fieldMap(2*fieldSet_.size());
forAll(fieldSet_, i)
if (foundObject<VolField<Type>>(fieldName_))
{
fieldMap.insert(fieldSet_[i].first(), fieldSet_[i].second());
return store
(
resultName_,
linearInterpolate(lookupObject<VolField<Type>>(fieldName_))
);
}
HashTable<const VolFieldType*> flds(obr_.lookupClass<VolFieldType>());
forAllConstIter(typename HashTable<const VolFieldType*>, 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;
}
}