DimensionedFieldFunctions.C
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-2016 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  IOobject
53  (
54  "pow(" + df.name() + ',' + name(r) + ')',
55  df.instance(),
56  df.db()
57  ),
58  df.mesh(),
59  pow(df.dimensions(), r)
60  )
61  );
62 
63  pow<Type, r, GeoMesh>(tPow.ref().field(), df.field());
64 
65  return tPow;
66 }
67 
68 
69 template<class Type, class GeoMesh, direction r>
71 pow
72 (
75 )
76 {
77  typedef typename powProduct<Type, r>::type powProductType;
78 
79  const DimensionedField<Type, GeoMesh>& df = tdf();
80 
83  (
84  tdf,
85  "pow(" + df.name() + ',' + name(r) + ')',
86  pow(df.dimensions(), r)
87  );
88 
89  pow<Type, r, GeoMesh>(tPow.ref().field(), df.field());
90 
91  tdf.clear();
92 
93  return tPow;
94 }
95 
96 template<class Type, class GeoMesh>
99 {
100  typedef typename outerProduct<Type, Type>::type outerProductType;
101 
103  (
105  (
106  IOobject
107  (
108  "sqr(" + df.name() + ')',
109  df.instance(),
110  df.db()
111  ),
112  df.mesh(),
113  sqr(df.dimensions())
114  )
115  );
116 
117  sqr(tSqr.ref().field(), df.field());
118 
119  return tSqr;
120 }
121 
122 template<class Type, class GeoMesh>
125 {
126  typedef typename outerProduct<Type, Type>::type outerProductType;
127 
128  const DimensionedField<Type, GeoMesh>& df = tdf();
129 
132  (
133  tdf,
134  "sqr(" + df.name() + ')',
135  sqr(df.dimensions())
136  );
137 
138  sqr(tSqr.ref().field(), df.field());
139 
140  tdf.clear();
141 
142  return tSqr;
143 }
144 
145 
146 template<class Type, class GeoMesh>
148 (
150 )
151 {
153  (
155  (
156  IOobject
157  (
158  "magSqr(" + df.name() + ')',
159  df.instance(),
160  df.db()
161  ),
162  df.mesh(),
163  sqr(df.dimensions())
164  )
165  );
166 
167  magSqr(tMagSqr.ref().field(), df.field());
168 
169  return tMagSqr;
170 }
171 
172 template<class Type, class GeoMesh>
174 (
176 )
177 {
178  const DimensionedField<Type, GeoMesh>& df = tdf();
179 
182  (
183  tdf,
184  "magSqr(" + df.name() + ')',
185  sqr(df.dimensions())
186  );
187 
188  magSqr(tMagSqr.ref().field(), df.field());
189 
190  tdf.clear();
191 
192  return tMagSqr;
193 }
194 
195 
196 template<class Type, class GeoMesh>
198 (
200 )
201 {
203  (
205  (
206  IOobject
207  (
208  "mag(" + df.name() + ')',
209  df.instance(),
210  df.db()
211  ),
212  df.mesh(),
213  df.dimensions()
214  )
215  );
216 
217  mag(tMag.ref().field(), df.field());
218 
219  return tMag;
220 }
221 
222 template<class Type, class GeoMesh>
224 (
226 )
227 {
228  const DimensionedField<Type, GeoMesh>& df = tdf();
229 
232  (
233  tdf,
234  "mag(" + df.name() + ')',
235  df.dimensions()
236  );
237 
238  mag(tMag.ref().field(), df.field());
239 
240  tdf.clear();
241 
242  return tMag;
243 }
244 
245 
246 template<class Type, class GeoMesh>
247 tmp
248 <
250  <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
251 >
253 {
254  typedef typename DimensionedField<Type, GeoMesh>::cmptType cmptType;
255 
257  (
259  (
260  IOobject
261  (
262  "cmptAv(" + df.name() + ')',
263  df.instance(),
264  df.db()
265  ),
266  df.mesh(),
267  df.dimensions()
268  )
269  );
270 
271  cmptAv(CmptAv.ref().field(), df.field());
272 
273  return CmptAv;
274 }
275 
276 template<class Type, class GeoMesh>
277 tmp
278 <
280  <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
281 >
283 {
284  typedef typename DimensionedField<Type, GeoMesh>::cmptType
285  cmptType;
286 
287  const DimensionedField<Type, GeoMesh>& df = tdf();
288 
291  (
292  tdf,
293  "cmptAv(" + df.name() + ')',
294  df.dimensions()
295  );
296 
297  cmptAv(CmptAv.ref().field(), df.field());
298 
299  tdf.clear();
300 
301  return CmptAv;
302 }
303 
304 #define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc) \
305  \
306 template<class Type, class GeoMesh> \
307 dimensioned<returnType> func \
308 ( \
309  const DimensionedField<Type, GeoMesh>& df \
310 ) \
311 { \
312  return dimensioned<Type> \
313  ( \
314  #func "(" + df.name() + ')', \
315  df.dimensions(), \
316  dfunc(df.field()) \
317  ); \
318 } \
319  \
320 template<class Type, class GeoMesh> \
321 dimensioned<returnType> func \
322 ( \
323  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
324 ) \
325 { \
326  dimensioned<returnType> res = func(tdf1()); \
327  tdf1.clear(); \
328  return res; \
329 }
330 
336 
337 #undef UNARY_REDUCTION_FUNCTION
338 
339 
340 BINARY_FUNCTION(Type, Type, Type, max)
341 BINARY_FUNCTION(Type, Type, Type, min)
342 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
343 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
344 
345 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
346 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
347 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
348 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
349 
350 
351 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
352 
353 UNARY_OPERATOR(Type, Type, -, negate, transform)
354 
355 BINARY_OPERATOR(Type, Type, scalar, *, '*', multiply)
356 BINARY_OPERATOR(Type, scalar, Type, *, '*', multiply)
357 BINARY_OPERATOR(Type, Type, scalar, /, '|', divide)
358 
359 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, '*', multiply)
360 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, '*', multiply)
361 
362 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide)
363 
364 
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 
367 #define PRODUCT_OPERATOR(product, op, opFunc) \
368  \
369 template<class Type1, class Type2, class GeoMesh> \
370 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
371 operator op \
372 ( \
373  const DimensionedField<Type1, GeoMesh>& df1, \
374  const DimensionedField<Type2, GeoMesh>& df2 \
375 ) \
376 { \
377  typedef typename product<Type1, Type2>::type productType; \
378  tmp<DimensionedField<productType, GeoMesh>> tRes \
379  ( \
380  new DimensionedField<productType, GeoMesh> \
381  ( \
382  IOobject \
383  ( \
384  '(' + df1.name() + #op + df2.name() + ')', \
385  df1.instance(), \
386  df1.db() \
387  ), \
388  df1.mesh(), \
389  df1.dimensions() op df2.dimensions() \
390  ) \
391  ); \
392  \
393  Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
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 DimensionedField<Type1, GeoMesh>& df1, \
403  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
404 ) \
405 { \
406  typedef typename product<Type1, Type2>::type productType; \
407  \
408  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
409  \
410  tmp<DimensionedField<productType, GeoMesh>> tRes = \
411  reuseTmpDimensionedField<productType, Type2, GeoMesh>::New \
412  ( \
413  tdf2, \
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  tdf2.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 DimensionedField<Type2, GeoMesh>& df2 \
431 ) \
432 { \
433  typedef typename product<Type1, Type2>::type productType; \
434  \
435  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
436  \
437  tmp<DimensionedField<productType, GeoMesh>> tRes = \
438  reuseTmpDimensionedField<productType, Type1, GeoMesh>::New \
439  ( \
440  tdf1, \
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  \
449  return tRes; \
450 } \
451  \
452 template<class Type1, class Type2, class GeoMesh> \
453 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh>> \
454 operator op \
455 ( \
456  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
457  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
458 ) \
459 { \
460  typedef typename product<Type1, Type2>::type productType; \
461  \
462  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
463  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
464  \
465  tmp<DimensionedField<productType, GeoMesh>> tRes = \
466  reuseTmpTmpDimensionedField \
467  <productType, Type1, Type1, Type2, GeoMesh>::New \
468  ( \
469  tdf1, \
470  tdf2, \
471  '(' + df1.name() + #op + df2.name() + ')', \
472  df1.dimensions() op df2.dimensions() \
473  ); \
474  \
475  Foam::opFunc(tRes.ref().field(), df1.field(), df2.field()); \
476  \
477  tdf1.clear(); \
478  tdf2.clear(); \
479  \
480  return tRes; \
481 } \
482  \
483 template<class Form, class Type, class GeoMesh> \
484 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh>> \
485 operator op \
486 ( \
487  const DimensionedField<Type, GeoMesh>& df1, \
488  const dimensioned<Form>& dvs \
489 ) \
490 { \
491  typedef typename product<Type, Form>::type productType; \
492  \
493  tmp<DimensionedField<productType, GeoMesh>> tRes \
494  ( \
495  new DimensionedField<productType, GeoMesh> \
496  ( \
497  IOobject \
498  ( \
499  '(' + df1.name() + #op + dvs.name() + ')', \
500  df1.instance(), \
501  df1.db() \
502  ), \
503  df1.mesh(), \
504  df1.dimensions() op dvs.dimensions() \
505  ) \
506  ); \
507  \
508  Foam::opFunc(tRes.ref().field(), df1.field(), dvs.value()); \
509  \
510  return tRes; \
511 } \
512  \
513 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
514 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
515 operator op \
516 ( \
517  const DimensionedField<Type, GeoMesh>& df1, \
518  const VectorSpace<Form,Cmpt,nCmpt>& vs \
519 ) \
520 { \
521  return df1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
522 } \
523  \
524  \
525 template<class Form, class Type, class GeoMesh> \
526 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh>> \
527 operator op \
528 ( \
529  const tmp<DimensionedField<Type, GeoMesh>>& tdf1, \
530  const dimensioned<Form>& dvs \
531 ) \
532 { \
533  typedef typename product<Type, Form>::type productType; \
534  \
535  const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
536  \
537  tmp<DimensionedField<productType, GeoMesh>> tRes = \
538  reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
539  ( \
540  tdf1, \
541  '(' + df1.name() + #op + dvs.name() + ')', \
542  df1.dimensions() op dvs.dimensions() \
543  ); \
544  \
545  Foam::opFunc(tRes.ref().field(), df1.field(), dvs.value()); \
546  \
547  tdf1.clear(); \
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 tmp<DimensionedField<Type, GeoMesh>>& tdf1, \
557  const VectorSpace<Form,Cmpt,nCmpt>& vs \
558 ) \
559 { \
560  return tdf1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
561 } \
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 DimensionedField<Type, GeoMesh>& df1 \
570 ) \
571 { \
572  typedef typename product<Form, Type>::type productType; \
573  tmp<DimensionedField<productType, GeoMesh>> tRes \
574  ( \
575  new DimensionedField<productType, GeoMesh> \
576  ( \
577  IOobject \
578  ( \
579  '(' + dvs.name() + #op + df1.name() + ')', \
580  df1.instance(), \
581  df1.db() \
582  ), \
583  df1.mesh(), \
584  dvs.dimensions() op df1.dimensions() \
585  ) \
586  ); \
587  \
588  Foam::opFunc(tRes.ref().field(), dvs.value(), df1.field()); \
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 DimensionedField<Type, GeoMesh>& df1 \
599 ) \
600 { \
601  return dimensioned<Form>(static_cast<const Form&>(vs)) op df1; \
602 } \
603  \
604 template<class Form, class Type, class GeoMesh> \
605 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
606 operator op \
607 ( \
608  const dimensioned<Form>& dvs, \
609  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
610 ) \
611 { \
612  typedef typename product<Form, Type>::type productType; \
613  \
614  const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
615  \
616  tmp<DimensionedField<productType, GeoMesh>> tRes = \
617  reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
618  ( \
619  tdf1, \
620  '(' + dvs.name() + #op + df1.name() + ')', \
621  dvs.dimensions() op df1.dimensions() \
622  ); \
623  \
624  Foam::opFunc(tRes.ref().field(), dvs.value(), df1.field()); \
625  \
626  tdf1.clear(); \
627  \
628  return tRes; \
629 } \
630  \
631 template<class Form, class Cmpt, direction nCmpt, class Type, class GeoMesh> \
632 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh>> \
633 operator op \
634 ( \
635  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
636  const tmp<DimensionedField<Type, GeoMesh>>& tdf1 \
637 ) \
638 { \
639  return dimensioned<Form>(static_cast<const Form&>(vs)) op tdf1; \
640 }
641 
644 
649 
650 #undef PRODUCT_OPERATOR
651 
652 
653 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
654 
655 } // End namespace Foam
656 
657 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
658 
659 #include "undefFieldFunctionsM.H"
660 
661 // ************************************************************************* //
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 objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:221
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)
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)
Type gSum(const FieldField< Field, Type > &f)
#define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc)
const dimensionSet & dimensions() const
Return dimensions.
const Field< Type > & field() const
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)
Type gMax(const FieldField< Field, Type > &f)
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)
Type gAverage(const FieldField< Field, Type > &f)
const Mesh & mesh() const
Return mesh.
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:54
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
const fileName & instance() const
Definition: IOobject.H:337
const word & name() const
Return name.
Definition: IOobject.H:260
Namespace for OpenFOAM.
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:465
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)