Skip to content
Snippets Groups Projects
Commit 2c2310dc authored by Andrew Heather's avatar Andrew Heather Committed by Mark OLESEN
Browse files

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
parent 70b55be6
Branches
Tags
1 merge request!499Function1 objectRegistry access
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -68,12 +68,8 @@ Foam::functionObjects::reference::reference
)
:
fieldExpression(name, runTime, dict),
positionIsSet_(false),
celli_(-1),
interpolationScheme_("cell"),
scale_(1),
localDict_(dict),
position_(Zero)
scale_(1)
{
read(dict);
......@@ -98,27 +94,6 @@ bool Foam::functionObjects::reference::read(const dictionary& dict)
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;
return true;
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -31,7 +31,7 @@ Group
Description
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:
......@@ -44,7 +44,7 @@ Description
r_c | field values at cell
s | optional scale factor (default = 1)
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)
\endvartable
......@@ -72,11 +72,12 @@ Usage
// Mandatory (inherited) entry (runtime modifiable)
field <field>;
// Reference value
refValue <Function1>;
// Optional entries (runtime modifiable)
position (0 0 0);
scale 1.0;
offset 0.0;
interpolationScheme cell;
// Optional (inherited) entries
...
......@@ -88,10 +89,9 @@ Usage
Property | Description | Type | Req'd | Dflt
type | Type name: reference | word | yes | -
field | Name of the operand field | word | yes | -
position | Position to sample | vector | no | \<not used\>
scale | Scale value | scalar | no | 1.0
offset | Offset value | scalar | no | 0.0
interpolationScheme | Sampling scheme | word | no | cell
refValue | Function1 reference value | Function1 | yes | -
offset | Offset value | type-value | no | zero
scale | Scale factor | scalar | no | 1
\endtable
The inherited entries are elaborated in:
......@@ -104,6 +104,7 @@ See also
- Foam::functionObject
- Foam::functionObjects::fvMeshFunctionObject
- Foam::functionObjects::fieldExpression
- Foam::Function1
- ExtendedCodeGuide::functionObjects::field::reference
SourceFiles
......@@ -135,23 +136,11 @@ class reference
{
// 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
dictionary localDict_;
//- Sample location
point position_;
//- Scale factor
scalar scale_;
// Private Member Functions
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -25,7 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "interpolation.H"
#include "Function1.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -40,36 +40,24 @@ bool Foam::functionObjects::reference::calcType()
{
const VolFieldType& vf = *vfPtr;
// non-mandatory
dimensioned<Type> offset("offset", vf.dimensions(), Zero, localDict_);
dimensioned<Type> cellValue("value", vf.dimensions(), Zero);
dimensioned<Type> refValue("refValue", vf.dimensions(), Zero);
if (positionIsSet_)
{
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)
);
if (celli_ != -1)
{
cellValue.value() =
interpolator().interpolate(position_, celli_, -1);
}
autoPtr<Function1<Type>> valuePtr
(
Function1<Type>::New("refValue", localDict_, &mesh_)
);
reduce(cellValue.value(), maxOp<Type>());
refValue.value() = valuePtr->value(this->time().value());
Log << " sampled value: " << cellValue.value() << endl;
}
Info<< " Reference value: " << refValue.value() << endl;
return store
(
resultName_,
scale_*(vf - cellValue + offset)
scale_*(vf - refValue + offset)
);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment