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