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-2020 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<productType, Type1, Type2, GeoMesh>::New \
437  ( \
438  tdf1, \
439  tdf2, \
440  '(' + df1.name() + #op + df2.name() + ')', \
441  df1.dimensions() op df2.dimensions() \
442  ); \
443  \
444  Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
445  \
446  tdf1.clear(); \
447  tdf2.clear(); \
448  \
449  return tRes; \
450 } \
451  \
452 template<class Form, class Type, class GeoMesh> \
453 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh>> \
454 operator op \
455 ( \
456  const DimensionedField<Type, GeoMesh>& df1, \
457  const dimensioned<Form>& dvs \
458 ) \
459 { \
460  typedef typename product<Type, Form>::type productType; \
461  \
462  tmp<DimensionedField<productType, GeoMesh>> tRes \
463  ( \
464  DimensionedField<productType, GeoMesh>::New \
465  ( \
466  '(' + df1.name() + #op + dvs.name() + ')', \
467  df1.mesh(), \
468  df1.dimensions() op dvs.dimensions() \
469  ) \
470  ); \
471  \
472  Foam::opFunc(tRes.ref().field(), df1.field(), dvs.value()); \
473  \
474  return tRes; \
475 } \
476  \
477 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
478 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
479 operator op \
480 ( \
481  const DimensionedField<Type, GeoMesh>& df1, \
482  const VectorSpace<Form,Cmpt,nCmpt>& vs \
483 ) \
484 { \
485  return df1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
486 } \
487  \
488  \
489 template<class Form, class Type, class GeoMesh> \
490 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh>> \
491 operator op \
492 ( \
493  const tmp<DimensionedField<Type, GeoMesh>>& tdf1, \
494  const dimensioned<Form>& dvs \
495 ) \
496 { \
497  typedef typename product<Type, Form>::type productType; \
498  \
499  const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
500  \
501  tmp<DimensionedField<productType, GeoMesh>> tRes = \
502  reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
503  ( \
504  tdf1, \
505  '(' + df1.name() + #op + dvs.name() + ')', \
506  df1.dimensions() op dvs.dimensions() \
507  ); \
508  \
509  Foam::opFunc(tRes.ref().field(), df1.field(), dvs.value()); \
510  \
511  tdf1.clear(); \
512  \
513  return tRes; \
514 } \
515  \
516 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
517 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
518 operator op \
519 ( \
520  const tmp<DimensionedField<Type, GeoMesh>>& tdf1, \
521  const VectorSpace<Form,Cmpt,nCmpt>& vs \
522 ) \
523 { \
524  return tdf1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
525 } \
526  \
527  \
528 template<class Form, class Type, class GeoMesh> \
529 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
530 operator op \
531 ( \
532  const dimensioned<Form>& dvs, \
533  const DimensionedField<Type, GeoMesh>& df1 \
534 ) \
535 { \
536  typedef typename product<Form, Type>::type productType; \
537  tmp<DimensionedField<productType, GeoMesh>> tRes \
538  ( \
539  DimensionedField<productType, GeoMesh>::New \
540  ( \
541  '(' + dvs.name() + #op + df1.name() + ')', \
542  df1.mesh(), \
543  dvs.dimensions() op df1.dimensions() \
544  ) \
545  ); \
546  \
547  Foam::opFunc(tRes.ref().field(), dvs.value(), df1.field()); \
548  \
549  return tRes; \
550 } \
551  \
552 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
553 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
554 operator op \
555 ( \
556  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
557  const DimensionedField<Type, GeoMesh>& df1 \
558 ) \
559 { \
560  return dimensioned<Form>(static_cast<const Form&>(vs)) op df1; \
561 } \
562  \
563 template<class Form, class Type, class GeoMesh> \
564 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
565 operator op \
566 ( \
567  const dimensioned<Form>& dvs, \
568  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
569 ) \
570 { \
571  typedef typename product<Form, Type>::type productType; \
572  \
573  const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
574  \
575  tmp<DimensionedField<productType, GeoMesh>> tRes = \
576  reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
577  ( \
578  tdf1, \
579  '(' + dvs.name() + #op + df1.name() + ')', \
580  dvs.dimensions() op df1.dimensions() \
581  ); \
582  \
583  Foam::opFunc(tRes.ref().field(), dvs.value(), df1.field()); \
584  \
585  tdf1.clear(); \
586  \
587  return tRes; \
588 } \
589  \
590 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
591 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
592 operator op \
593 ( \
594  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
595  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
596 ) \
597 { \
598  return dimensioned<Form>(static_cast<const Form&>(vs)) op tdf1; \
599 }
600 
603 
608 
609 #undef PRODUCT_OPERATOR
610 
611 
612 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
613 
614 } // End namespace Foam
615 
616 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
617 
618 #include "undefFieldFunctionsM.H"
619 
620 // ************************************************************************* //
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:181
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)