FieldFieldFunctionsM.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "FieldM.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
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.ref(), 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(New(tf)); \
67  Func(tRes.ref(), tf()); \
68  tf.clear(); \
69  return tRes; \
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 
75 #define UNARY_OPERATOR(ReturnType, Type, Op, OpFunc) \
76  \
77 TEMPLATE \
78 void OpFunc \
79 ( \
80  FieldField<Field, ReturnType>& res, \
81  const FieldField<Field, Type>& f \
82 ) \
83 { \
84  forAll(res, i) \
85  { \
86  OpFunc(res[i], f[i]); \
87  } \
88 } \
89  \
90 TEMPLATE \
91 tmp<FieldField<Field, ReturnType>> operator Op \
92 ( \
93  const FieldField<Field, Type>& f \
94 ) \
95 { \
96  tmp<FieldField<Field, ReturnType>> tRes \
97  ( \
98  FieldField<Field, Type>::NewCalculatedType(f) \
99  ); \
100  OpFunc(tRes.ref(), f); \
101  return tRes; \
102 } \
103  \
104 TEMPLATE \
105 tmp<FieldField<Field, ReturnType>> operator Op \
106 ( \
107  const tmp<FieldField<Field, Type>>& tf \
108 ) \
109 { \
110  tmp<FieldField<Field, ReturnType>> tRes(New(tf)); \
111  OpFunc(tRes.ref(), tf()); \
112  tf.clear(); \
113  return tRes; \
114 }
115 
116 
117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
118 
119 #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \
120  \
121 TEMPLATE \
122 void Func \
123 ( \
124  FieldField<Field, ReturnType>& f, \
125  const FieldField<Field, Type1>& f1, \
126  const FieldField<Field, Type2>& f2 \
127 ) \
128 { \
129  forAll(f, i) \
130  { \
131  Func(f[i], f1[i], f2[i]); \
132  } \
133 } \
134  \
135 TEMPLATE \
136 tmp<FieldField<Field, ReturnType>> Func \
137 ( \
138  const FieldField<Field, Type1>& f1, \
139  const FieldField<Field, Type2>& f2 \
140 ) \
141 { \
142  tmp<FieldField<Field, ReturnType>> tRes \
143  ( \
144  FieldField<Field, Type1>::NewCalculatedType(f1) \
145  ); \
146  Func(tRes.ref(), f1, f2); \
147  return tRes; \
148 } \
149  \
150 TEMPLATE \
151 tmp<FieldField<Field, ReturnType>> Func \
152 ( \
153  const FieldField<Field, Type1>& f1, \
154  const tmp<FieldField<Field, Type2>>& tf2 \
155 ) \
156 { \
157  tmp<FieldField<Field, ReturnType>> tRes \
158  ( \
159  reuseTmpFieldField<Field, ReturnType, Type2>::New(tf2) \
160  ); \
161  Func(tRes.ref(), f1, tf2()); \
162  tf2.clear(); \
163  return tRes; \
164 } \
165  \
166 TEMPLATE \
167 tmp<FieldField<Field, ReturnType>> Func \
168 ( \
169  const tmp<FieldField<Field, Type1>>& tf1, \
170  const FieldField<Field, Type2>& f2 \
171 ) \
172 { \
173  tmp<FieldField<Field, ReturnType>> tRes \
174  ( \
175  reuseTmpFieldField<Field, ReturnType, Type1>::New(tf1) \
176  ); \
177  Func(tRes.ref(), tf1(), f2); \
178  tf1.clear(); \
179  return tRes; \
180 } \
181  \
182 TEMPLATE \
183 tmp<FieldField<Field, ReturnType>> Func \
184 ( \
185  const tmp<FieldField<Field, Type1>>& tf1, \
186  const tmp<FieldField<Field, Type2>>& tf2 \
187 ) \
188 { \
189  tmp<FieldField<Field, ReturnType>> tRes \
190  ( \
191  reuseTmpTmpFieldField<Field, ReturnType, Type1, Type1, Type2>:: \
192  New(tf1, tf2) \
193  ); \
194  Func(tRes.ref(), tf1(), tf2()); \
195  tf1.clear(); \
196  tf2.clear(); \
197  return tRes; \
198 }
199 
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
204  \
205 TEMPLATE \
206 void Func \
207 ( \
208  FieldField<Field, ReturnType>& f, \
209  const Type1& s, \
210  const FieldField<Field, Type2>& f2 \
211 ) \
212 { \
213  forAll(f, i) \
214  { \
215  Func(f[i], s, f2[i]); \
216  } \
217 } \
218  \
219 TEMPLATE \
220 tmp<FieldField<Field, ReturnType>> Func \
221 ( \
222  const Type1& s, \
223  const FieldField<Field, Type2>& f2 \
224 ) \
225 { \
226  tmp<FieldField<Field, ReturnType>> tRes \
227  ( \
228  FieldField<Field, Type2>::NewCalculatedType(f2) \
229  ); \
230  Func(tRes.ref(), s, f2); \
231  return tRes; \
232 } \
233  \
234 TEMPLATE \
235 tmp<FieldField<Field, ReturnType>> Func \
236 ( \
237  const Type1& s, \
238  const tmp<FieldField<Field, Type2>>& tf2 \
239 ) \
240 { \
241  tmp<FieldField<Field, ReturnType>> tRes \
242  ( \
243  reuseTmpFieldField<Field, ReturnType, Type2>::New(tf2) \
244  ); \
245  Func(tRes.ref(), s, tf2()); \
246  tf2.clear(); \
247  return tRes; \
248 }
249 
250 
251 #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \
252  \
253 TEMPLATE \
254 void Func \
255 ( \
256  FieldField<Field, ReturnType>& f, \
257  const FieldField<Field, Type1>& f1, \
258  const Type2& s \
259 ) \
260 { \
261  forAll(f, i) \
262  { \
263  Func(f[i], f1[i], s); \
264  } \
265 } \
266  \
267 TEMPLATE \
268 tmp<FieldField<Field, ReturnType>> Func \
269 ( \
270  const FieldField<Field, Type1>& f1, \
271  const Type2& s \
272 ) \
273 { \
274  tmp<FieldField<Field, ReturnType>> tRes \
275  ( \
276  FieldField<Field, Type1>::NewCalculatedType(f1) \
277  ); \
278  Func(tRes.ref(), f1, s); \
279  return tRes; \
280 } \
281  \
282 TEMPLATE \
283 tmp<FieldField<Field, ReturnType>> Func \
284 ( \
285  const tmp<FieldField<Field, Type1>>& tf1, \
286  const Type2& s \
287 ) \
288 { \
289  tmp<FieldField<Field, ReturnType>> tRes \
290  ( \
291  reuseTmpFieldField<Field, ReturnType, Type1>::New(tf1) \
292  ); \
293  Func(tRes.ref(), tf1(), s); \
294  tf1.clear(); \
295  return tRes; \
296 }
297 
298 
299 #define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func) \
300  BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
301  BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
302 
303 
304 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
305 
306 #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
307  \
308 TEMPLATE \
309 void OpFunc \
310 ( \
311  FieldField<Field, ReturnType>& f, \
312  const FieldField<Field, Type1>& f1, \
313  const FieldField<Field, Type2>& f2 \
314 ) \
315 { \
316  forAll(f, i) \
317  { \
318  OpFunc(f[i], f1[i], f2[i]); \
319  } \
320 } \
321  \
322 TEMPLATE \
323 tmp<FieldField<Field, ReturnType>> operator Op \
324 ( \
325  const FieldField<Field, Type1>& f1, \
326  const FieldField<Field, Type2>& f2 \
327 ) \
328 { \
329  tmp<FieldField<Field, ReturnType>> tRes \
330  ( \
331  FieldField<Field, ReturnType>::NewCalculatedType(f1) \
332  ); \
333  OpFunc(tRes.ref(), f1, f2); \
334  return tRes; \
335 } \
336  \
337 TEMPLATE \
338 tmp<FieldField<Field, ReturnType>> operator Op \
339 ( \
340  const FieldField<Field, Type1>& f1, \
341  const tmp<FieldField<Field, Type2>>& tf2 \
342 ) \
343 { \
344  tmp<FieldField<Field, ReturnType>> tRes \
345  ( \
346  reuseTmpFieldField<Field, ReturnType, Type2>::New(tf2) \
347  ); \
348  OpFunc(tRes.ref(), f1, tf2()); \
349  tf2.clear(); \
350  return tRes; \
351 } \
352  \
353 TEMPLATE \
354 tmp<FieldField<Field, ReturnType>> operator Op \
355 ( \
356  const tmp<FieldField<Field, Type1>>& tf1, \
357  const FieldField<Field, Type2>& f2 \
358 ) \
359 { \
360  tmp<FieldField<Field, ReturnType>> tRes \
361  ( \
362  reuseTmpFieldField<Field, ReturnType, Type1>::New(tf1) \
363  ); \
364  OpFunc(tRes.ref(), tf1(), f2); \
365  tf1.clear(); \
366  return tRes; \
367 } \
368  \
369 TEMPLATE \
370 tmp<FieldField<Field, ReturnType>> operator Op \
371 ( \
372  const tmp<FieldField<Field, Type1>>& tf1, \
373  const tmp<FieldField<Field, Type2>>& tf2 \
374 ) \
375 { \
376  tmp<FieldField<Field, ReturnType>> tRes \
377  ( \
378  reuseTmpTmpFieldField<Field, ReturnType, Type1, Type1, Type2>:: \
379  New(tf1, tf2) \
380  ); \
381  OpFunc(tRes.ref(), tf1(), tf2()); \
382  tf1.clear(); \
383  tf2.clear(); \
384  return tRes; \
385 }
386 
387 
388 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
389 
390 #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
391  \
392 TEMPLATE \
393 void OpFunc \
394 ( \
395  FieldField<Field, ReturnType>& f, \
396  const Type1& s, \
397  const FieldField<Field, Type2>& f2 \
398 ) \
399 { \
400  forAll(f, i) \
401  { \
402  OpFunc(f[i], s, f2[i]); \
403  } \
404 } \
405  \
406 TEMPLATE \
407 tmp<FieldField<Field, ReturnType>> operator Op \
408 ( \
409  const Type1& s, \
410  const FieldField<Field, Type2>& f2 \
411 ) \
412 { \
413  tmp<FieldField<Field, ReturnType>> tRes \
414  ( \
415  FieldField<Field, Type2>::NewCalculatedType(f2) \
416  ); \
417  OpFunc(tRes.ref(), s, f2); \
418  return tRes; \
419 } \
420  \
421 TEMPLATE \
422 tmp<FieldField<Field, ReturnType>> operator Op \
423 ( \
424  const Type1& s, \
425  const tmp<FieldField<Field, Type2>>& tf2 \
426 ) \
427 { \
428  tmp<FieldField<Field, ReturnType>> tRes \
429  ( \
430  reuseTmpFieldField<Field, ReturnType, Type2>::New(tf2) \
431  ); \
432  OpFunc(tRes.ref(), s, tf2()); \
433  tf2.clear(); \
434  return tRes; \
435 }
436 
437 
438 #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc) \
439  \
440 TEMPLATE \
441 void OpFunc \
442 ( \
443  FieldField<Field, ReturnType>& f, \
444  const FieldField<Field, Type1>& f1, \
445  const Type2& s \
446 ) \
447 { \
448  forAll(f, i) \
449  { \
450  OpFunc(f[i], f1[i], s); \
451  } \
452 } \
453  \
454 TEMPLATE \
455 tmp<FieldField<Field, ReturnType>> operator Op \
456 ( \
457  const FieldField<Field, Type1>& f1, \
458  const Type2& s \
459 ) \
460 { \
461  tmp<FieldField<Field, ReturnType>> tRes \
462  ( \
463  FieldField<Field, Type1>::NewCalculatedType(f1) \
464  ); \
465  OpFunc(tRes.ref(), f1, s); \
466  return tRes; \
467 } \
468  \
469 TEMPLATE \
470 tmp<FieldField<Field, ReturnType>> operator Op \
471 ( \
472  const tmp<FieldField<Field, Type1>>& tf1, \
473  const Type2& s \
474 ) \
475 { \
476  tmp<FieldField<Field, ReturnType>> tRes \
477  ( \
478  reuseTmpFieldField<Field, ReturnType, Type1>::New(tf1) \
479  ); \
480  OpFunc(tRes.ref(), tf1(), s); \
481  tf1.clear(); \
482  return tRes; \
483 }
484 
485 
486 #define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
487  BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
488  BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc)
489 
490 // ************************************************************************* //
High performance macro functions for Field<Type> algebra. These expand using either array element acc...