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 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
235template<template<class> class Field, class Type>
236Type average(const FieldField<Field, Type>& f);
237
239
240
241//- Return min/max for a field of fields
242template<template<class> class Field, class Type>
243MinMax<Type> minMax(const FieldField<Field, Type>& f);
244
245TMP_UNARY_FUNCTION(MinMax<Type>, minMax)
246
247//- Return mag min/max for a field of fields
248template<template<class> class Field, class Type>
249scalarMinMax minMaxMag(const FieldField<Field, Type>& f);
250
252
253
254// With reduction on ReturnType
255#define G_UNARY_FUNCTION(ReturnType, gFunc, func, rFunc) \
256 \
257template<template<class> class Field, class Type> \
258ReturnType gFunc(const FieldField<Field, Type>& f); \
259TMP_UNARY_FUNCTION(ReturnType, gFunc)
260
264G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, sum)
266
268
269#undef G_UNARY_FUNCTION
270
271
272template<template<class> class Field, class Type>
273Type gAverage(const FieldField<Field, Type>& f);
274
276
277#undef TMP_UNARY_FUNCTION
278
279
280BINARY_FUNCTION(Type, Type, Type, max)
281BINARY_FUNCTION(Type, Type, Type, min)
282BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
283BINARY_FUNCTION(Type, Type, Type, cmptDivide)
284
285BINARY_TYPE_FUNCTION(Type, Type, Type, max)
286BINARY_TYPE_FUNCTION(Type, Type, Type, min)
287BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
288BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
289
291
292
293/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
294
295UNARY_OPERATOR(Type, Type, -, negate)
296
297BINARY_OPERATOR(Type, Type, scalar, *, multiply)
298BINARY_OPERATOR(Type, scalar, Type, *, multiply)
299BINARY_OPERATOR(Type, Type, scalar, /, divide)
300
301BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
302BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
303
304BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
305
306
307// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
308
309#define PRODUCT_OPERATOR(product, op, opFunc) \
310 \
311template \
312< \
313 template<class> class Field1, \
314 template<class> class Field2, \
315 class Type1, \
316 class Type2 \
317> \
318void opFunc \
319( \
320 FieldField<Field1, typename product<Type1, Type2>::type>& f, \
321 const FieldField<Field1, Type1>& f1, \
322 const FieldField<Field2, Type2>& f2 \
323); \
324 \
325template \
326< \
327 template<class> class Field1, \
328 template<class> class Field2, \
329 class Type1, \
330 class Type2 \
331> \
332tmp<FieldField<Field1, typename product<Type1, Type2>::type>> \
333operator op \
334( \
335 const FieldField<Field1, Type1>& f1, \
336 const FieldField<Field2, Type2>& f2 \
337); \
338 \
339template<template<class> class Field, class Type1, class Type2> \
340tmp<FieldField<Field, typename product<Type1, Type2>::type>> \
341operator op \
342( \
343 const FieldField<Field, Type1>& f1, \
344 const tmp<FieldField<Field, Type2>>& tf2 \
345); \
346 \
347template \
348< \
349 template<class> class Field1, \
350 template<class> class Field2, \
351 class Type1, \
352 class Type2 \
353> \
354tmp<FieldField<Field1, typename product<Type1, Type2>::type>> \
355operator op \
356( \
357 const FieldField<Field1, Type1>& f1, \
358 const tmp<FieldField<Field2, Type2>>& tf2 \
359); \
360 \
361template \
362< \
363 template<class> class Field1, \
364 template<class> class Field2, \
365 class Type1, \
366 class Type2 \
367> \
368tmp<FieldField<Field1, typename product<Type1, Type2>::type>> \
369operator op \
370( \
371 const tmp<FieldField<Field1, Type1>>& tf1, \
372 const FieldField<Field2, Type2>& f2 \
373); \
374 \
375template \
376< \
377 template<class> class Field1, \
378 template<class> class Field2, \
379 class Type1, \
380 class Type2 \
381> \
382tmp<FieldField<Field1, typename product<Type1, Type2>::type>> \
383operator op \
384( \
385 const tmp<FieldField<Field1, Type1>>& tf1, \
386 const tmp<FieldField<Field2, Type2>>& tf2 \
387); \
388 \
389template \
390< \
391 template<class> class Field, \
392 class Type, \
393 class Form, \
394 class Cmpt, \
395 direction nCmpt \
396> \
397void opFunc \
398( \
399 FieldField<Field, typename product<Type, Form>::type>& f, \
400 const FieldField<Field, Type>& f1, \
401 const VectorSpace<Form,Cmpt,nCmpt>& vs \
402); \
403 \
404template \
405< \
406 template<class> class Field, \
407 class Type, \
408 class Form, \
409 class Cmpt, \
410 direction nCmpt \
411> \
412tmp<FieldField<Field, typename product<Type, Form>::type>> \
413operator op \
414( \
415 const FieldField<Field, Type>& f1, \
416 const VectorSpace<Form,Cmpt,nCmpt>& vs \
417); \
418 \
419template \
420< \
421 template<class> class Field, \
422 class Type, \
423 class Form, \
424 class Cmpt, \
425 direction nCmpt \
426> \
427tmp<FieldField<Field, typename product<Type, Form>::type>> \
428operator op \
429( \
430 const tmp<FieldField<Field, Type>>& tf1, \
431 const VectorSpace<Form,Cmpt,nCmpt>& vs \
432); \
433 \
434template \
435< \
436 template<class> class Field, \
437 class Type, \
438 class Form, \
439 class Cmpt, \
440 direction nCmpt \
441> \
442void opFunc \
443( \
444 FieldField<Field, typename product<Form, Type>::type>& f, \
445 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
446 const FieldField<Field, Type>& f1 \
447); \
448 \
449template \
450< \
451 template<class> class Field, \
452 class Type, \
453 class Form, \
454 class Cmpt, \
455 direction nCmpt \
456> \
457tmp<FieldField<Field, typename product<Form, Type>::type>> \
458operator op \
459( \
460 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
461 const FieldField<Field, Type>& f1 \
462); \
463 \
464template \
465< \
466 template<class> class Field, \
467 class Type, \
468 class Form, \
469 class Cmpt, \
470 direction nCmpt \
471> \
472tmp<FieldField<Field, typename product<Form, Type>::type>> \
473operator op \
474( \
475 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
476 const tmp<FieldField<Field, Type>>& tf1 \
477);
478
479PRODUCT_OPERATOR(typeOfSum, +, add)
480PRODUCT_OPERATOR(typeOfSum, -, subtract)
481
482PRODUCT_OPERATOR(outerProduct, *, outer)
483PRODUCT_OPERATOR(crossProduct, ^, cross)
484PRODUCT_OPERATOR(innerProduct, &, dot)
485PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
486
487#undef PRODUCT_OPERATOR
488
489
490// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
491
492} // End namespace Foam
493
494// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
495
496#include "undefFieldFunctionsM.H"
497
498// ************************************************************************* //
#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 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 G_UNARY_FUNCTION(ReturnType, gFunc, func, rFunc)
#define TMP_UNARY_FUNCTION(returnType, func)
pTraits< Type >::cmptType cmptType
Component type.
Definition: FieldField.H:85
A min/max value pair with additional methods. In addition to conveniently storing values,...
Definition: MinMax.H:128
typeOfRank< typenamepTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank)>::type type
Definition: products.H:114
symmTypeOfRank< typenamepTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank)>::type type
Definition: products.H:170
pTraits< typenamepTraits< arg1 >::cmptType >::magType type
Definition: products.H:92
const volScalarField & T
#define PRODUCT_OPERATOR(product, op, opFunc)
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dimensionSet clip(const dimensionSet &ds1, const dimensionSet &ds2)
Definition: dimensionSet.C:278
Type gSum(const FieldField< Field, Type > &f)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
MinMax< scalar > scalarMinMax
A scalar min/max range.
Definition: MinMax.H:117
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
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:61
dimensioned< typename typeOfMag< Type >::type > sumMag(const DimensionedField< Type, GeoMesh > &df)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
void negate(FieldField< Field, Type > &res, const FieldField< Field, Type > &f)
void multiply(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
uint8_t direction
Definition: direction.H:56
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Type gAverage(const FieldField< Field, Type > &f)
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
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)
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh > > cmptAv(const DimensionedField< Type, GeoMesh > &df)
dimensioned< scalarMinMax > minMaxMag(const DimensionedField< Type, GeoMesh > &df)
Type gMax(const FieldField< Field, Type > &f)
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
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)
labelList f(nPoints)
Specialisation of FieldField<T> for scalar.