FieldFunctions.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2023 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 \*---------------------------------------------------------------------------*/
28 
29 #define TEMPLATE template<class Type>
30 #include "FieldFunctionsM.H"
31 #include "UPstream.H"
32 #include "MinMax.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
40 
41 template<class Type>
42 void component
43 (
44  Field<typename Field<Type>::cmptType>& res,
45  const UList<Type>& f,
46  const direction d
47 );
48 
49 
50 template<class Type>
51 void T(Field<Type>& res, const UList<Type>& f);
52 
53 
54 template<class Type, direction r>
55 void pow
56 (
57  Field<typename powProduct<Type, r>::type>& res,
58  const UList<Type>& vf
59 );
60 
61 
62 template<class Type, direction r>
64 pow
65 (
66  const UList<Type>& f,
68  = pTraits<typename powProduct<Type, r>::type>::zero
69 );
70 
71 template<class Type, direction r>
73 pow
74 (
75  const tmp<Field<Type>>& tf,
77  = pTraits<typename powProduct<Type, r>::type>::zero
78 );
79 
80 
81 template<class Type>
82 void sqr
83 (
84  Field<typename outerProduct<Type, Type>::type>& res,
85  const UList<Type>& vf
86 );
87 
88 template<class Type>
90 sqr(const UList<Type>& f);
91 
92 template<class Type>
94 sqr(const tmp<Field<Type>>& tf);
95 
96 
97 template<class Type>
98 void magSqr
99 (
100  Field<typename typeOfMag<Type>::type>& res,
101  const UList<Type>& f
102 );
103 
104 template<class Type>
106 magSqr(const UList<Type>& f);
107 
108 template<class Type>
110 magSqr(const tmp<Field<Type>>& tf);
111 
112 
113 template<class Type>
114 void mag
115 (
116  Field<typename typeOfMag<Type>::type>& res,
117  const UList<Type>& f
118 );
119 
120 template<class Type>
122 mag(const UList<Type>& f);
123 
124 template<class Type>
126 mag(const tmp<Field<Type>>& tf);
127 
128 
129 template<class Type>
130 void cmptMax(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
131 
132 template<class Type>
133 tmp<Field<typename Field<Type>::cmptType>> cmptMax(const UList<Type>& f);
134 
135 template<class Type>
136 tmp<Field<typename Field<Type>::cmptType>>
137 cmptMax(const tmp<Field<Type>>& tf);
138 
139 
140 template<class Type>
141 void cmptMin(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
142 
143 template<class Type>
144 tmp<Field<typename Field<Type>::cmptType>> cmptMin(const UList<Type>& f);
145 
146 template<class Type>
147 tmp<Field<typename Field<Type>::cmptType>>
148 cmptMin(const tmp<Field<Type>>& tf);
149 
150 
151 template<class Type>
152 void cmptAv(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
153 
154 template<class Type>
155 tmp<Field<typename Field<Type>::cmptType>> cmptAv(const UList<Type>& f);
156 
157 template<class Type>
158 tmp<Field<typename Field<Type>::cmptType>> cmptAv(const tmp<Field<Type>>& tf);
159 
160 
161 template<class Type>
162 void cmptMag(Field<Type>& res, const UList<Type>& f);
163 
164 template<class Type>
165 tmp<Field<Type>> cmptMag(const UList<Type>& f);
166 
167 template<class Type>
168 tmp<Field<Type>> cmptMag(const tmp<Field<Type>>& tf);
169 
170 
171 template<class Type>
172 void cmptMagSqr(Field<Type>& res, const UList<Type>& f);
173 
174 template<class Type>
175 tmp<Field<Type>> cmptMagSqr(const UList<Type>& f);
176 
177 template<class Type>
178 tmp<Field<Type>> cmptMagSqr(const tmp<Field<Type>>& tf);
179 
180 
181 #define TMP_UNARY_FUNCTION(ReturnType, Func) \
182  \
183  \
184 template<class Type> \
185 ReturnType Func(const tmp<Field<Type>>& tf1);
186 
187 template<class Type>
188 Type max(const UList<Type>& f);
189 
190 TMP_UNARY_FUNCTION(Type, max)
191 
192 template<class Type>
193 Type min(const UList<Type>& f);
194 
195 TMP_UNARY_FUNCTION(Type, min)
196 
197 template<class Type>
198 Type sum(const UList<Type>& f);
199 
200 TMP_UNARY_FUNCTION(Type, sum)
201 
202 
203 // From MinMaxOps.H:
204 // - Foam::minMax(const UList<Type>&)
205 // - Foam::minMaxMag(const UList<Type>&)
206 
207 TMP_UNARY_FUNCTION(MinMax<Type>, minMax)
209 
210 
211 template<class Type>
212 Type maxMagSqr(const UList<Type>& f);
213 
215 
216 template<class Type>
217 Type minMagSqr(const UList<Type>& f);
218 
220 
221 
222 template<class Type>
224 sumProd
225 (
226  const UList<Type>& f1,
227  const UList<Type>& f2
228 );
229 
230 template<class Type>
231 Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2);
232 
233 template<class Type>
234 typename outerProduct1<Type>::type sumSqr(const UList<Type>& f);
235 
236 template<class Type>
237 typename outerProduct1<Type>::type sumSqr(const tmp<Field<Type>>& tf);
238 
239 template<class Type>
240 typename typeOfMag<Type>::type sumMag(const UList<Type>& f);
241 
243 
244 template<class Type>
245 Type sumCmptMag(const UList<Type>& f);
246 
248 
249 template<class Type>
250 Type average(const UList<Type>& f);
251 
253 
254 
255 // With reduction on ReturnType
256 #define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \
257  \
258 template<class Type> \
259 ReturnType gFunc(const UList<Type>& f, const label comm = UPstream::worldComm);\
260 TMP_UNARY_FUNCTION(ReturnType, gFunc)
261 
262 G_UNARY_FUNCTION(Type, gMax, max, max)
263 G_UNARY_FUNCTION(Type, gMin, min, min)
264 G_UNARY_FUNCTION(Type, gSum, sum, sum)
268 
269 G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, sum)
271 
274 
275 #undef G_UNARY_FUNCTION
276 
277 
278 template<class Type>
280 (
281  const UList<Type>& f1,
282  const UList<Type>& f2,
283  const label comm = UPstream::worldComm
284 );
285 
286 template<class Type>
287 Type gSumCmptProd
288 (
289  const UList<Type>& f1,
290  const UList<Type>& f2,
291  const label comm = UPstream::worldComm
292 );
293 
294 template<class Type>
295 Type gAverage
296 (
297  const UList<Type>& f,
298  const label comm = UPstream::worldComm
299 );
300 
302 
303 #undef TMP_UNARY_FUNCTION
304 
305 
306 BINARY_FUNCTION(Type, Type, Type, max)
307 BINARY_FUNCTION(Type, Type, Type, min)
308 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
309 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
310 
311 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
312 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
313 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
314 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
315 
316 BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clamp)
318 BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip) // Same as clamp
319 
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 
322 TERNARY_FUNCTION(Type, Type, Type, scalar, lerp)
323 TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp)
324 
325 
326 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
327 
328 UNARY_OPERATOR(Type, Type, -, negate)
329 
330 BINARY_OPERATOR(Type, Type, scalar, *, multiply)
331 BINARY_OPERATOR(Type, scalar, Type, *, multiply)
332 BINARY_OPERATOR(Type, Type, scalar, /, divide)
333 
334 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
335 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
336 
337 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
338 
339 
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 
342 #define PRODUCT_OPERATOR(product, Op, OpFunc) \
343  \
344 template<class Type1, class Type2> \
345 void OpFunc \
346 ( \
347  Field<typename product<Type1, Type2>::type>& res, \
348  const UList<Type1>& f1, \
349  const UList<Type2>& f2 \
350 ); \
351  \
352 template<class Type1, class Type2> \
353 tmp<Field<typename product<Type1, Type2>::type>> \
354 operator Op(const UList<Type1>& f1, const UList<Type2>& f2); \
355  \
356 template<class Type1, class Type2> \
357 tmp<Field<typename product<Type1, Type2>::type>> \
358 operator Op(const UList<Type1>& f1, const tmp<Field<Type2>>& tf2); \
359  \
360 template<class Type1, class Type2> \
361 tmp<Field<typename product<Type1, Type2>::type>> \
362 operator Op(const tmp<Field<Type1>>& tf1, const UList<Type2>& f2); \
363  \
364 template<class Type1, class Type2> \
365 tmp<Field<typename product<Type1, Type2>::type>> \
366 operator Op(const tmp<Field<Type1>>& tf1, const tmp<Field<Type2>>& tf2); \
367  \
368 template<class Type, class Form, class Cmpt, direction nCmpt> \
369 void OpFunc \
370 ( \
371  Field<typename product<Type, Form>::type>& res, \
372  const UList<Type>& f1, \
373  const VectorSpace<Form,Cmpt,nCmpt>& vs \
374 ); \
375  \
376 template<class Type, class Form, class Cmpt, direction nCmpt> \
377 tmp<Field<typename product<Type, Form>::type>> \
378 operator Op(const UList<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs); \
379  \
380 template<class Type, class Form, class Cmpt, direction nCmpt> \
381 tmp<Field<typename product<Type, Form>::type>> \
382 operator Op(const tmp<Field<Type>>&tf1,const VectorSpace<Form,Cmpt,nCmpt>&vs); \
383  \
384 template<class Form, class Cmpt, direction nCmpt, class Type> \
385 void OpFunc \
386 ( \
387  Field<typename product<Form, Type>::type>& res, \
388  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
389  const UList<Type>& f1 \
390 ); \
391  \
392 template<class Form, class Cmpt, direction nCmpt, class Type> \
393 tmp<Field<typename product<Form, Type>::type>> \
394 operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const UList<Type>& f1); \
395  \
396 template<class Form, class Cmpt, direction nCmpt, class Type> \
397 tmp<Field<typename product<Form, Type>::type>> \
398 operator Op(const VectorSpace<Form,Cmpt,nCmpt>&vs,const tmp<Field<Type>>&tf1);
399 
400 PRODUCT_OPERATOR(typeOfSum, +, add)
401 PRODUCT_OPERATOR(typeOfSum, -, subtract)
402 
403 PRODUCT_OPERATOR(outerProduct, *, outer)
404 PRODUCT_OPERATOR(crossProduct, ^, cross)
405 PRODUCT_OPERATOR(innerProduct, &, dot)
406 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
407 
408 #undef PRODUCT_OPERATOR
409 
410 
411 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
412 
413 } // End namespace Foam
414 
415 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
416 
417 #include "undefFieldFunctionsM.H"
418 #include "scalarField.H"
419 
420 // ************************************************************************* //
dimensioned< typename typeOfMag< Type >::type > sumMag(const DimensionedField< Type, GeoMesh > &f1)
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &f1)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
type
Types of root.
Definition: Roots.H:52
void divide(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
uint8_t direction
Definition: direction.H:48
MinMax< scalar > scalarMinMax
A scalar min/max range.
Definition: MinMax.H:97
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &f1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Type gMin(const FieldField< Field, Type > &f)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
dimensionedSymmTensor sqr(const dimensionedVector &dv)
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:123
Type minMagSqr(const UList< Type > &f1)
scalarProduct< Type, Type >::type gSumProd(const UList< Type > &f1, const UList< Type > &f2, const label comm)
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
Type gSumCmptMag(const UList< Type > &f, const label comm)
void clip(Field< Type > &result, const UList< Type > &f1, const MinMax< Type > &s2)
#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc)
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
Definition: UPstream.H:411
void dotdot(FieldField< Field1, typename scalarProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Type sumCmptProd(const UList< Type > &f1, const UList< Type > &f2)
Type maxMagSqr(const UList< Type > &f1)
void outer(FieldField< Field1, typename outerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
#define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc)
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
complex sumProd(const UList< complex > &f1, const UList< complex > &f2)
Sum product.
Definition: complexField.C:245
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Definition: hashSets.C:54
Type gMaxMagSqr(const UList< Type > &f, const label comm)
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
Type gMinMagSqr(const UList< Type > &f, const label comm)
outerProduct1< Type >::type sumSqr(const UList< Type > &f1)
Type gSumCmptProd(const UList< Type > &f1, const UList< Type > &f2, const label comm)
Type gSum(const FieldField< Field, Type > &f)
void cmptMagSqr(Field< Type > &result, const UList< Type > &f1)
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
pTraits< arg1 >::cmptType type
Definition: products.H:163
Type sumCmptMag(const UList< Type > &f1)
void negate(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
Macro functions for Field<Type> algebra.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Type gMax(const FieldField< Field, Type > &f)
outerProduct1< Type >::type gSumSqr(const UList< Type > &f, const label comm)
scalarMinMax gMinMaxMag(const FieldField< Field, Type > &f)
labelList f(nPoints)
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
typeOfMag< Type >::type gSumMag(const FieldField< Field, Type > &f)
Represents 0/1 range or concept. Used for tagged dispatch or clamping.
Definition: pTraits.H:84
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:176
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensioned< scalarMinMax > minMaxMag(const DimensionedField< Type, GeoMesh > &f1)
Type gAverage(const FieldField< Field, Type > &f)
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax< Type >, clip)
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func)
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
void multiply(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
#define PRODUCT_OPERATOR(product, Op, OpFunc)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Namespace for OpenFOAM.
dimensionSet clamp(const dimensionSet &a, const dimensionSet &range)
Definition: dimensionSet.C:271
pTraits< typename pTraits< arg1 >::cmptType >::magType type
Definition: products.H:96
#define TMP_UNARY_FUNCTION(ReturnType, Func)