DimensionedFieldFunctions.C
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 
27 
28 #define TEMPLATE template<class Type, class GeoMesh>
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * //
37 
38 template<class Type, class GeoMesh, direction r>
39 tmp<DimensionedField<typename powProduct<Type, r>::type, GeoMesh>>
40 pow
41 (
44 )
45 {
46  typedef typename powProduct<Type, r>::type powProductType;
47 
49  (
51  (
52  "pow(" + df.name() + ',' + name(r) + ')',
53  df.mesh(),
54  pow(df.dimensions(), r)
55  )
56  );
57 
58  pow<Type, r, GeoMesh>(tPow.ref().field(), df.field());
59 
60  return tPow;
61 }
62 
63 
64 template<class Type, class GeoMesh, direction r>
66 pow
67 (
70 )
71 {
72  typedef typename powProduct<Type, r>::type powProductType;
73 
74  const DimensionedField<Type, GeoMesh>& df = tdf();
75 
78  (
79  tdf,
80  "pow(" + df.name() + ',' + name(r) + ')',
81  pow(df.dimensions(), r)
82  );
83 
84  pow<Type, r, GeoMesh>(tPow.ref().field(), df.field());
85 
86  tdf.clear();
87 
88  return tPow;
89 }
90 
91 template<class Type, class GeoMesh>
94 {
95  typedef typename outerProduct<Type, Type>::type outerProductType;
96 
98  (
100  (
101  "sqr(" + df.name() + ')',
102  df.mesh(),
103  sqr(df.dimensions())
104  )
105  );
106 
107  sqr(tSqr.ref().field(), df.field());
108 
109  return tSqr;
110 }
111 
112 template<class Type, class GeoMesh>
115 {
116  typedef typename outerProduct<Type, Type>::type outerProductType;
117 
118  const DimensionedField<Type, GeoMesh>& df = tdf();
119 
122  (
123  tdf,
124  "sqr(" + df.name() + ')',
125  sqr(df.dimensions())
126  );
127 
128  sqr(tSqr.ref().field(), df.field());
129 
130  tdf.clear();
131 
132  return tSqr;
133 }
134 
135 
136 template<class Type, class GeoMesh>
138 (
140 )
141 {
143  (
145  (
146  "magSqr(" + df.name() + ')',
147  df.mesh(),
148  sqr(df.dimensions())
149  )
150  );
151 
152  magSqr(tMagSqr.ref().field(), df.field());
153 
154  return tMagSqr;
155 }
156 
157 template<class Type, class GeoMesh>
159 (
161 )
162 {
163  const DimensionedField<Type, GeoMesh>& df = tdf();
164 
167  (
168  tdf,
169  "magSqr(" + df.name() + ')',
170  sqr(df.dimensions())
171  );
172 
173  magSqr(tMagSqr.ref().field(), df.field());
174 
175  tdf.clear();
176 
177  return tMagSqr;
178 }
179 
180 
181 template<class Type, class GeoMesh>
183 (
185 )
186 {
188  (
190  (
191  "mag(" + df.name() + ')',
192  df.mesh(),
193  df.dimensions()
194  )
195  );
196 
197  mag(tMag.ref().field(), df.field());
198 
199  return tMag;
200 }
201 
202 template<class Type, class GeoMesh>
204 (
206 )
207 {
208  const DimensionedField<Type, GeoMesh>& df = tdf();
209 
212  (
213  tdf,
214  "mag(" + df.name() + ')',
215  df.dimensions()
216  );
217 
218  mag(tMag.ref().field(), df.field());
219 
220  tdf.clear();
221 
222  return tMag;
223 }
224 
225 
226 template<class Type, class GeoMesh>
227 tmp
228 <
230  <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
231 >
233 {
234  typedef typename DimensionedField<Type, GeoMesh>::cmptType cmptType;
235 
237  (
239  (
240  "cmptAv(" + df.name() + ')',
241  df.mesh(),
242  df.dimensions()
243  )
244  );
245 
246  cmptAv(CmptAv.ref().field(), df.field());
247 
248  return CmptAv;
249 }
250 
251 template<class Type, class GeoMesh>
252 tmp
253 <
255  <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
256 >
258 {
259  typedef typename DimensionedField<Type, GeoMesh>::cmptType
260  cmptType;
261 
262  const DimensionedField<Type, GeoMesh>& df = tdf();
263 
266  (
267  tdf,
268  "cmptAv(" + df.name() + ')',
269  df.dimensions()
270  );
271 
272  cmptAv(CmptAv.ref().field(), df.field());
273 
274  tdf.clear();
275 
276  return CmptAv;
277 }
278 
279 #define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc) \
280  \
281 template<class Type, class GeoMesh> \
282 dimensioned<returnType> func \
283 ( \
284  const DimensionedField<Type, GeoMesh>& df \
285 ) \
286 { \
287  return dimensioned<Type> \
288  ( \
289  #func "(" + df.name() + ')', \
290  df.dimensions(), \
291  dfunc(df.field()) \
292  ); \
293 } \
294  \
295 template<class Type, class GeoMesh> \
296 dimensioned<returnType> func \
297 ( \
298  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
299 ) \
300 { \
301  dimensioned<returnType> res = func(tdf1()); \
302  tdf1.clear(); \
303  return res; \
304 }
305 
311 
312 #undef UNARY_REDUCTION_FUNCTION
313 
314 
315 BINARY_FUNCTION(Type, Type, Type, max)
316 BINARY_FUNCTION(Type, Type, Type, min)
317 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
318 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
319 
320 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
321 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
322 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
323 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
324 
325 
326 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
327 
328 UNARY_OPERATOR(Type, Type, -, negate, transform)
329 
330 BINARY_OPERATOR(Type, Type, scalar, *, '*', multiply)
331 BINARY_OPERATOR(Type, scalar, Type, *, '*', multiply)
332 BINARY_OPERATOR(Type, Type, scalar, /, '|', divide)
333 
334 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, '*', multiply)
335 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, '*', multiply)
336 
337 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide)
338 
339 
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 
342 #define PRODUCT_OPERATOR(product, op, opFunc) \
343  \
344 template<class Type1, class Type2, class GeoMesh> \
345 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
346 operator op \
347 ( \
348  const DimensionedField<Type1, GeoMesh>& df1, \
349  const DimensionedField<Type2, GeoMesh>& df2 \
350 ) \
351 { \
352  typedef typename product<Type1, Type2>::type productType; \
353  tmp<DimensionedField<productType, GeoMesh>> tRes \
354  ( \
355  DimensionedField<productType, GeoMesh>::New \
356  ( \
357  '(' + df1.name() + #op + df2.name() + ')', \
358  df1.mesh(), \
359  df1.dimensions() op df2.dimensions() \
360  ) \
361  ); \
362  \
363  Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
364  \
365  return tRes; \
366 } \
367  \
368 template<class Type1, class Type2, class GeoMesh> \
369 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
370 operator op \
371 ( \
372  const DimensionedField<Type1, GeoMesh>& df1, \
373  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
374 ) \
375 { \
376  typedef typename product<Type1, Type2>::type productType; \
377  \
378  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
379  \
380  tmp<DimensionedField<productType, GeoMesh>> tRes = \
381  reuseTmpDimensionedField<productType, Type2, GeoMesh>::New \
382  ( \
383  tdf2, \
384  '(' + df1.name() + #op + df2.name() + ')', \
385  df1.dimensions() op df2.dimensions() \
386  ); \
387  \
388  Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
389  \
390  tdf2.clear(); \
391  \
392  return tRes; \
393 } \
394  \
395 template<class Type1, class Type2, class GeoMesh> \
396 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
397 operator op \
398 ( \
399  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
400  const DimensionedField<Type2, GeoMesh>& df2 \
401 ) \
402 { \
403  typedef typename product<Type1, Type2>::type productType; \
404  \
405  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
406  \
407  tmp<DimensionedField<productType, GeoMesh>> tRes = \
408  reuseTmpDimensionedField<productType, Type1, GeoMesh>::New \
409  ( \
410  tdf1, \
411  '(' + df1.name() + #op + df2.name() + ')', \
412  df1.dimensions() op df2.dimensions() \
413  ); \
414  \
415  Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
416  \
417  tdf1.clear(); \
418  \
419  return tRes; \
420 } \
421  \
422 template<class Type1, class Type2, class GeoMesh> \
423 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
424 operator op \
425 ( \
426  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
427  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
428 ) \
429 { \
430  typedef typename product<Type1, Type2>::type productType; \
431  \
432  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
433  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
434  \
435  tmp<DimensionedField<productType, GeoMesh>> tRes = \
436  reuseTmpTmpDimensionedField \
437  <productType, Type1, Type1, Type2, GeoMesh>::New \
438  ( \
439  tdf1, \
440  tdf2, \
441  '(' + df1.name() + #op + df2.name() + ')', \
442  df1.dimensions() op df2.dimensions() \
443  ); \
444  \
445  Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
446  \
447  tdf1.clear(); \
448  tdf2.clear(); \
449  \
450  return tRes; \
451 } \
452  \
453 template<class Form, class Type, class GeoMesh> \
454 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh>> \
455 operator op \
456 ( \
457  const DimensionedField<Type, GeoMesh>& df1, \
458  const dimensioned<Form>& dvs \
459 ) \
460 { \
461  typedef typename product<Type, Form>::type productType; \
462  \
463  tmp<DimensionedField<productType, GeoMesh>> tRes \
464  ( \
465  DimensionedField<productType, GeoMesh>::New \
466  ( \
467  '(' + df1.name() + #op + dvs.name() + ')', \
468  df1.mesh(), \
469  df1.dimensions() op dvs.dimensions() \
470  ) \
471  ); \
472  \
473  Foam::opFunc(tRes.ref().field(), df1.field(), dvs.value()); \
474  \
475  return tRes; \
476 } \
477  \
478 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
479 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
480 operator op \
481 ( \
482  const DimensionedField<Type, GeoMesh>& df1, \
483  const VectorSpace<Form,Cmpt,nCmpt>& vs \
484 ) \
485 { \
486  return df1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
487 } \
488  \
489  \
490 template<class Form, class Type, class GeoMesh> \
491 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh>> \
492 operator op \
493 ( \
494  const tmp<DimensionedField<Type, GeoMesh>>& tdf1, \
495  const dimensioned<Form>& dvs \
496 ) \
497 { \
498  typedef typename product<Type, Form>::type productType; \
499  \
500  const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
501  \
502  tmp<DimensionedField<productType, GeoMesh>> tRes = \
503  reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
504  ( \
505  tdf1, \
506  '(' + df1.name() + #op + dvs.name() + ')', \
507  df1.dimensions() op dvs.dimensions() \
508  ); \
509  \
510  Foam::opFunc(tRes.ref().field(), df1.field(), dvs.value()); \
511  \
512  tdf1.clear(); \
513  \
514  return tRes; \
515 } \
516  \
517 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
518 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
519 operator op \
520 ( \
521  const tmp<DimensionedField<Type, GeoMesh>>& tdf1, \
522  const VectorSpace<Form,Cmpt,nCmpt>& vs \
523 ) \
524 { \
525  return tdf1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
526 } \
527  \
528  \
529 template<class Form, class Type, class GeoMesh> \
530 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
531 operator op \
532 ( \
533  const dimensioned<Form>& dvs, \
534  const DimensionedField<Type, GeoMesh>& df1 \
535 ) \
536 { \
537  typedef typename product<Form, Type>::type productType; \
538  tmp<DimensionedField<productType, GeoMesh>> tRes \
539  ( \
540  DimensionedField<productType, GeoMesh>::New \
541  ( \
542  '(' + dvs.name() + #op + df1.name() + ')', \
543  df1.mesh(), \
544  dvs.dimensions() op df1.dimensions() \
545  ) \
546  ); \
547  \
548  Foam::opFunc(tRes.ref().field(), dvs.value(), df1.field()); \
549  \
550  return tRes; \
551 } \
552  \
553 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
554 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
555 operator op \
556 ( \
557  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
558  const DimensionedField<Type, GeoMesh>& df1 \
559 ) \
560 { \
561  return dimensioned<Form>(static_cast<const Form&>(vs)) op df1; \
562 } \
563  \
564 template<class Form, class Type, class GeoMesh> \
565 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
566 operator op \
567 ( \
568  const dimensioned<Form>& dvs, \
569  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
570 ) \
571 { \
572  typedef typename product<Form, Type>::type productType; \
573  \
574  const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
575  \
576  tmp<DimensionedField<productType, GeoMesh>> tRes = \
577  reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
578  ( \
579  tdf1, \
580  '(' + dvs.name() + #op + df1.name() + ')', \
581  dvs.dimensions() op df1.dimensions() \
582  ); \
583  \
584  Foam::opFunc(tRes.ref().field(), dvs.value(), df1.field()); \
585  \
586  tdf1.clear(); \
587  \
588  return tRes; \
589 } \
590  \
591 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
592 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
593 operator op \
594 ( \
595  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
596  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
597 ) \
598 { \
599  return dimensioned<Form>(static_cast<const Form&>(vs)) op tdf1; \
600 }
601 
604 
609 
610 #undef PRODUCT_OPERATOR
611 
612 
613 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
614 
615 } // End namespace Foam
616 
617 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
618 
619 #include "undefFieldFunctionsM.H"
620 
621 // ************************************************************************* //
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
scalar gSumMag(const FieldField< Field, Type > &f)
#define PRODUCT_OPERATOR(product, op, opFunc)
#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)
const word & name() const
Return name.
Definition: IOobject.H:303
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)
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
dimensionedSymmTensor sqr(const dimensionedVector &dv)
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#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)
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)
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 > &)
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
const dimensionSet & dimensions() const
Return dimensions.
Type gSum(const FieldField< Field, Type > &f)
#define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
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)
const Mesh & mesh() const
Return mesh.
Type gMax(const FieldField< Field, Type > &f)
const Field< Type > & field() const
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
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)
Type gAverage(const FieldField< Field, Type > &f)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
dimensioned< scalar > mag(const dimensioned< Type > &)
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:46
A class for managing temporary objects.
Definition: PtrList.H:53
Namespace for OpenFOAM.
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:477
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)