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-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::expressions::fieldExpr::parseDriver
28
29Description
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
42Note
43 Use namespace debug switch \c fieldExpr for scanner (2), parser (4)
44
45SourceFiles
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
62namespace Foam
63{
64namespace expressions
65{
66namespace fieldExpr
67{
68
69/*---------------------------------------------------------------------------*\
70 Class parseDriver Declaration
71\*---------------------------------------------------------------------------*/
72
73class parseDriver
74:
75 public parsing::genericRagelLemonDriver,
76 public expressions::exprDriver
77{
78protected:
79
80 // Protected Data
81
82 //- The field size
83 label size_;
84
85public:
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;
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_;
126
127 //- The point field size for the expression
128 virtual label pointSize() const
129 {
130 return size_;
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
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
190#endif
191
192// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193
194#endif
195
196// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Base driver for parsing (field) values.
Definition: exprDriver.H:141
const exprResult & result() const noexcept
Const access to expression result.
Definition: exprDriver.H:391
const dictionary & dict() const noexcept
The dictionary with all input data/specification.
Definition: exprDriver.H:385
void setResult(Field< Type > *, bool wantPointData=false)
Set result field, taking ownership of the pointer.
Definition: exprResultI.H:359
Driver for generic primitive field expressions.
virtual label size() const
The natural field size for the expression.
tmp< Field< Type > > getField(const word &fieldName) const
Return named field (variable) if available.
virtual label pointSize() const
The point field size for the expression.
virtual unsigned parse(const std::string &expr, size_t pos=0, size_t len=std::string::npos)
Execute the parser.
void setResult(Field< Type > *ptr, bool pointVal=false)
Set result.
void operator=(const parseDriver &)=delete
parseDriver(const parseDriver &)=delete
tmp< scalarField > field_rand(label seed=0, bool gaussian=false) const
A uniform random field.
tmp< scalarField > field_randGaussian(label seed=0) const
A Gaussian random field.
virtual ~parseDriver()=default
Destructor.
Generic interface code for Ragel/Lemon combination Subclasses should implement one or more process() ...
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition: className.H:67
Namespace for OpenFOAM.
dimensionedScalar pos(const dimensionedScalar &ds)
Specialisations of Field<T> for scalar, vector and tensor.