diff --git a/src/functionObjects/field/reference/reference.C b/src/functionObjects/field/reference/reference.C index d9177443de5987606a787b08a9ec5542dcabeda9..e3e4168337de05da87a48a9102f249f30fbb1e6c 100644 --- a/src/functionObjects/field/reference/reference.C +++ b/src/functionObjects/field/reference/reference.C @@ -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; diff --git a/src/functionObjects/field/reference/reference.H b/src/functionObjects/field/reference/reference.H index 1c35615bffc48b7033b568942e5dc79c4d3c816e..f3c42ed8b1f6fd94382efd839336c4185899b40d 100644 --- a/src/functionObjects/field/reference/reference.H +++ b/src/functionObjects/field/reference/reference.H @@ -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 diff --git a/src/functionObjects/field/reference/referenceTemplates.C b/src/functionObjects/field/reference/referenceTemplates.C index cda6bc56d08c976e3f48dc89b2a4f4be46054a76..500507023ccf310de1e55b9bfd064fbf28762638 100644 --- a/src/functionObjects/field/reference/referenceTemplates.C +++ b/src/functionObjects/field/reference/referenceTemplates.C @@ -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) ); }