Loading...
Searching...
No Matches
fvExpressionField.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) 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::functionObjects::fvExpressionField
28
29Group
30 grpFieldFunctionObjects
31
32Description
33 Function object that generates or modifies a field based on expressions.
34
35Usage
36 A minimal example:
37 \verbatim
38 exprFieldFO
39 {
40 // Mandatory entries
41 type exprField;
42 libs (fieldFunctionObjects);
43 field <word>; // pTotal;
44 expression "p + 0.5*(rho*magSqr(U))";
45
46 // Optional entries
47 action <word>; // none, new, modify
48 autowrite <bool>;
49 store <bool>;
50 dimensions [ Pa ]; // for new field only
51 readFields (<wordList>); // (p U rho), for post-process mode only
52 useNamePrefix false; // for new field only
53
54 // Inherited entries
55 ...
56 }
57
58 // Modify an existing field
59 <name2>
60 {
61 type exprField;
62 libs (fieldFunctionObjects);
63 field pTotal;
64 action modify;
65
66 // Static pressure only in these regions
67 fieldMask "(mag(pos()) < 0.05) && (pos().y() > 0)";
68 expression "p";
69 }
70 \endverbatim
71
72 where the entries mean:
73 \table
74 Property | Description | Type | Reqd | Deflt
75 type | Type name: exprField | word | yes |
76 libs | Libraries: fieldFunctionObjects | wordList | yes |
77 field | Name of input or output field | word | yes |
78 expression | Field evaluation expression | string | yes |
79 action | Type of operation: see below | word | no | new
80 autowrite | Add AUTO_WRITE to created field | bool | no | false
81 store | Store calculated field | bool | no | true
82 fieldMask | Masking as logical expression | string | no | ""
83 dimensions | Apply specified dimensions to created field | dim-spec | no |
84 readFields | Preload named fields (post-process mode) | wordList | no |
85 useNamePrefix | Add prefix scoping to output name | bool | no | false
86 \endtable
87
88 Options for the \c action entry:
89 \plaintable
90 none | No operation
91 new | Define field based on expression (default)
92 modify | Adjust field according to expression and fieldMask
93 \endplaintable
94
95 The inherited entries are elaborated in:
96 - \link fieldExpression.H \endlink
97
98Note
99 The \c useNamePrefix entry is always ignored for the \c modify action.
100
101SourceFiles
102 fvExpressionField.C
103
104\*---------------------------------------------------------------------------*/
105
106#ifndef Foam_functionObjects_fvExpressionField_H
107#define Foam_functionObjects_fvExpressionField_H
108
109#include "fvMeshFunctionObject.H"
110#include "volumeExprDriver.H"
111#include "Enum.H"
112#include "dimensionSet.H"
113
114// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
115
116namespace Foam
117{
118namespace functionObjects
119{
120
121/*---------------------------------------------------------------------------*\
122 Class fvExpressionField Declaration
123\*---------------------------------------------------------------------------*/
124
126:
128{
129public:
130
131 // Public Data Types
132
133 //- Action type enumeration
134 enum actionType : unsigned char
135 {
136 opNone = 0,
137 opNew,
138 opModify
139 };
140
141 //- Action type names
142 static const Enum<actionType> actionNames_;
143
144
145protected:
146
147 // Private Data
148
149 //- The context dictionary
151
152 //- Name of the field
153 word fieldName_;
154
155 //- Names fields to preload
157
158 //- The field-mask expression (modify mode)
159 expressions::exprString maskExpr_;
160
161 //- Expression to evaluate
162 expressions::exprString valueExpr_;
163
164 //- Dimensions for new field
165 dimensionSet dimensions_;
166
167 //- Operation mode
169
170 //- Set AUTO_WRITE for new field
171 bool autowrite_;
172
173 //- Store calculated field
174 bool store_;
175
176 //- True if dimensions_ should be used (creation)
177 bool hasDimensions_;
178
179 //- Load fields from files (not from objectRegistry)
180 bool loadFromFiles_;
181
182 autoPtr<expressions::volumeExprDriver> driver_;
183
184
185 // Private Member Functions
186
187 //- Attempt load from io, store on database if successful
188 template<class FieldType>
189 bool loadAndStore(const IOobject& io);
190
191 //- Forward to loadAndStore for supported types
192 template<class Type>
193 bool loadField(const IOobject& io);
194
195 //- Attempt to load specified fields
196 label loadFields(const UList<word>& fieldSet_);
197
198 //- Sets the values of the output field based on a condition
199 template<class GeoField>
200 bool setField
201 (
202 GeoField& output,
203 const GeoField& evaluated,
204 const boolField& cond
205 );
206
207 //- Execute the requested action
208 bool performAction(bool doWrite);
209
210public:
211
212 //- Runtime type information
213 TypeName("exprField");
214
216 // Constructors
218 //- Construct from name, Time and dictionary
220 (
221 const word& name,
222 const Time& runTime,
223 const dictionary& dict,
224 const bool loadFromFiles = false
225 );
226
227 //- No copy construct
228 fvExpressionField(const fvExpressionField&) = delete;
229
230 //- No copy assignment
231 void operator=(const fvExpressionField&) = delete;
232
233
234 //- Destructor
236
237
238 // Member Functions
239
240 //- Qualified/unqualified field name (depends on action)
241 virtual word fieldName() const;
242
243 //- Read the function-object dictionary
244 virtual bool read(const dictionary& dict);
246 //- Execute the function-object operations
247 virtual bool execute();
248
249 //- Write the function-object results
250 virtual bool write();
251};
252
253
254// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256} // End namespace functionObjects
257} // End namespace Foam
258
259// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261#endif
262
263// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
A variant of Foam::string with expansion of dictionary variables into a comma-separated form.
Definition exprString.H:58
Function object that generates or modifies a field based on expressions.
expressions::exprString maskExpr_
The field-mask expression (modify mode).
void operator=(const fvExpressionField &)=delete
No copy assignment.
bool setField(GeoField &output, const GeoField &evaluated, const boolField &cond)
Sets the values of the output field based on a condition.
autoPtr< expressions::volumeExprDriver > driver_
bool performAction(bool doWrite)
Execute the requested action.
dimensionSet dimensions_
Dimensions for new field.
dictionary dict_
The context dictionary.
bool loadFromFiles_
Load fields from files (not from objectRegistry).
bool autowrite_
Set AUTO_WRITE for new field.
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
bool hasDimensions_
True if dimensions_ should be used (creation).
bool loadAndStore(const IOobject &io)
Attempt load from io, store on database if successful.
static const Enum< actionType > actionNames_
Action type names.
fvExpressionField(const fvExpressionField &)=delete
No copy construct.
@ opNew
Create/overwrite field (default).
label loadFields(const UList< word > &fieldSet_)
Attempt to load specified fields.
fvExpressionField(const word &name, const Time &runTime, const dictionary &dict, const bool loadFromFiles=false)
Construct from name, Time and dictionary.
virtual bool execute()
Execute the function-object operations.
virtual word fieldName() const
Qualified/unqualified field name (depends on action).
expressions::exprString valueExpr_
Expression to evaluate.
wordList preloadFields_
Names fields to preload.
virtual bool write()
Write the function-object results.
bool loadField(const IOobject &io)
Forward to loadAndStore for supported types.
TypeName("exprField")
Runtime type information.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
const auto & io
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
Field< bool > boolField
Specialisation of Field<T> for bool.
Definition boolField.H:47
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68