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 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#define TEMPLATE template<class Type>
30#include "FieldFunctionsM.H"
31#include "UPstream.H"
32#include "MinMax.H"
33
34// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35
36namespace Foam
37{
38
39// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
40
41template<class Type>
42void component
43(
44 Field<typename Field<Type>::cmptType>& res,
45 const UList<Type>& f,
46 const direction d
47);
48
49
50template<class Type>
51void T(Field<Type>& res, const UList<Type>& f);
52
53
54template<class Type, direction r>
55void pow
56(
57 Field<typename powProduct<Type, r>::type>& res,
58 const UList<Type>& vf
59);
60
61
62template<class Type, direction r>
63tmp<Field<typename powProduct<Type, r>::type>>
64pow
65(
66 const UList<Type>& f,
68 = pTraits<typename powProduct<Type, r>::type>::zero
69);
70
71template<class Type, direction r>
72tmp<Field<typename powProduct<Type, r>::type>>
73pow
74(
75 const tmp<Field<Type>>& tf,
77 = pTraits<typename powProduct<Type, r>::type>::zero
78);
79
80
81template<class Type>
82void sqr
83(
84 Field<typename outerProduct<Type, Type>::type>& res,
85 const UList<Type>& vf
86);
87
88template<class Type>
89tmp<Field<typename outerProduct<Type, Type>::type>>
90sqr(const UList<Type>& f);
91
92template<class Type>
93tmp<Field<typename outerProduct<Type, Type>::type>>
94sqr(const tmp<Field<Type>>& tf);
95
96
97template<class Type>
98void magSqr
99(
100 Field<typename typeOfMag<Type>::type>& res,
101 const UList<Type>& f
102);
103
104template<class Type>
105tmp<Field<typename typeOfMag<Type>::type>>
106magSqr(const UList<Type>& f);
107
108template<class Type>
109tmp<Field<typename typeOfMag<Type>::type>>
110magSqr(const tmp<Field<Type>>& tf);
111
112
113template<class Type>
114void mag
115(
116 Field<typename typeOfMag<Type>::type>& res,
117 const UList<Type>& f
118);
119
120template<class Type>
121tmp<Field<typename typeOfMag<Type>::type>>
122mag(const UList<Type>& f);
123
124template<class Type>
125tmp<Field<typename typeOfMag<Type>::type>>
126mag(const tmp<Field<Type>>& tf);
127
128
129template<class Type>
130void cmptMax(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
131
132template<class Type>
133tmp<Field<typename Field<Type>::cmptType>> cmptMax(const UList<Type>& f);
134
135template<class Type>
136tmp<Field<typename Field<Type>::cmptType>>
137cmptMax(const tmp<Field<Type>>& tf);
138
139
140template<class Type>
141void cmptMin(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
142
143template<class Type>
144tmp<Field<typename Field<Type>::cmptType>> cmptMin(const UList<Type>& f);
145
146template<class Type>
147tmp<Field<typename Field<Type>::cmptType>>
148cmptMin(const tmp<Field<Type>>& tf);
149
150
151template<class Type>
152void cmptAv(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
153
154template<class Type>
155tmp<Field<typename Field<Type>::cmptType>> cmptAv(const UList<Type>& f);
156
157template<class Type>
158tmp<Field<typename Field<Type>::cmptType>> cmptAv(const tmp<Field<Type>>& tf);
159
160
161template<class Type>
162void cmptMag(Field<Type>& res, const UList<Type>& f);
163
164template<class Type>
165tmp<Field<Type>> cmptMag(const UList<Type>& f);
166
167template<class Type>
168tmp<Field<Type>> cmptMag(const tmp<Field<Type>>& tf);
169
170
171template<class Type>
172void cmptMagSqr(Field<Type>& res, const UList<Type>& f);
173
174template<class Type>
175tmp<Field<Type>> cmptMagSqr(const UList<Type>& f);
176
177template<class Type>
178tmp<Field<Type>> cmptMagSqr(const tmp<Field<Type>>& tf);
179
180
181#define TMP_UNARY_FUNCTION(ReturnType, Func) \
182 \
183 \
184template<class Type> \
185ReturnType Func(const tmp<Field<Type>>& tf1);
186
187template<class Type>
188Type max(const UList<Type>& f);
189
191
192template<class Type>
193Type min(const UList<Type>& f);
194
196
197template<class Type>
198Type sum(const UList<Type>& f);
199
201
202
203// From MinMaxOps.H:
204// - Foam::minMax(const UList<Type>&)
205// - Foam::minMaxMag(const UList<Type>&)
206
207TMP_UNARY_FUNCTION(MinMax<Type>, minMax)
209
210
211template<class Type>
212Type maxMagSqr(const UList<Type>& f);
213
215
216template<class Type>
217Type minMagSqr(const UList<Type>& f);
218
220
221
222template<class Type>
225(
226 const UList<Type>& f1,
227 const UList<Type>& f2
228);
229
230template<class Type>
231Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2);
232
233template<class Type>
234typename outerProduct1<Type>::type sumSqr(const UList<Type>& f);
235
236template<class Type>
237typename outerProduct1<Type>::type sumSqr(const tmp<Field<Type>>& tf);
238
239template<class Type>
240typename typeOfMag<Type>::type sumMag(const UList<Type>& f);
241
243
244template<class Type>
245Type sumCmptMag(const UList<Type>& f);
246
248
249template<class Type>
250Type average(const UList<Type>& f);
251
253
254
255// With reduction on ReturnType
256#define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \
257 \
258template<class Type> \
259ReturnType gFunc(const UList<Type>& f, const label comm = UPstream::worldComm);\
260TMP_UNARY_FUNCTION(ReturnType, gFunc)
261
268
269G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, sum)
271
274
275#undef G_UNARY_FUNCTION
276
277
278template<class Type>
280(
281 const UList<Type>& f1,
282 const UList<Type>& f2,
283 const label comm = UPstream::worldComm
284);
285
286template<class Type>
287Type gSumCmptProd
288(
289 const UList<Type>& f1,
290 const UList<Type>& f2,
291 const label comm = UPstream::worldComm
292);
293
294template<class Type>
295Type gAverage
296(
297 const UList<Type>& f,
298 const label comm = UPstream::worldComm
299);
300
302
303#undef TMP_UNARY_FUNCTION
304
305
306BINARY_FUNCTION(Type, Type, Type, max)
307BINARY_FUNCTION(Type, Type, Type, min)
308BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
309BINARY_FUNCTION(Type, Type, Type, cmptDivide)
310
311BINARY_TYPE_FUNCTION(Type, Type, Type, max)
312BINARY_TYPE_FUNCTION(Type, Type, Type, min)
313BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
314BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
315
316BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip)
317
318
319// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
320
321UNARY_OPERATOR(Type, Type, -, negate)
322
323BINARY_OPERATOR(Type, Type, scalar, *, multiply)
324BINARY_OPERATOR(Type, scalar, Type, *, multiply)
325BINARY_OPERATOR(Type, Type, scalar, /, divide)
326
327BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
328BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
329
330BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
331
332
333// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334
335#define PRODUCT_OPERATOR(product, Op, OpFunc) \
336 \
337template<class Type1, class Type2> \
338void OpFunc \
339( \
340 Field<typename product<Type1, Type2>::type>& res, \
341 const UList<Type1>& f1, \
342 const UList<Type2>& f2 \
343); \
344 \
345template<class Type1, class Type2> \
346tmp<Field<typename product<Type1, Type2>::type>> \
347operator Op(const UList<Type1>& f1, const UList<Type2>& f2); \
348 \
349template<class Type1, class Type2> \
350tmp<Field<typename product<Type1, Type2>::type>> \
351operator Op(const UList<Type1>& f1, const tmp<Field<Type2>>& tf2); \
352 \
353template<class Type1, class Type2> \
354tmp<Field<typename product<Type1, Type2>::type>> \
355operator Op(const tmp<Field<Type1>>& tf1, const UList<Type2>& f2); \
356 \
357template<class Type1, class Type2> \
358tmp<Field<typename product<Type1, Type2>::type>> \
359operator Op(const tmp<Field<Type1>>& tf1, const tmp<Field<Type2>>& tf2); \
360 \
361template<class Type, class Form, class Cmpt, direction nCmpt> \
362void OpFunc \
363( \
364 Field<typename product<Type, Form>::type>& res, \
365 const UList<Type>& f1, \
366 const VectorSpace<Form,Cmpt,nCmpt>& vs \
367); \
368 \
369template<class Type, class Form, class Cmpt, direction nCmpt> \
370tmp<Field<typename product<Type, Form>::type>> \
371operator Op(const UList<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs); \
372 \
373template<class Type, class Form, class Cmpt, direction nCmpt> \
374tmp<Field<typename product<Type, Form>::type>> \
375operator Op(const tmp<Field<Type>>&tf1,const VectorSpace<Form,Cmpt,nCmpt>&vs); \
376 \
377template<class Form, class Cmpt, direction nCmpt, class Type> \
378void OpFunc \
379( \
380 Field<typename product<Form, Type>::type>& res, \
381 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
382 const UList<Type>& f1 \
383); \
384 \
385template<class Form, class Cmpt, direction nCmpt, class Type> \
386tmp<Field<typename product<Form, Type>::type>> \
387operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const UList<Type>& f1); \
388 \
389template<class Form, class Cmpt, direction nCmpt, class Type> \
390tmp<Field<typename product<Form, Type>::type>> \
391operator Op(const VectorSpace<Form,Cmpt,nCmpt>&vs,const tmp<Field<Type>>&tf1);
392
393PRODUCT_OPERATOR(typeOfSum, +, add)
394PRODUCT_OPERATOR(typeOfSum, -, subtract)
395
396PRODUCT_OPERATOR(outerProduct, *, outer)
397PRODUCT_OPERATOR(crossProduct, ^, cross)
398PRODUCT_OPERATOR(innerProduct, &, dot)
399PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
400
401#undef PRODUCT_OPERATOR
402
403
404// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
405
406} // End namespace Foam
407
408// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
409
410#include "undefFieldFunctionsM.H"
411#include "scalarField.H"
412
413// ************************************************************************* //
#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)
#define G_UNARY_FUNCTION(ReturnType, gFunc, func, rFunc)
#define TMP_UNARY_FUNCTION(returnType, func)
High performance macro functions for Field<Type> algebra. These expand using either array element acc...
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:86
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:293
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< arg1 >::cmptType type
Definition: products.H:157
pTraits< typenamepTraits< arg1 >::cmptType >::magType type
Definition: products.H:92
type
Volume classification types.
Definition: volumeType.H:66
const volScalarField & T
#define PRODUCT_OPERATOR(product, op, opFunc)
Namespace for OpenFOAM.
scalarProduct< Type, Type >::type gSumProd(const UList< Type > &f1, const UList< Type > &f2, 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: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 > &)
Type sumCmptProd(const UList< Type > &f1, const UList< Type > &f2)
MinMax< scalar > scalarMinMax
A scalar min/max range.
Definition: MinMax.H:117
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Type maxMagSqr(const UList< Type > &f)
void cmptMagSqr(Field< Type > &res, const UList< Type > &f)
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)
Type gMaxMagSqr(const UList< Type > &f, const label comm)
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)
complex sumProd(const UList< complex > &f1, const UList< complex > &f2)
Sum product.
Definition: complexField.C:191
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)
outerProduct1< Type >::type sumSqr(const UList< 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 minMagSqr(const UList< Type > &f)
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)
outerProduct1< Type >::type gSumSqr(const UList< Type > &f, const label comm)
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh > > cmptAv(const DimensionedField< Type, GeoMesh > &df)
Type gMinMagSqr(const UList< Type > &f, const label comm)
dimensioned< scalarMinMax > minMaxMag(const DimensionedField< Type, GeoMesh > &df)
Type gSumCmptMag(const UList< Type > &f, const label comm)
Type gMax(const FieldField< Field, Type > &f)
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
Type sumCmptMag(const UList< 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)
Type gSumCmptProd(const UList< Type > &f1, const UList< Type > &f2, const label comm)
labelList f(nPoints)