ENH: reference function object - retrieve reference using Function1

Note: previous behaviour to set the reference to a cell value can be recovered
by using the new 'sample' Function1
This commit is contained in:
Andrew Heather
2021-10-13 21:26:02 +01:00
committed by Mark Olesen
parent 70b55be684
commit 2c2310dc17
3 changed files with 25 additions and 73 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -68,12 +68,8 @@ Foam::functionObjects::reference::reference
) )
: :
fieldExpression(name, runTime, dict), fieldExpression(name, runTime, dict),
positionIsSet_(false),
celli_(-1),
interpolationScheme_("cell"),
scale_(1),
localDict_(dict), localDict_(dict),
position_(Zero) scale_(1)
{ {
read(dict); read(dict);
@ -98,27 +94,6 @@ bool Foam::functionObjects::reference::read(const dictionary& dict)
Log << " scale: " << scale_ << nl; Log << " scale: " << scale_ << nl;
} }
if (dict.readIfPresent("position", position_))
{
Log << " sample position: " << position_ << nl;
positionIsSet_ = true;
celli_ = mesh_.findCell(position_);
label celli = returnReduce(celli_, maxOp<label>());
if (celli == -1)
{
FatalIOErrorInFunction(dict)
<< "Sample cell could not be found at position "
<< position_ << exit(FatalIOError);
}
interpolationScheme_ =
dict.getOrDefault<word>("interpolationScheme", "cell");
}
Log << endl; Log << endl;
return true; return true;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -31,7 +31,7 @@ Group
Description Description
Computes a field whose values are offset to a reference Computes a field whose values are offset to a reference
value obtained by sampling the field at a user-specified location. value obtained by from a Function1.
The field values are calculated using: The field values are calculated using:
@ -44,7 +44,7 @@ Description
r_c | field values at cell r_c | field values at cell
s | optional scale factor (default = 1) s | optional scale factor (default = 1)
f_{c}(t) | current field values at cell at this time f_{c}(t) | current field values at cell at this time
f_p | field value at position f_p | reference value
f_{off} | offset field value (default = 0) f_{off} | offset field value (default = 0)
\endvartable \endvartable
@ -72,11 +72,12 @@ Usage
// Mandatory (inherited) entry (runtime modifiable) // Mandatory (inherited) entry (runtime modifiable)
field <field>; field <field>;
// Reference value
refValue <Function1>;
// Optional entries (runtime modifiable) // Optional entries (runtime modifiable)
position (0 0 0);
scale 1.0; scale 1.0;
offset 0.0; offset 0.0;
interpolationScheme cell;
// Optional (inherited) entries // Optional (inherited) entries
... ...
@ -88,10 +89,9 @@ Usage
Property | Description | Type | Req'd | Dflt Property | Description | Type | Req'd | Dflt
type | Type name: reference | word | yes | - type | Type name: reference | word | yes | -
field | Name of the operand field | word | yes | - field | Name of the operand field | word | yes | -
position | Position to sample | vector | no | \<not used\> refValue | Function1 reference value | Function1 | yes | -
scale | Scale value | scalar | no | 1.0 offset | Offset value | type-value | no | zero
offset | Offset value | scalar | no | 0.0 scale | Scale factor | scalar | no | 1
interpolationScheme | Sampling scheme | word | no | cell
\endtable \endtable
The inherited entries are elaborated in: The inherited entries are elaborated in:
@ -104,6 +104,7 @@ See also
- Foam::functionObject - Foam::functionObject
- Foam::functionObjects::fvMeshFunctionObject - Foam::functionObjects::fvMeshFunctionObject
- Foam::functionObjects::fieldExpression - Foam::functionObjects::fieldExpression
- Foam::Function1
- ExtendedCodeGuide::functionObjects::field::reference - ExtendedCodeGuide::functionObjects::field::reference
SourceFiles SourceFiles
@ -135,23 +136,11 @@ class reference
{ {
// Private Data // Private Data
//- Flag to indicate that the position is set
bool positionIsSet_;
//- Sample cell
label celli_;
//- Interpolation scheme
word interpolationScheme_;
//- Scale factor
scalar scale_;
//- Local copy of dictionary used for construction //- Local copy of dictionary used for construction
dictionary localDict_; dictionary localDict_;
//- Sample location //- Scale factor
point position_; scalar scale_;
// Private Member Functions // Private Member Functions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "interpolation.H" #include "Function1.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -40,36 +40,24 @@ bool Foam::functionObjects::reference::calcType()
{ {
const VolFieldType& vf = *vfPtr; const VolFieldType& vf = *vfPtr;
// non-mandatory
dimensioned<Type> offset("offset", vf.dimensions(), Zero, localDict_); dimensioned<Type> offset("offset", vf.dimensions(), Zero, localDict_);
dimensioned<Type> cellValue("value", vf.dimensions(), Zero); dimensioned<Type> refValue("refValue", vf.dimensions(), Zero);
if (positionIsSet_) autoPtr<Function1<Type>> valuePtr
{
cellValue.value() = -pTraits<Type>::one*GREAT;
// Might trigger parallel comms (e.g. volPointInterpolation, if
// result is not yet cached) so have all processors do it
autoPtr<interpolation<Type>> interpolator
( (
interpolation<Type>::New(interpolationScheme_, vf) Function1<Type>::New("refValue", localDict_, &mesh_)
); );
if (celli_ != -1) refValue.value() = valuePtr->value(this->time().value());
{
cellValue.value() =
interpolator().interpolate(position_, celli_, -1);
}
reduce(cellValue.value(), maxOp<Type>()); Info<< " Reference value: " << refValue.value() << endl;
Log << " sampled value: " << cellValue.value() << endl;
}
return store return store
( (
resultName_, resultName_,
scale_*(vf - cellValue + offset) scale_*(vf - refValue + offset)
); );
} }