FreeFOAM The Cross-Platform CFD Toolkit
FieldFunctions.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include <OpenFOAM/scalarField.H>
27 
28 #define TEMPLATE template<class Type>
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
37 
38 template<class Type>
39 void component
40 (
41  Field<typename Field<Type>::cmptType>& res,
42  const UList<Type>& f,
43  const direction d
44 );
45 
46 
47 template<class Type>
48 void T(Field<Type>& res, const UList<Type>& f);
49 
50 
51 template<class Type, int r>
52 void pow
53 (
54  Field<typename powProduct<Type, r>::type>& res,
55  const UList<Type>& vf
56 );
57 
58 
59 template<class Type, int r>
61 pow
62 (
63  const UList<Type>& f,
65  = pTraits<typename powProduct<Type, r>::type>::zero
66 );
67 
68 template<class Type, int r>
70 pow
71 (
72  const tmp<Field<Type> >& tf,
74  = pTraits<typename powProduct<Type, r>::type>::zero
75 );
76 
77 
78 template<class Type>
79 void sqr
80 (
81  Field<typename outerProduct<Type, Type>::type>& res,
82  const UList<Type>& vf
83 );
84 
85 template<class Type>
87 sqr(const UList<Type>& f);
88 
89 template<class Type>
91 sqr(const tmp<Field<Type> >& tf);
92 
93 
94 template<class Type>
95 void magSqr(Field<scalar>& res, const UList<Type>& f);
96 
97 template<class Type>
98 tmp<Field<scalar> > magSqr(const UList<Type>& f);
99 
100 template<class Type>
101 tmp<Field<scalar> > magSqr(const tmp<Field<Type> >& tf);
102 
103 
104 template<class Type>
105 void mag(Field<scalar>& res, const UList<Type>& f);
106 
107 template<class Type>
108 tmp<Field<scalar> > mag(const UList<Type>& f);
109 
110 template<class Type>
111 tmp<Field<scalar> > mag(const tmp<Field<Type> >& tf);
112 
113 
114 template<class Type>
115 void cmptMax(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
116 
117 template<class Type>
118 tmp<Field<typename Field<Type>::cmptType> > cmptMax(const UList<Type>& f);
119 
120 template<class Type>
121 tmp<Field<typename Field<Type>::cmptType> >
122 cmptMax(const tmp<Field<Type> >& tf);
123 
124 
125 template<class Type>
126 void cmptMin(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
127 
128 template<class Type>
129 tmp<Field<typename Field<Type>::cmptType> > cmptMin(const UList<Type>& f);
130 
131 template<class Type>
132 tmp<Field<typename Field<Type>::cmptType> >
133 cmptMin(const tmp<Field<Type> >& tf);
134 
135 
136 template<class Type>
137 void cmptAv(Field<typename Field<Type>::cmptType>& res, const UList<Type>& f);
138 
139 template<class Type>
140 tmp<Field<typename Field<Type>::cmptType> > cmptAv(const UList<Type>& f);
141 
142 template<class Type>
143 tmp<Field<typename Field<Type>::cmptType> > cmptAv(const tmp<Field<Type> >& tf);
144 
145 
146 template<class Type>
147 void cmptMag(Field<Type>& res, const UList<Type>& f);
148 
149 template<class Type>
150 tmp<Field<Type> > cmptMag(const UList<Type>& f);
151 
152 template<class Type>
153 tmp<Field<Type> > cmptMag(const tmp<Field<Type> >& tf);
154 
155 #define TMP_UNARY_FUNCTION(ReturnType, Func) \
156  \
157 template<class Type> \
158 ReturnType Func(const tmp<Field<Type> >& tf1);
159 
160 template<class Type>
161 Type max(const UList<Type>& f);
162 
163 TMP_UNARY_FUNCTION(Type, max)
164 
165 template<class Type>
166 Type min(const UList<Type>& f);
167 
168 TMP_UNARY_FUNCTION(Type, min)
169 
170 template<class Type>
171 Type sum(const UList<Type>& f);
172 
173 TMP_UNARY_FUNCTION(Type, sum)
174 
175 
176 template<class Type>
177 scalar sumProd(const UList<Type>& f1, const UList<Type>& f2);
178 
179 template<class Type>
180 Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2);
181 
182 template<class Type>
183 scalar sumSqr(const UList<Type>& f);
184 
185 TMP_UNARY_FUNCTION(scalar, sumSqr)
186 
187 template<class Type>
188 scalar sumMag(const UList<Type>& f);
189 
190 TMP_UNARY_FUNCTION(scalar, sumMag)
191 
192 template<class Type>
193 Type sumCmptMag(const UList<Type>& f);
194 
196 
197 template<class Type>
198 Type average(const UList<Type>& f);
199 
201 
202 
203 #define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \
204  \
205 template<class Type> \
206 ReturnType gFunc(const UList<Type>& f); \
207 TMP_UNARY_FUNCTION(ReturnType, gFunc)
208 
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)
215 
216 #undef G_UNARY_FUNCTION
217 
218 template<class Type>
219 scalar gSumProd(const UList<Type>& f1, const UList<Type>& f2);
220 
221 template<class Type>
222 Type gSumCmptProd(const UList<Type>& f1, const UList<Type>& f2);
223 
224 template<class Type>
225 Type gAverage(const UList<Type>& f);
226 
228 
229 #undef TMP_UNARY_FUNCTION
230 
231 
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)
236 
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)
241 
242 
243 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
244 
245 UNARY_OPERATOR(Type, Type, -, negate)
246 
247 BINARY_OPERATOR(Type, Type, scalar, *, multiply)
248 BINARY_OPERATOR(Type, scalar, Type, *, multiply)
249 BINARY_OPERATOR(Type, Type, scalar, /, divide)
250 
251 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
252 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
253 
254 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
255 
256 
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 
259 #define PRODUCT_OPERATOR(product, Op, OpFunc) \
260  \
261 template<class Type1, class Type2> \
262 void OpFunc \
263 ( \
264  Field<typename product<Type1, Type2>::type>& res, \
265  const UList<Type1>& f1, \
266  const UList<Type2>& f2 \
267 ); \
268  \
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); \
272  \
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); \
276  \
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); \
280  \
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); \
284  \
285 template<class Type, class Form, class Cmpt, int nCmpt> \
286 void OpFunc \
287 ( \
288  Field<typename product<Type, Form>::type>& res, \
289  const UList<Type>& f1, \
290  const VectorSpace<Form,Cmpt,nCmpt>& vs \
291 ); \
292  \
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); \
296  \
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);\
300  \
301 template<class Form, class Cmpt, int nCmpt, class Type> \
302 void OpFunc \
303 ( \
304  Field<typename product<Form, Type>::type>& res, \
305  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
306  const UList<Type>& f1 \
307 ); \
308  \
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); \
312  \
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);
316 
317 PRODUCT_OPERATOR(typeOfSum, +, add)
318 PRODUCT_OPERATOR(typeOfSum, -, subtract)
319 
320 PRODUCT_OPERATOR(outerProduct, *, outer)
321 PRODUCT_OPERATOR(crossProduct, ^, cross)
322 PRODUCT_OPERATOR(innerProduct, &, dot)
323 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
324 
325 #undef PRODUCT_OPERATOR
326 
327 
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329 
330 } // End namespace Foam
331 
332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333 
335 
336 // ************************ vim: set sw=4 sts=4 et: ************************ //