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-2021 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 UNARY_FUNCTION(Type, Type, cmptMag, cmptMag);
280 
281 
282 #define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc) \
283  \
284 template<class Type, class GeoMesh> \
285 dimensioned<returnType> func \
286 ( \
287  const DimensionedField<Type, GeoMesh>& df \
288 ) \
289 { \
290  return dimensioned<Type> \
291  ( \
292  #func "(" + df.name() + ')', \
293  df.dimensions(), \
294  dfunc(df.field()) \
295  ); \
296 } \
297  \
298 template<class Type, class GeoMesh> \
299 dimensioned<returnType> func \
300 ( \
301  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
302 ) \
303 { \
304  dimensioned<returnType> res = func(tdf1()); \
305  tdf1.clear(); \
306  return res; \
307 }
308 
314 
315 #undef UNARY_REDUCTION_FUNCTION
316 
317 
318 BINARY_FUNCTION(Type, Type, Type, max)
319 BINARY_FUNCTION(Type, Type, Type, min)
320 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
321 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
322 
323 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
324 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
325 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
326 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
327 
328 
329 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
330 
331 UNARY_OPERATOR(Type, Type, -, negate, transform)
332 
333 BINARY_OPERATOR(Type, Type, scalar, *, '*', multiply)
334 BINARY_OPERATOR(Type, scalar, Type, *, '*', multiply)
335 BINARY_OPERATOR(Type, Type, scalar, /, '|', divide)
336 
337 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, '*', multiply)
338 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, '*', multiply)
339 
340 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide)
341 
342 
343 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
344 
345 #define PRODUCT_OPERATOR(product, op, opFunc) \
346  \
347 template<class Type1, class Type2, class GeoMesh> \
348 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
349 operator op \
350 ( \
351  const DimensionedField<Type1, GeoMesh>& df1, \
352  const DimensionedField<Type2, GeoMesh>& df2 \
353 ) \
354 { \
355  typedef typename product<Type1, Type2>::type productType; \
356  tmp<DimensionedField<productType, GeoMesh>> tRes \
357  ( \
358  DimensionedField<productType, GeoMesh>::New \
359  ( \
360  '(' + df1.name() + #op + df2.name() + ')', \
361  df1.mesh(), \
362  df1.dimensions() op df2.dimensions() \
363  ) \
364  ); \
365  \
366  Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
367  \
368  return tRes; \
369 } \
370  \
371 template<class Type1, class Type2, class GeoMesh> \
372 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
373 operator op \
374 ( \
375  const DimensionedField<Type1, GeoMesh>& df1, \
376  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
377 ) \
378 { \
379  typedef typename product<Type1, Type2>::type productType; \
380  \
381  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
382  \
383  tmp<DimensionedField<productType, GeoMesh>> tRes = \
384  reuseTmpDimensionedField<productType, Type2, GeoMesh>::New \
385  ( \
386  tdf2, \
387  '(' + df1.name() + #op + df2.name() + ')', \
388  df1.dimensions() op df2.dimensions() \
389  ); \
390  \
391  Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
392  \
393  tdf2.clear(); \
394  \
395  return tRes; \
396 } \
397  \
398 template<class Type1, class Type2, class GeoMesh> \
399 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
400 operator op \
401 ( \
402  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
403  const DimensionedField<Type2, GeoMesh>& df2 \
404 ) \
405 { \
406  typedef typename product<Type1, Type2>::type productType; \
407  \
408  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
409  \
410  tmp<DimensionedField<productType, GeoMesh>> tRes = \
411  reuseTmpDimensionedField<productType, Type1, GeoMesh>::New \
412  ( \
413  tdf1, \
414  '(' + df1.name() + #op + df2.name() + ')', \
415  df1.dimensions() op df2.dimensions() \
416  ); \
417  \
418  Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
419  \
420  tdf1.clear(); \
421  \
422  return tRes; \
423 } \
424  \
425 template<class Type1, class Type2, class GeoMesh> \
426 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
427 operator op \
428 ( \
429  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
430  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
431 ) \
432 { \
433  typedef typename product<Type1, Type2>::type productType; \
434  \
435  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
436  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
437  \
438  tmp<DimensionedField<productType, GeoMesh>> tRes = \
439  reuseTmpTmpDimensionedField<productType, Type1, Type2, GeoMesh>::New \
440  ( \
441  tdf1, \
442  tdf2, \
443  '(' + df1.name() + #op + df2.name() + ')', \
444  df1.dimensions() op df2.dimensions() \
445  ); \
446  \
447  Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
448  \
449  tdf1.clear(); \
450  tdf2.clear(); \
451  \
452  return tRes; \
453 } \
454  \
455 template<class Form, class Type, class GeoMesh> \
456 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh>> \
457 operator op \
458 ( \
459  const DimensionedField<Type, GeoMesh>& df1, \
460  const dimensioned<Form>& dvs \
461 ) \
462 { \
463  typedef typename product<Type, Form>::type productType; \
464  \
465  tmp<DimensionedField<productType, GeoMesh>> tRes \
466  ( \
467  DimensionedField<productType, GeoMesh>::New \
468  ( \
469  '(' + df1.name() + #op + dvs.name() + ')', \
470  df1.mesh(), \
471  df1.dimensions() op dvs.dimensions() \
472  ) \
473  ); \
474  \
475  Foam::opFunc(tRes.ref().field(), df1.field(), dvs.value()); \
476  \
477  return tRes; \
478 } \
479  \
480 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
481 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
482 operator op \
483 ( \
484  const DimensionedField<Type, GeoMesh>& df1, \
485  const VectorSpace<Form,Cmpt,nCmpt>& vs \
486 ) \
487 { \
488  return df1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
489 } \
490  \
491  \
492 template<class Form, class Type, class GeoMesh> \
493 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh>> \
494 operator op \
495 ( \
496  const tmp<DimensionedField<Type, GeoMesh>>& tdf1, \
497  const dimensioned<Form>& dvs \
498 ) \
499 { \
500  typedef typename product<Type, Form>::type productType; \
501  \
502  const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
503  \
504  tmp<DimensionedField<productType, GeoMesh>> tRes = \
505  reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
506  ( \
507  tdf1, \
508  '(' + df1.name() + #op + dvs.name() + ')', \
509  df1.dimensions() op dvs.dimensions() \
510  ); \
511  \
512  Foam::opFunc(tRes.ref().field(), df1.field(), dvs.value()); \
513  \
514  tdf1.clear(); \
515  \
516  return tRes; \
517 } \
518  \
519 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
520 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
521 operator op \
522 ( \
523  const tmp<DimensionedField<Type, GeoMesh>>& tdf1, \
524  const VectorSpace<Form,Cmpt,nCmpt>& vs \
525 ) \
526 { \
527  return tdf1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
528 } \
529  \
530  \
531 template<class Form, class Type, class GeoMesh> \
532 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
533 operator op \
534 ( \
535  const dimensioned<Form>& dvs, \
536  const DimensionedField<Type, GeoMesh>& df1 \
537 ) \
538 { \
539  typedef typename product<Form, Type>::type productType; \
540  tmp<DimensionedField<productType, GeoMesh>> tRes \
541  ( \
542  DimensionedField<productType, GeoMesh>::New \
543  ( \
544  '(' + dvs.name() + #op + df1.name() + ')', \
545  df1.mesh(), \
546  dvs.dimensions() op df1.dimensions() \
547  ) \
548  ); \
549  \
550  Foam::opFunc(tRes.ref().field(), dvs.value(), df1.field()); \
551  \
552  return tRes; \
553 } \
554  \
555 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
556 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
557 operator op \
558 ( \
559  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
560  const DimensionedField<Type, GeoMesh>& df1 \
561 ) \
562 { \
563  return dimensioned<Form>(static_cast<const Form&>(vs)) op df1; \
564 } \
565  \
566 template<class Form, class Type, class GeoMesh> \
567 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
568 operator op \
569 ( \
570  const dimensioned<Form>& dvs, \
571  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
572 ) \
573 { \
574  typedef typename product<Form, Type>::type productType; \
575  \
576  const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
577  \
578  tmp<DimensionedField<productType, GeoMesh>> tRes = \
579  reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
580  ( \
581  tdf1, \
582  '(' + dvs.name() + #op + df1.name() + ')', \
583  dvs.dimensions() op df1.dimensions() \
584  ); \
585  \
586  Foam::opFunc(tRes.ref().field(), dvs.value(), df1.field()); \
587  \
588  tdf1.clear(); \
589  \
590  return tRes; \
591 } \
592  \
593 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
594 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
595 operator op \
596 ( \
597  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
598  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
599 ) \
600 { \
601  return dimensioned<Form>(static_cast<const Form&>(vs)) op tdf1; \
602 }
603 
606 
611 
612 #undef PRODUCT_OPERATOR
613 
614 
615 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
616 
617 } // End namespace Foam
618 
619 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
620 
621 #include "undefFieldFunctionsM.H"
622 
623 // ************************************************************************* //
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)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
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:315
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)
dimensionSet cmptMag(const dimensionSet &)
Definition: dimensionSet.C:275
#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
UNARY_FUNCTION(Type, Type, cmptMag, cmptMag)
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:483
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)