1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "DimensionedFieldReuseFunctions.H"
28 #define TEMPLATE template<class Type, class GeoMesh>
29 #include "DimensionedFieldFunctionsM.C"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * //
38 template<class Type, class GeoMesh, int r>
39 tmp<DimensionedField<typename powProduct<Type, r>::type, GeoMesh> >
42 const DimensionedField<Type, GeoMesh>& df,
43 typename powProduct<Type, r>::type
46 typedef typename powProduct<Type, r>::type powProductType;
48 tmp<DimensionedField<powProductType, GeoMesh> > tPow
50 new DimensionedField<powProductType, GeoMesh>
54 "pow(" + df.name() + ',' + name(r) + ')',
59 pow(df.dimensions(), r)
63 pow<Type, r, GeoMesh>(tPow().field(), df.field());
69 template<class Type, class GeoMesh, int r>
70 tmp<DimensionedField<typename powProduct<Type, r>::type, GeoMesh> >
73 const tmp<DimensionedField<Type, GeoMesh> >& tdf,
74 typename powProduct<Type, r>::type
77 typedef typename powProduct<Type, r>::type powProductType;
79 const DimensionedField<Type, GeoMesh>& df = tdf();
81 tmp<DimensionedField<powProductType, GeoMesh> > tPow =
82 reuseTmpDimensionedField<powProductType, Type, GeoMesh>::New
85 "pow(" + df.name() + ',' + name(r) + ')',
86 pow(df.dimensions(), r)
89 pow<Type, r, GeoMesh>(tPow().field(), df.field());
91 reuseTmpDimensionedField<powProductType, Type, GeoMesh>::clear(tdf);
96 template<class Type, class GeoMesh>
97 tmp<DimensionedField<typename outerProduct<Type, Type>::type, GeoMesh> >
98 sqr(const DimensionedField<Type, GeoMesh>& df)
100 typedef typename outerProduct<Type, Type>::type outerProductType;
102 tmp<DimensionedField<outerProductType, GeoMesh> > tSqr
104 new DimensionedField<outerProductType, GeoMesh>
108 "sqr(" + df.name() + ')',
117 sqr(tSqr().field(), df.field());
122 template<class Type, class GeoMesh>
123 tmp<DimensionedField<typename outerProduct<Type, Type>::type, GeoMesh> >
124 sqr(const tmp<DimensionedField<Type, GeoMesh> >& tdf)
126 typedef typename outerProduct<Type, Type>::type outerProductType;
128 const DimensionedField<Type, GeoMesh>& df = tdf();
130 tmp<DimensionedField<outerProductType, GeoMesh> > tSqr =
131 reuseTmpDimensionedField<outerProductType, Type, GeoMesh>::New
134 "sqr(" + df.name() + ')',
138 sqr(tSqr().field(), df.field());
140 reuseTmpDimensionedField<outerProductType, Type, GeoMesh>::clear(tdf);
146 template<class Type, class GeoMesh>
147 tmp<DimensionedField<scalar, GeoMesh> > magSqr
149 const DimensionedField<Type, GeoMesh>& df
152 tmp<DimensionedField<scalar, GeoMesh> > tMagSqr
154 new DimensionedField<scalar, GeoMesh>
158 "magSqr(" + df.name() + ')',
167 magSqr(tMagSqr().field(), df.field());
172 template<class Type, class GeoMesh>
173 tmp<DimensionedField<scalar, GeoMesh> > magSqr
175 const tmp<DimensionedField<Type, GeoMesh> >& tdf
178 const DimensionedField<Type, GeoMesh>& df = tdf();
180 tmp<DimensionedField<scalar, GeoMesh> > tMagSqr =
181 reuseTmpDimensionedField<scalar, Type, GeoMesh>::New
184 "magSqr(" + df.name() + ')',
188 magSqr(tMagSqr().field(), df.field());
190 reuseTmpDimensionedField<scalar, Type, GeoMesh>::clear(tdf);
196 template<class Type, class GeoMesh>
197 tmp<DimensionedField<scalar, GeoMesh> > mag
199 const DimensionedField<Type, GeoMesh>& df
202 tmp<DimensionedField<scalar, GeoMesh> > tMag
204 new DimensionedField<scalar, GeoMesh>
208 "mag(" + df.name() + ')',
217 mag(tMag().field(), df.field());
222 template<class Type, class GeoMesh>
223 tmp<DimensionedField<scalar, GeoMesh> > mag
225 const tmp<DimensionedField<Type, GeoMesh> >& tdf
228 const DimensionedField<Type, GeoMesh>& df = tdf();
230 tmp<DimensionedField<scalar, GeoMesh> > tMag =
231 reuseTmpDimensionedField<scalar, Type, GeoMesh>::New
234 "mag(" + df.name() + ')',
238 mag(tMag().field(), df.field());
240 reuseTmpDimensionedField<scalar, Type, GeoMesh>::clear(tdf);
246 template<class Type, class GeoMesh>
250 <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
252 cmptAv(const DimensionedField<Type, GeoMesh>& df)
254 typedef typename DimensionedField<Type, GeoMesh>::cmptType cmptType;
256 tmp<DimensionedField<cmptType, GeoMesh> > CmptAv
258 new DimensionedField<scalar, GeoMesh>
262 "cmptAv(" + df.name() + ')',
271 cmptAv(CmptAv().field(), df.field());
276 template<class Type, class GeoMesh>
280 <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
282 cmptAv(const tmp<DimensionedField<Type, GeoMesh> >& tdf)
284 typedef typename DimensionedField<Type, GeoMesh>::cmptType
287 const DimensionedField<Type, GeoMesh>& df = tdf();
289 tmp<DimensionedField<cmptType, GeoMesh> > CmptAv =
290 reuseTmpDimensionedField<cmptType, Type, GeoMesh>::New
293 "cmptAv(" + df.name() + ')',
297 cmptAv(CmptAv().field(), df.field());
299 reuseTmpDimensionedField<cmptType, Type, GeoMesh>::clear(tdf);
304 #define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc) \
306 template<class Type, class GeoMesh> \
307 dimensioned<returnType> func \
309 const DimensionedField<Type, GeoMesh>& df \
312 return dimensioned<Type> \
314 #func "(" + df.name() + ')', \
320 template<class Type, class GeoMesh> \
321 dimensioned<returnType> func \
323 const tmp<DimensionedField<Type, GeoMesh> >& tdf1 \
326 dimensioned<returnType> res = func(tdf1()); \
331 UNARY_REDUCTION_FUNCTION(Type, max, gMax)
332 UNARY_REDUCTION_FUNCTION(Type, min, gMin)
333 UNARY_REDUCTION_FUNCTION(Type, sum, gSum)
334 UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
335 UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
337 #undef UNARY_REDUCTION_FUNCTION
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)
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)
351 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
353 UNARY_OPERATOR(Type, Type, -, negate, transform)
355 BINARY_OPERATOR(Type, Type, scalar, *, '*', multiply)
356 BINARY_OPERATOR(Type, scalar, Type, *, '*', multiply)
357 BINARY_OPERATOR(Type, Type, scalar, /, '|', divide)
359 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, '*', multiply)
360 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, '*', multiply)
362 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide)
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
367 #define PRODUCT_OPERATOR(product, op, opFunc) \
369 template<class Type1, class Type2, class GeoMesh> \
370 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh> > \
373 const DimensionedField<Type1, GeoMesh>& df1, \
374 const DimensionedField<Type2, GeoMesh>& df2 \
377 typedef typename product<Type1, Type2>::type productType; \
378 tmp<DimensionedField<productType, GeoMesh> > tRes \
380 new DimensionedField<productType, GeoMesh> \
384 '(' + df1.name() + #op + df2.name() + ')', \
389 df1.dimensions() op df2.dimensions() \
393 Foam::opFunc(tRes().field(), df1.field(), df2.field()); \
398 template<class Type1, class Type2, class GeoMesh> \
399 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh> > \
402 const DimensionedField<Type1, GeoMesh>& df1, \
403 const tmp<DimensionedField<Type2, GeoMesh> >& tdf2 \
406 typedef typename product<Type1, Type2>::type productType; \
408 const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
410 tmp<DimensionedField<productType, GeoMesh> > tRes = \
411 reuseTmpDimensionedField<productType, Type2, GeoMesh>::New \
414 '(' + df1.name() + #op + df2.name() + ')', \
415 df1.dimensions() op df2.dimensions() \
418 Foam::opFunc(tRes().field(), df1.field(), df2.field()); \
420 reuseTmpDimensionedField<productType, Type2, GeoMesh>::clear(tdf2); \
425 template<class Type1, class Type2, class GeoMesh> \
426 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh> > \
429 const tmp<DimensionedField<Type1, GeoMesh> >& tdf1, \
430 const DimensionedField<Type2, GeoMesh>& df2 \
433 typedef typename product<Type1, Type2>::type productType; \
435 const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
437 tmp<DimensionedField<productType, GeoMesh> > tRes = \
438 reuseTmpDimensionedField<productType, Type1, GeoMesh>::New \
441 '(' + df1.name() + #op + df2.name() + ')', \
442 df1.dimensions() op df2.dimensions() \
445 Foam::opFunc(tRes().field(), df1.field(), df2.field()); \
447 reuseTmpDimensionedField<productType, Type1, GeoMesh>::clear(tdf1); \
452 template<class Type1, class Type2, class GeoMesh> \
453 tmp<DimensionedField<typename product<Type1, Type2>::type, GeoMesh> > \
456 const tmp<DimensionedField<Type1, GeoMesh> >& tdf1, \
457 const tmp<DimensionedField<Type2, GeoMesh> >& tdf2 \
460 typedef typename product<Type1, Type2>::type productType; \
462 const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
463 const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
465 tmp<DimensionedField<productType, GeoMesh> > tRes = \
466 reuseTmpTmpDimensionedField \
467 <productType, Type1, Type1, Type2, GeoMesh>::New \
471 '(' + df1.name() + #op + df2.name() + ')', \
472 df1.dimensions() op df2.dimensions() \
475 Foam::opFunc(tRes().field(), df1.field(), df2.field()); \
477 reuseTmpTmpDimensionedField \
478 <productType, Type1, Type1, Type2, GeoMesh>::clear(tdf1, tdf2); \
483 template<class Form, class Type, class GeoMesh> \
484 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh> > \
487 const DimensionedField<Type, GeoMesh>& df1, \
488 const dimensioned<Form>& dvs \
491 typedef typename product<Type, Form>::type productType; \
493 tmp<DimensionedField<productType, GeoMesh> > tRes \
495 new DimensionedField<productType, GeoMesh> \
499 '(' + df1.name() + #op + dvs.name() + ')', \
504 df1.dimensions() op dvs.dimensions() \
508 Foam::opFunc(tRes().field(), df1.field(), dvs.value()); \
513 template<class Form, class Cmpt, int nCmpt, class Type, class GeoMesh> \
514 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh> > \
517 const DimensionedField<Type, GeoMesh>& df1, \
518 const VectorSpace<Form,Cmpt,nCmpt>& vs \
521 return df1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
525 template<class Form, class Type, class GeoMesh> \
526 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh> > \
529 const tmp<DimensionedField<Type, GeoMesh> >& tdf1, \
530 const dimensioned<Form>& dvs \
533 typedef typename product<Type, Form>::type productType; \
535 const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
537 tmp<DimensionedField<productType, GeoMesh> > tRes = \
538 reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
541 '(' + df1.name() + #op + dvs.name() + ')', \
542 df1.dimensions() op dvs.dimensions() \
545 Foam::opFunc(tRes().field(), df1.field(), dvs.value()); \
547 reuseTmpDimensionedField<productType, Type, GeoMesh>::clear(tdf1); \
552 template<class Form, class Cmpt, int nCmpt, class Type, class GeoMesh> \
553 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh> > \
556 const tmp<DimensionedField<Type, GeoMesh> >& tdf1, \
557 const VectorSpace<Form,Cmpt,nCmpt>& vs \
560 return tdf1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
564 template<class Form, class Type, class GeoMesh> \
565 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh> > \
568 const dimensioned<Form>& dvs, \
569 const DimensionedField<Type, GeoMesh>& df1 \
572 typedef typename product<Form, Type>::type productType; \
573 tmp<DimensionedField<productType, GeoMesh> > tRes \
575 new DimensionedField<productType, GeoMesh> \
579 '(' + dvs.name() + #op + df1.name() + ')', \
584 dvs.dimensions() op df1.dimensions() \
588 Foam::opFunc(tRes().field(), dvs.value(), df1.field()); \
593 template<class Form, class Cmpt, int nCmpt, class Type, class GeoMesh> \
594 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh> > \
597 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
598 const DimensionedField<Type, GeoMesh>& df1 \
601 return dimensioned<Form>(static_cast<const Form&>(vs)) op df1; \
604 template<class Form, class Type, class GeoMesh> \
605 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh> > \
608 const dimensioned<Form>& dvs, \
609 const tmp<DimensionedField<Type, GeoMesh> >& tdf1 \
612 typedef typename product<Form, Type>::type productType; \
614 const DimensionedField<Type, GeoMesh>& df1 = tdf1(); \
616 tmp<DimensionedField<productType, GeoMesh> > tRes = \
617 reuseTmpDimensionedField<productType, Type, GeoMesh>::New \
620 '(' + dvs.name() + #op + df1.name() + ')', \
621 dvs.dimensions() op df1.dimensions() \
624 Foam::opFunc(tRes().field(), dvs.value(), df1.field()); \
626 reuseTmpDimensionedField<productType, Type, GeoMesh>::clear(tdf1); \
631 template<class Form, class Cmpt, int nCmpt, class Type, class GeoMesh> \
632 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh> > \
635 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
636 const tmp<DimensionedField<Type, GeoMesh> >& tdf1 \
639 return dimensioned<Form>(static_cast<const Form&>(vs)) op tdf1; \
642 PRODUCT_OPERATOR(typeOfSum, +, add)
643 PRODUCT_OPERATOR(typeOfSum, -, subtract)
645 PRODUCT_OPERATOR(outerProduct, *, outer)
646 PRODUCT_OPERATOR(crossProduct, ^, cross)
647 PRODUCT_OPERATOR(innerProduct, &, dot)
648 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
650 #undef PRODUCT_OPERATOR
653 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
655 } // End namespace Foam
657 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
659 #include "undefFieldFunctionsM.H"
661 // ************************************************************************* //