Loading...
Searching...
No Matches
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-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 "volumeExprDriver.H"
29#include "volumeExprScanner.H"
30#include "error.H"
31#include "fvPatch.H"
32#include "fvMesh.H"
33#include "className.H"
36// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37
38namespace Foam
39{
40namespace expressions
41{
42namespace volumeExpr
43{
44
46
52 volume
53);
54
59 idName,
60 volume
61);
62
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),
100{
101 resetTimeReference(nullptr);
102 resetDb(mesh_.thisDb());
103}
104
105
107(
108 const fvMesh& mesh,
109 const parseDriver& rhs,
110 const dictionary& dict
111)
112:
113 parsing::genericRagelLemonDriver(),
115 mesh_(mesh),
116 resultType_(),
117 isLogical_(false),
118 hasDimensions_(false),
119 fieldGeoType_(NO_DATA),
121{
122 resetTimeReference(nullptr);
123 resetDb(mesh_.thisDb());
124}
125
126
128(
129 const word& meshName,
130 const fvMesh& mesh
131)
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(),
147 mesh_(mesh),
148 resultType_(),
149 isLogical_(false),
150 fieldGeoType_(NO_DATA),
151 resultDimensions_()
152{
154 resetDb(mesh_.thisDb());
155}
156
157
158// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
159
161(
162 const dictionary& dict
163)
164{
166
167 resultDimensions_.clear(); // Avoid stickiness
168
169 hasDimensions_ = resultDimensions_.readIfPresent("dimensions", dict);
171 return true;
172}
173
174
175// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
176
178(
179 const std::string& expr,
180 size_t pos,
181 size_t len
182)
183{
184 scanner scan(this->debugScanner());
186 scan.process(expr, pos, len, *this);
187
188 return 0;
189}
190
191
193{
194 resultField_.reset(nullptr);
195
196 // Characteristics
197 resultType_.clear();
198 isLogical_ = false;
200}
201
202
205{
206 const auto* regIOobjectPtr = resultField_.get();
207
208 if (!regIOobjectPtr)
209 {
210 return nullptr;
211 }
212
214
215 switch (fieldGeoType_)
216 {
217 #undef doLocalCode
218 #define doLocalCode(GeoField) \
219 { \
220 const auto* ptr = dynamic_cast<const GeoField*>(regIOobjectPtr); \
221 typedef typename GeoField::value_type Type; \
222 \
223 if (ptr) \
224 { \
225 zField.reset \
226 ( \
227 GeoField::New \
228 ( \
229 word(pTraits<Type>::typeName) + word("(zero)"), \
230 (*ptr).mesh(), \
231 dimensioned<Type>(Zero), \
232 /* zeroGradient (volume) or calculated (other) */ \
233 defaultBoundaryType(*ptr) \
234 ).ptr() \
235 ); \
236 break; \
237 } \
238 }
239
241 {
247 break;
248 }
250 {
256 break;
257 }
259 {
265 break;
266 }
267 default: break;
268 #undef doLocalCode
269 }
270
271 // if (!zField)
272 // {
273 // // Report
274 // }
275
276 return zField;
277}
278
279
280// ************************************************************************* //
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:65
T * get() noexcept
Return pointer to managed object without nullptr checking.
Definition autoPtr.H:216
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
void resetDb(const objectRegistry *obrPtr=nullptr)
Reset the objectRegistry (for functions).
Definition exprDriver.C:135
bool debugScanner() const noexcept
Read access to scanner debug.
void resetTimeReference(const TimeState *ts)
Reset the time-state reference.
Definition exprDriver.C:123
const dictionary & dict() const noexcept
The dictionary with all input data/specification.
Definition exprDriver.H:455
Base driver for parsing value expressions associated with an fvMesh.
virtual bool readDict(const dictionary &dict)
Read variables, tables etc.
fvExprDriver(enum exprDriver::searchControls search=exprDriver::searchControls::DEFAULT_SEARCH, const dictionary &dict=dictionary::null)
Default construct, and default construct with search preferences.
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.
expressions::FieldAssociation fieldGeoType_
A volume/surface/point 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.
parseDriver(const parseDriver &)=delete
bool hasDimensions_
Requested use of dimensions.
virtual const fvMesh & mesh() const
The mesh we are attached to.
autoPtr< regIOobject > resultField_
The results (volume, surface, point).
bool isLogical_
A logical (bool-like) field (but actually a scalar).
void clearField()
Clear out local copies of the field.
dimensionSet resultDimensions_
The result dimensions.
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:85
A class for handling words, derived from Foam::string.
Definition word.H:66
Macro definitions for declaring ClassName(), NamespaceName(), etc.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
#define doLocalCode(FieldType, Variable)
Namespace for volume field expressions parsing and evaluation.
A namespace for expression-related classes/traits etc.
Collection of static functions and data related to parsing and an isolated namespace for lexers,...
Namespace for OpenFOAM.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
dimensionedScalar pos(const dimensionedScalar &ds)
GeometricField< vector, fvPatchField, volMesh > volVectorField
GeometricField< tensor, pointPatchField, pointMesh > pointTensorField
GeometricField< scalar, pointPatchField, pointMesh > pointScalarField
GeometricField< sphericalTensor, pointPatchField, pointMesh > pointSphericalTensorField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
GeometricField< symmTensor, pointPatchField, pointMesh > pointSymmTensorField
GeometricField< tensor, fvPatchField, volMesh > volTensorField
GeometricField< tensor, fvsPatchField, surfaceMesh > surfaceTensorField
GeometricField< sphericalTensor, fvPatchField, volMesh > volSphericalTensorField
GeometricField< sphericalTensor, fvsPatchField, surfaceMesh > surfaceSphericalTensorField
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
GeometricField< symmTensor, fvsPatchField, surfaceMesh > surfaceSymmTensorField
dictionary dict