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 | Copyright (C) 2011-2015 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, int 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, int r>
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, int r>
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>
83 sqr(const FieldField<Field, Type>& f);
84 
85 template<template<class> class Field, class 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 <template<class> class Field, class Type, class Form, class Cmpt, int nCmpt> \
350 void opFunc \
351 ( \
352  FieldField<Field, typename product<Type, Form>::type>& f, \
353  const FieldField<Field, Type>& f1, \
354  const VectorSpace<Form,Cmpt,nCmpt>& vs \
355 ); \
356  \
357 template \
358 <template<class> class Field, class Type, class Form, class Cmpt, int nCmpt> \
359 tmp<FieldField<Field, typename product<Type, Form>::type> > \
360 operator op \
361 ( \
362  const FieldField<Field, Type>& f1, \
363  const VectorSpace<Form,Cmpt,nCmpt>& vs \
364 ); \
365  \
366 template \
367 <template<class> class Field, class Type, class Form, class Cmpt, int nCmpt> \
368 tmp<FieldField<Field, typename product<Type, Form>::type> > \
369 operator op \
370 ( \
371  const tmp<FieldField<Field, Type> >& tf1, \
372  const VectorSpace<Form,Cmpt,nCmpt>& vs \
373 ); \
374  \
375 template \
376 <template<class> class Field, class Form, class Cmpt, int nCmpt, class Type> \
377 void opFunc \
378 ( \
379  FieldField<Field, typename product<Form, Type>::type>& f, \
380  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
381  const FieldField<Field, Type>& f1 \
382 ); \
383  \
384 template \
385 <template<class> class Field, class Form, class Cmpt, int nCmpt, class Type> \
386 tmp<FieldField<Field, typename product<Form, Type>::type> > \
387 operator op \
388 ( \
389  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
390  const FieldField<Field, Type>& f1 \
391 ); \
392  \
393 template \
394 <template<class> class Field, class Form, class Cmpt, int nCmpt, class Type> \
395 tmp<FieldField<Field, typename product<Form, Type>::type> > \
396 operator op \
397 ( \
398  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
399  const tmp<FieldField<Field, Type> >& tf1 \
400 );
401 
402 PRODUCT_OPERATOR(typeOfSum, +, add)
403 PRODUCT_OPERATOR(typeOfSum, -, subtract)
404 
405 PRODUCT_OPERATOR(outerProduct, *, outer)
406 PRODUCT_OPERATOR(crossProduct, ^, cross)
407 PRODUCT_OPERATOR(innerProduct, &, dot)
408 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
409 
410 #undef PRODUCT_OPERATOR
411 
412 
413 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
414 
415 } // End namespace Foam
416 
417 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
418 
419 #include "undefFieldFunctionsM.H"
420 
421 // ************************************************************************* //
BINARY_TYPE_OPERATOR_SF
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
Definition: DimensionedFieldFunctionsM.C:531
BINARY_OPERATOR
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
Definition: DimensionedFieldFunctionsM.C:417
Foam::subtract
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:871
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:41
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
G_UNARY_FUNCTION
#define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc)
Definition: FieldFieldFunctions.H:219
Foam::gAverage
Type gAverage(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:571
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, int(pTraits< arg1 >::rank)+int(pTraits< arg2 >::rank) >::type type
Definition: products.H:72
TMP_UNARY_FUNCTION
#define TMP_UNARY_FUNCTION(returnType, func)
Definition: FieldFieldFunctions.H:188
Foam::dot
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:875
undefFieldFunctionsM.H
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:564
BINARY_FUNCTION
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
Definition: DimensionedFieldFunctionsM.C:142
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::powProduct::type
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *int(pTraits< arg1 >::rank) >::type type
Definition: products.H:118
Foam::divide
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
Foam::cmptMin
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:269
tf
const tensorField & tf
Definition: getPatchFieldTensor.H:36
Foam::cmptMag
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:359
Foam::cmptMax
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:224
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:55
f1
scalar f1
Definition: createFields.H:28
Foam::pow
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Definition: dimensionedScalar.C:73
Foam::sumMag
dimensioned< scalar > sumMag(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:334
PRODUCT_OPERATOR
#define PRODUCT_OPERATOR(product, op, opFunc)
Definition: FieldFieldFunctions.H:268
Foam::negate
void negate(FieldField< Field, Type > &res, const FieldField< Field, Type > &f)
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:870
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
FieldFieldFunctionsM.H
High performance macro functions for Field<Type> algebra. These expand using either array element acc...
sf
volScalarField sf(fieldObject, mesh)
Foam::gSumMag
scalar gSumMag(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:565
BINARY_TYPE_FUNCTION
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
Definition: DimensionedFieldFunctionsM.C:410
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::cmptDivide
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::FieldField::cmptType
pTraits< Type >::cmptType cmptType
Component type.
Definition: FieldField.H:82
scalarFieldField.H
Specialisation of FieldField<T> for scalar.
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::cmptAv
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:252
UNARY_OPERATOR
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
Definition: DimensionedFieldFunctionsM.C:86
f
labelList f(nPoints)
Foam::outer
void outer(FieldField< Field1, typename outerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:873
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:333
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::gMin
Type gMin(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:563
BINARY_TYPE_OPERATOR_FS
#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc)
Definition: DimensionedFieldFunctionsM.C:608
Foam::multiply
void multiply(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::cross
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:874
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:562
Foam::average
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:335
Foam::dotdot
void dotdot(FieldField< Field1, typename scalarProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:876