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 -------------------------------------------------------------------------------
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 :
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 :
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 :
147  mesh_(mesh),
148  resultType_(),
149  isLogical_(false),
150  fieldGeoType_(NO_DATA),
151  resultDimensions_()
152 {
153  resetTimeReference(nullptr);
154  resetDb(mesh_.thisDb());
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;
205 }
206 
207 
210 {
211  const auto* regIOobjectPtr = resultField_.get();
212 
213  if (!regIOobjectPtr)
214  {
215  return nullptr;
216  }
217 
218  autoPtr<regIOobject> zField;
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 // ************************************************************************* //
Foam::expressions::volumeExpr::parseDriver::dupZeroField
autoPtr< regIOobject > dupZeroField() const
A zero-initialized field with the same type as the result field.
Definition: volumeExprDriver.C:209
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::expressions::NO_DATA
No data.
Definition: exprFieldAssociation.H:45
Foam::expressions::volumeExpr::parseDriver
Driver for volume, surface, point field expressions.
Definition: volumeExprDriver.H:230
Foam::expressions::volumeExpr::parseDriver::clearField
void clearField()
Clear out local copies of the field.
Definition: volumeExprDriver.C:197
Foam::expressions::volumeExpr::parseDriver::parseDriver
parseDriver(const parseDriver &)=delete
Foam::expressions::fvExprDriver
Base driver for parsing value expressions associated with an fvMesh.
Definition: fvExprDriver.H:136
Foam::fieldTypes::volume
const wordList volume
Standard volume field types (scalar, vector, tensor, etc)
Foam::expressions::VOLUME_DATA
Volume data.
Definition: exprFieldAssociation.H:48
doLocalCode
#define doLocalCode(GeoField)
volumeExprScanner.H
Foam::expressions::volumeExpr::parseDriver::resultType_
word resultType_
The result type-name.
Definition: volumeExprDriver.H:248
Foam::expressions::FACE_DATA
Face data.
Definition: exprFieldAssociation.H:47
error.H
Foam::expressions::volumeExpr::parseDriver::readDict
virtual bool readDict(const dictionary &dict)
Read variables, tables etc.
Definition: volumeExprDriver.C:161
Foam::parsing::genericRagelLemonDriver
Generic interface code for Ragel/Lemon combination Subclasses should implement one or more process() ...
Definition: genericRagelLemonDriver.H:59
Foam::expressions::volumeExpr::parseDriver::resultField_
autoPtr< regIOobject > resultField_
The results (volume, surface, point)
Definition: volumeExprDriver.H:243
className.H
Macro definitions for declaring ClassName(), NamespaceName(), etc.
volumeExprDriver.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::expressions::volumeExpr::scanner
Ragel lexer/scanner interface for volume expressions.
Definition: volumeExprScanner.H:53
Foam::expressions::volumeExpr::parseDriver::fieldGeoType_
expressions::FieldAssociation fieldGeoType_
A volume/surface/point field.
Definition: volumeExprDriver.H:257
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::expressions::volumeExpr::parseDriver::isLogical_
bool isLogical_
A logical (bool-like) field (but actually a scalar)
Definition: volumeExprDriver.H:251
Foam::autoPtr< Foam::regIOobject >
Foam::expressions::POINT_DATA
Point data.
Definition: exprFieldAssociation.H:46
Foam::expressions::volumeExpr::defineTypeNameAndDebug
defineTypeNameAndDebug(parseDriver, 0)
Foam::expressions::volumeExpr::scanner::process
bool process(const std::string &str, size_t pos, size_t len, parseDriver &driver_)
Evaluate sub-string.
Foam::expressions::volumeExpr::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(fvExprDriver, parseDriver, dictionary, volume)
fvPatch.H
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::expressions::volumeExpr::parseDriver::parse
virtual unsigned parse(const std::string &expr, size_t pos=0, size_t len=std::string::npos)
Execute the parser.
Definition: volumeExprDriver.C:183
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177