patchExprDriver.H
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 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 Class
27  Foam::expressions::patchExpr::parseDriver
28 
29 Description
30  Driver for patch expressions
31 
32  In addition to the standard mathematical functions, operations and
33  logical and relational operations, the patch expressions support the
34  following driver-specific functions:
35 
36  Functions
37  \table
38  Function | Description | Number of arguments |
39  pos | The face centres | 0 |
40  pts | The face points | 0 |
41  area | The face area magnitudes | 0 |
42  weightAverage| Area weighted average | 1 |
43  weightSum | Area weighted sum | 1 |
44  face | The face areaNormal vectors | 0 |
45  point | A point-field point value | 1 |
46  faceToPoint | Interpolate face values onto points | 1 |
47  pointToFace | Interpolate point values onto faces | 1 |
48  rand | Random field | 0/1 |
49  \endtable
50 
51 Note
52  Use namespace debug switch \c patchExpr for scanner (2), parser (4)
53  or dictionary controls as per Foam::expressions::exprDriver.
54 
55 SourceFiles
56  patchExprDriver.C
57  patchExprDriverFields.C
58  patchExprDriverTemplates.C
59 
60 \*---------------------------------------------------------------------------*/
61 
62 #ifndef expressions_patchExprDriver_H
63 #define expressions_patchExprDriver_H
64 
65 #include "patchExprFwd.H"
66 #include "fvExprDriver.H"
67 #include "Enum.H"
68 #include "volFields.H"
69 #include "surfaceFields.H"
70 #include "pointFields.H"
72 
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 
75 namespace Foam
76 {
77 namespace expressions
78 {
79 namespace patchExpr
80 {
81 
82 /*---------------------------------------------------------------------------*\
83  Class parseDriver Declaration
84 \*---------------------------------------------------------------------------*/
85 
86 class parseDriver
87 :
88  public parsing::genericRagelLemonDriver,
89  public expressions::fvExprDriver
90 {
91  // Private Member Functions
92 
93  static const fvPatch& getFvPatch
94  (
95  const fvMesh& fvm,
96  const dictionary& dict
97  );
98 
99 
100 protected:
101 
102  // Protected Data
103 
104  //- The referenced patch
105  const fvPatch& patch_;
106 
107 
108  // Protected Member Functions
109 
110  // No copy copy construct
111  parseDriver(const parseDriver&) = delete;
112 
113  // No copy assignment
114  void operator=(const parseDriver&) = delete;
115 
116 
117 public:
118 
119  ClassName("patchExpr::driver");
120 
121  // Constructors
122 
123  //- Construct for specified patch
124  explicit parseDriver(const fvPatch& p);
125 
126  //- Construct for specified patch with given dictionary
127  parseDriver(const fvPatch& p, const dictionary& dict);
128 
129  //- Construct for specified patch with copy of driver context
130  parseDriver(const fvPatch& p, const parseDriver& driver_);
131 
132  //- Construct with patchName for the given mesh
133  parseDriver(const word& patchName, const fvMesh& mesh);
134 
135  //- Construct with "patch" (mandatory) and "region" (optional)
136  //- specified in dictionary
137  parseDriver(const dictionary& dict, const fvMesh& mesh);
138 
139  //- Clone
141  {
143  (
144  new parseDriver(this->patch_, *this)
145  );
146  }
147 
148 
149  //- Destructor
150  virtual ~parseDriver() = default;
151 
152 
153  // Public Member Functions
154 
155  //- The mesh we are attached to
156  virtual const fvMesh& mesh() const
157  {
158  return patch_.boundaryMesh().mesh();
159  }
160 
161  //- The underlying field size for the expression
162  virtual label size() const
163  {
164  return patch_.patch().size();
165  }
166 
167  //- The underlying point field size for the expression
168  virtual label pointSize() const
169  {
170  return patch_.patch().nPoints();
171  }
172 
173  //- Field size associated with different geometric field types
174  inline label size(const FieldAssociation geoType) const;
175 
176 
177  // Evaluation
178 
179  //- Perform parsing on (sub) string
180  using genericRagelLemonDriver::content;
181 
182  //- Execute the parser.
183  // The return value currently has no meaning.
184  virtual unsigned parse
185  (
186  const std::string& expr,
187  size_t pos = 0,
188  size_t len = std::string::npos
189  );
190 
191 
192  // Field Information
193 
194  // Fields
195 
196  //- Set result
197  template<class Type>
198  void setResult(Field<Type>* ptr, bool pointVal = false)
199  {
200  result().setResult<Type>(ptr, pointVal);
201  }
202 
203 
204  //- Retrieve variable as field if possible.
205  // Test tmp for validity to determine success of the operation.
206  template<class Type>
207  tmp<Field<Type>> getVariableIfAvailable(const word& fldName) const;
208 
209  //- Retrieve field (vol field)
210  template<class Type>
212  getVolField(const word& fldName);
213 
214  //- Retrieve field (surface field)
215  template<class Type>
217  getSurfaceField(const word& fldName);
218 
219  //- Retrieve field (point field)
220  template<class Type>
222  getPointField(const word& fldName);
223 
224  //- Return named field
225  template<class Type>
226  tmp<Field<Type>> getField(const word& fldName);
227 
228 
229  // Field "shape" conversions
230 
231  //- Interpolate face to point
232  template<class Type>
234 
235  //- Interpolate point to face values
236  template<class Type>
238 
239 
240  // Custom Field Functions
241 
242  //- The area-weighted average of a field
243  template<class Type>
244  Type areaAverage(const Field<Type>& fld) const
245  {
246  return weightedAverage(patch_.magSf(), fld);
247  }
248 
249  //- The area-weighted sum of a field
250  template<class Type>
251  Type areaSum(const Field<Type>& fld) const
252  {
253  return weightedSum(patch_.magSf(), fld);
254  }
255 
256  //- The face area magnitudes [magSf] - (swak = area)
258 
259  //- The face centres - (swak = pos)
261 
262  //- The face areas with their vector direction [Sf] - (swak = face)
264 
265  //- The patch point locations - (swak = pts)
267 
268  //- A uniform random field
269  tmp<scalarField> field_rand(label seed=0, bool gaussian=false) const;
270 
271  //- A Gaussian random field
272  tmp<scalarField> field_randGaussian(label seed=0) const
273  {
274  return field_rand(seed, true);
275  }
276 };
277 
278 
279 // Template specializations
280 
281 //- Retrieve field (surface field: bool)
282 template<>
283 tmp<Field<bool>> parseDriver::getSurfaceField<bool>(const word& fldName);
284 
285 //- Retrieve field (point field: bool)
286 template<>
287 tmp<Field<bool>> parseDriver::getPointField<bool>(const word& fldName);
288 
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 } // End namespace patchExpr
293 } // End namespace expressions
294 } // End namespace Foam
295 
296 
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298 
299 #include "patchExprDriverI.H"
300 
301 #ifdef NoRepository
302  #include "patchExprDriverTemplates.C"
303 #endif
304 
305 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
306 
307 #endif
308 
309 // ************************************************************************* //
volFields.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::expressions::patchExpr::parseDriver::field_pointField
tmp< vectorField > field_pointField() const
The patch point locations - (swak = pts)
Definition: patchExprDriverFields.C:80
Foam::expressions::patchExpr::parseDriver::ClassName
ClassName("patchExpr::driver")
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::expressions::patchExpr::parseDriver::setResult
void setResult(Field< Type > *ptr, bool pointVal=false)
Set result.
Definition: patchExprDriver.H:252
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::expressions::patchExpr::parseDriver::getVariableIfAvailable
tmp< Field< Type > > getVariableIfAvailable(const word &fldName) const
Retrieve variable as field if possible.
Foam::expressions::patchExpr::parseDriver::parse
virtual unsigned parse(const std::string &expr, size_t pos=0, size_t len=std::string::npos)
Execute the parser.
Definition: patchExprDriver.C:157
patchExprFwd.H
Foam::expressions::patchExpr::parseDriver::field_faceArea
tmp< scalarField > field_faceArea() const
The face area magnitudes [magSf] - (swak = area)
Definition: patchExprDriverFields.C:59
Foam::expressions::patchExpr::parseDriver::areaAverage
Type areaAverage(const Field< Type > &fld) const
The area-weighted average of a field.
Definition: patchExprDriver.H:298
Foam::expressions::patchExpr::parseDriver::getField
tmp< Field< Type > > getField(const word &fldName)
Return named field.
Foam::expressions::fvExprDriver
Base driver for parsing value expressions associated with an fvMesh.
Definition: fvExprDriver.H:137
surfaceFields.H
Foam::surfaceFields.
fvExprDriver.H
Foam::fvBoundaryMesh::mesh
const fvMesh & mesh() const
Return the mesh reference.
Definition: fvBoundaryMesh.H:102
Foam::expressions::patchExpr::parseDriver::operator=
void operator=(const parseDriver &)=delete
genericRagelLemonDriver.H
Foam::fvPatch::boundaryMesh
const fvBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: fvPatch.H:203
Foam::expressions::patchExpr::parseDriver::size
virtual label size() const
The underlying field size for the expression.
Definition: patchExprDriver.H:216
Foam::expressions::patchExpr::FieldAssociation
FieldAssociation
The field association for patch expressions (mutually exclusive)
Definition: patchExprFwd.H:57
Foam::expressions::patchExpr::parseDriver::getSurfaceField
tmp< Field< Type > > getSurfaceField(const word &fldName)
Retrieve field (surface field)
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::expressions::exprDriver::weightedAverage
static Type weightedAverage(const scalarField &weights, const Field< Type > &fld)
The (global) weighted average of a field, with stabilisation.
Foam::parsing::genericRagelLemonDriver
Generic interface code for Ragel/Lemon combination Subclasses should implement one or more process() ...
Definition: genericRagelLemonDriver.H:59
Foam::expressions::patchExpr::parseDriver::field_areaNormal
tmp< vectorField > field_areaNormal() const
The face areas with their vector direction [Sf] - (swak = face)
Definition: patchExprDriverFields.C:73
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::expressions::patchExpr::parseDriver::pointSize
virtual label pointSize() const
The underlying point field size for the expression.
Definition: patchExprDriver.H:222
field
rDeltaTY field()
fld
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;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::expressions::patchExpr::parseDriver::field_rand
tmp< scalarField > field_rand(label seed=0, bool gaussian=false) const
A uniform random field.
Definition: patchExprDriverFields.C:88
Foam::PrimitivePatch::nPoints
label nPoints() const
Return number of points supporting patch faces.
Definition: PrimitivePatch.H:316
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
patchExprDriverTemplates.C
Foam::expressions::patchExpr::parseDriver::field_faceCentre
tmp< vectorField > field_faceCentre() const
The face centres - (swak = pos)
Definition: patchExprDriverFields.C:66
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::expressions::patchExpr::parseDriver
Driver for patch expressions.
Definition: patchExprDriver.H:140
Foam::expressions::patchExpr::parseDriver::pointToFace
tmp< Field< Type > > pointToFace(const Field< Type > &field) const
Interpolate point to face values.
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::expressions::exprDriver::dict
const dictionary & dict() const
The dictionary with all input data/specification.
Definition: exprDriver.H:299
Foam::expressions::exprDriver::result
virtual const exprResult & result() const
Const access to expression result.
Definition: exprDriver.H:305
Foam::fvPatch::patch
const polyPatch & patch() const
Return the polyPatch.
Definition: fvPatch.H:161
Foam::expressions::patchExpr::parseDriver::getVolField
tmp< Field< Type > > getVolField(const word &fldName)
Retrieve field (vol field)
Foam::expressions::patchExpr::parseDriver::areaSum
Type areaSum(const Field< Type > &fld) const
The area-weighted sum of a field.
Definition: patchExprDriver.H:305
Foam::expressions::exprResult::setResult
void setResult(Field< Type > *, bool wantPointData=false)
Set result field, taking ownership of the pointer.
Definition: exprResultI.H:397
Foam::expressions::patchExpr::parseDriver::faceToPoint
tmp< Field< Type > > faceToPoint(const Field< Type > &field) const
Interpolate face to point.
Foam::expressions::patchExpr::parseDriver::getPointField
tmp< Field< Type > > getPointField(const word &fldName)
Retrieve field (point field)
Foam::expressions::patchExpr::parseDriver::~parseDriver
virtual ~parseDriver()=default
Destructor.
Foam::fvPatch::magSf
const scalarField & magSf() const
Return face area magnitudes.
Definition: fvPatch.C:150
Foam::expressions::patchExpr::parseDriver::parseDriver
parseDriver(const parseDriver &)=delete
Foam::expressions::patchExpr::parseDriver::patch_
const fvPatch & patch_
The referenced patch.
Definition: patchExprDriver.H:159
Foam::expressions::exprDriver::weightedSum
static Type weightedSum(const scalarField &weights, const Field< Type > &fld)
The (global) weighted sum (integral) of a field.
Foam::expressions::patchExpr::parseDriver::mesh
virtual const fvMesh & mesh() const
The mesh we are attached to.
Definition: patchExprDriver.H:210
Foam::expressions::patchExpr::parseDriver::field_randGaussian
tmp< scalarField > field_randGaussian(label seed=0) const
A Gaussian random field.
Definition: patchExprDriver.H:326
Foam::expressions::patchExpr::parseDriver::clone
virtual autoPtr< expressions::fvExprDriver > clone() const
Clone.
Definition: patchExprDriver.H:194
pointFields.H
patchExprDriverI.H
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177
Enum.H