1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "GeometricFieldReuseFunctions.H"
30 template<class Type, template<class> class PatchField, class GeoMesh>
31 #include "GeometricFieldFunctionsM.C"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * //
40 template<class Type, template<class> class PatchField, class GeoMesh>
45 typename GeometricField<Type, PatchField, GeoMesh>::cmptType,
49 const GeometricField<Type, PatchField, GeoMesh>& gf,
53 component(gcf.internalField(), gf.internalField(), d);
54 component(gcf.boundaryField(), gf.boundaryField(), d);
58 template<class Type, template<class> class PatchField, class GeoMesh>
61 GeometricField<Type, PatchField, GeoMesh>& gf,
62 const GeometricField<Type, PatchField, GeoMesh>& gf1
65 T(gf.internalField(), gf1.internalField());
66 T(gf.boundaryField(), gf1.boundaryField());
70 template<class Type, template<class> class PatchField, class GeoMesh, int r>
73 GeometricField<typename powProduct<Type, r>::type, PatchField, GeoMesh>& gf,
74 const GeometricField<Type, PatchField, GeoMesh>& gf1
77 pow(gf.internalField(), gf1.internalField(), r);
78 pow(gf.boundaryField(), gf1.boundaryField(), r);
81 template<class Type, template<class> class PatchField, class GeoMesh, int r>
82 tmp<GeometricField<typename powProduct<Type, r>::type, PatchField, GeoMesh> >
85 const GeometricField<Type, PatchField, GeoMesh>& gf,
86 typename powProduct<Type, r>::type
89 typedef typename powProduct<Type, r>::type powProductType;
91 tmp<GeometricField<powProductType, PatchField, GeoMesh> > tPow
93 new GeometricField<powProductType, PatchField, GeoMesh>
97 "pow(" + gf.name() + ',' + name(r) + ')',
104 pow(gf.dimensions(), r)
108 pow<Type, r, PatchField, GeoMesh>(tPow(), gf);
114 template<class Type, template<class> class PatchField, class GeoMesh, int r>
115 tmp<GeometricField<typename powProduct<Type, r>::type, PatchField, GeoMesh> >
118 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf,
119 typename powProduct<Type, r>::type
122 typedef typename powProduct<Type, r>::type powProductType;
124 const GeometricField<Type, PatchField, GeoMesh>& gf = tgf();
126 tmp<GeometricField<powProductType, PatchField, GeoMesh> > tPow
128 new GeometricField<powProductType, PatchField, GeoMesh>
132 "pow(" + gf.name() + ',' + name(r) + ')',
139 pow(gf.dimensions(), r)
143 pow<Type, r, PatchField, GeoMesh>(tPow(), gf);
151 template<class Type, template<class> class PatchField, class GeoMesh>
155 <typename outerProduct<Type, Type>::type, PatchField, GeoMesh>& gf,
156 const GeometricField<Type, PatchField, GeoMesh>& gf1
159 sqr(gf.internalField(), gf1.internalField());
160 sqr(gf.boundaryField(), gf1.boundaryField());
163 template<class Type, template<class> class PatchField, class GeoMesh>
168 typename outerProduct<Type, Type>::type,
173 sqr(const GeometricField<Type, PatchField, GeoMesh>& gf)
175 typedef typename outerProduct<Type, Type>::type outerProductType;
177 tmp<GeometricField<outerProductType, PatchField, GeoMesh> > tSqr
179 new GeometricField<outerProductType, PatchField, GeoMesh>
183 "sqr(" + gf.name() + ')',
199 template<class Type, template<class> class PatchField, class GeoMesh>
204 typename outerProduct<Type, Type>::type,
209 sqr(const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf)
211 typedef typename outerProduct<Type, Type>::type outerProductType;
213 const GeometricField<Type, PatchField, GeoMesh>& gf = tgf();
215 tmp<GeometricField<outerProductType, PatchField, GeoMesh> > tSqr
217 new GeometricField<outerProductType, PatchField, GeoMesh>
221 "sqr(" + gf.name() + ')',
240 template<class Type, template<class> class PatchField, class GeoMesh>
243 GeometricField<scalar, PatchField, GeoMesh>& gsf,
244 const GeometricField<Type, PatchField, GeoMesh>& gf
247 magSqr(gsf.internalField(), gf.internalField());
248 magSqr(gsf.boundaryField(), gf.boundaryField());
251 template<class Type, template<class> class PatchField, class GeoMesh>
252 tmp<GeometricField<scalar, PatchField, GeoMesh> > magSqr
254 const GeometricField<Type, PatchField, GeoMesh>& gf
257 tmp<GeometricField<scalar, PatchField, GeoMesh> > tMagSqr
259 new GeometricField<scalar, PatchField, GeoMesh>
263 "magSqr(" + gf.name() + ')',
274 magSqr(tMagSqr(), gf);
279 template<class Type, template<class> class PatchField, class GeoMesh>
280 tmp<GeometricField<scalar, PatchField, GeoMesh> > magSqr
282 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf
285 const GeometricField<Type, PatchField, GeoMesh>& gf = tgf();
287 tmp<GeometricField<scalar, PatchField, GeoMesh> > tMagSqr
289 new GeometricField<scalar, PatchField, GeoMesh>
293 "magSqr(" + gf.name() + ')',
304 magSqr(tMagSqr(), gf);
312 template<class Type, template<class> class PatchField, class GeoMesh>
315 GeometricField<scalar, PatchField, GeoMesh>& gsf,
316 const GeometricField<Type, PatchField, GeoMesh>& gf
319 mag(gsf.internalField(), gf.internalField());
320 mag(gsf.boundaryField(), gf.boundaryField());
323 template<class Type, template<class> class PatchField, class GeoMesh>
324 tmp<GeometricField<scalar, PatchField, GeoMesh> > mag
326 const GeometricField<Type, PatchField, GeoMesh>& gf
329 tmp<GeometricField<scalar, PatchField, GeoMesh> > tMag
331 new GeometricField<scalar, PatchField, GeoMesh>
335 "mag(" + gf.name() + ')',
351 template<class Type, template<class> class PatchField, class GeoMesh>
352 tmp<GeometricField<scalar, PatchField, GeoMesh> > mag
354 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf
357 const GeometricField<Type, PatchField, GeoMesh>& gf = tgf();
359 tmp<GeometricField<scalar, PatchField, GeoMesh> > tMag
361 new GeometricField<scalar, PatchField, GeoMesh>
365 "mag(" + gf.name() + ')',
384 template<class Type, template<class> class PatchField, class GeoMesh>
389 typename GeometricField<Type, PatchField, GeoMesh>::cmptType,
393 const GeometricField<Type, PatchField, GeoMesh>& gf
396 cmptAv(gcf.internalField(), gf.internalField());
397 cmptAv(gcf.boundaryField(), gf.boundaryField());
400 template<class Type, template<class> class PatchField, class GeoMesh>
405 typename GeometricField<Type, PatchField, GeoMesh>::cmptType,
410 cmptAv(const GeometricField<Type, PatchField, GeoMesh>& gf)
412 typedef typename GeometricField<Type, PatchField, GeoMesh>::cmptType
415 tmp<GeometricField<cmptType, PatchField, GeoMesh> > CmptAv
417 new GeometricField<scalar, PatchField, GeoMesh>
421 "cmptAv(" + gf.name() + ')',
432 cmptAv(CmptAv(), gf);
437 template<class Type, template<class> class PatchField, class GeoMesh>
442 typename GeometricField<Type, PatchField, GeoMesh>::cmptType,
447 cmptAv(const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf)
449 typedef typename GeometricField<Type, PatchField, GeoMesh>::cmptType
452 const GeometricField<Type, PatchField, GeoMesh>& gf = tgf();
454 tmp<GeometricField<cmptType, PatchField, GeoMesh> > CmptAv
456 new GeometricField<scalar, PatchField, GeoMesh>
460 "cmptAv(" + gf.name() + ')',
471 cmptAv(CmptAv(), gf);
479 #define UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(returnType, func, gFunc) \
481 template<class Type, template<class> class PatchField, class GeoMesh> \
482 dimensioned<returnType> func \
484 const GeometricField<Type, PatchField, GeoMesh>& gf \
487 return dimensioned<Type> \
489 #func "(" + gf.name() + ')', \
491 Foam::func(gFunc(gf.internalField()), gFunc(gf.boundaryField())) \
495 template<class Type, template<class> class PatchField, class GeoMesh> \
496 dimensioned<returnType> func \
498 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf1 \
501 dimensioned<returnType> res = func(tgf1()); \
506 UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, max, gMax)
507 UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, min, gMin)
509 #undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY
512 #define UNARY_REDUCTION_FUNCTION(returnType, func, gFunc) \
514 template<class Type, template<class> class PatchField, class GeoMesh> \
515 dimensioned<returnType> func \
517 const GeometricField<Type, PatchField, GeoMesh>& gf \
520 return dimensioned<Type> \
522 #func "(" + gf.name() + ')', \
524 gFunc(gf.internalField()) \
528 template<class Type, template<class> class PatchField, class GeoMesh> \
529 dimensioned<returnType> func \
531 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf1 \
534 dimensioned<returnType> res = func(tgf1()); \
539 UNARY_REDUCTION_FUNCTION(Type, sum, gSum)
540 UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
541 UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
543 #undef UNARY_REDUCTION_FUNCTION
546 BINARY_FUNCTION(Type, Type, Type, max)
547 BINARY_FUNCTION(Type, Type, Type, min)
548 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
549 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
551 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
552 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
553 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
554 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
557 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
559 UNARY_OPERATOR(Type, Type, -, negate, transform)
561 #ifndef __INTEL_COMPILER
562 BINARY_OPERATOR(Type, Type, scalar, *, '*', multiply)
563 BINARY_OPERATOR(Type, scalar, Type, *, '*', multiply)
565 BINARY_OPERATOR(Type, Type, scalar, /, '|', divide)
567 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, '*', multiply)
568 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, '*', multiply)
570 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide)
573 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
575 #define PRODUCT_OPERATOR(product, op, opFunc) \
578 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
582 <typename product<Type1, Type2>::type, PatchField, GeoMesh>& gf, \
583 const GeometricField<Type1, PatchField, GeoMesh>& gf1, \
584 const GeometricField<Type2, PatchField, GeoMesh>& gf2 \
587 Foam::opFunc(gf.internalField(), gf1.internalField(), gf2.internalField());\
588 Foam::opFunc(gf.boundaryField(), gf1.boundaryField(), gf2.boundaryField());\
592 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
595 GeometricField<typename product<Type1, Type2>::type, PatchField, GeoMesh> \
599 const GeometricField<Type1, PatchField, GeoMesh>& gf1, \
600 const GeometricField<Type2, PatchField, GeoMesh>& gf2 \
603 typedef typename product<Type1, Type2>::type productType; \
604 tmp<GeometricField<productType, PatchField, GeoMesh> > tRes \
606 new GeometricField<productType, PatchField, GeoMesh> \
610 '(' + gf1.name() + #op + gf2.name() + ')', \
617 gf1.dimensions() op gf2.dimensions() \
621 Foam::opFunc(tRes(), gf1, gf2); \
627 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
630 GeometricField<typename product<Type1, Type2>::type, PatchField, GeoMesh> \
634 const GeometricField<Type1, PatchField, GeoMesh>& gf1, \
635 const tmp<GeometricField<Type2, PatchField, GeoMesh> >& tgf2 \
638 typedef typename product<Type1, Type2>::type productType; \
640 const GeometricField<Type2, PatchField, GeoMesh>& gf2 = tgf2(); \
642 tmp<GeometricField<productType, PatchField, GeoMesh> > tRes = \
643 reuseTmpGeometricField<productType, Type2, PatchField, GeoMesh>::New \
646 '(' + gf1.name() + #op + gf2.name() + ')', \
647 gf1.dimensions() op gf2.dimensions() \
650 Foam::opFunc(tRes(), gf1, gf2); \
652 reuseTmpGeometricField<productType, Type2, PatchField, GeoMesh> \
659 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
662 GeometricField<typename product<Type1, Type2>::type, PatchField, GeoMesh> \
666 const tmp<GeometricField<Type1, PatchField, GeoMesh> >& tgf1, \
667 const GeometricField<Type2, PatchField, GeoMesh>& gf2 \
670 typedef typename product<Type1, Type2>::type productType; \
672 const GeometricField<Type1, PatchField, GeoMesh>& gf1 = tgf1(); \
674 tmp<GeometricField<productType, PatchField, GeoMesh> > tRes = \
675 reuseTmpGeometricField<productType, Type1, PatchField, GeoMesh>::New \
678 '(' + gf1.name() + #op + gf2.name() + ')', \
679 gf1.dimensions() op gf2.dimensions() \
682 Foam::opFunc(tRes(), gf1, gf2); \
684 reuseTmpGeometricField<productType, Type1, PatchField, GeoMesh> \
691 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
694 GeometricField<typename product<Type1, Type2>::type, PatchField, GeoMesh> \
698 const tmp<GeometricField<Type1, PatchField, GeoMesh> >& tgf1, \
699 const tmp<GeometricField<Type2, PatchField, GeoMesh> >& tgf2 \
702 typedef typename product<Type1, Type2>::type productType; \
704 const GeometricField<Type1, PatchField, GeoMesh>& gf1 = tgf1(); \
705 const GeometricField<Type2, PatchField, GeoMesh>& gf2 = tgf2(); \
707 tmp<GeometricField<productType, PatchField, GeoMesh> > tRes = \
708 reuseTmpTmpGeometricField \
709 <productType, Type1, Type1, Type2, PatchField, GeoMesh>::New \
713 '(' + gf1.name() + #op + gf2.name() + ')', \
714 gf1.dimensions() op gf2.dimensions() \
717 Foam::opFunc(tRes(), gf1, gf2); \
719 reuseTmpTmpGeometricField \
720 <productType, Type1, Type1, Type2, PatchField, GeoMesh> \
721 ::clear(tgf1, tgf2); \
727 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
731 <typename product<Type, Form>::type, PatchField, GeoMesh>& gf, \
732 const GeometricField<Type, PatchField, GeoMesh>& gf1, \
733 const dimensioned<Form>& dvs \
736 Foam::opFunc(gf.internalField(), gf1.internalField(), dvs.value()); \
737 Foam::opFunc(gf.boundaryField(), gf1.boundaryField(), dvs.value()); \
741 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
742 tmp<GeometricField<typename product<Type, Form>::type, PatchField, GeoMesh> > \
745 const GeometricField<Type, PatchField, GeoMesh>& gf1, \
746 const dimensioned<Form>& dvs \
749 typedef typename product<Type, Form>::type productType; \
751 tmp<GeometricField<productType, PatchField, GeoMesh> > tRes \
753 new GeometricField<productType, PatchField, GeoMesh> \
757 '(' + gf1.name() + #op + dvs.name() + ')', \
764 gf1.dimensions() op dvs.dimensions() \
768 Foam::opFunc(tRes(), gf1, dvs); \
778 class Type, template<class> class PatchField, \
781 tmp<GeometricField<typename product<Form, Type>::type, PatchField, GeoMesh> > \
784 const GeometricField<Type, PatchField, GeoMesh>& gf1, \
785 const VectorSpace<Form,Cmpt,nCmpt>& vs \
788 return gf1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
793 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
794 tmp<GeometricField<typename product<Type, Form>::type, PatchField, GeoMesh> > \
797 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf1, \
798 const dimensioned<Form>& dvs \
801 typedef typename product<Type, Form>::type productType; \
803 const GeometricField<Type, PatchField, GeoMesh>& gf1 = tgf1(); \
805 tmp<GeometricField<productType, PatchField, GeoMesh> > tRes = \
806 reuseTmpGeometricField<productType, Type, PatchField, GeoMesh>::New \
809 '(' + gf1.name() + #op + dvs.name() + ')', \
810 gf1.dimensions() op dvs.dimensions() \
813 Foam::opFunc(tRes(), gf1, dvs); \
815 reuseTmpGeometricField<productType, Type, PatchField, GeoMesh> \
826 class Type, template<class> class PatchField, \
829 tmp<GeometricField<typename product<Form, Type>::type, PatchField, GeoMesh> > \
832 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf1, \
833 const VectorSpace<Form,Cmpt,nCmpt>& vs \
836 return tgf1 op dimensioned<Form>(static_cast<const Form&>(vs)); \
841 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
845 <typename product<Form, Type>::type, PatchField, GeoMesh>& gf, \
846 const dimensioned<Form>& dvs, \
847 const GeometricField<Type, PatchField, GeoMesh>& gf1 \
850 Foam::opFunc(gf.internalField(), dvs.value(), gf1.internalField()); \
851 Foam::opFunc(gf.boundaryField(), dvs.value(), gf1.boundaryField()); \
855 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
856 tmp<GeometricField<typename product<Form, Type>::type, PatchField, GeoMesh> > \
859 const dimensioned<Form>& dvs, \
860 const GeometricField<Type, PatchField, GeoMesh>& gf1 \
863 typedef typename product<Form, Type>::type productType; \
864 tmp<GeometricField<productType, PatchField, GeoMesh> > tRes \
866 new GeometricField<productType, PatchField, GeoMesh> \
870 '(' + dvs.name() + #op + gf1.name() + ')', \
877 dvs.dimensions() op gf1.dimensions() \
881 Foam::opFunc(tRes(), dvs, gf1); \
891 class Type, template<class> class PatchField, \
894 tmp<GeometricField<typename product<Form, Type>::type, PatchField, GeoMesh> > \
897 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
898 const GeometricField<Type, PatchField, GeoMesh>& gf1 \
901 return dimensioned<Form>(static_cast<const Form&>(vs)) op gf1; \
905 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
906 tmp<GeometricField<typename product<Form, Type>::type, PatchField, GeoMesh> > \
909 const dimensioned<Form>& dvs, \
910 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf1 \
913 typedef typename product<Form, Type>::type productType; \
915 const GeometricField<Type, PatchField, GeoMesh>& gf1 = tgf1(); \
917 tmp<GeometricField<productType, PatchField, GeoMesh> > tRes = \
918 reuseTmpGeometricField<productType, Type, PatchField, GeoMesh>::New \
921 '(' + dvs.name() + #op + gf1.name() + ')', \
922 dvs.dimensions() op gf1.dimensions() \
925 Foam::opFunc(tRes(), dvs, gf1); \
927 reuseTmpGeometricField<productType, Type, PatchField, GeoMesh> \
938 class Type, template<class> class PatchField, \
941 tmp<GeometricField<typename product<Form, Type>::type, PatchField, GeoMesh> > \
944 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
945 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf1 \
948 return dimensioned<Form>(static_cast<const Form&>(vs)) op tgf1; \
951 PRODUCT_OPERATOR(typeOfSum, +, add)
952 PRODUCT_OPERATOR(typeOfSum, -, subtract)
954 PRODUCT_OPERATOR(outerProduct, *, outer)
955 PRODUCT_OPERATOR(crossProduct, ^, cross)
956 PRODUCT_OPERATOR(innerProduct, &, dot)
957 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
959 #undef PRODUCT_OPERATOR
962 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
964 } // End namespace Foam
966 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
968 #include "undefFieldFunctionsM.H"
970 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //