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 "scalarField.H"
29 #define TEMPLATE template<class Type>
30 #include "FieldFunctionsM.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
42 Field<typename Field<Type>::cmptType>& res,
49 void T(Field<Type>& res, const UList<Type>& f);
52 template<class Type, int r>
55 Field<typename powProduct<Type, r>::type>& res,
60 template<class Type, int r>
61 tmp<Field<typename powProduct<Type, r>::type> >
65 typename powProduct<Type, r>::type
66 = pTraits<typename powProduct<Type, r>::type>::zero
69 template<class Type, int r>
70 tmp<Field<typename powProduct<Type, r>::type> >
73 const tmp<Field<Type> >& tf,
74 typename powProduct<Type, r>::type
75 = pTraits<typename powProduct<Type, r>::type>::zero
82 Field<typename outerProduct<Type, Type>::type>& res,
87 tmp<Field<typename outerProduct<Type, Type>::type> >
88 sqr(const UList<Type>& f);
91 tmp<Field<typename outerProduct<Type, Type>::type> >
92 sqr(const tmp<Field<Type> >& tf);
96 void magSqr(Field<scalar>& res, const UList<Type>& f);
99 tmp<Field<scalar> > magSqr(const UList<Type>& f);
102 tmp<Field<scalar> > magSqr(const tmp<Field<Type> >& tf);
106 void mag(Field<scalar>& res, const UList<Type>& f);
109 tmp<Field<scalar> > mag(const UList<Type>& f);
112 tmp<Field<scalar> > mag(const tmp<Field<Type> >& tf);
116 void cmptMax(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
119 tmp<Field<typename Field<Type>::cmptType> > cmptMax(const UList<Type>& f);
122 tmp<Field<typename Field<Type>::cmptType> >
123 cmptMax(const tmp<Field<Type> >& tf);
127 void cmptMin(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
130 tmp<Field<typename Field<Type>::cmptType> > cmptMin(const UList<Type>& f);
133 tmp<Field<typename Field<Type>::cmptType> >
134 cmptMin(const tmp<Field<Type> >& tf);
138 void cmptAv(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
141 tmp<Field<typename Field<Type>::cmptType> > cmptAv(const UList<Type>& f);
144 tmp<Field<typename Field<Type>::cmptType> > cmptAv(const tmp<Field<Type> >& tf);
148 void cmptMag(Field<Type>& res, const UList<Type>& f);
151 tmp<Field<Type> > cmptMag(const UList<Type>& f);
154 tmp<Field<Type> > cmptMag(const tmp<Field<Type> >& tf);
156 #define TMP_UNARY_FUNCTION(ReturnType, Func) \
158 template<class Type> \
159 ReturnType Func(const tmp<Field<Type> >& tf1);
162 Type max(const UList<Type>& f);
164 TMP_UNARY_FUNCTION(Type, max)
167 Type min(const UList<Type>& f);
169 TMP_UNARY_FUNCTION(Type, min)
172 Type sum(const UList<Type>& f);
174 TMP_UNARY_FUNCTION(Type, sum)
178 scalar sumProd(const UList<Type>& f1, const UList<Type>& f2);
181 Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2);
184 scalar sumSqr(const UList<Type>& f);
186 TMP_UNARY_FUNCTION(scalar, sumSqr)
189 scalar sumMag(const UList<Type>& f);
191 TMP_UNARY_FUNCTION(scalar, sumMag)
194 Type sumCmptMag(const UList<Type>& f);
196 TMP_UNARY_FUNCTION(Type, sumCmptMag)
199 Type average(const UList<Type>& f);
201 TMP_UNARY_FUNCTION(Type, average)
204 #define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \
206 template<class Type> \
207 ReturnType gFunc(const UList<Type>& f); \
208 TMP_UNARY_FUNCTION(ReturnType, gFunc)
210 G_UNARY_FUNCTION(Type, gMax, max, max)
211 G_UNARY_FUNCTION(Type, gMin, min, min)
212 G_UNARY_FUNCTION(Type, gSum, sum, sum)
213 G_UNARY_FUNCTION(scalar, gSumSqr, sumSqr, sum)
214 G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
215 G_UNARY_FUNCTION(Type, gSumCmptMag, sumCmptMag, sum)
217 #undef G_UNARY_FUNCTION
220 scalar gSumProd(const UList<Type>& f1, const UList<Type>& f2);
223 Type gSumCmptProd(const UList<Type>& f1, const UList<Type>& f2);
226 Type gAverage(const UList<Type>& f);
228 TMP_UNARY_FUNCTION(Type, gAverage)
230 #undef TMP_UNARY_FUNCTION
233 BINARY_FUNCTION(Type, Type, Type, max)
234 BINARY_FUNCTION(Type, Type, Type, min)
235 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
236 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
238 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
239 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
240 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
241 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
244 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
246 UNARY_OPERATOR(Type, Type, -, negate)
248 BINARY_OPERATOR(Type, Type, scalar, *, multiply)
249 BINARY_OPERATOR(Type, scalar, Type, *, multiply)
250 BINARY_OPERATOR(Type, Type, scalar, /, divide)
252 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
253 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
255 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 #define PRODUCT_OPERATOR(product, Op, OpFunc) \
262 template<class Type1, class Type2> \
265 Field<typename product<Type1, Type2>::type>& res, \
266 const UList<Type1>& f1, \
267 const UList<Type2>& f2 \
270 template<class Type1, class Type2> \
271 tmp<Field<typename product<Type1, Type2>::type> > \
272 operator Op(const UList<Type1>& f1, const UList<Type2>& f2); \
274 template<class Type1, class Type2> \
275 tmp<Field<typename product<Type1, Type2>::type> > \
276 operator Op(const UList<Type1>& f1, const tmp<Field<Type2> >& tf2); \
278 template<class Type1, class Type2> \
279 tmp<Field<typename product<Type1, Type2>::type> > \
280 operator Op(const tmp<Field<Type1> >& tf1, const UList<Type2>& f2); \
282 template<class Type1, class Type2> \
283 tmp<Field<typename product<Type1, Type2>::type> > \
284 operator Op(const tmp<Field<Type1> >& tf1, const tmp<Field<Type2> >& tf2); \
286 template<class Type, class Form, class Cmpt, int nCmpt> \
289 Field<typename product<Type, Form>::type>& res, \
290 const UList<Type>& f1, \
291 const VectorSpace<Form,Cmpt,nCmpt>& vs \
294 template<class Type, class Form, class Cmpt, int nCmpt> \
295 tmp<Field<typename product<Type, Form>::type> > \
296 operator Op(const UList<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs); \
298 template<class Type, class Form, class Cmpt, int nCmpt> \
299 tmp<Field<typename product<Type, Form>::type> > \
300 operator Op(const tmp<Field<Type> >&tf1,const VectorSpace<Form,Cmpt,nCmpt>&vs);\
302 template<class Form, class Cmpt, int nCmpt, class Type> \
305 Field<typename product<Form, Type>::type>& res, \
306 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
307 const UList<Type>& f1 \
310 template<class Form, class Cmpt, int nCmpt, class Type> \
311 tmp<Field<typename product<Form, Type>::type> > \
312 operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const UList<Type>& f1); \
314 template<class Form, class Cmpt, int nCmpt, class Type> \
315 tmp<Field<typename product<Form, Type>::type> > \
316 operator Op(const VectorSpace<Form,Cmpt,nCmpt>&vs,const tmp<Field<Type> >&tf1);
318 PRODUCT_OPERATOR(typeOfSum, +, add)
319 PRODUCT_OPERATOR(typeOfSum, -, subtract)
321 PRODUCT_OPERATOR(outerProduct, *, outer)
322 PRODUCT_OPERATOR(crossProduct, ^, cross)
323 PRODUCT_OPERATOR(innerProduct, &, dot)
324 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
326 #undef PRODUCT_OPERATOR
329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331 } // End namespace Foam
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 #include "undefFieldFunctionsM.H"
337 // ************************************************************************* //