referenceTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2018-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "interpolation.H"
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
32 template<class Type>
33 bool Foam::functionObjects::reference::calcType()
34 {
35  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
36 
37  const VolFieldType* vfPtr = findObject<VolFieldType>(fieldName_);
38 
39  if (vfPtr)
40  {
41  const VolFieldType& vf = *vfPtr;
42 
43  dimensioned<Type> offset("offset", vf.dimensions(), Zero, localDict_);
44 
45  dimensioned<Type> cellValue("value", vf.dimensions(), Zero);
46 
47  if (positionIsSet_)
48  {
49  cellValue.value() = -pTraits<Type>::one*GREAT;
50 
51  // Might trigger parallel comms (e.g. volPointInterpolation, if
52  // result is not yet cached) so have all processors do it
53  autoPtr<interpolation<Type>> interpolator
54  (
55  interpolation<Type>::New(interpolationScheme_, vf)
56  );
57 
58  if (celli_ != -1)
59  {
60  cellValue.value() =
61  interpolator().interpolate(position_, celli_, -1);
62  }
63 
64  reduce(cellValue.value(), maxOp<Type>());
65 
66  Log << " sampled value: " << cellValue.value() << endl;
67  }
68 
69  return store
70  (
72  scale_*(vf - cellValue + offset)
73  );
74  }
75 
76  return false;
77 }
78 
79 
80 // ************************************************************************* //
Log
#define Log
Definition: PDRblock.C:34
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
interpolation.H
Foam::functionObjects::regionFunctionObject::store
bool store(word &fieldName, const tmp< ObjectType > &tfield, bool cacheable=false)
Store the field in the (sub) objectRegistry under the given name.
Definition: regionFunctionObjectTemplates.C:107
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::interpolation::New
static autoPtr< interpolation< Type > > New(const word &interpolationType, const GeometricField< Type, fvPatchField, volMesh > &psi)
Return a reference to the specified interpolation scheme.
Definition: interpolationNew.C:36
Foam::functionObjects::fieldExpression::fieldName_
word fieldName_
Name of field to process.
Definition: fieldExpression.H:112
Foam::functionObjects::fieldExpression::resultName_
word resultName_
Name of result field.
Definition: fieldExpression.H:115