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-2024 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>>
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().primitiveFieldRef(), df.primitiveField());
59 
60  return tPow;
61 }
62 
63 
64 template<class Type, class GeoMesh, direction r>
65 tmp<DimensionedField<typename powProduct<Type, r>::type, GeoMesh>>
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().primitiveFieldRef(), df.primitiveField());
85 
86  tdf.clear();
87 
88  return tPow;
89 }
90 
91 template<class Type, class GeoMesh>
92 tmp<DimensionedField<typename outerProduct<Type, Type>::type, 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().primitiveFieldRef(), df.primitiveField());
108 
109  return tSqr;
110 }
111 
112 template<class Type, class GeoMesh>
113 tmp<DimensionedField<typename outerProduct<Type, Type>::type, 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().primitiveFieldRef(), df.primitiveField());
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().primitiveFieldRef(), df.primitiveField());
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().primitiveFieldRef(), df.primitiveField());
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().primitiveFieldRef(), df.primitiveField());
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().primitiveFieldRef(), df.primitiveField());
219 
220  tdf.clear();
221 
222  return tMag;
223 }
224 
225 
226 template<class Type, class GeoMesh>
227 tmp
228 <
229  DimensionedField
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().primitiveFieldRef(), df.primitiveField());
247 
248  return CmptAv;
249 }
250 
251 template<class Type, class GeoMesh>
252 tmp
253 <
254  DimensionedField
256 >
258 {
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().primitiveFieldRef(), df.primitiveField());
273 
274  tdf.clear();
275 
276  return CmptAv;
277 }
278 
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.primitiveField()) \
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 \
367  ( \
368  tRes.ref().primitiveFieldRef(), \
369  df1.primitiveField(), \
370  df2.primitiveField() \
371  ); \
372  \
373  return tRes; \
374 } \
375  \
376 template<class Type1, class Type2, class GeoMesh> \
377 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
378 operator op \
379 ( \
380  const DimensionedField<Type1, GeoMesh>& df1, \
381  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
382 ) \
383 { \
384  typedef typename product<Type1, Type2>::type productType; \
385  \
386  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
387  \
388  tmp<DimensionedField<productType, GeoMesh>> tRes = \
389  reuseTmpDimensionedField<productType, Type2, GeoMesh>::New \
390  ( \
391  tdf2, \
392  '(' + df1.name() + #op + df2.name() + ')', \
393  df1.dimensions() op df2.dimensions() \
394  ); \
395  \
396  Foam::opFunc \
397  ( \
398  tRes.ref().primitiveFieldRef(), \
399  df1.primitiveField(), \
400  df2.primitiveField() \
401  ); \
402  \
403  tdf2.clear(); \
404  \
405  return tRes; \
406 } \
407  \
408 template<class Type1, class Type2, class GeoMesh> \
409 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
410 operator op \
411 ( \
412  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
413  const DimensionedField<Type2, GeoMesh>& df2 \
414 ) \
415 { \
416  typedef typename product<Type1, Type2>::type productType; \
417  \
418  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
419  \
420  tmp<DimensionedField<productType, GeoMesh>> tRes = \
421  reuseTmpDimensionedField<productType, Type1, GeoMesh>::New \
422  ( \
423  tdf1, \
424  '(' + df1.name() + #op + df2.name() + ')', \
425  df1.dimensions() op df2.dimensions() \
426  ); \
427  \
428  Foam::opFunc \
429  ( \
430  tRes.ref().primitiveFieldRef(), \
431  df1.primitiveField(), \
432  df2.primitiveField() \
433  ); \
434  \
435  tdf1.clear(); \
436  \
437  return tRes; \
438 } \
439  \
440 template<class Type1, class Type2, class GeoMesh> \
441 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
442 operator op \
443 ( \
444  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
445  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
446 ) \
447 { \
448  typedef typename product<Type1, Type2>::type productType; \
449  \
450  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
451  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
452  \
453  tmp<DimensionedField<productType, GeoMesh>> tRes = \
454  reuseTmpTmpDimensionedField<productType, Type1, Type2, GeoMesh>::New \
455  ( \
456  tdf1, \
457  tdf2, \
458  '(' + df1.name() + #op + df2.name() + ')', \
459  df1.dimensions() op df2.dimensions() \
460  ); \
461  \
462  Foam::opFunc \
463  ( \
464  tRes.ref().primitiveFieldRef(), \
465  df1.primitiveField(), \
466  df2.primitiveField() \
467  ); \
468  \
469  tdf1.clear(); \
470  tdf2.clear(); \
471  \
472  return tRes; \
473 } \
474  \
475 template<class Form, class Type, class GeoMesh> \
476 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh>> \
477 operator op \
478 ( \
479  const DimensionedField<Type, GeoMesh>& df1, \
480  const dimensioned<Form>& dvs \
481 ) \
482 { \
483  typedef typename product<Type, Form>::type productType; \
484  \
485  tmp<DimensionedField<productType, GeoMesh>> tRes \
486  ( \
487  DimensionedField<productType, GeoMesh>::New \
488  ( \
489  '(' + df1.name() + #op + dvs.name() + ')', \
490  df1.mesh(), \
491  df1.dimensions() op dvs.dimensions() \
492  ) \
493  ); \
494  \
495  Foam::opFunc \
496  ( \
497  tRes.ref().primitiveFieldRef(), \
498  df1.primitiveField(), \
499  dvs.value() \
500  ); \
501  \
502  return tRes; \
503 } \
504  \
505 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
506 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
507 operator op \
508 ( \
509  const DimensionedField<Type, GeoMesh>& df1, \
510  const VectorSpace<Form,Cmpt,nCmpt>& vs \
511 ) \
512 { \
513  return df1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
514 } \
515  \
516  \
517 template<class Form, class Type, class GeoMesh> \
518 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh>> \
519 operator op \
520 ( \
521  const tmp<DimensionedField<Type, GeoMesh>>& tdf1, \
522  const dimensioned<Form>& dvs \
523 ) \
524 { \
525  typedef typename product<Type, Form>::type productType; \
526  \
527  const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
528  \
529  tmp<DimensionedField<productType, GeoMesh>> tRes = \
530  reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
531  ( \
532  tdf1, \
533  '(' + df1.name() + #op + dvs.name() + ')', \
534  df1.dimensions() op dvs.dimensions() \
535  ); \
536  \
537  Foam::opFunc \
538  ( \
539  tRes.ref().primitiveFieldRef(), \
540  df1.primitiveField(), \
541  dvs.value() \
542  ); \
543  \
544  tdf1.clear(); \
545  \
546  return tRes; \
547 } \
548  \
549 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
550 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
551 operator op \
552 ( \
553  const tmp<DimensionedField<Type, GeoMesh>>& tdf1, \
554  const VectorSpace<Form,Cmpt,nCmpt>& vs \
555 ) \
556 { \
557  return tdf1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
558 } \
559  \
560  \
561 template<class Form, class Type, class GeoMesh> \
562 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
563 operator op \
564 ( \
565  const dimensioned<Form>& dvs, \
566  const DimensionedField<Type, GeoMesh>& df1 \
567 ) \
568 { \
569  typedef typename product<Form, Type>::type productType; \
570  tmp<DimensionedField<productType, GeoMesh>> tRes \
571  ( \
572  DimensionedField<productType, GeoMesh>::New \
573  ( \
574  '(' + dvs.name() + #op + df1.name() + ')', \
575  df1.mesh(), \
576  dvs.dimensions() op df1.dimensions() \
577  ) \
578  ); \
579  \
580  Foam::opFunc \
581  ( \
582  tRes.ref().primitiveFieldRef(), \
583  dvs.value(), \
584  df1.primitiveField() \
585  ); \
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 DimensionedField<Type, GeoMesh>& df1 \
596 ) \
597 { \
598  return dimensioned<Form>(static_cast<const Form&>(vs)) op df1; \
599 } \
600  \
601 template<class Form, class Type, class GeoMesh> \
602 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
603 operator op \
604 ( \
605  const dimensioned<Form>& dvs, \
606  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
607 ) \
608 { \
609  typedef typename product<Form, Type>::type productType; \
610  \
611  const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
612  \
613  tmp<DimensionedField<productType, GeoMesh>> tRes = \
614  reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
615  ( \
616  tdf1, \
617  '(' + dvs.name() + #op + df1.name() + ')', \
618  dvs.dimensions() op df1.dimensions() \
619  ); \
620  \
621  Foam::opFunc \
622  ( \
623  tRes.ref().primitiveFieldRef(), \
624  dvs.value(), \
625  df1.primitiveField() \
626  ); \
627  \
628  tdf1.clear(); \
629  \
630  return tRes; \
631 } \
632  \
633 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
634 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
635 operator op \
636 ( \
637  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
638  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
639 ) \
640 { \
641  return dimensioned<Form>(static_cast<const Form&>(vs)) op tdf1; \
642 }
643 
646 
651 
652 #undef PRODUCT_OPERATOR
653 
654 
655 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
656 
657 } // End namespace Foam
658 
659 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
660 
661 #include "undefFieldFunctionsM.H"
662 
663 // ************************************************************************* //
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
#define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc)
#define PRODUCT_OPERATOR(product, op, opFunc)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const dimensionSet & dimensions() const
Return dimensions.
const Field< Type > & primitiveField() const
Return a const-reference to the primitive field.
const Mesh & mesh() const
Return mesh.
Field< Type >::cmptType cmptType
Component type of the elements of the field.
const word & name() const
Return name.
Definition: IOobject.H:310
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:90
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:136
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
Namespace for OpenFOAM.
void negate(FieldField< Field, Type > &res, const FieldField< Field, Type > &f)
Type gSum(const FieldField< Field, Type > &f)
scalar gSumMag(const FieldField< Field, Type > &f)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
UNARY_FUNCTION(Type, Type, cmptMag, cmptMag)
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &df)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:504
dimensioned< scalar > mag(const dimensioned< Type > &)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
dimensionSet cmptMag(const dimensionSet &)
Definition: dimensionSet.C:296
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
Type gAverage(const FieldField< Field, Type > &f)
void dotdot(FieldField< Field1, typename scalarProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Type gMin(const FieldField< Field, Type > &f)
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
void multiply(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
Type gMax(const FieldField< Field, Type > &f)
void outer(FieldField< Field1, typename outerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< scalar > sumMag(const DimensionedField< Type, GeoMesh > &df)