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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
35template<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_ = mesh.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
70template<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
90template<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
104template<class Type>
106{
107 const auto& mesh = this->template mesh<fvMesh>();
108
109 const auto* fieldPtr =
110 mesh.template cfindObject<VolumeField<Type>>(fieldName_);
111
112 if (!fieldPtr)
113 {
115 << "Unable to find field " << fieldName_ << " on the mesh database"
116 << ". Valid " << VolumeField<Type>::typeName << " fields are:"
117 << mesh.template sortedNames<VolumeField<Type>>()
118 << exit(FatalError);
119 }
120
121
122 // Might trigger parallel comms (e.g. volPointInterpolation, if
123 // result is not yet cached) so have all processors do it
124 autoPtr<interpolation<Type>> interpolator
125 (
126 interpolation<Type>::New(interpolationScheme_, *fieldPtr)
127 );
128
129 Type result = pTraits<Type>::min;
130
131 setSampleCell();
132
133 if (celli_ != -1)
134 {
135 result = interpolator().interpolate(position_, celli_, -1);
136 }
137
138 reduce(result, maxOp<Type>());
139
140 DebugInfo << "sampled value: " << result << endl;
141
142 return result;
143}
144
145
146template<class Type>
148(
149 const scalar x1,
150 const scalar x2
151) const
152{
154
155 return Zero;
156}
157
158
159template<class Type>
161{
162 os.writeEntry("field", fieldName_);
163 os.writeEntry("position", position_);
164
165 os.writeEntryIfDifferent<word>
166 (
167 "interpolationScheme", "cell", interpolationScheme_
168 );
169}
170
171
172template<class Type>
174{
176 os.endEntry();
177
178 os.beginBlock(word(this->name() + "Coeffs"));
179 writeEntries(os);
180 os.endBlock();
181}
182
183
184// ************************************************************************* //
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:96
Generic GeometricField class.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base class for volume field interpolation.
Definition: interpolation.H:60
Registry of regIOobjects.
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
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))
#define DebugInfo
Report an information message using Foam::Info.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:44
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict