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 | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #define TEMPLATE template<class Type>
27 #include "FieldFunctionsM.H"
28 #include "UPstream.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
36 
37 template<class Type>
38 void component
39 (
40  Field<typename Field<Type>::cmptType>& res,
41  const UList<Type>& f,
42  const direction d
43 );
44 
45 
46 template<class Type>
47 void T(Field<Type>& res, const UList<Type>& f);
48 
49 
50 template<class Type, direction r>
51 void pow
52 (
53  Field<typename powProduct<Type, r>::type>& res,
54  const UList<Type>& vf
55 );
56 
57 
58 template<class Type, direction r>
59 tmp<Field<typename powProduct<Type, r>::type>>
60 pow
61 (
62  const UList<Type>& f,
64  = pTraits<typename powProduct<Type, r>::type>::zero
65 );
66 
67 template<class Type, direction r>
68 tmp<Field<typename powProduct<Type, r>::type>>
69 pow
70 (
71  const tmp<Field<Type>>& tf,
73  = pTraits<typename powProduct<Type, r>::type>::zero
74 );
75 
76 
77 template<class Type>
78 void sqr
79 (
80  Field<typename outerProduct<Type, Type>::type>& res,
81  const UList<Type>& vf
82 );
83 
84 template<class Type>
85 tmp<Field<typename outerProduct<Type, Type>::type>>
86 sqr(const UList<Type>& f);
87 
88 template<class Type>
89 tmp<Field<typename outerProduct<Type, Type>::type>>
90 sqr(const tmp<Field<Type>>& tf);
91 
92 
93 template<class Type>
94 void magSqr(Field<scalar>& res, const UList<Type>& f);
95 
96 template<class Type>
97 tmp<Field<scalar>> magSqr(const UList<Type>& f);
98 
99 template<class Type>
100 tmp<Field<scalar>> magSqr(const tmp<Field<Type>>& tf);
101 
102 
103 template<class Type>
104 void mag(Field<scalar>& res, const UList<Type>& f);
105 
106 template<class Type>
107 tmp<Field<scalar>> mag(const UList<Type>& f);
108 
109 template<class Type>
110 tmp<Field<scalar>> mag(const tmp<Field<Type>>& tf);
111 
112 
113 template<class Type>
114 void cmptMax(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
115 
116 template<class Type>
117 tmp<Field<typename Field<Type>::cmptType>> cmptMax(const UList<Type>& f);
118 
119 template<class Type>
120 tmp<Field<typename Field<Type>::cmptType>>
121 cmptMax(const tmp<Field<Type>>& tf);
122 
123 
124 template<class Type>
125 void cmptMin(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
126 
127 template<class Type>
128 tmp<Field<typename Field<Type>::cmptType>> cmptMin(const UList<Type>& f);
129 
130 template<class Type>
131 tmp<Field<typename Field<Type>::cmptType>>
132 cmptMin(const tmp<Field<Type>>& tf);
133 
134 
135 template<class Type>
136 void cmptAv(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
137 
138 template<class Type>
139 tmp<Field<typename Field<Type>::cmptType>> cmptAv(const UList<Type>& f);
140 
141 template<class Type>
142 tmp<Field<typename Field<Type>::cmptType>> cmptAv(const tmp<Field<Type>>& tf);
143 
144 
145 template<class Type>
146 void cmptMag(Field<Type>& res, const UList<Type>& f);
147 
148 template<class Type>
149 tmp<Field<Type>> cmptMag(const UList<Type>& f);
150 
151 template<class Type>
152 tmp<Field<Type>> cmptMag(const tmp<Field<Type>>& tf);
153 
154 #define TMP_UNARY_FUNCTION(ReturnType, Func) \
155  \
156 template<class Type> \
157 ReturnType Func(const tmp<Field<Type>>& tf1);
158 
159 template<class Type>
160 Type max(const UList<Type>& f);
161 
162 TMP_UNARY_FUNCTION(Type, max)
163 
164 template<class Type>
165 Type min(const UList<Type>& f);
166 
167 TMP_UNARY_FUNCTION(Type, min)
168 
169 template<class Type>
170 Type sum(const UList<Type>& f);
171 
172 TMP_UNARY_FUNCTION(Type, sum)
173 
174 template<class Type>
175 Type maxMagSqr(const UList<Type>& f);
176 
178 
179 template<class Type>
180 Type minMagSqr(const UList<Type>& f);
181 
183 
184 
185 template<class Type>
186 scalar sumProd(const UList<Type>& f1, const UList<Type>& f2);
187 
188 template<class Type>
189 Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2);
190 
191 template<class Type>
192 scalar sumSqr(const UList<Type>& f);
193 
194 TMP_UNARY_FUNCTION(scalar, sumSqr)
195 
196 template<class Type>
197 scalar sumMag(const UList<Type>& f);
198 
199 TMP_UNARY_FUNCTION(scalar, sumMag)
200 
201 template<class Type>
202 Type sumCmptMag(const UList<Type>& f);
203 
205 
206 template<class Type>
207 Type average(const UList<Type>& f);
208 
210 
211 
212 #define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \
213  \
214 template<class Type> \
215 ReturnType gFunc(const UList<Type>& f, const label comm = UPstream::worldComm);\
216 TMP_UNARY_FUNCTION(ReturnType, gFunc)
217 
218 G_UNARY_FUNCTION(Type, gMax, max, max)
219 G_UNARY_FUNCTION(Type, gMin, min, min)
220 G_UNARY_FUNCTION(Type, gSum, sum, sum)
226 
227 #undef G_UNARY_FUNCTION
228 
229 template<class Type>
230 scalar gSumProd
231 (
232  const UList<Type>& f1,
233  const UList<Type>& f2,
234  const label comm = UPstream::worldComm
235 );
236 
237 template<class Type>
238 Type gSumCmptProd
239 (
240  const UList<Type>& f1,
241  const UList<Type>& f2,
242  const label comm = UPstream::worldComm
243 );
244 
245 template<class Type>
246 Type gAverage
247 (
248  const UList<Type>& f,
249  const label comm = UPstream::worldComm
250 );
251 
253 
254 #undef TMP_UNARY_FUNCTION
255 
256 
257 BINARY_FUNCTION(Type, Type, Type, max)
258 BINARY_FUNCTION(Type, Type, Type, min)
259 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
260 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
261 
262 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
263 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
264 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
265 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
266 
267 
268 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
269 
270 UNARY_OPERATOR(Type, Type, -, negate)
271 
272 BINARY_OPERATOR(Type, Type, scalar, *, multiply)
273 BINARY_OPERATOR(Type, scalar, Type, *, multiply)
274 BINARY_OPERATOR(Type, Type, scalar, /, divide)
275 
276 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
277 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
278 
279 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
280 
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 #define PRODUCT_OPERATOR(product, Op, OpFunc) \
285  \
286 template<class Type1, class Type2> \
287 void OpFunc \
288 ( \
289  Field<typename product<Type1, Type2>::type>& res, \
290  const UList<Type1>& f1, \
291  const UList<Type2>& f2 \
292 ); \
293  \
294 template<class Type1, class Type2> \
295 tmp<Field<typename product<Type1, Type2>::type>> \
296 operator Op(const UList<Type1>& f1, const UList<Type2>& f2); \
297  \
298 template<class Type1, class Type2> \
299 tmp<Field<typename product<Type1, Type2>::type>> \
300 operator Op(const UList<Type1>& f1, const tmp<Field<Type2>>& tf2); \
301  \
302 template<class Type1, class Type2> \
303 tmp<Field<typename product<Type1, Type2>::type>> \
304 operator Op(const tmp<Field<Type1>>& tf1, const UList<Type2>& f2); \
305  \
306 template<class Type1, class Type2> \
307 tmp<Field<typename product<Type1, Type2>::type>> \
308 operator Op(const tmp<Field<Type1>>& tf1, const tmp<Field<Type2>>& tf2); \
309  \
310 template<class Type, class Form, class Cmpt, direction nCmpt> \
311 void OpFunc \
312 ( \
313  Field<typename product<Type, Form>::type>& res, \
314  const UList<Type>& f1, \
315  const VectorSpace<Form,Cmpt,nCmpt>& vs \
316 ); \
317  \
318 template<class Type, class Form, class Cmpt, direction nCmpt> \
319 tmp<Field<typename product<Type, Form>::type>> \
320 operator Op(const UList<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs); \
321  \
322 template<class Type, class Form, class Cmpt, direction nCmpt> \
323 tmp<Field<typename product<Type, Form>::type>> \
324 operator Op(const tmp<Field<Type>>&tf1,const VectorSpace<Form,Cmpt,nCmpt>&vs); \
325  \
326 template<class Form, class Cmpt, direction nCmpt, class Type> \
327 void OpFunc \
328 ( \
329  Field<typename product<Form, Type>::type>& res, \
330  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
331  const UList<Type>& f1 \
332 ); \
333  \
334 template<class Form, class Cmpt, direction nCmpt, class Type> \
335 tmp<Field<typename product<Form, Type>::type>> \
336 operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const UList<Type>& f1); \
337  \
338 template<class Form, class Cmpt, direction nCmpt, class Type> \
339 tmp<Field<typename product<Form, Type>::type>> \
340 operator Op(const VectorSpace<Form,Cmpt,nCmpt>&vs,const tmp<Field<Type>>&tf1);
341 
342 PRODUCT_OPERATOR(typeOfSum, +, add)
343 PRODUCT_OPERATOR(typeOfSum, -, subtract)
344 
345 PRODUCT_OPERATOR(outerProduct, *, outer)
346 PRODUCT_OPERATOR(crossProduct, ^, cross)
347 PRODUCT_OPERATOR(innerProduct, &, dot)
348 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
349 
350 #undef PRODUCT_OPERATOR
351 
352 
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354 
355 } // End namespace Foam
356 
357 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
358 
359 #include "undefFieldFunctionsM.H"
360 #include "scalarField.H"
361 
362 // ************************************************************************* //
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
scalar gSumMag(const FieldField< Field, Type > &f)
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
void multiply(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Type gMin(const FieldField< Field, Type > &f)
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &df)
Type minMagSqr(const UList< Type > &f)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
uint8_t direction
Definition: direction.H:45
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:86
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
Type gSumCmptMag(const UList< Type > &f, const label comm)
#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:90
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:275
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)
const tensorField & tf
scalar f1
Definition: createFields.H:28
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 > &)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
scalar sumProd(const UList< Type > &f1, const UList< Type > &f2)
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)
Type gSumCmptProd(const UList< Type > &f1, const UList< Type > &f2, const label comm)
Type gSum(const FieldField< Field, Type > &f)
Type sumCmptMag(const UList< Type > &f)
scalar gSumSqr(const UList< Type > &f, const label comm)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
scalar gSumProd(const UList< Type > &f1, const UList< Type > &f2, const label comm)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
High performance macro functions for Field<Type> algebra. These expand using either array element acc...
dimensioned< scalar > magSqr(const dimensioned< Type > &)
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)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:136
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
scalar sumSqr(const UList< Type > &f)
void negate(FieldField< Field, Type > &res, const FieldField< Field, Type > &f)
Type gAverage(const FieldField< Field, Type > &f)
Type maxMagSqr(const UList< Type > &f)
dimensioned< scalar > mag(const dimensioned< Type > &)
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
#define PRODUCT_OPERATOR(product, Op, OpFunc)
Namespace for OpenFOAM.
#define TMP_UNARY_FUNCTION(ReturnType, Func)
dimensioned< scalar > sumMag(const DimensionedField< Type, GeoMesh > &df)