FieldFieldFunctions.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 #include "scalarFieldField.H"
30 
31 #define TEMPLATE template<template<class> class Field, class Type>
32 #include "FieldFieldFunctionsM.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 /* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
40 
41 template<template<class> class Field, class Type>
42 void component
43 (
44  FieldField<Field, typename FieldField<Field, Type>::cmptType>& sf,
45  const FieldField<Field, Type>& f,
46  const direction d
47 );
48 
49 template<template<class> class Field, class Type>
50 void T(FieldField<Field, Type>& f1, const FieldField<Field, Type>& f2);
51 
52 
53 template<template<class> class Field, class Type, direction r>
54 void pow
55 (
56  FieldField<Field, typename powProduct<Type, r>::type>& f,
57  const FieldField<Field, Type>& vf
58 );
59 
60 template<template<class> class Field, class Type, direction r>
62 pow
63 (
64  const FieldField<Field, Type>& f, typename powProduct<Type, r>::type
65  = pTraits<typename powProduct<Type, r>::type>::zero
66 );
67 
68 template<template<class> class Field, class Type, direction r>
70 pow
71 (
72  const tmp<FieldField<Field, Type>>& tf, typename powProduct<Type, r>::type
73  = pTraits<typename powProduct<Type, r>::type>::zero
74 );
75 
76 
77 template<template<class> class Field, class Type>
78 void sqr
79 (
80  FieldField<Field, typename outerProduct<Type, Type>::type>& f,
81  const FieldField<Field, Type>& vf
82 );
83 
84 template<template<class> class Field, class Type>
86 sqr(const FieldField<Field, Type>& f);
87 
88 template<template<class> class Field, class Type>
90 sqr(const tmp<FieldField<Field, Type>>& tf);
91 
92 
93 template<template<class> class Field, class Type>
94 void magSqr
95 (
96  FieldField<Field, typename typeOfMag<Type>::type>& sf,
97  const FieldField<Field, Type>& f
98 );
99 
100 template<template<class> class Field, class Type>
102 magSqr(const FieldField<Field, Type>& f);
103 
104 template<template<class> class Field, class Type>
106 magSqr(const tmp<FieldField<Field, Type>>& tf);
107 
108 
109 template<template<class> class Field, class Type>
110 void mag
111 (
112  FieldField<Field, typename typeOfMag<Type>::type>& res,
113  const FieldField<Field, Type>& f
114 );
115 
116 template<template<class> class Field, class Type>
118 mag(const FieldField<Field, Type>& f);
119 
120 template<template<class> class Field, class Type>
122 mag(const tmp<FieldField<Field, Type>>& tf);
123 
124 
125 template<template<class> class Field, class Type>
126 void cmptMax
127 (
128  FieldField<Field, typename FieldField<Field, Type>::cmptType>& cf,
129  const FieldField<Field, Type>& f
130 );
131 
132 template<template<class> class Field, class Type>
133 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType>> cmptMax
134 (
135  const FieldField<Field, Type>& f
136 );
137 
138 template<template<class> class Field, class Type>
139 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType>> cmptMax
140 (
141  const tmp<FieldField<Field, Type>>& tf
142 );
143 
144 
145 template<template<class> class Field, class Type>
146 void cmptMin
147 (
148  FieldField<Field, typename FieldField<Field, Type>::cmptType>& cf,
149  const FieldField<Field, Type>& f
150 );
151 
152 template<template<class> class Field, class Type>
153 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType>> cmptMin
154 (
155  const FieldField<Field, Type>& f
156 );
157 
158 template<template<class> class Field, class Type>
159 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType>> cmptMin
160 (
161  const tmp<FieldField<Field, Type>>& tf
162 );
163 
164 
165 template<template<class> class Field, class Type>
166 void cmptAv
167 (
168  FieldField<Field, typename FieldField<Field, Type>::cmptType>& cf,
169  const FieldField<Field, Type>& f
170 );
171 
172 template<template<class> class Field, class Type>
173 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType>> cmptAv
174 (
175  const FieldField<Field, Type>& f
176 );
177 
178 template<template<class> class Field, class Type>
179 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType>> cmptAv
180 (
181  const tmp<FieldField<Field, Type>>& tf
182 );
183 
184 
185 template<template<class> class Field, class Type>
186 void cmptMag
187 (
188  FieldField<Field, Type>& cf,
189  const FieldField<Field, Type>& f
190 );
191 
192 template<template<class> class Field, class Type>
193 tmp<FieldField<Field, Type>> cmptMag
194 (
195  const FieldField<Field, Type>& f
196 );
197 
198 template<template<class> class Field, class Type>
199 tmp<FieldField<Field, Type>> cmptMag
200 (
201  const tmp<FieldField<Field, Type>>& tf
202 );
203 
204 
205 #define TMP_UNARY_FUNCTION(returnType, func) \
206  \
207 template<template<class> class Field, class Type> \
208 returnType func(const tmp<FieldField<Field, Type>>& tf1);
209 
210 
211 template<template<class> class Field, class Type>
212 Type max(const FieldField<Field, Type>& f);
213 
214 TMP_UNARY_FUNCTION(Type, max)
215 
216 
217 template<template<class> class Field, class Type>
218 Type min(const FieldField<Field, Type>& f);
219 
220 TMP_UNARY_FUNCTION(Type, min)
221 
222 
223 template<template<class> class Field, class Type>
224 Type sum(const FieldField<Field, Type>& f);
225 
226 TMP_UNARY_FUNCTION(Type, sum)
227 
228 
229 template<template<class> class Field, class Type>
230 typename typeOfMag<Type>::type sumMag(const FieldField<Field, Type>& f);
231 
233 
234 
235 template<template<class> class Field, class Type>
236 Type average(const FieldField<Field, Type>& f);
237 
239 
240 
241 //- Return min/max for a field of fields
242 template<template<class> class Field, class Type>
243 MinMax<Type> minMax(const FieldField<Field, Type>& f);
244 
245 TMP_UNARY_FUNCTION(MinMax<Type>, minMax)
246 
247 //- Return mag min/max for a field of fields
248 template<template<class> class Field, class Type>
249 scalarMinMax minMaxMag(const FieldField<Field, Type>& f);
250 
253 
254 // With reduction on ReturnType
255 #define G_UNARY_FUNCTION(ReturnType, gFunc, func, rFunc) \
256  \
257 template<template<class> class Field, class Type> \
258 ReturnType gFunc(const FieldField<Field, Type>& f); \
259 TMP_UNARY_FUNCTION(ReturnType, gFunc)
260 
261 G_UNARY_FUNCTION(Type, gMax, max, max)
262 G_UNARY_FUNCTION(Type, gMin, min, min)
263 G_UNARY_FUNCTION(Type, gSum, sum, sum)
264 G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, sum)
266 
268 
269 #undef G_UNARY_FUNCTION
270 
271 
272 template<template<class> class Field, class Type>
273 Type gAverage(const FieldField<Field, Type>& f);
274 
276 
277 #undef TMP_UNARY_FUNCTION
278 
279 
280 BINARY_FUNCTION(Type, Type, Type, max)
281 BINARY_FUNCTION(Type, Type, Type, min)
282 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
283 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
284 
285 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
286 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
287 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
288 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
289 
290 // Note: works with zero_one through implicit conversion to MinMax
291 BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clamp)
292 
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 
295 TERNARY_FUNCTION(Type, Type, Type, scalar, lerp)
296 TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp)
297 
298 
299 /* * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * */
300 
301 UNARY_OPERATOR(Type, Type, -, negate)
302 
303 BINARY_OPERATOR(Type, Type, scalar, *, multiply)
304 BINARY_OPERATOR(Type, scalar, Type, *, multiply)
305 BINARY_OPERATOR(Type, Type, scalar, /, divide)
306 
307 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
308 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
309 
310 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
311 
313 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
314 
315 #define PRODUCT_OPERATOR(product, op, opFunc) \
316  \
317 template \
318 < \
319  template<class> class Field1, \
320  template<class> class Field2, \
321  class Type1, \
322  class Type2 \
323 > \
324 void opFunc \
325 ( \
326  FieldField<Field1, typename product<Type1, Type2>::type>& f, \
327  const FieldField<Field1, Type1>& f1, \
328  const FieldField<Field2, Type2>& f2 \
329 ); \
330  \
331 template \
332 < \
333  template<class> class Field1, \
334  template<class> class Field2, \
335  class Type1, \
336  class Type2 \
337 > \
338 tmp<FieldField<Field1, typename product<Type1, Type2>::type>> \
339 operator op \
340 ( \
341  const FieldField<Field1, Type1>& f1, \
342  const FieldField<Field2, Type2>& f2 \
343 ); \
344  \
345 template<template<class> class Field, class Type1, class Type2> \
346 tmp<FieldField<Field, typename product<Type1, Type2>::type>> \
347 operator op \
348 ( \
349  const FieldField<Field, Type1>& f1, \
350  const tmp<FieldField<Field, Type2>>& tf2 \
351 ); \
352  \
353 template \
354 < \
355  template<class> class Field1, \
356  template<class> class Field2, \
357  class Type1, \
358  class Type2 \
359 > \
360 tmp<FieldField<Field1, typename product<Type1, Type2>::type>> \
361 operator op \
362 ( \
363  const FieldField<Field1, Type1>& f1, \
364  const tmp<FieldField<Field2, Type2>>& tf2 \
365 ); \
366  \
367 template \
368 < \
369  template<class> class Field1, \
370  template<class> class Field2, \
371  class Type1, \
372  class Type2 \
373 > \
374 tmp<FieldField<Field1, typename product<Type1, Type2>::type>> \
375 operator op \
376 ( \
377  const tmp<FieldField<Field1, Type1>>& tf1, \
378  const FieldField<Field2, Type2>& f2 \
379 ); \
380  \
381 template \
382 < \
383  template<class> class Field1, \
384  template<class> class Field2, \
385  class Type1, \
386  class Type2 \
387 > \
388 tmp<FieldField<Field1, typename product<Type1, Type2>::type>> \
389 operator op \
390 ( \
391  const tmp<FieldField<Field1, Type1>>& tf1, \
392  const tmp<FieldField<Field2, Type2>>& tf2 \
393 ); \
394  \
395 template \
396 < \
397  template<class> class Field, \
398  class Type, \
399  class Form, \
400  class Cmpt, \
401  direction nCmpt \
402 > \
403 void opFunc \
404 ( \
405  FieldField<Field, typename product<Type, Form>::type>& f, \
406  const FieldField<Field, Type>& f1, \
407  const VectorSpace<Form,Cmpt,nCmpt>& vs \
408 ); \
409  \
410 template \
411 < \
412  template<class> class Field, \
413  class Type, \
414  class Form, \
415  class Cmpt, \
416  direction nCmpt \
417 > \
418 tmp<FieldField<Field, typename product<Type, Form>::type>> \
419 operator op \
420 ( \
421  const FieldField<Field, Type>& f1, \
422  const VectorSpace<Form,Cmpt,nCmpt>& vs \
423 ); \
424  \
425 template \
426 < \
427  template<class> class Field, \
428  class Type, \
429  class Form, \
430  class Cmpt, \
431  direction nCmpt \
432 > \
433 tmp<FieldField<Field, typename product<Type, Form>::type>> \
434 operator op \
435 ( \
436  const tmp<FieldField<Field, Type>>& tf1, \
437  const VectorSpace<Form,Cmpt,nCmpt>& vs \
438 ); \
439  \
440 template \
441 < \
442  template<class> class Field, \
443  class Type, \
444  class Form, \
445  class Cmpt, \
446  direction nCmpt \
447 > \
448 void opFunc \
449 ( \
450  FieldField<Field, typename product<Form, Type>::type>& f, \
451  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
452  const FieldField<Field, Type>& f1 \
453 ); \
454  \
455 template \
456 < \
457  template<class> class Field, \
458  class Type, \
459  class Form, \
460  class Cmpt, \
461  direction nCmpt \
462 > \
463 tmp<FieldField<Field, typename product<Form, Type>::type>> \
464 operator op \
465 ( \
466  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
467  const FieldField<Field, Type>& f1 \
468 ); \
469  \
470 template \
471 < \
472  template<class> class Field, \
473  class Type, \
474  class Form, \
475  class Cmpt, \
476  direction nCmpt \
477 > \
478 tmp<FieldField<Field, typename product<Form, Type>::type>> \
479 operator op \
480 ( \
481  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
482  const tmp<FieldField<Field, Type>>& tf1 \
483 );
484 
485 PRODUCT_OPERATOR(typeOfSum, +, add)
486 PRODUCT_OPERATOR(typeOfSum, -, subtract)
487 
488 PRODUCT_OPERATOR(outerProduct, *, outer)
489 PRODUCT_OPERATOR(crossProduct, ^, cross)
490 PRODUCT_OPERATOR(innerProduct, &, dot)
491 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
492 
493 #undef PRODUCT_OPERATOR
494 
495 
496 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
497 
498 } // End namespace Foam
499 
500 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
501 
502 #include "undefFieldFunctionsM.H"
503 
504 // ************************************************************************* //
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:46
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)
#define G_UNARY_FUNCTION(ReturnType, gFunc, func, rFunc)
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)
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define TMP_UNARY_FUNCTION(returnType, func)
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)
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)
void outer(FieldField< Field1, typename outerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
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 > &)
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Definition: hashSets.C:54
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
Type gSum(const FieldField< Field, Type > &f)
#define PRODUCT_OPERATOR(product, op, opFunc)
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
void negate(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1)
Specialisation of FieldField<T> for scalar.
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)
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)
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)
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:176
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Macro functions for FieldField<Type> algebra.
pTraits< Type >::cmptType cmptType
Component type.
Definition: FieldField.H:83
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)
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