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 -------------------------------------------------------------------------------
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 "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 
38 namespace Foam
39 {
40 namespace expressions
41 {
42 namespace volumeExpr
43 {
44 
46 
48 (
51  dictionary,
52  volume
53 );
54 
56 (
59  idName,
60  volume
61 );
62 
64 (
67  dictionary,
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);
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(),
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);
123  resetDb(mesh_.thisDb());
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 {
166 
167  resultDimensions_.clear(); // Avoid stickiness
168 
169  hasDimensions_ = resultDimensions_.readIfPresent("dimensions", dict);
170 
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;
199  fieldGeoType_ = NO_DATA;
200 }
201 
202 
205 {
206  const auto* regIOobjectPtr = resultField_.get();
207 
208  if (!regIOobjectPtr)
209  {
210  return nullptr;
211  }
212 
213  autoPtr<regIOobject> zField;
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 // ************************************************************************* //
void resetTimeReference(const TimeState *ts)
Reset the time-state reference.
Definition: exprDriver.C:123
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
addNamedToRunTimeSelectionTable(fvExprDriver, parseDriver, dictionary, volume)
autoPtr< regIOobject > dupZeroField() const
A zero-initialized field with the same type as the result field.
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
Ragel lexer/scanner interface for volume expressions.
parseDriver(const parseDriver &)=delete
Base driver for parsing value expressions associated with an fvMesh.
Definition: fvExprDriver.H:132
Macros for easy insertion into run-time selection tables.
GeometricField< tensor, pointPatchField, pointMesh > pointTensorField
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:376
void clearField()
Clear out local copies of the field.
dimensionedScalar pos(const dimensionedScalar &ds)
defineTypeNameAndDebug(parseDriver, 0)
#define doLocalCode(GeoField)
dynamicFvMesh & mesh
const fvMesh & mesh_
The referenced mesh.
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual unsigned parse(const std::string &expr, size_t pos=0, size_t len=std::string::npos)
Execute the parser.
GeometricField< scalar, pointPatchField, pointMesh > pointScalarField
virtual bool readDict(const dictionary &dict)
Read variables, tables etc.
const wordList volume
Standard volume field types (scalar, vector, tensor, etc)
bool process(const std::string &str, size_t pos, size_t len, parseDriver &driver_)
Evaluate sub-string.
GeometricField< sphericalTensor, pointPatchField, pointMesh > pointSphericalTensorField
virtual bool readDict(const dictionary &dict)
Read variables, tables etc.
Definition: fvExprDriver.C:146
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
void resetDb(const objectRegistry *obrPtr=nullptr)
Reset the objectRegistry (for functions)
Definition: exprDriver.C:135
GeometricField< symmTensor, pointPatchField, pointMesh > pointSymmTensorField
Driver for volume, surface, point field expressions.
Namespace for OpenFOAM.