initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / fields / FieldFields / FieldField / FieldFieldFunctionsM.C
blob444b55d3803ee125dab88cc0e162f6f0af973dd2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 "FieldFieldReuseFunctions.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 #define UNARY_FUNCTION(ReturnType, Type, Func)                                \
33                                                                               \
34 TEMPLATE                                                                      \
35 void Func                                                                     \
36 (                                                                             \
37     FieldField<Field, ReturnType>& res,                                       \
38     const FieldField<Field, Type>& f                                          \
39 )                                                                             \
40 {                                                                             \
41     forAll(res, i)                                                            \
42     {                                                                         \
43         Func(res[i], f[i]);                                                   \
44     }                                                                         \
45 }                                                                             \
46                                                                               \
47 TEMPLATE                                                                      \
48 tmp<FieldField<Field, ReturnType> > Func                                      \
49 (                                                                             \
50     const FieldField<Field, Type>& f                                          \
51 )                                                                             \
52 {                                                                             \
53     tmp<FieldField<Field, ReturnType> > tRes                                  \
54     (                                                                         \
55         FieldField<Field, ReturnType>::NewCalculatedType(f)                   \
56     );                                                                        \
57     Func(tRes(), f);                                                          \
58     return tRes;                                                              \
59 }                                                                             \
60                                                                               \
61 TEMPLATE                                                                      \
62 tmp<FieldField<Field, ReturnType> > Func                                      \
63 (                                                                             \
64     const tmp<FieldField<Field, Type> >& tf                                   \
65 )                                                                             \
66 {                                                                             \
67     tmp<FieldField<Field, ReturnType> > tRes                                  \
68     (                                                                         \
69         reuseTmpFieldField<Field, Type, Type>::New(tf)                        \
70     );                                                                        \
71     Func(tRes(), tf());                                                       \
72     reuseTmpFieldField<Field, Type, Type>::clear(tf);                         \
73     return tRes;                                                              \
77 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
79 #define UNARY_OPERATOR(ReturnType, Type, Op, OpFunc)                          \
80                                                                               \
81 TEMPLATE                                                                      \
82 void OpFunc                                                                   \
83 (                                                                             \
84     FieldField<Field, ReturnType>& res,                                       \
85     const FieldField<Field, Type>& f                                          \
86 )                                                                             \
87 {                                                                             \
88     forAll(res, i)                                                            \
89     {                                                                         \
90         OpFunc(res[i], f[i]);                                                 \
91     }                                                                         \
92 }                                                                             \
93                                                                               \
94 TEMPLATE                                                                      \
95 tmp<FieldField<Field, ReturnType> > operator Op                               \
96 (                                                                             \
97     const FieldField<Field, Type>& f                                          \
98 )                                                                             \
99 {                                                                             \
100     tmp<FieldField<Field, ReturnType> > tRes                                  \
101     (                                                                         \
102         FieldField<Field, Type>::NewCalculatedType(f)                         \
103     );                                                                        \
104     OpFunc(tRes(), f);                                                        \
105     return tRes;                                                              \
106 }                                                                             \
107                                                                               \
108 TEMPLATE                                                                      \
109 tmp<FieldField<Field, ReturnType> > operator Op                               \
110 (                                                                             \
111     const tmp<FieldField<Field, Type> >& tf                                   \
112 )                                                                             \
113 {                                                                             \
114     tmp<FieldField<Field, ReturnType> > tRes                                  \
115     (                                                                         \
116         reuseTmpFieldField<Field, Type, Type>::New(tf)                        \
117     );                                                                        \
118     OpFunc(tRes(), tf());                                                     \
119     reuseTmpFieldField<Field, Type, Type>::clear(tf);                         \
120     return tRes;                                                              \
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)                       \
127                                                                               \
128 TEMPLATE                                                                      \
129 void Func                                                                     \
130 (                                                                             \
131     FieldField<Field, ReturnType>& f,                                         \
132     const FieldField<Field, Type1>& f1,                                       \
133     const FieldField<Field, Type2>& f2                                        \
134 )                                                                             \
135 {                                                                             \
136     forAll(f, i)                                                              \
137     {                                                                         \
138         Func(f[i], f1[i], f2[i]);                                             \
139     }                                                                         \
140 }                                                                             \
141                                                                               \
142 TEMPLATE                                                                      \
143 tmp<FieldField<Field, ReturnType> > Func                                      \
144 (                                                                             \
145     const FieldField<Field, Type1>& f1,                                       \
146     const FieldField<Field, Type2>& f2                                        \
147 )                                                                             \
148 {                                                                             \
149     tmp<FieldField<Field, ReturnType> > tRes                                  \
150     (                                                                         \
151         FieldField<Field, Type1>::NewCalculatedType(f1)                       \
152     );                                                                        \
153     Func(tRes(), f1, f2);                                                     \
154     return tRes;                                                              \
155 }                                                                             \
156                                                                               \
157 TEMPLATE                                                                      \
158 tmp<FieldField<Field, ReturnType> > Func                                      \
159 (                                                                             \
160     const FieldField<Field, Type1>& f1,                                       \
161     const tmp<FieldField<Field, Type2> >& tf2                                 \
162 )                                                                             \
163 {                                                                             \
164     tmp<FieldField<Field, ReturnType> > tRes                                  \
165     (                                                                         \
166         reuseTmpFieldField<Field, ReturnType, Type2>::New(tf2)                \
167     );                                                                        \
168     Func(tRes(), f1, tf2());                                                  \
169     reuseTmpFieldField<Field, ReturnType, Type2>::clear(tf2);                 \
170     return tRes;                                                              \
171 }                                                                             \
172                                                                               \
173 TEMPLATE                                                                      \
174 tmp<FieldField<Field, ReturnType> > Func                                      \
175 (                                                                             \
176     const tmp<FieldField<Field, Type1> >& tf1,                                \
177     const FieldField<Field, Type2>& f2                                        \
178 )                                                                             \
179 {                                                                             \
180     tmp<FieldField<Field, ReturnType> > tRes                                  \
181     (                                                                         \
182         reuseTmpFieldField<Field, ReturnType, Type1>::New(tf1)                \
183     );                                                                        \
184     Func(tRes(), tf1(), f2);                                                  \
185     reuseTmpFieldField<Field, ReturnType, Type1>::clear(tf1);                 \
186     return tRes;                                                              \
187 }                                                                             \
188                                                                               \
189 TEMPLATE                                                                      \
190 tmp<FieldField<Field, ReturnType> > Func                                      \
191 (                                                                             \
192     const tmp<FieldField<Field, Type1> >& tf1,                                \
193     const tmp<FieldField<Field, Type2> >& tf2                                 \
194 )                                                                             \
195 {                                                                             \
196     tmp<FieldField<Field, ReturnType> > tRes                                  \
197     (                                                                         \
198         reuseTmpTmpFieldField<Field, ReturnType, Type1, Type1, Type2>::       \
199             New(tf1, tf2)                                                     \
200     );                                                                        \
201     Func(tRes(), tf1(), tf2());                                               \
202     reuseTmpTmpFieldField<Field, ReturnType, Type1, Type1, Type2>::           \
203         clear(tf1, tf2);                                                      \
204     return tRes;                                                              \
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func)               \
211                                                                               \
212 TEMPLATE                                                                      \
213 void Func                                                                     \
214 (                                                                             \
215     FieldField<Field, ReturnType>& f,                                         \
216     const FieldField<Field, Type1>& f1,                                       \
217     const Type2& s                                                            \
218 )                                                                             \
219 {                                                                             \
220     forAll(f, i)                                                              \
221     {                                                                         \
222         Func(f[i], f1[i], s);                                                 \
223     }                                                                         \
224 }                                                                             \
225                                                                               \
226 TEMPLATE                                                                      \
227 tmp<FieldField<Field, ReturnType> > Func                                      \
228 (                                                                             \
229     const FieldField<Field, Type1>& f1,                                       \
230     const Type2& s                                                            \
231 )                                                                             \
232 {                                                                             \
233     tmp<FieldField<Field, ReturnType> > tRes                                  \
234     (                                                                         \
235         FieldField<Field, Type1>::NewCalculatedType(f1)                       \
236     );                                                                        \
237     Func(tRes(), f1, s);                                                      \
238     return tRes;                                                              \
239 }                                                                             \
240                                                                               \
241 TEMPLATE                                                                      \
242 tmp<FieldField<Field, ReturnType> > Func                                      \
243 (                                                                             \
244     const tmp<FieldField<Field, Type1> >& tf1,                                \
245     const Type2& s                                                            \
246 )                                                                             \
247 {                                                                             \
248     tmp<FieldField<Field, ReturnType> > tRes                                  \
249     (                                                                         \
250         reuseTmpFieldField<Field, ReturnType, Type1>::New(tf1)                \
251     );                                                                        \
252     Func(tRes(), tf1(), s);                                                   \
253     reuseTmpFieldField<Field, ReturnType, Type1>::clear(tf1);                 \
254     return tRes;                                                              \
258 #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)               \
259                                                                               \
260 TEMPLATE                                                                      \
261 void Func                                                                     \
262 (                                                                             \
263     FieldField<Field, ReturnType>& f,                                         \
264     const Type1& s,                                                           \
265     const FieldField<Field, Type2>& f2                                        \
266 )                                                                             \
267 {                                                                             \
268     forAll(f, i)                                                              \
269     {                                                                         \
270         Func(f[i], s, f2[i]);                                                 \
271     }                                                                         \
272 }                                                                             \
273                                                                               \
274 TEMPLATE                                                                      \
275 tmp<FieldField<Field, ReturnType> > Func                                      \
276 (                                                                             \
277     const Type1& s,                                                           \
278     const FieldField<Field, Type2>& f2                                        \
279 )                                                                             \
280 {                                                                             \
281     tmp<FieldField<Field, ReturnType> > tRes                                  \
282     (                                                                         \
283         FieldField<Field, Type2>::NewCalculatedType(f2)                       \
284     );                                                                        \
285     Func(tRes(), s, f2);                                                      \
286     return tRes;                                                              \
287 }                                                                             \
288                                                                               \
289 TEMPLATE                                                                      \
290 tmp<FieldField<Field, ReturnType> > Func                                      \
291 (                                                                             \
292     const Type1& s,                                                           \
293     const tmp<FieldField<Field, Type2> >& tf2                                 \
294 )                                                                             \
295 {                                                                             \
296     tmp<FieldField<Field, ReturnType> > tRes                                  \
297     (                                                                         \
298         reuseTmpFieldField<Field, ReturnType, Type2>::New(tf2)                \
299     );                                                                        \
300     Func(tRes(), s, tf2());                                                   \
301     reuseTmpFieldField<Field, ReturnType, Type2>::clear(tf2);                 \
302     return tRes;                                                              \
306 #define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)                  \
307     BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func)                   \
308     BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
313 #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc)                 \
314                                                                               \
315 TEMPLATE                                                                      \
316 void OpFunc                                                                   \
317 (                                                                             \
318     FieldField<Field, ReturnType>& f,                                         \
319     const FieldField<Field, Type1>& f1,                                       \
320     const FieldField<Field, Type2>& f2                                        \
321 )                                                                             \
322 {                                                                             \
323     forAll(f, i)                                                              \
324     {                                                                         \
325         OpFunc(f[i], f1[i], f2[i]);                                           \
326     }                                                                         \
327 }                                                                             \
328                                                                               \
329 TEMPLATE                                                                      \
330 tmp<FieldField<Field, ReturnType> > operator Op                               \
331 (                                                                             \
332     const FieldField<Field, Type1>& f1,                                       \
333     const FieldField<Field, Type2>& f2                                        \
334 )                                                                             \
335 {                                                                             \
336     tmp<FieldField<Field, ReturnType> > tRes                                  \
337     (                                                                         \
338         FieldField<Field, ReturnType>::NewCalculatedType(f1)                  \
339     );                                                                        \
340     OpFunc(tRes(), f1, f2);                                                   \
341     return tRes;                                                              \
342 }                                                                             \
343                                                                               \
344 TEMPLATE                                                                      \
345 tmp<FieldField<Field, ReturnType> > operator Op                               \
346 (                                                                             \
347     const FieldField<Field, Type1>& f1,                                       \
348     const tmp<FieldField<Field, Type2> >& tf2                                 \
349 )                                                                             \
350 {                                                                             \
351     tmp<FieldField<Field, ReturnType> > tRes                                  \
352     (                                                                         \
353         reuseTmpFieldField<Field, ReturnType, Type2>::New(tf2)                \
354     );                                                                        \
355     OpFunc(tRes(), f1, tf2());                                                \
356     reuseTmpFieldField<Field, ReturnType, Type2>::clear(tf2);                 \
357     return tRes;                                                              \
358 }                                                                             \
359                                                                               \
360 TEMPLATE                                                                      \
361 tmp<FieldField<Field, ReturnType> > operator Op                               \
362 (                                                                             \
363     const tmp<FieldField<Field, Type1> >& tf1,                                \
364     const FieldField<Field, Type2>& f2                                        \
365 )                                                                             \
366 {                                                                             \
367     tmp<FieldField<Field, ReturnType> > tRes                                  \
368     (                                                                         \
369         reuseTmpFieldField<Field, ReturnType, Type1>::New(tf1)                \
370     );                                                                        \
371     OpFunc(tRes(), tf1(), f2);                                                \
372     reuseTmpFieldField<Field, ReturnType, Type1>::clear(tf1);                 \
373     return tRes;                                                              \
374 }                                                                             \
375                                                                               \
376 TEMPLATE                                                                      \
377 tmp<FieldField<Field, ReturnType> > operator Op                               \
378 (                                                                             \
379     const tmp<FieldField<Field, Type1> >& tf1,                                \
380     const tmp<FieldField<Field, Type2> >& tf2                                 \
381 )                                                                             \
382 {                                                                             \
383     tmp<FieldField<Field, ReturnType> > tRes                                  \
384     (                                                                         \
385         reuseTmpTmpFieldField<Field, ReturnType, Type1, Type1, Type2>::       \
386             New(tf1, tf2)                                                     \
387     );                                                                        \
388     OpFunc(tRes(), tf1(), tf2());                                             \
389     reuseTmpTmpFieldField<Field, ReturnType, Type1, Type1, Type2>::           \
390         clear(tf1, tf2);                                                      \
391     return tRes;                                                              \
395 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
397 #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc)         \
398                                                                               \
399 TEMPLATE                                                                      \
400 void OpFunc                                                                   \
401 (                                                                             \
402     FieldField<Field, ReturnType>& f,                                         \
403     const Type1& s,                                                           \
404     const FieldField<Field, Type2>& f2                                        \
405 )                                                                             \
406 {                                                                             \
407     forAll(f, i)                                                              \
408     {                                                                         \
409         OpFunc(f[i], s, f2[i]);                                               \
410     }                                                                         \
411 }                                                                             \
412                                                                               \
413 TEMPLATE                                                                      \
414 tmp<FieldField<Field, ReturnType> > operator Op                               \
415 (                                                                             \
416     const Type1& s,                                                           \
417     const FieldField<Field, Type2>& f2                                        \
418 )                                                                             \
419 {                                                                             \
420     tmp<FieldField<Field, ReturnType> > tRes                                  \
421     (                                                                         \
422         FieldField<Field, Type2>::NewCalculatedType(f2)                       \
423     );                                                                        \
424     OpFunc(tRes(), s, f2);                                                    \
425     return tRes;                                                              \
426 }                                                                             \
427                                                                               \
428 TEMPLATE                                                                      \
429 tmp<FieldField<Field, ReturnType> > operator Op                               \
430 (                                                                             \
431     const Type1& s,                                                           \
432     const tmp<FieldField<Field, Type2> >& tf2                                 \
433 )                                                                             \
434 {                                                                             \
435     tmp<FieldField<Field, ReturnType> > tRes                                  \
436     (                                                                         \
437         reuseTmpFieldField<Field, ReturnType, Type2>::New(tf2)                \
438     );                                                                        \
439     OpFunc(tRes(), s, tf2());                                                 \
440     reuseTmpFieldField<Field, ReturnType, Type2>::clear(tf2);                 \
441     return tRes;                                                              \
445 #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc)         \
446                                                                               \
447 TEMPLATE                                                                      \
448 void OpFunc                                                                   \
449 (                                                                             \
450     FieldField<Field, ReturnType>& f,                                         \
451     const FieldField<Field, Type1>& f1,                                       \
452     const Type2& s                                                            \
453 )                                                                             \
454 {                                                                             \
455     forAll(f, i)                                                              \
456     {                                                                         \
457         OpFunc(f[i], f1[i], s);                                               \
458     }                                                                         \
459 }                                                                             \
460                                                                               \
461 TEMPLATE                                                                      \
462 tmp<FieldField<Field, ReturnType> > operator Op                               \
463 (                                                                             \
464     const FieldField<Field, Type1>& f1,                                       \
465     const Type2& s                                                            \
466 )                                                                             \
467 {                                                                             \
468     tmp<FieldField<Field, ReturnType> > tRes                                  \
469     (                                                                         \
470         FieldField<Field, Type1>::NewCalculatedType(f1)                       \
471     );                                                                        \
472     OpFunc(tRes(), f1, s);                                                    \
473     return tRes;                                                              \
474 }                                                                             \
475                                                                               \
476 TEMPLATE                                                                      \
477 tmp<FieldField<Field, ReturnType> > operator Op                               \
478 (                                                                             \
479     const tmp<FieldField<Field, Type1> >& tf1,                                \
480     const Type2& s                                                            \
481 )                                                                             \
482 {                                                                             \
483     tmp<FieldField<Field, ReturnType> > tRes                                  \
484     (                                                                         \
485         reuseTmpFieldField<Field, ReturnType, Type1>::New(tf1)                \
486     );                                                                        \
487     OpFunc(tRes(), tf1(), s);                                                 \
488     reuseTmpFieldField<Field, ReturnType, Type1>::clear(tf1);                 \
489     return tRes;                                                              \
493 #define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc)            \
494     BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc)             \
495     BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc)
497 // ************************************************************************* //