Loading...
Searching...
No Matches
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>
36void Foam::Function1Types::Sample<Type>::setSampleCell() const
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 (returnReduceAnd(celli_ < 0))
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>
105Type Foam::Function1Types::Sample<Type>::value(const scalar x) const
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>
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// ************************************************************************* //
static const char *const typeName
Typename for Field.
Definition Field.H:93
virtual void writeData(Ostream &os) const
Write as primitive (inline) format.
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
virtual Type value(const scalar x) const
Return Sample value.
Sample(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
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:92
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition Function1.C:156
Function1(const word &entryName, const objectRegistry *obrPtr=nullptr)
Construct from entry name.
Definition Function1.C:31
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const MeshType & mesh(const word &regionName=word::null) const
Return the mesh database if this Function1 was created using a mesh.
static autoPtr< interpolation< Type > > New(const word &interpolationType, const GeometricField< Type, fvPatchField, volMesh > &psi)
Return a reference to the specified interpolation scheme.
Registry of regIOobjects.
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition error.H:688
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
auto & name
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.
vectorIOField pointIOField
pointIOField is a vectorIOField.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
vector point
Point is a vector.
Definition point.H:37
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict