volumeExprDriver.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) 2019-2021 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 "volumeExprDriver.H"
29#include "volumeExprScanner.H"
30#include "error.H"
31#include "fvPatch.H"
32#include "fvMesh.H"
33#include "className.H"
35
36// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37
38namespace Foam
39{
40namespace expressions
41{
42namespace volumeExpr
43{
44
46
48(
52 volume
53);
54
56(
59 idName,
60 volume
61);
62
64(
68 internalField
69);
70
72(
75 idName,
76 internalField
77);
78
79} // End namespace volumeExpr
80} // End namespace expressions
81} // End namespace Foam
82
83
84// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
85
87(
88 const fvMesh& mesh,
89 const dictionary& dict
90)
91:
92 parsing::genericRagelLemonDriver(),
93 expressions::fvExprDriver(dict),
94 mesh_(mesh),
95 resultType_(),
96 isLogical_(false),
97 hasDimensions_(false),
98 fieldGeoType_(NO_DATA),
99 resultDimensions_()
100{
101 resetTimeReference(nullptr);
103}
104
105
107(
108 const fvMesh& mesh,
109 const parseDriver& rhs,
110 const dictionary& dict
111)
112:
113 parsing::genericRagelLemonDriver(),
114 expressions::fvExprDriver(rhs, dict),
115 mesh_(mesh),
116 resultType_(),
117 isLogical_(false),
118 hasDimensions_(false),
119 fieldGeoType_(NO_DATA),
120 resultDimensions_()
121{
122 resetTimeReference(nullptr);
124}
125
126
128(
129 const word& meshName,
130 const fvMesh& mesh
131)
132:
134{
135 //?? Info<< "Warn that meshName is ignored?" << nl;
136}
137
138
140(
141 const dictionary& dict,
142 const fvMesh& mesh
143)
144:
145 parsing::genericRagelLemonDriver(),
146 expressions::fvExprDriver(dict),
147 mesh_(mesh),
148 resultType_(),
149 isLogical_(false),
150 fieldGeoType_(NO_DATA),
151 resultDimensions_()
152{
153 resetTimeReference(nullptr);
155}
156
157
158// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
159
161(
162 const dictionary& dict
163)
164{
165 expressions::fvExprDriver::readDict(dict);
166
167 resultDimensions_.clear(); // Avoid stickiness
168
169 hasDimensions_ = resultDimensions_.readEntry
170 (
171 "dimensions",
172 dict,
173 false // mandatory=false
174 );
175
176 return true;
177}
178
179
180// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
181
183(
184 const std::string& expr,
185 size_t pos,
186 size_t len
187)
188{
189 scanner scan(this->debugScanner());
190
191 scan.process(expr, pos, len, *this);
192
193 return 0;
194}
195
196
198{
199 resultField_.reset(nullptr);
200
201 // Characteristics
202 resultType_.clear();
203 isLogical_ = false;
204 fieldGeoType_ = NO_DATA;
205}
206
207
210{
211 const auto* regIOobjectPtr = resultField_.get();
212
213 if (!regIOobjectPtr)
214 {
215 return nullptr;
216 }
217
219
220 switch (fieldGeoType_)
221 {
222 #undef doLocalCode
223 #define doLocalCode(GeoField) \
224 { \
225 const auto* ptr = dynamic_cast<const GeoField*>(regIOobjectPtr); \
226 typedef typename GeoField::value_type Type; \
227 \
228 if (ptr) \
229 { \
230 zField.reset \
231 ( \
232 GeoField::New \
233 ( \
234 word(pTraits<Type>::typeName) + word("(zero)"), \
235 (*ptr).mesh(), \
236 dimensioned<Type>(Zero), \
237 /* zeroGradient (volume) or calculated (other) */ \
238 defaultBoundaryType(*ptr) \
239 ).ptr() \
240 ); \
241 break; \
242 } \
243 }
244
246 {
252 break;
253 }
255 {
261 break;
262 }
264 {
270 break;
271 }
272 default: break;
273 #undef doLocalCode
274 }
275
276 // if (!zField)
277 // {
278 // // Report
279 // }
280
281 return zField;
282}
283
284
285// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
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
void resetDb(const objectRegistry *obrPtr=nullptr)
Reset the objectRegistry (for functions)
Definition: exprDriver.C:142
void resetTimeReference(const TimeState *ts)
Reset the time-state reference.
Definition: exprDriver.C:130
Base driver for parsing value expressions associated with an fvMesh.
Definition: fvExprDriver.H:139
Driver for volume, surface, point field expressions.
const fvMesh & mesh_
The referenced mesh.
autoPtr< regIOobject > dupZeroField() const
A zero-initialized field with the same type as the result field.
virtual unsigned parse(const std::string &expr, size_t pos=0, size_t len=std::string::npos)
Execute the parser.
virtual bool readDict(const dictionary &dict)
Read variables, tables etc.
void clearField()
Clear out local copies of the field.
Ragel lexer/scanner interface for volume expressions.
bool process(const std::string &str, size_t pos, size_t len, parseDriver &driver_)
Evaluate sub-string.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:302
A class for handling words, derived from Foam::string.
Definition: word.H:68
Macro definitions for declaring ClassName(), NamespaceName(), etc.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
@ VOLUME_DATA
Volume data.
Namespace for OpenFOAM.
dimensionedScalar pos(const dimensionedScalar &ds)
dictionary dict
#define doLocalCode(GeoField)