initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / fields / Fields / Field / FieldFunctions.H
blobe2eeba3e06819a122d9c0771c206c245a9dc7128
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
37 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
39 template<class Type>
40 void component
42     Field<typename Field<Type>::cmptType>& res,
43     const UList<Type>& f,
44     const direction d
48 template<class Type>
49 void T(Field<Type>& res, const UList<Type>& f);
52 template<class Type, int r>
53 void pow
55     Field<typename powProduct<Type, r>::type>& res,
56     const UList<Type>& vf
60 template<class Type, int r>
61 tmp<Field<typename powProduct<Type, r>::type> >
62 pow
64     const UList<Type>& f,
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> >
71 pow
73     const tmp<Field<Type> >& tf,
74     typename powProduct<Type, r>::type
75       = pTraits<typename powProduct<Type, r>::type>::zero
79 template<class Type>
80 void sqr
82     Field<typename outerProduct<Type, Type>::type>& res,
83     const UList<Type>& vf
86 template<class Type>
87 tmp<Field<typename outerProduct<Type, Type>::type> >
88 sqr(const UList<Type>& f);
90 template<class Type>
91 tmp<Field<typename outerProduct<Type, Type>::type> >
92 sqr(const tmp<Field<Type> >& tf);
95 template<class Type>
96 void magSqr(Field<scalar>& res, const UList<Type>& f);
98 template<class Type>
99 tmp<Field<scalar> > magSqr(const UList<Type>& f);
101 template<class Type>
102 tmp<Field<scalar> > magSqr(const tmp<Field<Type> >& tf);
105 template<class Type>
106 void mag(Field<scalar>& res, const UList<Type>& f);
108 template<class Type>
109 tmp<Field<scalar> > mag(const UList<Type>& f);
111 template<class Type>
112 tmp<Field<scalar> > mag(const tmp<Field<Type> >& tf);
115 template<class Type>
116 void cmptMax(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
118 template<class Type>
119 tmp<Field<typename Field<Type>::cmptType> > cmptMax(const UList<Type>& f);
121 template<class Type>
122 tmp<Field<typename Field<Type>::cmptType> >
123 cmptMax(const tmp<Field<Type> >& tf);
126 template<class Type>
127 void cmptMin(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
129 template<class Type>
130 tmp<Field<typename Field<Type>::cmptType> > cmptMin(const UList<Type>& f);
132 template<class Type>
133 tmp<Field<typename Field<Type>::cmptType> >
134 cmptMin(const tmp<Field<Type> >& tf);
137 template<class Type>
138 void cmptAv(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
140 template<class Type>
141 tmp<Field<typename Field<Type>::cmptType> > cmptAv(const UList<Type>& f);
143 template<class Type>
144 tmp<Field<typename Field<Type>::cmptType> > cmptAv(const tmp<Field<Type> >& tf);
147 template<class Type>
148 void cmptMag(Field<Type>& res, const UList<Type>& f);
150 template<class Type>
151 tmp<Field<Type> > cmptMag(const UList<Type>& f);
153 template<class Type>
154 tmp<Field<Type> > cmptMag(const tmp<Field<Type> >& tf);
156 #define TMP_UNARY_FUNCTION(ReturnType, Func)                                  \
157                                                                               \
158 template<class Type>                                                          \
159 ReturnType Func(const tmp<Field<Type> >& tf1);
161 template<class Type>
162 Type max(const UList<Type>& f);
164 TMP_UNARY_FUNCTION(Type, max)
166 template<class Type>
167 Type min(const UList<Type>& f);
169 TMP_UNARY_FUNCTION(Type, min)
171 template<class Type>
172 Type sum(const UList<Type>& f);
174 TMP_UNARY_FUNCTION(Type, sum)
177 template<class Type>
178 scalar sumProd(const UList<Type>& f1, const UList<Type>& f2);
180 template<class Type>
181 Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2);
183 template<class Type>
184 scalar sumSqr(const UList<Type>& f);
186 TMP_UNARY_FUNCTION(scalar, sumSqr)
188 template<class Type>
189 scalar sumMag(const UList<Type>& f);
191 TMP_UNARY_FUNCTION(scalar, sumMag)
193 template<class Type>
194 Type sumCmptMag(const UList<Type>& f);
196 TMP_UNARY_FUNCTION(Type, sumCmptMag)
198 template<class Type>
199 Type average(const UList<Type>& f);
201 TMP_UNARY_FUNCTION(Type, average)
204 #define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc)                      \
205                                                                               \
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
219 template<class Type>
220 scalar gSumProd(const UList<Type>& f1, const UList<Type>& f2);
222 template<class Type>
223 Type gSumCmptProd(const UList<Type>& f1, const UList<Type>& f2);
225 template<class Type>
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)                                 \
261                                                                               \
262 template<class Type1, class Type2>                                            \
263 void OpFunc                                                                   \
264 (                                                                             \
265     Field<typename product<Type1, Type2>::type>& res,                         \
266     const UList<Type1>& f1,                                                   \
267     const UList<Type2>& f2                                                    \
268 );                                                                            \
269                                                                               \
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);                  \
273                                                                               \
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);           \
277                                                                               \
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);           \
281                                                                               \
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);    \
285                                                                               \
286 template<class Type, class Form, class Cmpt, int nCmpt>                       \
287 void OpFunc                                                                   \
288 (                                                                             \
289     Field<typename product<Type, Form>::type>& res,                           \
290     const UList<Type>& f1,                                                    \
291     const VectorSpace<Form,Cmpt,nCmpt>& vs                                    \
292 );                                                                            \
293                                                                               \
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);   \
297                                                                               \
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);\
301                                                                               \
302 template<class Form, class Cmpt, int nCmpt, class Type>                       \
303 void OpFunc                                                                   \
304 (                                                                             \
305     Field<typename product<Form, Type>::type>& res,                           \
306     const VectorSpace<Form,Cmpt,nCmpt>& vs,                                   \
307     const UList<Type>& f1                                                     \
308 );                                                                            \
309                                                                               \
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);   \
313                                                                               \
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 // ************************************************************************* //