SampleFunction1.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) 2021 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 "SampleFunction1.H"
29 #include "volFields.H"
30 #include "interpolation.H"
31 #include "pointIOField.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 template<class Type>
37 {
38  const polyMesh& mesh = this->template mesh<polyMesh>();
39 
40  const auto& points = static_cast<const pointIOField&>(mesh.points());
41 
42  if (pointEventNo_ < points.eventNo())
43  {
44  pointEventNo_ = points.eventNo();
45 
46  celli_ = this->template mesh<fvMesh>().findCell(position_);
47 
48  if (!returnReduce(celli_ != -1, orOp<bool>()))
49  {
51  << "Sample cell could not be found at position "
52  << position_ << nl
53  << exit(FatalError);
54  }
55 
56  if (debug)
57  {
58  Pout<< "Position: " << position_
59  << " celli:" << celli_
60  << " eventNo:" << pointEventNo_
61  << " points eventNo:" << points.eventNo()
62  << endl;
63  }
64  }
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69 
70 template<class Type>
72 (
73  const word& entryName,
74  const dictionary& dict,
75  const objectRegistry* obrPtr
76 )
77 :
78  Function1<Type>(entryName, dict, obrPtr),
79  fieldName_(dict.get<word>("field")),
80  position_(dict.get<point>("position")),
81  interpolationScheme_
82  (
83  dict.getOrDefault<word>("interpolationScheme", "cell")
84  ),
85  celli_(-1),
86  pointEventNo_(-1)
87 {}
88 
89 
90 template<class Type>
92 :
93  Function1<Type>(s),
94  fieldName_(s.fieldName_),
95  position_(s.position_),
96  interpolationScheme_(s.interpolationScheme_),
97  celli_(s.celli_),
98  pointEventNo_(s.pointEventNo_)
99 {}
100 
101 
102 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
103 
104 template<class Type>
106 {
107  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
108 
109  const auto& mesh = this->template mesh<fvMesh>();
110 
111  const auto* fieldPtr = mesh.template cfindObject<VolFieldType>(fieldName_);
112 
113  if (!fieldPtr)
114  {
116  << "Unable to find field " << fieldName_ << " on the mesh database"
117  << ". Valid " << VolFieldType::typeName << " fields are:"
118  << mesh.names(VolFieldType::typeName)
119  << exit(FatalError);
120  }
121 
122 
123  // Might trigger parallel comms (e.g. volPointInterpolation, if
124  // result is not yet cached) so have all processors do it
125  autoPtr<interpolation<Type>> interpolator
126  (
127  interpolation<Type>::New(interpolationScheme_, *fieldPtr)
128  );
129 
130  Type result = pTraits<Type>::min;
131 
132  setSampleCell();
133 
134  if (celli_ != -1)
135  {
136  result = interpolator().interpolate(position_, celli_, -1);
137  }
138 
139  reduce(result, maxOp<Type>());
140 
141  DebugInfo << "sampled value: " << result << endl;
142 
143  return result;
144 }
145 
146 
147 template<class Type>
149 (
150  const scalar x1,
151  const scalar x2
152 ) const
153 {
155 
156  return Zero;
157 }
158 
159 
160 template<class Type>
162 {
163  os.writeEntry("field", fieldName_);
164  os.writeEntry("position", position_);
165 
166  os.writeEntryIfDifferent<word>
167  (
168  "interpolationScheme", "cell", interpolationScheme_
169  );
170 }
171 
172 
173 template<class Type>
175 {
177  os.endEntry();
178 
179  os.beginBlock(word(this->name() + "Coeffs"));
180  writeEntries(os);
181  os.endBlock();
182 }
183 
184 
185 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::Function1Types::Sample::Sample
Sample(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
Definition: SampleFunction1.C:72
volFields.H
Foam::maxOp
Definition: ops.H:223
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::Function1Types::Sample::integrate
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: SampleFunction1.C:149
pointIOField.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
interpolation.H
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
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::pointIOField
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:44
Foam::Function1Types::Sample::value
virtual Type value(const scalar x) const
Return Sample value.
Definition: SampleFunction1.C:105
Foam::Function1::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:174
Foam::interpolation
Abstract base class for interpolation.
Definition: mappedPatchFieldBase.H:96
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::Function1Types::Sample::writeEntries
void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: SampleFunction1.C:161
SampleFunction1.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:382
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Vector< scalar >
Foam::Function1Types::Sample::writeData
virtual void writeData(Ostream &os) const
Write as primitive (inline) format.
Definition: SampleFunction1.C:174
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
points
const pointField & points
Definition: gmvOutputHeader.H:1
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::Function1Types::Sample
Definition: SampleFunction1.H:65
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeometricField< Type, fvPatchField, volMesh >