FieldFieldFunctions.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 #include "scalarFieldField.H"
27 
28 #define TEMPLATE template<template<class> class Field, class Type>
29 #include "FieldFieldFunctionsM.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 /* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
37 
38 template<template<class> class Field, class Type>
39 void component
40 (
41  FieldField<Field, typename FieldField<Field, Type>::cmptType>& sf,
42  const FieldField<Field, Type>& f,
43  const direction d
44 );
45 
46 template<template<class> class Field, class Type>
47 void T(FieldField<Field, Type>& f1, const FieldField<Field, Type>& f2);
48 
49 
50 template<template<class> class Field, class Type, direction r>
51 void pow
52 (
53  FieldField<Field, typename powProduct<Type, r>::type>& f,
54  const FieldField<Field, Type>& vf
55 );
56 
57 template<template<class> class Field, class Type, direction r>
58 tmp<FieldField<Field, typename powProduct<Type, r>::type>>
59 pow
60 (
61  const FieldField<Field, Type>& f, typename powProduct<Type, r>::type
62  = pTraits<typename powProduct<Type, r>::type>::zero
63 );
64 
65 template<template<class> class Field, class Type, direction r>
66 tmp<FieldField<Field, typename powProduct<Type, r>::type>>
67 pow
68 (
69  const tmp<FieldField<Field, Type>>& tf, typename powProduct<Type, r>::type
70  = pTraits<typename powProduct<Type, r>::type>::zero
71 );
72 
73 
74 template<template<class> class Field, class Type>
75 void sqr
76 (
77  FieldField<Field, typename outerProduct<Type, Type>::type>& f,
78  const FieldField<Field, Type>& vf
79 );
80 
81 template<template<class> class Field, class Type>
82 tmp<FieldField<Field, typename outerProduct<Type, Type>::type>>
83 sqr(const FieldField<Field, Type>& f);
84 
85 template<template<class> class Field, class Type>
86 tmp<FieldField<Field, typename outerProduct<Type, Type>::type>>
87 sqr(const tmp<FieldField<Field, Type>>& tf);
88 
89 template<template<class> class Field, class Type>
90 void magSqr(FieldField<Field, scalar>& sf, const FieldField<Field, Type>& f);
91 
92 template<template<class> class Field, class Type>
93 tmp<FieldField<Field, scalar>> magSqr(const FieldField<Field, Type>& f);
94 
95 template<template<class> class Field, class Type>
96 tmp<FieldField<Field, scalar>> magSqr(const tmp<FieldField<Field, Type>>& tf);
97 
98 template<template<class> class Field, class Type>
99 void mag(FieldField<Field, scalar>& sf, const FieldField<Field, Type>& f);
100 
101 template<template<class> class Field, class Type>
102 tmp<FieldField<Field, scalar>> mag(const FieldField<Field, Type>& f);
103 
104 template<template<class> class Field, class Type>
105 tmp<FieldField<Field, scalar>> mag(const tmp<FieldField<Field, Type>>& tf);
106 
107 
108 template<template<class> class Field, class Type>
109 void cmptMax
110 (
111  FieldField<Field, typename FieldField<Field, Type>::cmptType>& cf,
112  const FieldField<Field, Type>& f
113 );
114 
115 template<template<class> class Field, class Type>
116 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType>> cmptMax
117 (
118  const FieldField<Field, Type>& f
119 );
120 
121 template<template<class> class Field, class Type>
122 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType>> cmptMax
123 (
124  const tmp<FieldField<Field, Type>>& tf
125 );
126 
127 
128 template<template<class> class Field, class Type>
129 void cmptMin
130 (
131  FieldField<Field, typename FieldField<Field, Type>::cmptType>& cf,
132  const FieldField<Field, Type>& f
133 );
134 
135 template<template<class> class Field, class Type>
136 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType>> cmptMin
137 (
138  const FieldField<Field, Type>& f
139 );
140 
141 template<template<class> class Field, class Type>
142 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType>> cmptMin
143 (
144  const tmp<FieldField<Field, Type>>& tf
145 );
146 
147 
148 template<template<class> class Field, class Type>
149 void cmptAv
150 (
151  FieldField<Field, typename FieldField<Field, Type>::cmptType>& cf,
152  const FieldField<Field, Type>& f
153 );
154 
155 template<template<class> class Field, class Type>
156 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType>> cmptAv
157 (
158  const FieldField<Field, Type>& f
159 );
160 
161 template<template<class> class Field, class Type>
162 tmp<FieldField<Field, typename FieldField<Field, Type>::cmptType>> cmptAv
163 (
164  const tmp<FieldField<Field, Type>>& tf
165 );
166 
167 
168 template<template<class> class Field, class Type>
169 void cmptMag
170 (
171  FieldField<Field, Type>& cf,
172  const FieldField<Field, Type>& f
173 );
174 
175 template<template<class> class Field, class Type>
176 tmp<FieldField<Field, Type>> cmptMag
177 (
178  const FieldField<Field, Type>& f
179 );
180 
181 template<template<class> class Field, class Type>
182 tmp<FieldField<Field, Type>> cmptMag
183 (
184  const tmp<FieldField<Field, Type>>& tf
185 );
186 
187 
188 #define TMP_UNARY_FUNCTION(returnType, func) \
189  \
190 template<template<class> class Field, class Type> \
191 returnType func(const tmp<FieldField<Field, Type>>& tf1);
192 
193 template<template<class> class Field, class Type>
194 Type max(const FieldField<Field, Type>& f);
195 
196 TMP_UNARY_FUNCTION(Type, max)
197 
198 template<template<class> class Field, class Type>
199 Type min(const FieldField<Field, Type>& f);
200 
201 TMP_UNARY_FUNCTION(Type, min)
202 
203 template<template<class> class Field, class Type>
204 Type sum(const FieldField<Field, Type>& f);
205 
206 TMP_UNARY_FUNCTION(Type, sum)
207 
208 template<template<class> class Field, class Type>
209 scalar sumMag(const FieldField<Field, Type>& f);
210 
211 TMP_UNARY_FUNCTION(scalar, sumMag)
212 
213 template<template<class> class Field, class Type>
214 Type average(const FieldField<Field, Type>& f);
215 
217 
218 
219 #define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \
220  \
221 template<template<class> class Field, class Type> \
222 returnType gFunc(const FieldField<Field, Type>& f); \
223 TMP_UNARY_FUNCTION(returnType, gFunc)
224 
225 G_UNARY_FUNCTION(Type, gMax, max, max)
226 G_UNARY_FUNCTION(Type, gMin, min, min)
227 G_UNARY_FUNCTION(Type, gSum, sum, sum)
229 
230 #undef G_UNARY_FUNCTION
231 
232 
233 template<template<class> class Field, class Type>
234 Type gAverage(const FieldField<Field, Type>& f);
235 
237 
238 #undef TMP_UNARY_FUNCTION
239 
240 
241 BINARY_FUNCTION(Type, Type, Type, max)
242 BINARY_FUNCTION(Type, Type, Type, min)
243 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
244 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
245 
246 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
247 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
248 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
249 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
250 
251 
252 /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
253 
254 UNARY_OPERATOR(Type, Type, -, negate)
255 
256 BINARY_OPERATOR(Type, Type, scalar, *, multiply)
257 BINARY_OPERATOR(Type, scalar, Type, *, multiply)
258 BINARY_OPERATOR(Type, Type, scalar, /, divide)
259 
260 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
261 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
262 
263 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
264 
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 #define PRODUCT_OPERATOR(product, op, opFunc) \
269  \
270 template \
271 < \
272  template<class> class Field1, \
273  template<class> class Field2, \
274  class Type1, \
275  class Type2 \
276 > \
277 void opFunc \
278 ( \
279  FieldField<Field1, typename product<Type1, Type2>::type>& f, \
280  const FieldField<Field1, Type1>& f1, \
281  const FieldField<Field2, Type2>& f2 \
282 ); \
283  \
284 template \
285 < \
286  template<class> class Field1, \
287  template<class> class Field2, \
288  class Type1, \
289  class Type2 \
290 > \
291 tmp<FieldField<Field1, typename product<Type1, Type2>::type>> \
292 operator op \
293 ( \
294  const FieldField<Field1, Type1>& f1, \
295  const FieldField<Field2, Type2>& f2 \
296 ); \
297  \
298 template<template<class> class Field, class Type1, class Type2> \
299 tmp<FieldField<Field, typename product<Type1, Type2>::type>> \
300 operator op \
301 ( \
302  const FieldField<Field, Type1>& f1, \
303  const tmp<FieldField<Field, Type2>>& tf2 \
304 ); \
305  \
306 template \
307 < \
308  template<class> class Field1, \
309  template<class> class Field2, \
310  class Type1, \
311  class Type2 \
312 > \
313 tmp<FieldField<Field1, typename product<Type1, Type2>::type>> \
314 operator op \
315 ( \
316  const FieldField<Field1, Type1>& f1, \
317  const tmp<FieldField<Field2, Type2>>& tf2 \
318 ); \
319  \
320 template \
321 < \
322  template<class> class Field1, \
323  template<class> class Field2, \
324  class Type1, \
325  class Type2 \
326 > \
327 tmp<FieldField<Field1, typename product<Type1, Type2>::type>> \
328 operator op \
329 ( \
330  const tmp<FieldField<Field1, Type1>>& tf1, \
331  const FieldField<Field2, Type2>& f2 \
332 ); \
333  \
334 template \
335 < \
336  template<class> class Field1, \
337  template<class> class Field2, \
338  class Type1, \
339  class Type2 \
340 > \
341 tmp<FieldField<Field1, typename product<Type1, Type2>::type>> \
342 operator op \
343 ( \
344  const tmp<FieldField<Field1, Type1>>& tf1, \
345  const tmp<FieldField<Field2, Type2>>& tf2 \
346 ); \
347  \
348 template \
349 < \
350  template<class> class Field, \
351  class Type, \
352  class Form, \
353  class Cmpt, \
354  direction nCmpt \
355 > \
356 void opFunc \
357 ( \
358  FieldField<Field, typename product<Type, Form>::type>& f, \
359  const FieldField<Field, Type>& f1, \
360  const VectorSpace<Form,Cmpt,nCmpt>& vs \
361 ); \
362  \
363 template \
364 < \
365  template<class> class Field, \
366  class Type, \
367  class Form, \
368  class Cmpt, \
369  direction nCmpt \
370 > \
371 tmp<FieldField<Field, typename product<Type, Form>::type>> \
372 operator op \
373 ( \
374  const FieldField<Field, Type>& f1, \
375  const VectorSpace<Form,Cmpt,nCmpt>& vs \
376 ); \
377  \
378 template \
379 < \
380  template<class> class Field, \
381  class Type, \
382  class Form, \
383  class Cmpt, \
384  direction nCmpt \
385 > \
386 tmp<FieldField<Field, typename product<Type, Form>::type>> \
387 operator op \
388 ( \
389  const tmp<FieldField<Field, Type>>& tf1, \
390  const VectorSpace<Form,Cmpt,nCmpt>& vs \
391 ); \
392  \
393 template \
394 < \
395  template<class> class Field, \
396  class Type, \
397  class Form, \
398  class Cmpt, \
399  direction nCmpt \
400 > \
401 void opFunc \
402 ( \
403  FieldField<Field, typename product<Form, Type>::type>& f, \
404  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
405  const FieldField<Field, Type>& f1 \
406 ); \
407  \
408 template \
409 < \
410  template<class> class Field, \
411  class Type, \
412  class Form, \
413  class Cmpt, \
414  direction nCmpt \
415 > \
416 tmp<FieldField<Field, typename product<Form, Type>::type>> \
417 operator op \
418 ( \
419  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
420  const FieldField<Field, Type>& f1 \
421 ); \
422  \
423 template \
424 < \
425  template<class> class Field, \
426  class Type, \
427  class Form, \
428  class Cmpt, \
429  direction nCmpt \
430 > \
431 tmp<FieldField<Field, typename product<Form, Type>::type>> \
432 operator op \
433 ( \
434  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
435  const tmp<FieldField<Field, Type>>& tf1 \
436 );
437 
438 PRODUCT_OPERATOR(typeOfSum, +, add)
439 PRODUCT_OPERATOR(typeOfSum, -, subtract)
440 
441 PRODUCT_OPERATOR(outerProduct, *, outer)
442 PRODUCT_OPERATOR(crossProduct, ^, cross)
443 PRODUCT_OPERATOR(innerProduct, &, dot)
444 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
445 
446 #undef PRODUCT_OPERATOR
447 
448 
449 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
450 
451 } // End namespace Foam
452 
453 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
454 
455 #include "undefFieldFunctionsM.H"
456 
457 // ************************************************************************* //
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)
#define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc)
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)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
uint8_t direction
Definition: direction.H:45
#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:90
#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)
const tensorField & tf
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 > &)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
Type gSum(const FieldField< Field, Type > &f)
#define PRODUCT_OPERATOR(product, op, opFunc)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Specialisation of FieldField<T> for scalar.
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
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)
void negate(FieldField< Field, Type > &res, const FieldField< Field, Type > &f)
High performance macro functions for Field<Type> algebra. These expand using either array element acc...
pTraits< Type >::cmptType cmptType
Component type.
Definition: FieldField.H:82
Type gAverage(const FieldField< Field, 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)
Namespace for OpenFOAM.
dimensioned< scalar > sumMag(const DimensionedField< Type, GeoMesh > &df)