initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / fields / Fields / Field / FieldFunctionsM.C
blob11a4606543e5ef5e231ff19b5d2029ca09bc2c3d
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 "FieldM.H"
28 #include "FieldReuseFunctions.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 #define UNARY_FUNCTION(ReturnType, Type, Func)                                \
33                                                                               \
34 TEMPLATE                                                                      \
35 void Func(Field<ReturnType>& res, const UList<Type>& f)                       \
36 {                                                                             \
37     TFOR_ALL_F_OP_FUNC_F(ReturnType, res, =, ::Foam::Func, Type, f)           \
38 }                                                                             \
39                                                                               \
40 TEMPLATE                                                                      \
41 tmp<Field<ReturnType> > Func(const UList<Type>& f)                            \
42 {                                                                             \
43     tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f.size()));            \
44     Func(tRes(), f);                                                          \
45     return tRes;                                                              \
46 }                                                                             \
47                                                                               \
48 TEMPLATE                                                                      \
49 tmp<Field<ReturnType> > Func(const tmp<Field<Type> >& tf)                     \
50 {                                                                             \
51     tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type>::New(tf);       \
52     Func(tRes(), tf());                                                       \
53     reuseTmp<ReturnType, Type>::clear(tf);                                    \
54     return tRes;                                                              \
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 #define UNARY_OPERATOR(ReturnType, Type, Op, OpFunc)                          \
61                                                                               \
62 TEMPLATE                                                                      \
63 void OpFunc(Field<ReturnType>& res, const UList<Type>& f)                     \
64 {                                                                             \
65     TFOR_ALL_F_OP_OP_F(ReturnType, res, =, Op, Type, f)                       \
66 }                                                                             \
67                                                                               \
68 TEMPLATE                                                                      \
69 tmp<Field<ReturnType> > operator Op(const UList<Type>& f)                     \
70 {                                                                             \
71     tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f.size()));            \
72     OpFunc(tRes(), f);                                                        \
73     return tRes;                                                              \
74 }                                                                             \
75                                                                               \
76 TEMPLATE                                                                      \
77 tmp<Field<ReturnType> > operator Op(const tmp<Field<Type> >& tf)              \
78 {                                                                             \
79     tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type>::New(tf);       \
80     OpFunc(tRes(), tf());                                                     \
81     reuseTmp<ReturnType, Type>::clear(tf);                                    \
82     return tRes;                                                              \
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
88 #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)                       \
89                                                                               \
90 TEMPLATE                                                                      \
91 void Func                                                                     \
92 (                                                                             \
93     Field<ReturnType>& res,                                                   \
94     const UList<Type1>& f1,                                                   \
95     const UList<Type2>& f2                                                    \
96 )                                                                             \
97 {                                                                             \
98     TFOR_ALL_F_OP_FUNC_F_F                                                    \
99     (                                                                         \
100         ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, f2                \
101     )                                                                         \
102 }                                                                             \
103                                                                               \
104 TEMPLATE                                                                      \
105 tmp<Field<ReturnType> > Func                                                  \
106 (                                                                             \
107     const UList<Type1>& f1,                                                   \
108     const UList<Type2>& f2                                                    \
109 )                                                                             \
110 {                                                                             \
111     tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size()));           \
112     Func(tRes(), f1, f2);                                                     \
113     return tRes;                                                              \
114 }                                                                             \
115                                                                               \
116 TEMPLATE                                                                      \
117 tmp<Field<ReturnType> > Func                                                  \
118 (                                                                             \
119     const UList<Type1>& f1,                                                   \
120     const tmp<Field<Type2> >& tf2                                             \
121 )                                                                             \
122 {                                                                             \
123     tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2);     \
124     Func(tRes(), f1, tf2());                                                  \
125     reuseTmp<ReturnType, Type2>::clear(tf2);                                  \
126     return tRes;                                                              \
127 }                                                                             \
128                                                                               \
129 TEMPLATE                                                                      \
130 tmp<Field<ReturnType> > Func                                                  \
131 (                                                                             \
132     const tmp<Field<Type1> >& tf1,                                            \
133     const UList<Type2>& f2                                                    \
134 )                                                                             \
135 {                                                                             \
136     tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1);     \
137     Func(tRes(), tf1(), f2);                                                  \
138     reuseTmp<ReturnType, Type1>::clear(tf1);                                  \
139     return tRes;                                                              \
140 }                                                                             \
141                                                                               \
142 TEMPLATE                                                                      \
143 tmp<Field<ReturnType> > Func                                                  \
144 (                                                                             \
145     const tmp<Field<Type1> >& tf1,                                            \
146     const tmp<Field<Type2> >& tf2                                             \
147 )                                                                             \
148 {                                                                             \
149     tmp<Field<ReturnType> > tRes =                                            \
150         reuseTmpTmp<ReturnType, Type1, Type1, Type2>::New(tf1, tf2);          \
151     Func(tRes(), tf1(), tf2());                                               \
152     reuseTmpTmp<ReturnType, Type1, Type1, Type2>::clear(tf1, tf2);            \
153     return tRes;                                                              \
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func)               \
160                                                                               \
161 TEMPLATE                                                                      \
162 void Func                                                                     \
163 (                                                                             \
164     Field<ReturnType>& res,                                                   \
165     const Type1& s1,                                                          \
166     const UList<Type2>& f2                                                    \
167 )                                                                             \
168 {                                                                             \
169     TFOR_ALL_F_OP_FUNC_S_F                                                    \
170     (                                                                         \
171         ReturnType, res, =, ::Foam::Func, Type1, s1, Type2, f2                \
172     )                                                                         \
173 }                                                                             \
174                                                                               \
175 TEMPLATE                                                                      \
176 tmp<Field<ReturnType> > Func                                                  \
177 (                                                                             \
178     const Type1& s1,                                                          \
179     const UList<Type2>& f2                                                    \
180 )                                                                             \
181 {                                                                             \
182     tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f2.size()));           \
183     Func(tRes(), s1, f2);                                                     \
184     return tRes;                                                              \
185 }                                                                             \
186                                                                               \
187 TEMPLATE                                                                      \
188 tmp<Field<ReturnType> > Func                                                  \
189 (                                                                             \
190     const Type1& s1,                                                          \
191     const tmp<Field<Type2> >& tf2                                             \
192 )                                                                             \
193 {                                                                             \
194     tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2);     \
195     Func(tRes(), s1, tf2());                                                  \
196     reuseTmp<ReturnType, Type2>::clear(tf2);                                  \
197     return tRes;                                                              \
201 #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)               \
202                                                                               \
203 TEMPLATE                                                                      \
204 void Func                                                                     \
205 (                                                                             \
206     Field<ReturnType>& res,                                                   \
207     const UList<Type1>& f1,                                                   \
208     const Type2& s2                                                           \
209 )                                                                             \
210 {                                                                             \
211     TFOR_ALL_F_OP_FUNC_F_S                                                    \
212     (                                                                         \
213         ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, s2                \
214     )                                                                         \
215 }                                                                             \
216                                                                               \
217 TEMPLATE                                                                      \
218 tmp<Field<ReturnType> > Func                                                  \
219 (                                                                             \
220     const UList<Type1>& f1,                                                   \
221     const Type2& s2                                                           \
222 )                                                                             \
223 {                                                                             \
224     tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size()));           \
225     Func(tRes(), f1, s2);                                                     \
226     return tRes;                                                              \
227 }                                                                             \
228                                                                               \
229 TEMPLATE                                                                      \
230 tmp<Field<ReturnType> > Func                                                  \
231 (                                                                             \
232     const tmp<Field<Type1> >& tf1,                                            \
233     const Type2& s2                                                           \
234 )                                                                             \
235 {                                                                             \
236     tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1);     \
237     Func(tRes(), tf1(), s2);                                                  \
238     reuseTmp<ReturnType, Type1>::clear(tf1);                                  \
239     return tRes;                                                              \
243 #define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)                  \
244     BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func)                   \
245     BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc)                 \
251                                                                               \
252 TEMPLATE                                                                      \
253 void OpFunc                                                                   \
254 (                                                                             \
255     Field<ReturnType>& res,                                                   \
256     const UList<Type1>& f1,                                                   \
257     const UList<Type2>& f2                                                    \
258 )                                                                             \
259 {                                                                             \
260     TFOR_ALL_F_OP_F_OP_F(ReturnType, res, =, Type1, f1, Op, Type2, f2)        \
261 }                                                                             \
262                                                                               \
263 TEMPLATE                                                                      \
264 tmp<Field<ReturnType> > operator Op                                           \
265 (                                                                             \
266     const UList<Type1>& f1,                                                   \
267     const UList<Type2>& f2                                                    \
268 )                                                                             \
269 {                                                                             \
270     tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size()));           \
271     OpFunc(tRes(), f1, f2);                                                   \
272     return tRes;                                                              \
273 }                                                                             \
274                                                                               \
275 TEMPLATE                                                                      \
276 tmp<Field<ReturnType> > operator Op                                           \
277 (                                                                             \
278     const UList<Type1>& f1,                                                   \
279     const tmp<Field<Type2> >& tf2                                             \
280 )                                                                             \
281 {                                                                             \
282     tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2);     \
283     OpFunc(tRes(), f1, tf2());                                                \
284     reuseTmp<ReturnType, Type2>::clear(tf2);                                  \
285     return tRes;                                                              \
286 }                                                                             \
287                                                                               \
288 TEMPLATE                                                                      \
289 tmp<Field<ReturnType> > operator Op                                           \
290 (                                                                             \
291     const tmp<Field<Type1> >& tf1,                                            \
292     const UList<Type2>& f2                                                    \
293 )                                                                             \
294 {                                                                             \
295     tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1);     \
296     OpFunc(tRes(), tf1(), f2);                                                \
297     reuseTmp<ReturnType, Type1>::clear(tf1);                                  \
298     return tRes;                                                              \
299 }                                                                             \
300                                                                               \
301 TEMPLATE                                                                      \
302 tmp<Field<ReturnType> > operator Op                                           \
303 (                                                                             \
304     const tmp<Field<Type1> >& tf1,                                            \
305     const tmp<Field<Type2> >& tf2                                             \
306 )                                                                             \
307 {                                                                             \
308     tmp<Field<ReturnType> > tRes =                                            \
309         reuseTmpTmp<ReturnType, Type1, Type1, Type2>::New(tf1, tf2);          \
310     OpFunc(tRes(), tf1(), tf2());                                             \
311     reuseTmpTmp<ReturnType, Type1, Type1, Type2>::clear(tf1, tf2);            \
312     return tRes;                                                              \
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
318 #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc)         \
319                                                                               \
320 TEMPLATE                                                                      \
321 void OpFunc                                                                   \
322 (                                                                             \
323     Field<ReturnType>& res,                                                   \
324     const Type1& s1,                                                          \
325     const UList<Type2>& f2                                                    \
326 )                                                                             \
327 {                                                                             \
328     TFOR_ALL_F_OP_S_OP_F(ReturnType, res, =, Type1, s1, Op, Type2, f2)        \
329 }                                                                             \
330                                                                               \
331 TEMPLATE                                                                      \
332 tmp<Field<ReturnType> > operator Op                                           \
333 (                                                                             \
334     const Type1& s1,                                                          \
335     const UList<Type2>& f2                                                    \
336 )                                                                             \
337 {                                                                             \
338     tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f2.size()));           \
339     OpFunc(tRes(), s1, f2);                                                   \
340     return tRes;                                                              \
341 }                                                                             \
342                                                                               \
343 TEMPLATE                                                                      \
344 tmp<Field<ReturnType> > operator Op                                           \
345 (                                                                             \
346     const Type1& s1,                                                          \
347     const tmp<Field<Type2> >& tf2                                             \
348 )                                                                             \
349 {                                                                             \
350     tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2);     \
351     OpFunc(tRes(), s1, tf2());                                                \
352     reuseTmp<ReturnType, Type2>::clear(tf2);                                  \
353     return tRes;                                                              \
357 #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc)         \
358                                                                               \
359 TEMPLATE                                                                      \
360 void OpFunc                                                                   \
361 (                                                                             \
362     Field<ReturnType>& res,                                                   \
363     const UList<Type1>& f1,                                                   \
364     const Type2& s2                                                           \
365 )                                                                             \
366 {                                                                             \
367     TFOR_ALL_F_OP_F_OP_S(ReturnType, res, =, Type1, f1, Op, Type2, s2)        \
368 }                                                                             \
369                                                                               \
370 TEMPLATE                                                                      \
371 tmp<Field<ReturnType> > operator Op                                           \
372 (                                                                             \
373     const UList<Type1>& f1,                                                   \
374     const Type2& s2                                                           \
375 )                                                                             \
376 {                                                                             \
377     tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size()));           \
378     OpFunc(tRes(), f1, s2);                                                   \
379     return tRes;                                                              \
380 }                                                                             \
381                                                                               \
382 TEMPLATE                                                                      \
383 tmp<Field<ReturnType> > operator Op                                           \
384 (                                                                             \
385     const tmp<Field<Type1> >& tf1,                                            \
386     const Type2& s2                                                           \
387 )                                                                             \
388 {                                                                             \
389     tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1);     \
390     OpFunc(tRes(), tf1(), s2);                                                \
391     reuseTmp<ReturnType, Type1>::clear(tf1);                                  \
392     return tRes;                                                              \
396 #define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc)            \
397     BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc)             \
398     BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc)
401 // ************************************************************************* //