fieldsExpression.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) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::functionObjects::fieldsExpression
29 
30 Group
31  grpFieldFunctionObjects
32 
33 Description
34  Intermediate class for handling field expression function objects
35  (e.g. \c add, \c subtract etc.) whereinto more than one fields are input.
36 
37 Usage
38  Minimal example by using \c system/controlDict.functions:
39  \verbatim
40  <userDefinedSubDictName1>
41  {
42  // Mandatory and other optional entries
43  ...
44 
45  // Optional (inherited) entries (runtime modifiable)
46  fields (<field1> <field2> ... <fieldN>);
47  result <fieldResult>;
48  }
49  \endverbatim
50 
51  where the entries mean:
52  \table
53  Property | Description | Type | Req'd | Dflt
54  fields | Names of operand fields | wordList | yes | -
55  result | Names of output fields | wordList | no | <FO>(<f1>,...)
56  \endtable
57 
58 See also
59  - Foam::functionObject
60  - Foam::functionObjects::fvMeshFunctionObject
61  - ExtendedCodeGuide::functionObjects::field::fieldsExpression
62 
63 SourceFiles
64  fieldsExpression.C
65  fieldsExpressionTemplates.C
66 
67 \*---------------------------------------------------------------------------*/
68 
69 #ifndef functionObjects_fieldsExpression_H
70 #define functionObjects_fieldsExpression_H
71 
72 #include "fvMeshFunctionObject.H"
73 #include "volFieldsFwd.H"
74 
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 
77 namespace Foam
78 {
79 namespace functionObjects
80 {
81 
82 /*---------------------------------------------------------------------------*\
83  Class fieldsExpression Declaration
84 \*---------------------------------------------------------------------------*/
85 
86 class fieldsExpression
87 :
88  public fvMeshFunctionObject
89 {
90 protected:
91 
92  // Protected Member Data
93 
94  //- Names of fields to process
96 
97  //- Name of result fields
98  word resultName_;
99 
100 
101  // Protected Member Functions
102 
104  (
105  const word& typeName,
106  const wordList& defaultArg = wordList::null()
107  );
108 
109  //- Call 'calcFieldType' for the given functionObject
110  // for 'volField' and 'surfaceField' field types
111  template<class Type, class FOType>
112  bool calcFieldTypes(FOType& fo);
113 
114  //- Call 'calcFieldTypes' for the given 'Type' and functionObject
115  template<class Type, class FOType>
116  bool calcType(FOType& fo);
117 
118  //- Call 'calcType' for the given functionObject
119  // for each primitive type
120  template<class FOType>
121  bool calcAllTypes(FOType& fo);
122 
123  //- Calculate expression
124  virtual bool calc() = 0;
125 
126 
127 public:
128 
129  //- Runtime type information
130  TypeName("fieldsExpression");
131 
132 
133  // Constructors
134 
135  //- Construct from Time and dictionary
137  (
138  const word& name,
139  const Time& runTime,
140  const dictionary& dict,
142  const word& resultName = word::null
143  );
144 
145  //- No copy construct
146  fieldsExpression(const fieldsExpression&) = delete;
147 
148  //- No copy assignment
149  void operator=(const fieldsExpression&) = delete;
150 
151 
152  //- Destructor
153  virtual ~fieldsExpression() = default;
154 
155 
156  // Member Functions
157 
158  //- Read the fieldsExpression data
159  virtual bool read(const dictionary& dict);
160 
161  //- Calculate the result fields
162  virtual bool execute();
163 
164  //- Write the result fields
165  virtual bool write();
166 
167  //- Clear the result fields from the objectRegistry
168  virtual bool clear();
169 };
170 
171 
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 
174 } // End namespace functionObjects
175 } // End namespace Foam
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 #ifdef NoRepository
180  #include "fieldsExpressionTemplates.C"
181 #endif
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 #endif
186 
187 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
volFieldsFwd.H
Foam::functionObjects::fieldsExpression::calcFieldTypes
bool calcFieldTypes(FOType &fo)
Call 'calcFieldType' for the given functionObject.
Definition: fieldsExpressionTemplates.C:36
Foam::functionObjects::fieldsExpression::read
virtual bool read(const dictionary &dict)
Read the fieldsExpression data.
Definition: fieldsExpression.C:105
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::List< word >::null
static const List< word > & null()
Return a null List.
Definition: ListI.H:109
Foam::functionObjects::fieldsExpression::execute
virtual bool execute()
Calculate the result fields.
Definition: fieldsExpression.C:120
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
fvMeshFunctionObject.H
Foam::functionObjects::fieldsExpression::TypeName
TypeName("fieldsExpression")
Runtime type information.
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::fieldsExpression::fieldsExpression
fieldsExpression(const word &name, const Time &runTime, const dictionary &dict, const wordList &fieldNames=wordList::null(), const word &resultName=word::null)
Construct from Time and dictionary.
Definition: fieldsExpression.C:78
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
fieldsExpressionTemplates.C
Foam::functionObjects::fieldsExpression::calcAllTypes
bool calcAllTypes(FOType &fo)
Call 'calcType' for the given functionObject.
Definition: fieldsExpressionTemplates.C:79
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
fieldNames
const wordRes fieldNames(propsDict.getOrDefault< wordRes >("fields", wordRes()))
Foam::functionObjects::fieldsExpression::calc
virtual bool calc()=0
Calculate expression.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::functionObjects::fieldsExpression
Intermediate class for handling field expression function objects (e.g. add, subtract etc....
Definition: fieldsExpression.H:103
Foam::functionObjects::fieldsExpression::write
virtual bool write()
Write the result fields.
Definition: fieldsExpression.C:138
Foam::functionObjects::fieldsExpression::calcType
bool calcType(FOType &fo)
Call 'calcFieldTypes' for the given 'Type' and functionObject.
Definition: fieldsExpressionTemplates.C:72
Foam::List< word >
Foam::functionObjects::fieldsExpression::fieldNames_
wordList fieldNames_
Names of fields to process.
Definition: fieldsExpression.H:112
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
Foam::functionObjects::fieldsExpression::resultName_
word resultName_
Name of result fields.
Definition: fieldsExpression.H:115
Foam::functionObjects::fieldsExpression::operator=
void operator=(const fieldsExpression &)=delete
No copy assignment.
Foam::functionObjects::fieldsExpression::~fieldsExpression
virtual ~fieldsExpression()=default
Destructor.
Foam::functionObjects::fieldsExpression::setResultName
void setResultName(const word &typeName, const wordList &defaultArg=wordList::null())
Definition: fieldsExpression.C:46
Foam::functionObjects::fieldsExpression::clear
virtual bool clear()
Clear the result fields from the objectRegistry.
Definition: fieldsExpression.C:144