fieldsExpression.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::functionObjects::fieldsExpression
26 
27 Description
28  Base class for expressions involving multiple fields
29 
30 See also
31  Foam::functionObjects::fvMeshFunctionObject
32 
33 SourceFiles
34  fieldsExpression.C
35  fieldsExpressionTemplates.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef fieldsExpression_functionObject_H
40 #define fieldsExpression_functionObject_H
41 
42 #include "fvMeshFunctionObject.H"
43 #include "volFieldsFwd.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 namespace functionObjects
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class fieldsExpression Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class fieldsExpression
57 :
59 {
60 protected:
61 
62  // Protected member data
63 
64  //- Names of fields to process
66 
67  //- Name of result fields
69 
70 
71  // Protected member functions
72 
73  //- Set the result name
74  void setResultName
75  (
76  const word& functionName,
77  const wordList& defaultFieldNames = wordList::null()
78  );
79 
80  //- Operate on the fields and store the result. Supported overload.
81  template
82  <
83  template<class> class GeoField,
84  template<class ...> class Op,
85  class TypeA,
86  class TypeB,
87  class Enable = Op<TypeA, TypeB>
88  >
89  bool opAndStore
90  (
91  const GeoField<TypeA>& a,
92  const GeoField<TypeB>& b
93  );
94 
95  //- Operate on the fields and store the result. Not-supported overload.
96  template
97  <
98  template<class> class GeoField,
99  template<class ...> class Op,
100  class ... Args
101  >
102  bool opAndStore(const Args& ...);
103 
104  //- Fold the fields expression up one place
105  template
106  <
107  template<class> class GeoField,
108  template<class ...> class Op,
109  class TypeA,
110  class TypeB
111  >
112  bool foldAB(const label i);
113 
114  //- Fold the fields expression up one place
115  template
116  <
117  template<class> class GeoField,
118  template<class ...> class Op,
119  class TypeA
120  >
121  bool foldA(const label i);
122 
123  //- Fold the fields expression up one place
124  template
125  <
126  template<class> class GeoField,
127  template<class ...> class Op
128  >
129  bool fold(const label i);
130 
131  //- Calculate and store the fields expression for the given geometric
132  // field type and operation
133  template<template<class> class GeoField, template<class ...> class Op>
134  bool calcGeoFieldOp();
135 
136  //- Calculate and store the fields expression for the given operation
137  template<template<class ...> class Op>
138  bool calcOp();
139 
140  //- Perform calculation on the list of fields and return success
141  virtual bool calc() = 0;
142 
143 
144 public:
145 
146  //- Runtime type information
147  TypeName("fieldsExpression");
148 
149 
150  // Constructors
151 
152  //- Construct from Time and dictionary
154  (
155  const word& name,
156  const Time& runTime,
157  const dictionary& dict,
159  const word& resultName = word::null
160  );
161 
162  //- Disallow default bitwise copy construction
163  fieldsExpression(const fieldsExpression&) = delete;
164 
165 
166  //- Destructor
167  virtual ~fieldsExpression();
168 
169 
170  // Member Functions
171 
172  //- Read the fieldsExpression data
173  virtual bool read(const dictionary&);
174 
175  //- Return the list of fields required
176  virtual wordList fields() const;
177 
178  //- Calculate the result fields
179  virtual bool execute();
180 
181  //- Write the result fields
182  virtual bool write();
183 
184  //- Clear the result fields from the objectRegistry
185  virtual bool clear();
186 
187 
188  // Member Operators
189 
190  //- Disallow default bitwise assignment
191  void operator=(const fieldsExpression&) = delete;
192 };
193 
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 } // End namespace functionObjects
198 } // End namespace Foam
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 #ifdef NoRepository
203  #include "fieldsExpressionTemplates.C"
204 #endif
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 #endif
209 
210 // ************************************************************************* //
static const List< word > & null()
Return a null List.
Definition: ListI.H:118
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A functionName is a word starting with '#'.
Definition: functionName.H:60
const word & name() const
Return the name of this functionObject.
Base class for expressions involving multiple fields.
bool foldA(const label i)
Fold the fields expression up one place.
bool calcGeoFieldOp()
Calculate and store the fields expression for the given geometric.
wordList fieldNames_
Names of fields to process.
virtual wordList fields() const
Return the list of fields required.
bool fold(const label i)
Fold the fields expression up one place.
word resultName_
Name of result fields.
void setResultName(const word &functionName, const wordList &defaultFieldNames=wordList::null())
Set the result name.
virtual bool clear()
Clear the result fields from the objectRegistry.
TypeName("fieldsExpression")
Runtime type information.
bool foldAB(const label i)
Fold the fields expression up one place.
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.
virtual bool execute()
Calculate the result fields.
bool opAndStore(const GeoField< TypeA > &a, const GeoField< TypeB > &b)
Operate on the fields and store the result. Supported overload.
virtual bool write()
Write the result fields.
bool calcOp()
Calculate and store the fields expression for the given operation.
virtual bool calc()=0
Perform calculation on the list of fields and return success.
virtual bool read(const dictionary &)
Read the fieldsExpression data.
void operator=(const fieldsExpression &)=delete
Disallow default bitwise assignment.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
static List< word > fieldNames
Definition: globalFoam.H:46
volScalarField & b
Definition: createFields.H:27
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
#define Op(opName, op)
Definition: ops.H:100
dictionary dict