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-2020 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 
86  // Protected Member Functions
87 
88  // No copy copy construct
89  parseDriver(const parseDriver&) = delete;
90 
91  // No copy assignment
92  void operator=(const parseDriver&) = delete;
93 
94 
95 public:
96 
97  ClassName("fieldExpr::driver");
98 
99  // Constructors
100 
101  //- Default construct - uses size = 1
102  parseDriver();
103 
104  //- Construct with specified size
105  explicit parseDriver(const label len);
106 
107  //- Construct for specified size with given dictionary
108  parseDriver(const label len, const dictionary& dict);
109 
110  //- Construct for specified size with copy of driver context
111  parseDriver(const label len, const parseDriver& rhs);
112 
113 
114  //- Destructor
115  virtual ~parseDriver() = default;
116 
117 
118  // Public Member Functions
119 
120  //- The underlying field size for the expression
121  virtual label size() const
122  {
123  return size_;
124  }
125 
126  //- The underlying point field size for the expression
127  virtual label pointSize() const
128  {
129  return size_;
130  }
131 
132 
133  // Evaluation
134 
135  //- Perform parsing on (sub) string
136  using genericRagelLemonDriver::content;
137 
138  //- Execute the parser
139  // The return value currently has no meaning.
140  virtual unsigned parse
141  (
142  const std::string& expr,
143  size_t pos = 0,
144  size_t len = std::string::npos
145  );
146 
147 
148  // Fields
149 
150  //- Set result
151  template<class Type>
152  void setResult(Field<Type>* ptr, bool pointVal = false)
153  {
154  result().setResult<Type>(ptr, pointVal);
155  }
156 
157 
158  // New Fields
159 
160  //- Return named field (variable) if available
161  template<class Type>
163  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:62
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 underlying point field size for the expression.
Definition: fieldExprDriver.H:136
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:161
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:112
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:121
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::expressions::fieldExpr::parseDriver::parseDriver
parseDriver()
Default construct - uses size = 1.
Definition: fieldExprDriver.C:52
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::expressions::fieldExpr::parseDriver::size
virtual label size() const
The underlying field size for the expression.
Definition: fieldExprDriver.H:130
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
fieldExprDriverTemplates.C
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::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:96
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177