Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / foam / fields / FieldFields / FieldField / FieldFieldFunctionsM.C
blob2dfaff58e181c477d7f518a61398c0168e80ecaa
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "FieldM.H"
27 #include "FieldFieldReuseFunctions.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 #define UNARY_FUNCTION(ReturnType, Type, Func)                                \
32                                                                               \
33 TEMPLATE                                                                      \
34 void Func                                                                     \
35 (                                                                             \
36     FieldField<Field, ReturnType>& res,                                       \
37     const FieldField<Field, Type>& f                                          \
38 )                                                                             \
39 {                                                                             \
40     forAll(res, i)                                                            \
41     {                                                                         \
42         Func(res[i], f[i]);                                                   \
43     }                                                                         \
44 }                                                                             \
45                                                                               \
46 TEMPLATE                                                                      \
47 tmp<FieldField<Field, ReturnType> > Func                                      \
48 (                                                                             \
49     const FieldField<Field, Type>& f                                          \
50 )                                                                             \
51 {                                                                             \
52     tmp<FieldField<Field, ReturnType> > tRes                                  \
53     (                                                                         \
54         FieldField<Field, ReturnType>::NewCalculatedType(f)                   \
55     );                                                                        \
56     Func(tRes(), f);                                                          \
57     return tRes;                                                              \
58 }                                                                             \
59                                                                               \
60 TEMPLATE                                                                      \
61 tmp<FieldField<Field, ReturnType> > Func                                      \
62 (                                                                             \
63     const tmp<FieldField<Field, Type> >& tf                                   \
64 )                                                                             \
65 {                                                                             \
66     tmp<FieldField<Field, ReturnType> > tRes                                  \
67     (                                                                         \
68         reuseTmpFieldField<Field, Type, Type>::New(tf)                        \
69     );                                                                        \
70     Func(tRes(), tf());                                                       \
71     reuseTmpFieldField<Field, Type, Type>::clear(tf);                         \
72     return tRes;                                                              \
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
78 #define UNARY_OPERATOR(ReturnType, Type, Op, OpFunc)                          \
79                                                                               \
80 TEMPLATE                                                                      \
81 void OpFunc                                                                   \
82 (                                                                             \
83     FieldField<Field, ReturnType>& res,                                       \
84     const FieldField<Field, Type>& f                                          \
85 )                                                                             \
86 {                                                                             \
87     forAll(res, i)                                                            \
88     {                                                                         \
89         OpFunc(res[i], f[i]);                                                 \
90     }                                                                         \
91 }                                                                             \
92                                                                               \
93 TEMPLATE                                                                      \
94 tmp<FieldField<Field, ReturnType> > operator Op                               \
95 (                                                                             \
96     const FieldField<Field, Type>& f                                          \
97 )                                                                             \
98 {                                                                             \
99     tmp<FieldField<Field, ReturnType> > tRes                                  \
100     (                                                                         \
101         FieldField<Field, Type>::NewCalculatedType(f)                         \
102     );                                                                        \
103     OpFunc(tRes(), f);                                                        \
104     return tRes;                                                              \
105 }                                                                             \
106                                                                               \
107 TEMPLATE                                                                      \
108 tmp<FieldField<Field, ReturnType> > operator Op                               \
109 (                                                                             \
110     const tmp<FieldField<Field, Type> >& tf                                   \
111 )                                                                             \
112 {                                                                             \
113     tmp<FieldField<Field, ReturnType> > tRes                                  \
114     (                                                                         \
115         reuseTmpFieldField<Field, Type, Type>::New(tf)                        \
116     );                                                                        \
117     OpFunc(tRes(), tf());                                                     \
118     reuseTmpFieldField<Field, Type, Type>::clear(tf);                         \
119     return tRes;                                                              \
123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)                       \
126                                                                               \
127 TEMPLATE                                                                      \
128 void Func                                                                     \
129 (                                                                             \
130     FieldField<Field, ReturnType>& f,                                         \
131     const FieldField<Field, Type1>& f1,                                       \
132     const FieldField<Field, Type2>& f2                                        \
133 )                                                                             \
134 {                                                                             \
135     forAll(f, i)                                                              \
136     {                                                                         \
137         Func(f[i], f1[i], f2[i]);                                             \
138     }                                                                         \
139 }                                                                             \
140                                                                               \
141 TEMPLATE                                                                      \
142 tmp<FieldField<Field, ReturnType> > Func                                      \
143 (                                                                             \
144     const FieldField<Field, Type1>& f1,                                       \
145     const FieldField<Field, Type2>& f2                                        \
146 )                                                                             \
147 {                                                                             \
148     tmp<FieldField<Field, ReturnType> > tRes                                  \
149     (                                                                         \
150         FieldField<Field, Type1>::NewCalculatedType(f1)                       \
151     );                                                                        \
152     Func(tRes(), f1, f2);                                                     \
153     return tRes;                                                              \
154 }                                                                             \
155                                                                               \
156 TEMPLATE                                                                      \
157 tmp<FieldField<Field, ReturnType> > Func                                      \
158 (                                                                             \
159     const FieldField<Field, Type1>& f1,                                       \
160     const tmp<FieldField<Field, Type2> >& tf2                                 \
161 )                                                                             \
162 {                                                                             \
163     tmp<FieldField<Field, ReturnType> > tRes                                  \
164     (                                                                         \
165         reuseTmpFieldField<Field, ReturnType, Type2>::New(tf2)                \
166     );                                                                        \
167     Func(tRes(), f1, tf2());                                                  \
168     reuseTmpFieldField<Field, ReturnType, Type2>::clear(tf2);                 \
169     return tRes;                                                              \
170 }                                                                             \
171                                                                               \
172 TEMPLATE                                                                      \
173 tmp<FieldField<Field, ReturnType> > Func                                      \
174 (                                                                             \
175     const tmp<FieldField<Field, Type1> >& tf1,                                \
176     const FieldField<Field, Type2>& f2                                        \
177 )                                                                             \
178 {                                                                             \
179     tmp<FieldField<Field, ReturnType> > tRes                                  \
180     (                                                                         \
181         reuseTmpFieldField<Field, ReturnType, Type1>::New(tf1)                \
182     );                                                                        \
183     Func(tRes(), tf1(), f2);                                                  \
184     reuseTmpFieldField<Field, ReturnType, Type1>::clear(tf1);                 \
185     return tRes;                                                              \
186 }                                                                             \
187                                                                               \
188 TEMPLATE                                                                      \
189 tmp<FieldField<Field, ReturnType> > Func                                      \
190 (                                                                             \
191     const tmp<FieldField<Field, Type1> >& tf1,                                \
192     const tmp<FieldField<Field, Type2> >& tf2                                 \
193 )                                                                             \
194 {                                                                             \
195     tmp<FieldField<Field, ReturnType> > tRes                                  \
196     (                                                                         \
197         reuseTmpTmpFieldField<Field, ReturnType, Type1, Type1, Type2>::       \
198             New(tf1, tf2)                                                     \
199     );                                                                        \
200     Func(tRes(), tf1(), tf2());                                               \
201     reuseTmpTmpFieldField<Field, ReturnType, Type1, Type1, Type2>::           \
202         clear(tf1, tf2);                                                      \
203     return tRes;                                                              \
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func)               \
210                                                                               \
211 TEMPLATE                                                                      \
212 void Func                                                                     \
213 (                                                                             \
214     FieldField<Field, ReturnType>& f,                                         \
215     const FieldField<Field, Type1>& f1,                                       \
216     const Type2& s                                                            \
217 )                                                                             \
218 {                                                                             \
219     forAll(f, i)                                                              \
220     {                                                                         \
221         Func(f[i], f1[i], s);                                                 \
222     }                                                                         \
223 }                                                                             \
224                                                                               \
225 TEMPLATE                                                                      \
226 tmp<FieldField<Field, ReturnType> > Func                                      \
227 (                                                                             \
228     const FieldField<Field, Type1>& f1,                                       \
229     const Type2& s                                                            \
230 )                                                                             \
231 {                                                                             \
232     tmp<FieldField<Field, ReturnType> > tRes                                  \
233     (                                                                         \
234         FieldField<Field, Type1>::NewCalculatedType(f1)                       \
235     );                                                                        \
236     Func(tRes(), f1, s);                                                      \
237     return tRes;                                                              \
238 }                                                                             \
239                                                                               \
240 TEMPLATE                                                                      \
241 tmp<FieldField<Field, ReturnType> > Func                                      \
242 (                                                                             \
243     const tmp<FieldField<Field, Type1> >& tf1,                                \
244     const Type2& s                                                            \
245 )                                                                             \
246 {                                                                             \
247     tmp<FieldField<Field, ReturnType> > tRes                                  \
248     (                                                                         \
249         reuseTmpFieldField<Field, ReturnType, Type1>::New(tf1)                \
250     );                                                                        \
251     Func(tRes(), tf1(), s);                                                   \
252     reuseTmpFieldField<Field, ReturnType, Type1>::clear(tf1);                 \
253     return tRes;                                                              \
257 #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)               \
258                                                                               \
259 TEMPLATE                                                                      \
260 void Func                                                                     \
261 (                                                                             \
262     FieldField<Field, ReturnType>& f,                                         \
263     const Type1& s,                                                           \
264     const FieldField<Field, Type2>& f2                                        \
265 )                                                                             \
266 {                                                                             \
267     forAll(f, i)                                                              \
268     {                                                                         \
269         Func(f[i], s, f2[i]);                                                 \
270     }                                                                         \
271 }                                                                             \
272                                                                               \
273 TEMPLATE                                                                      \
274 tmp<FieldField<Field, ReturnType> > Func                                      \
275 (                                                                             \
276     const Type1& s,                                                           \
277     const FieldField<Field, Type2>& f2                                        \
278 )                                                                             \
279 {                                                                             \
280     tmp<FieldField<Field, ReturnType> > tRes                                  \
281     (                                                                         \
282         FieldField<Field, Type2>::NewCalculatedType(f2)                       \
283     );                                                                        \
284     Func(tRes(), s, f2);                                                      \
285     return tRes;                                                              \
286 }                                                                             \
287                                                                               \
288 TEMPLATE                                                                      \
289 tmp<FieldField<Field, ReturnType> > Func                                      \
290 (                                                                             \
291     const Type1& s,                                                           \
292     const tmp<FieldField<Field, Type2> >& tf2                                 \
293 )                                                                             \
294 {                                                                             \
295     tmp<FieldField<Field, ReturnType> > tRes                                  \
296     (                                                                         \
297         reuseTmpFieldField<Field, ReturnType, Type2>::New(tf2)                \
298     );                                                                        \
299     Func(tRes(), s, tf2());                                                   \
300     reuseTmpFieldField<Field, ReturnType, Type2>::clear(tf2);                 \
301     return tRes;                                                              \
305 #define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)                  \
306     BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func)                   \
307     BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc)                 \
313                                                                               \
314 TEMPLATE                                                                      \
315 void OpFunc                                                                   \
316 (                                                                             \
317     FieldField<Field, ReturnType>& f,                                         \
318     const FieldField<Field, Type1>& f1,                                       \
319     const FieldField<Field, Type2>& f2                                        \
320 )                                                                             \
321 {                                                                             \
322     forAll(f, i)                                                              \
323     {                                                                         \
324         OpFunc(f[i], f1[i], f2[i]);                                           \
325     }                                                                         \
326 }                                                                             \
327                                                                               \
328 TEMPLATE                                                                      \
329 tmp<FieldField<Field, ReturnType> > operator Op                               \
330 (                                                                             \
331     const FieldField<Field, Type1>& f1,                                       \
332     const FieldField<Field, Type2>& f2                                        \
333 )                                                                             \
334 {                                                                             \
335     tmp<FieldField<Field, ReturnType> > tRes                                  \
336     (                                                                         \
337         FieldField<Field, ReturnType>::NewCalculatedType(f1)                  \
338     );                                                                        \
339     OpFunc(tRes(), f1, f2);                                                   \
340     return tRes;                                                              \
341 }                                                                             \
342                                                                               \
343 TEMPLATE                                                                      \
344 tmp<FieldField<Field, ReturnType> > operator Op                               \
345 (                                                                             \
346     const FieldField<Field, Type1>& f1,                                       \
347     const tmp<FieldField<Field, Type2> >& tf2                                 \
348 )                                                                             \
349 {                                                                             \
350     tmp<FieldField<Field, ReturnType> > tRes                                  \
351     (                                                                         \
352         reuseTmpFieldField<Field, ReturnType, Type2>::New(tf2)                \
353     );                                                                        \
354     OpFunc(tRes(), f1, tf2());                                                \
355     reuseTmpFieldField<Field, ReturnType, Type2>::clear(tf2);                 \
356     return tRes;                                                              \
357 }                                                                             \
358                                                                               \
359 TEMPLATE                                                                      \
360 tmp<FieldField<Field, ReturnType> > operator Op                               \
361 (                                                                             \
362     const tmp<FieldField<Field, Type1> >& tf1,                                \
363     const FieldField<Field, Type2>& f2                                        \
364 )                                                                             \
365 {                                                                             \
366     tmp<FieldField<Field, ReturnType> > tRes                                  \
367     (                                                                         \
368         reuseTmpFieldField<Field, ReturnType, Type1>::New(tf1)                \
369     );                                                                        \
370     OpFunc(tRes(), tf1(), f2);                                                \
371     reuseTmpFieldField<Field, ReturnType, Type1>::clear(tf1);                 \
372     return tRes;                                                              \
373 }                                                                             \
374                                                                               \
375 TEMPLATE                                                                      \
376 tmp<FieldField<Field, ReturnType> > operator Op                               \
377 (                                                                             \
378     const tmp<FieldField<Field, Type1> >& tf1,                                \
379     const tmp<FieldField<Field, Type2> >& tf2                                 \
380 )                                                                             \
381 {                                                                             \
382     tmp<FieldField<Field, ReturnType> > tRes                                  \
383     (                                                                         \
384         reuseTmpTmpFieldField<Field, ReturnType, Type1, Type1, Type2>::       \
385             New(tf1, tf2)                                                     \
386     );                                                                        \
387     OpFunc(tRes(), tf1(), tf2());                                             \
388     reuseTmpTmpFieldField<Field, ReturnType, Type1, Type1, Type2>::           \
389         clear(tf1, tf2);                                                      \
390     return tRes;                                                              \
394 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
396 #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc)         \
397                                                                               \
398 TEMPLATE                                                                      \
399 void OpFunc                                                                   \
400 (                                                                             \
401     FieldField<Field, ReturnType>& f,                                         \
402     const Type1& s,                                                           \
403     const FieldField<Field, Type2>& f2                                        \
404 )                                                                             \
405 {                                                                             \
406     forAll(f, i)                                                              \
407     {                                                                         \
408         OpFunc(f[i], s, f2[i]);                                               \
409     }                                                                         \
410 }                                                                             \
411                                                                               \
412 TEMPLATE                                                                      \
413 tmp<FieldField<Field, ReturnType> > operator Op                               \
414 (                                                                             \
415     const Type1& s,                                                           \
416     const FieldField<Field, Type2>& f2                                        \
417 )                                                                             \
418 {                                                                             \
419     tmp<FieldField<Field, ReturnType> > tRes                                  \
420     (                                                                         \
421         FieldField<Field, Type2>::NewCalculatedType(f2)                       \
422     );                                                                        \
423     OpFunc(tRes(), s, f2);                                                    \
424     return tRes;                                                              \
425 }                                                                             \
426                                                                               \
427 TEMPLATE                                                                      \
428 tmp<FieldField<Field, ReturnType> > operator Op                               \
429 (                                                                             \
430     const Type1& s,                                                           \
431     const tmp<FieldField<Field, Type2> >& tf2                                 \
432 )                                                                             \
433 {                                                                             \
434     tmp<FieldField<Field, ReturnType> > tRes                                  \
435     (                                                                         \
436         reuseTmpFieldField<Field, ReturnType, Type2>::New(tf2)                \
437     );                                                                        \
438     OpFunc(tRes(), s, tf2());                                                 \
439     reuseTmpFieldField<Field, ReturnType, Type2>::clear(tf2);                 \
440     return tRes;                                                              \
444 #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc)         \
445                                                                               \
446 TEMPLATE                                                                      \
447 void OpFunc                                                                   \
448 (                                                                             \
449     FieldField<Field, ReturnType>& f,                                         \
450     const FieldField<Field, Type1>& f1,                                       \
451     const Type2& s                                                            \
452 )                                                                             \
453 {                                                                             \
454     forAll(f, i)                                                              \
455     {                                                                         \
456         OpFunc(f[i], f1[i], s);                                               \
457     }                                                                         \
458 }                                                                             \
459                                                                               \
460 TEMPLATE                                                                      \
461 tmp<FieldField<Field, ReturnType> > operator Op                               \
462 (                                                                             \
463     const FieldField<Field, Type1>& f1,                                       \
464     const Type2& s                                                            \
465 )                                                                             \
466 {                                                                             \
467     tmp<FieldField<Field, ReturnType> > tRes                                  \
468     (                                                                         \
469         FieldField<Field, Type1>::NewCalculatedType(f1)                       \
470     );                                                                        \
471     OpFunc(tRes(), f1, s);                                                    \
472     return tRes;                                                              \
473 }                                                                             \
474                                                                               \
475 TEMPLATE                                                                      \
476 tmp<FieldField<Field, ReturnType> > operator Op                               \
477 (                                                                             \
478     const tmp<FieldField<Field, Type1> >& tf1,                                \
479     const Type2& s                                                            \
480 )                                                                             \
481 {                                                                             \
482     tmp<FieldField<Field, ReturnType> > tRes                                  \
483     (                                                                         \
484         reuseTmpFieldField<Field, ReturnType, Type1>::New(tf1)                \
485     );                                                                        \
486     OpFunc(tRes(), tf1(), s);                                                 \
487     reuseTmpFieldField<Field, ReturnType, Type1>::clear(tf1);                 \
488     return tRes;                                                              \
492 #define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc)            \
493     BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc)             \
494     BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc)
496 // ************************************************************************* //