fieldExprDriver.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-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 Class
27  Foam::expressions::fieldExpr::parseDriver
28 
29 Description
30  Driver for generic primitive field expressions
31 
32  In addition to the standard mathematical functions, operations and
33  logical and relational operations, the volume expression support the
34  following driver-specific functions:
35 
36  Functions
37  \table
38  Function | Description | Number of arguments |
39  rand | Random field | 0/1 |
40  \endtable
41 
42 Note
43  Use namespace debug switch \c fieldExpr for scanner (2), parser (4)
44 
45 SourceFiles
46  fieldExprDriver.C
47  fieldExprDriverFields.C
48  fieldExprDriverTemplates.C
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #ifndef expressions_fieldExprDriver_H
53 #define expressions_fieldExprDriver_H
54 
55 #include "fieldExprFwd.H"
56 #include "exprDriver.H"
57 #include "primitiveFields.H"
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 namespace Foam
63 {
64 namespace expressions
65 {
66 namespace fieldExpr
67 {
68 
69 /*---------------------------------------------------------------------------*\
70  Class parseDriver Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 class parseDriver
74 :
75  public parsing::genericRagelLemonDriver,
76  public expressions::exprDriver
77 {
78 protected:
79 
80  // Protected Data
81 
82  //- The field size
83  label size_;
84 
85 public:
86 
87  ClassName("fieldExpr::driver");
88 
89  // Generated Methods
90 
91  // No copy copy construct
92  parseDriver(const parseDriver&) = delete;
93 
94  // No copy assignment
95  void operator=(const parseDriver&) = delete;
96 
97 
98  // Constructors
99 
100  //- Default construct (size=1), or with specified size
101  explicit parseDriver(const label len = 1);
102 
103  //- Construct for specified size with given dictionary
104  parseDriver(const label len, const dictionary& dict);
105 
106  //- Construct for specified size, copy of driver context
108  (
109  const label len,
110  const parseDriver& rhs,
111  const dictionary& dict
112  );
113 
114 
115  //- Destructor
116  virtual ~parseDriver() = default;
117 
118 
119  // Public Member Functions
120 
121  //- The natural field size for the expression
122  virtual label size() const
123  {
124  return size_;
125  }
126 
127  //- The point field size for the expression
128  virtual label pointSize() const
129  {
130  return size_;
131  }
132 
133 
134  // Evaluation
135 
136  //- Perform parsing on (sub) string
137  using genericRagelLemonDriver::content;
138 
139  //- Execute the parser
140  // The return value currently has no meaning.
141  virtual unsigned parse
142  (
143  const std::string& expr,
144  size_t pos = 0,
145  size_t len = std::string::npos
146  );
147 
148 
149  // Fields
150 
151  //- Set result
152  template<class Type>
153  void setResult(Field<Type>* ptr, bool pointVal = false)
154  {
155  result().setResult<Type>(ptr, pointVal);
156  }
157 
158 
159  // New Fields
160 
161  //- Return named field (variable) if available
162  template<class Type>
163  tmp<Field<Type>> getField(const word& fieldName) const;
164 
165 
166  // Custom Field Functions
167 
168  //- A uniform random field
169  tmp<scalarField> field_rand(label seed=0, bool gaussian=false) const;
170 
171  //- A Gaussian random field
172  tmp<scalarField> field_randGaussian(label seed=0) const
173  {
174  return field_rand(seed, true);
175  }
176 };
177 
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 } // End namespace fieldExpr
182 } // End namespace expressions
183 } // End namespace Foam
184 
185 
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 
188 #ifdef NoRepository
189  #include "fieldExprDriverTemplates.C"
190 #endif
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 #endif
195 
196 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::expressions::fieldExpr::parseDriver::getField
tmp< Field< Type > > getField(const word &fieldName) const
Return named field (variable) if available.
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
fieldExprFwd.H
Foam::expressions::fieldExpr::parseDriver
Driver for generic primitive field expressions.
Definition: fieldExprDriver.H:82
Foam::expressions::fieldExpr::parseDriver::pointSize
virtual label pointSize() const
The point field size for the expression.
Definition: fieldExprDriver.H:137
Foam::expressions::exprDriver::result
const exprResult & result() const noexcept
Const access to expression result.
Definition: exprDriver.H:390
Foam::expressions::fieldExpr::parseDriver::field_randGaussian
tmp< scalarField > field_randGaussian(label seed=0) const
A Gaussian random field.
Definition: fieldExprDriver.H:181
Foam::expressions::fieldExpr::parseDriver::ClassName
ClassName("fieldExpr::driver")
primitiveFields.H
Specialisations of Field<T> for scalar, vector and tensor.
exprDriver.H
genericRagelLemonDriver.H
Foam::expressions::fieldExpr::parseDriver::operator=
void operator=(const parseDriver &)=delete
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::expressions::fieldExpr::parseDriver::setResult
void setResult(Field< Type > *ptr, bool pointVal=false)
Set result.
Definition: fieldExprDriver.H:162
Foam::expressions::fieldExpr::parseDriver::~parseDriver
virtual ~parseDriver()=default
Destructor.
Foam::parsing::genericRagelLemonDriver
Generic interface code for Ragel/Lemon combination Subclasses should implement one or more process() ...
Definition: genericRagelLemonDriver.H:59
Foam::expressions::exprDriver
Base driver for parsing (field) values.
Definition: exprDriver.H:139
Foam::expressions::fieldExpr::parseDriver::size_
label size_
The field size.
Definition: fieldExprDriver.H:92
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::expressions::fieldExpr::parseDriver::field_rand
tmp< scalarField > field_rand(label seed=0, bool gaussian=false) const
A uniform random field.
Definition: fieldExprDriverFields.C:34
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::expressions::fieldExpr::parseDriver::size
virtual label size() const
The natural field size for the expression.
Definition: fieldExprDriver.H:131
Foam::expressions::fieldExpr::parseDriver::parseDriver
parseDriver(const parseDriver &)=delete
Foam::expressions::exprDriver::dict
const dictionary & dict() const noexcept
The dictionary with all input data/specification.
Definition: exprDriver.H:384
fieldExprDriverTemplates.C
Foam::expressions::exprResult::setResult
void setResult(Field< Type > *, bool wantPointData=false)
Set result field, taking ownership of the pointer.
Definition: exprResultI.H:359
Foam::expressions::fieldExpr::parseDriver::parse
virtual unsigned parse(const std::string &expr, size_t pos=0, size_t len=std::string::npos)
Execute the parser.
Definition: fieldExprDriver.C:91
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177