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