FieldFunctions.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) 2011-2026 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 \*---------------------------------------------------------------------------*/
25 
26 #include "UPstream.H"
27 
28 #define TEMPLATE template<class Type>
29 #include "FieldFunctionsM.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
37 
38 template<class Type>
39 void component
40 (
41  Field<typename Field<Type>::cmptType>& res,
42  const UList<Type>& f,
43  const direction d
44 );
45 
46 
47 template<class Type>
48 void T(Field<Type>& res, const UList<Type>& f);
49 
50 
51 template<class Type, direction r>
52 void pow
53 (
54  Field<typename powProduct<Type, r>::type>& res,
55  const Field<Type>& vf
56 );
57 
58 template<class Type, direction r>
59 void pow
60 (
61  Field<typename powProduct<Type, r>::type>& res,
62  const SubField<Type>& vf
63 );
64 
65 
66 template<class Type, direction r>
67 tmp<Field<typename powProduct<Type, r>::type>>
68 pow
69 (
70  const Field<Type>& f,
72  = pTraits<typename powProduct<Type, r>::type>::zero
73 );
74 
75 template<class Type, direction r>
76 tmp<Field<typename powProduct<Type, r>::type>>
77 pow
78 (
79  const SubField<Type>& f,
81  = pTraits<typename powProduct<Type, r>::type>::zero
82 );
83 
84 template<class Type, direction r>
85 tmp<Field<typename powProduct<Type, r>::type>>
86 pow
87 (
88  const tmp<Field<Type>>& tf,
90  = pTraits<typename powProduct<Type, r>::type>::zero
91 );
92 
93 
94 template<class Type>
95 void sqr
96 (
97  Field<typename outerProduct<Type, Type>::type>& res,
98  const UList<Type>& vf
99 );
100 
101 template<class Type>
102 tmp<Field<typename outerProduct<Type, Type>::type>>
103 sqr(const Field<Type>& f);
104 
105 template<class Type>
106 tmp<Field<typename outerProduct<Type, Type>::type>>
107 sqr(const SubField<Type>& f);
108 
109 template<class Type>
110 tmp<Field<typename outerProduct<Type, Type>::type>>
111 sqr(const tmp<Field<Type>>& tf);
112 
113 
114 template<class Type>
115 void magSqr(Field<scalar>& res, const UList<Type>& f);
116 
117 template<class Type>
118 tmp<Field<scalar>> magSqr(const Field<Type>& f);
119 
120 template<class Type>
121 tmp<Field<scalar>> magSqr(const SubField<Type>& f);
122 
123 template<class Type>
124 tmp<Field<scalar>> magSqr(const tmp<Field<Type>>& tf);
125 
126 
127 template<class Type>
128 void mag(Field<scalar>& res, const UList<Type>& f);
129 
130 template<class Type>
131 tmp<Field<scalar>> mag(const Field<Type>& f);
132 
133 template<class Type>
134 tmp<Field<scalar>> mag(const SubField<Type>& f);
135 
136 template<class Type>
137 tmp<Field<scalar>> mag(const tmp<Field<Type>>& tf);
138 
139 
140 template<class Type>
141 void cmptMax(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
142 
143 template<class Type>
144 tmp<Field<typename Field<Type>::cmptType>> cmptMax(const Field<Type>& f);
145 
146 template<class Type>
147 tmp<Field<typename Field<Type>::cmptType>> cmptMax(const SubField<Type>& f);
148 
149 template<class Type>
150 tmp<Field<typename Field<Type>::cmptType>>
151 cmptMax(const tmp<Field<Type>>& tf);
152 
153 
154 template<class Type>
155 void cmptMin(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
156 
157 template<class Type>
158 tmp<Field<typename Field<Type>::cmptType>> cmptMin(const Field<Type>& f);
159 
160 template<class Type>
161 tmp<Field<typename Field<Type>::cmptType>> cmptMin(const SubField<Type>& f);
162 
163 template<class Type>
164 tmp<Field<typename Field<Type>::cmptType>>
165 cmptMin(const tmp<Field<Type>>& tf);
166 
167 
168 template<class Type>
169 void cmptAv(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
170 
171 template<class Type>
172 tmp<Field<typename Field<Type>::cmptType>> cmptAv(const Field<Type>& f);
173 
174 template<class Type>
175 tmp<Field<typename Field<Type>::cmptType>> cmptAv(const SubField<Type>& f);
176 
177 template<class Type>
178 tmp<Field<typename Field<Type>::cmptType>> cmptAv(const tmp<Field<Type>>& tf);
179 
180 
181 template<class Type>
182 void cmptMag(Field<Type>& res, const UList<Type>& f);
183 
184 template<class Type>
185 tmp<Field<Type>> cmptMag(const Field<Type>& f);
186 
187 template<class Type>
188 tmp<Field<Type>> cmptMag(const SubField<Type>& f);
189 
190 template<class Type>
191 tmp<Field<Type>> cmptMag(const tmp<Field<Type>>& tf);
192 
193 
194 BINARY_FUNCTION(Type, Type, Type, max)
195 BINARY_FUNCTION(Type, Type, Type, min)
196 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
197 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
198 
199 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
200 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
201 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
202 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
203 
204 
205 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
206 
207 UNARY_OPERATOR(Type, Type, -, negate)
208 
209 BINARY_OPERATOR(Type, Type, scalar, *, multiply)
210 BINARY_OPERATOR(Type, scalar, Type, *, multiply)
211 BINARY_OPERATOR(Type, Type, scalar, /, divide)
212 
213 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
214 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
215 
216 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
217 
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 #define PRODUCT_OPERATOR(product, Op, OpFunc) \
222  \
223 template<class Type1, class Type2> \
224 void OpFunc \
225 ( \
226  Field<typename product<Type1, Type2>::type>& res, \
227  const UList<Type1>& f1, \
228  const UList<Type2>& f2 \
229 ); \
230  \
231 template<class Type1, class Type2> \
232 tmp<Field<typename product<Type1, Type2>::type>> \
233 operator Op(const Field<Type1>& f1, const Field<Type2>& f2); \
234  \
235 template<class Type1, class Type2> \
236 tmp<Field<typename product<Type1, Type2>::type>> \
237 operator Op(const Field<Type1>& f1, const SubField<Type2>& f2); \
238  \
239 template<class Type1, class Type2> \
240 tmp<Field<typename product<Type1, Type2>::type>> \
241 operator Op(const SubField<Type1>& f1, const Field<Type2>& f2); \
242  \
243 template<class Type1, class Type2> \
244 tmp<Field<typename product<Type1, Type2>::type>> \
245 operator Op(const SubField<Type1>& f1, const SubField<Type2>& f2); \
246  \
247 template<class Type1, class Type2> \
248 tmp<Field<typename product<Type1, Type2>::type>> \
249 operator Op(const Field<Type1>& f1, const tmp<Field<Type2>>& tf2); \
250  \
251 template<class Type1, class Type2> \
252 tmp<Field<typename product<Type1, Type2>::type>> \
253 operator Op(const SubField<Type1>& f1, const tmp<Field<Type2>>& tf2); \
254  \
255 template<class Type1, class Type2> \
256 tmp<Field<typename product<Type1, Type2>::type>> \
257 operator Op(const tmp<Field<Type1>>& tf1, const Field<Type2>& f2); \
258  \
259 template<class Type1, class Type2> \
260 tmp<Field<typename product<Type1, Type2>::type>> \
261 operator Op(const tmp<Field<Type1>>& tf1, const SubField<Type2>& f2); \
262  \
263 template<class Type1, class Type2> \
264 tmp<Field<typename product<Type1, Type2>::type>> \
265 operator Op(const tmp<Field<Type1>>& tf1, const tmp<Field<Type2>>& tf2); \
266  \
267 template<class Type, class Form, class Cmpt, direction nCmpt> \
268 void OpFunc \
269 ( \
270  Field<typename product<Type, Form>::type>& res, \
271  const UList<Type>& f1, \
272  const VectorSpace<Form,Cmpt,nCmpt>& vs \
273 ); \
274  \
275 template<class Type, class Form, class Cmpt, direction nCmpt> \
276 tmp<Field<typename product<Type, Form>::type>> \
277 operator Op(const Field<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs); \
278  \
279 template<class Type, class Form, class Cmpt, direction nCmpt> \
280 tmp<Field<typename product<Type, Form>::type>> \
281 operator Op(const SubField<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs); \
282  \
283 template<class Type, class Form, class Cmpt, direction nCmpt> \
284 tmp<Field<typename product<Type, Form>::type>> \
285 operator Op(const tmp<Field<Type>>&tf1,const VectorSpace<Form,Cmpt,nCmpt>&vs); \
286  \
287 template<class Form, class Cmpt, direction nCmpt, class Type> \
288 void OpFunc \
289 ( \
290  Field<typename product<Form, Type>::type>& res, \
291  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
292  const UList<Type>& f1 \
293 ); \
294  \
295 template<class Form, class Cmpt, direction nCmpt, class Type> \
296 tmp<Field<typename product<Form, Type>::type>> \
297 operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const Field<Type>& f1); \
298  \
299 template<class Form, class Cmpt, direction nCmpt, class Type> \
300 tmp<Field<typename product<Form, Type>::type>> \
301 operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const SubField<Type>& f1); \
302  \
303 template<class Form, class Cmpt, direction nCmpt, class Type> \
304 tmp<Field<typename product<Form, Type>::type>> \
305 operator Op(const VectorSpace<Form,Cmpt,nCmpt>&vs,const tmp<Field<Type>>&tf1);
306 
307 PRODUCT_OPERATOR(typeOfSum, +, add)
308 PRODUCT_OPERATOR(typeOfSum, -, subtract)
309 
310 PRODUCT_OPERATOR(outerProduct, *, outer)
311 PRODUCT_OPERATOR(crossProduct, ^, cross)
312 PRODUCT_OPERATOR(innerProduct, &, dot)
313 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
314 
315 #undef PRODUCT_OPERATOR
316 
317 
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319 
320 } // End namespace Foam
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 #include "undefFieldFunctionsM.H"
325 
326 // ************************************************************************* //
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
High performance macro functions for Field<Type> algebra. These expand using either array element acc...
#define PRODUCT_OPERATOR(product, Op, OpFunc)
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:98
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:90
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:136
const tensorField & tf
Namespace for OpenFOAM.
void subtract(GeometricField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
void outer(GeometricField< typename outerProduct< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
void add(GeometricField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
tmp< DimensionedField< Type, GeoMesh, Field > > cmptMultiply(const DimensionedField< Type, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type, GeoMesh, PrimitiveField2 > &df2)
void divide(pointPatchField< Type > &f, const pointPatchField< Type > &f1, const pointPatchField< scalar > &f2)
void cmptMax(Field< typename Field< Type >::cmptType > &res, const UList< Type > &f)
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void component(GeometricField< typename GeometricField< Type, GeoMesh, PrimitiveField1 >::cmptType, GeoMesh, PrimitiveField1 > &gcf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf, const direction d)
tmp< DimensionedField< Type, GeoMesh, Field > > cmptDivide(const DimensionedField< Type, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type, GeoMesh, PrimitiveField2 > &df2)
void dotdot(GeometricField< typename scalarProduct< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void cmptMin(Field< typename Field< Type >::cmptType > &res, const UList< Type > &f)
void cross(GeometricField< typename crossProduct< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
tmp< DimensionedField< typename powProduct< Type, r >::type, GeoMesh, Field > > pow(const DimensionedField< Type, GeoMesh, PrimitiveField > &df, typename powProduct< Type, r >::type)
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh, PrimitiveField >::cmptType, GeoMesh, Field >> cmptAv(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void multiply(pointPatchField< Type > &f, const pointPatchField< scalar > &f1, const pointPatchField< Type > &f2)
void negate(pointPatchField< Type > &f, const pointPatchField< Type > &f1)
tmp< DimensionedField< Type, GeoMesh, Field > > cmptMag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
tmp< DimensionedField< scalar, GeoMesh, Field > > magSqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void T(GeometricField< Type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf1)
uint8_t direction
Definition: direction.H:45
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void dot(GeometricField< typename innerProduct< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
labelList f(nPoints)