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 "scalarField.H"
28 #define TEMPLATE template<class Type>
29 #include "FieldFunctionsM.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
41 Field<typename Field<Type>::cmptType>& res,
48 void T(Field<Type>& res, const UList<Type>& f);
51 template<class Type, int r>
54 Field<typename powProduct<Type, r>::type>& res,
59 template<class Type, int r>
60 tmp<Field<typename powProduct<Type, r>::type> >
64 typename powProduct<Type, r>::type
65 = pTraits<typename powProduct<Type, r>::type>::zero
68 template<class Type, int r>
69 tmp<Field<typename powProduct<Type, r>::type> >
72 const tmp<Field<Type> >& tf,
73 typename powProduct<Type, r>::type
74 = pTraits<typename powProduct<Type, r>::type>::zero
81 Field<typename outerProduct<Type, Type>::type>& res,
86 tmp<Field<typename outerProduct<Type, Type>::type> >
87 sqr(const UList<Type>& f);
90 tmp<Field<typename outerProduct<Type, Type>::type> >
91 sqr(const tmp<Field<Type> >& tf);
95 void magSqr(Field<scalar>& res, const UList<Type>& f);
98 tmp<Field<scalar> > magSqr(const UList<Type>& f);
101 tmp<Field<scalar> > magSqr(const tmp<Field<Type> >& tf);
105 void mag(Field<scalar>& res, const UList<Type>& f);
108 tmp<Field<scalar> > mag(const UList<Type>& f);
111 tmp<Field<scalar> > mag(const tmp<Field<Type> >& tf);
115 void cmptMax(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
118 tmp<Field<typename Field<Type>::cmptType> > cmptMax(const UList<Type>& f);
121 tmp<Field<typename Field<Type>::cmptType> >
122 cmptMax(const tmp<Field<Type> >& tf);
126 void cmptMin(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
129 tmp<Field<typename Field<Type>::cmptType> > cmptMin(const UList<Type>& f);
132 tmp<Field<typename Field<Type>::cmptType> >
133 cmptMin(const tmp<Field<Type> >& tf);
137 void cmptAv(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
140 tmp<Field<typename Field<Type>::cmptType> > cmptAv(const UList<Type>& f);
143 tmp<Field<typename Field<Type>::cmptType> > cmptAv(const tmp<Field<Type> >& tf);
147 void cmptMag(Field<Type>& res, const UList<Type>& f);
150 tmp<Field<Type> > cmptMag(const UList<Type>& f);
153 tmp<Field<Type> > cmptMag(const tmp<Field<Type> >& tf);
155 #define TMP_UNARY_FUNCTION(ReturnType, Func) \
157 template<class Type> \
158 ReturnType Func(const tmp<Field<Type> >& tf1);
161 Type max(const UList<Type>& f);
163 TMP_UNARY_FUNCTION(Type, max)
166 Type min(const UList<Type>& f);
168 TMP_UNARY_FUNCTION(Type, min)
171 Type sum(const UList<Type>& f);
173 TMP_UNARY_FUNCTION(Type, sum)
177 scalar sumProd(const UList<Type>& f1, const UList<Type>& f2);
180 Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2);
183 scalar sumSqr(const UList<Type>& f);
185 TMP_UNARY_FUNCTION(scalar, sumSqr)
188 scalar sumMag(const UList<Type>& f);
190 TMP_UNARY_FUNCTION(scalar, sumMag)
193 Type sumCmptMag(const UList<Type>& f);
195 TMP_UNARY_FUNCTION(Type, sumCmptMag)
198 Type average(const UList<Type>& f);
200 TMP_UNARY_FUNCTION(Type, average)
203 #define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \
205 template<class Type> \
206 ReturnType gFunc(const UList<Type>& f); \
207 TMP_UNARY_FUNCTION(ReturnType, gFunc)
209 G_UNARY_FUNCTION(Type, gMax, max, max)
210 G_UNARY_FUNCTION(Type, gMin, min, min)
211 G_UNARY_FUNCTION(Type, gSum, sum, sum)
212 G_UNARY_FUNCTION(scalar, gSumSqr, sumSqr, sum)
213 G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
214 G_UNARY_FUNCTION(Type, gSumCmptMag, sumCmptMag, sum)
216 #undef G_UNARY_FUNCTION
219 scalar gSumProd(const UList<Type>& f1, const UList<Type>& f2);
222 Type gSumCmptProd(const UList<Type>& f1, const UList<Type>& f2);
225 Type gAverage(const UList<Type>& f);
227 TMP_UNARY_FUNCTION(Type, gAverage)
229 #undef TMP_UNARY_FUNCTION
232 BINARY_FUNCTION(Type, Type, Type, max)
233 BINARY_FUNCTION(Type, Type, Type, min)
234 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
235 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
237 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
238 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
239 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
240 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
243 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
245 UNARY_OPERATOR(Type, Type, -, negate)
247 BINARY_OPERATOR(Type, Type, scalar, *, multiply)
248 BINARY_OPERATOR(Type, scalar, Type, *, multiply)
249 BINARY_OPERATOR(Type, Type, scalar, /, divide)
251 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
252 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
254 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 #define PRODUCT_OPERATOR(product, Op, OpFunc) \
261 template<class Type1, class Type2> \
264 Field<typename product<Type1, Type2>::type>& res, \
265 const UList<Type1>& f1, \
266 const UList<Type2>& f2 \
269 template<class Type1, class Type2> \
270 tmp<Field<typename product<Type1, Type2>::type> > \
271 operator Op(const UList<Type1>& f1, const UList<Type2>& f2); \
273 template<class Type1, class Type2> \
274 tmp<Field<typename product<Type1, Type2>::type> > \
275 operator Op(const UList<Type1>& f1, const tmp<Field<Type2> >& tf2); \
277 template<class Type1, class Type2> \
278 tmp<Field<typename product<Type1, Type2>::type> > \
279 operator Op(const tmp<Field<Type1> >& tf1, const UList<Type2>& f2); \
281 template<class Type1, class Type2> \
282 tmp<Field<typename product<Type1, Type2>::type> > \
283 operator Op(const tmp<Field<Type1> >& tf1, const tmp<Field<Type2> >& tf2); \
285 template<class Type, class Form, class Cmpt, int nCmpt> \
288 Field<typename product<Type, Form>::type>& res, \
289 const UList<Type>& f1, \
290 const VectorSpace<Form,Cmpt,nCmpt>& vs \
293 template<class Type, class Form, class Cmpt, int nCmpt> \
294 tmp<Field<typename product<Type, Form>::type> > \
295 operator Op(const UList<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs); \
297 template<class Type, class Form, class Cmpt, int nCmpt> \
298 tmp<Field<typename product<Type, Form>::type> > \
299 operator Op(const tmp<Field<Type> >&tf1,const VectorSpace<Form,Cmpt,nCmpt>&vs);\
301 template<class Form, class Cmpt, int nCmpt, class Type> \
304 Field<typename product<Form, Type>::type>& res, \
305 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
306 const UList<Type>& f1 \
309 template<class Form, class Cmpt, int nCmpt, class Type> \
310 tmp<Field<typename product<Form, Type>::type> > \
311 operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const UList<Type>& f1); \
313 template<class Form, class Cmpt, int nCmpt, class Type> \
314 tmp<Field<typename product<Form, Type>::type> > \
315 operator Op(const VectorSpace<Form,Cmpt,nCmpt>&vs,const tmp<Field<Type> >&tf1);
317 PRODUCT_OPERATOR(typeOfSum, +, add)
318 PRODUCT_OPERATOR(typeOfSum, -, subtract)
320 PRODUCT_OPERATOR(outerProduct, *, outer)
321 PRODUCT_OPERATOR(crossProduct, ^, cross)
322 PRODUCT_OPERATOR(innerProduct, &, dot)
323 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
325 #undef PRODUCT_OPERATOR
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 } // End namespace Foam
332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 #include "undefFieldFunctionsM.H"
336 // ************************************************************************* //