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-2023 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 functionObjects_fieldsExpression_H
40 #define functionObjects_fieldsExpression_H
41 
42 #include "fvMeshFunctionObject.H"
43 #include "volFieldsFwd.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 template<class Type, class GeoMesh>
51 class DimensionedField;
52 
53 namespace functionObjects
54 {
55 
56 /*---------------------------------------------------------------------------*\
57  Class fieldsExpression Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 class fieldsExpression
61 :
63 {
64 protected:
65 
66  // Protected member data
67 
68  //- Names of fields to process
70 
71  //- Name of result fields
73 
74 
75  // Protected member functions
76 
77  //- Set the result name
78  void setResultName
79  (
80  const word& functionName,
81  const wordList& defaultFieldNames = wordList::null()
82  );
83 
84  //- Operate on the fields and store the result. Supported overload.
85  template
86  <
87  template<class> class GeoField,
88  template<class ...> class Op,
89  class TypeA,
90  class TypeB,
91  class Enable = Op<TypeA, TypeB>
92  >
93  bool opAndStore
94  (
95  const GeoField<TypeA>& a,
96  const GeoField<TypeB>& b
97  );
98 
99  //- Operate on the fields and store the result. Not-supported overload.
100  template
101  <
102  template<class> class GeoField,
103  template<class ...> class Op,
104  class ... Args
105  >
106  bool opAndStore(const Args& ...);
107 
108  //- Fold the fields expression up one place
109  template
110  <
111  template<class> class GeoField,
112  template<class ...> class Op,
113  class TypeA,
114  class TypeB
115  >
116  bool foldAB(const label i);
117 
118  //- Fold the fields expression up one place
119  template
120  <
121  template<class> class GeoField,
122  template<class ...> class Op,
123  class TypeA
124  >
125  bool foldA(const label i);
126 
127  //- Fold the fields expression up one place
128  template
129  <
130  template<class> class GeoField,
131  template<class ...> class Op
132  >
133  bool fold(const label i);
134 
135  //- Calculate and store the fields expression for the given geometric
136  // field type and operation
137  template<template<class> class GeoField, template<class ...> class Op>
138  bool calcGeoFieldOp();
139 
140  //- Calculate and store the fields expression for the given operation
141  template<template<class ...> class Op>
142  bool calcOp();
143 
144  //- Perform calculation on the list of fields and return success
145  virtual bool calc() = 0;
146 
147 
148 public:
149 
150  //- Runtime type information
151  TypeName("fieldsExpression");
152 
153 
154  // Constructors
155 
156  //- Construct from Time and dictionary
158  (
159  const word& name,
160  const Time& runTime,
161  const dictionary& dict,
163  const word& resultName = word::null
164  );
165 
166  //- Disallow default bitwise copy construction
167  fieldsExpression(const fieldsExpression&) = delete;
168 
169 
170  //- Destructor
171  virtual ~fieldsExpression();
172 
173 
174  // Member Functions
175 
176  //- Read the fieldsExpression data
177  virtual bool read(const dictionary&);
178 
179  //- Return the list of fields required
180  virtual wordList fields() const;
181 
182  //- Calculate the result fields
183  virtual bool execute();
184 
185  //- Write the result fields
186  virtual bool write();
187 
188  //- Clear the result fields from the objectRegistry
189  virtual bool clear();
190 
191 
192  // Member Operators
193 
194  //- Disallow default bitwise assignment
195  void operator=(const fieldsExpression&) = delete;
196 };
197 
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 } // End namespace functionObjects
202 } // End namespace Foam
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 #ifdef NoRepository
207  #include "fieldsExpressionTemplates.C"
208 #endif
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 #endif
213 
214 // ************************************************************************* //
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 keyword definitions, which are a keyword followed by any number of values (e....
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:25
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