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