DimensionedFieldFunctionsM.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-2020 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 
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 #define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc) \
31  \
32 TEMPLATE \
33 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
34 ( \
35  const DimensionedField<Type1, GeoMesh>& df1 \
36 ) \
37 { \
38  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
39  ( \
40  DimensionedField<ReturnType, GeoMesh>::New \
41  ( \
42  #Func "(" + df1.name() + ')', \
43  df1.mesh(), \
44  Dfunc(df1.dimensions()) \
45  ) \
46  ); \
47  \
48  Func(tRes.ref().field(), df1.field()); \
49  \
50  return tRes; \
51 } \
52  \
53 TEMPLATE \
54 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
55 ( \
56  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1 \
57 ) \
58 { \
59  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
60  \
61  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
62  ( \
63  reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::New \
64  ( \
65  tdf1, \
66  #Func "(" + df1.name() + ')', \
67  Dfunc(df1.dimensions()) \
68  ) \
69  ); \
70  \
71  Func(tRes.ref().field(), df1.field()); \
72  \
73  tdf1.clear(); \
74  \
75  return tRes; \
76 }
77 
78 
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80 
81 #define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc) \
82  \
83 TEMPLATE \
84 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
85 ( \
86  const DimensionedField<Type1, GeoMesh>& df1 \
87 ) \
88 { \
89  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
90  ( \
91  DimensionedField<ReturnType, GeoMesh>::New \
92  ( \
93  #Op + df1.name(), \
94  df1.mesh(), \
95  Dfunc(df1.dimensions()) \
96  ) \
97  ); \
98  \
99  Foam::OpFunc(tRes.ref().field(), df1.field()); \
100  \
101  return tRes; \
102 } \
103  \
104 TEMPLATE \
105 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
106 ( \
107  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1 \
108 ) \
109 { \
110  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
111  \
112  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
113  ( \
114  reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::New \
115  ( \
116  tdf1, \
117  #Op + df1.name(), \
118  Dfunc(df1.dimensions()) \
119  ) \
120  ); \
121  \
122  Foam::OpFunc(tRes.ref().field(), df1.field()); \
123  \
124  tdf1.clear(); \
125  \
126  return tRes; \
127 }
128 
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \
133  \
134 TEMPLATE \
135 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
136 ( \
137  const DimensionedField<Type1, GeoMesh>& df1, \
138  const DimensionedField<Type2, GeoMesh>& df2 \
139 ) \
140 { \
141  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
142  ( \
143  DimensionedField<ReturnType, GeoMesh>::New \
144  ( \
145  #Func "(" + df1.name() + ',' + df2.name() + ')', \
146  df1.mesh(), \
147  Func(df1.dimensions(), df2.dimensions()) \
148  ) \
149  ); \
150  \
151  Func(tRes.ref().field(), df1.field(), df2.field()); \
152  \
153  return tRes; \
154 } \
155  \
156 TEMPLATE \
157 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
158 ( \
159  const DimensionedField<Type1, GeoMesh>& df1, \
160  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
161 ) \
162 { \
163  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
164  \
165  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
166  ( \
167  reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::New \
168  ( \
169  tdf2, \
170  #Func "(" + df1.name() + ',' + df2.name() + ')', \
171  Func(df1.dimensions(), df2.dimensions()) \
172  ) \
173  ); \
174  \
175  Func(tRes.ref().field(), df1.field(), df2.field()); \
176  \
177  tdf2.clear(); \
178  \
179  return tRes; \
180 } \
181  \
182 TEMPLATE \
183 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
184 ( \
185  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
186  const DimensionedField<Type2, GeoMesh>& df2 \
187 ) \
188 { \
189  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
190  \
191  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
192  ( \
193  reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::New \
194  ( \
195  tdf1, \
196  #Func "(" + df1.name() + ',' + df2.name() + ')', \
197  Func(df1.dimensions(), df2.dimensions()) \
198  ) \
199  ); \
200  \
201  Func(tRes.ref().field(), df1.field(), df2.field()); \
202  \
203  tdf1.clear(); \
204  \
205  return tRes; \
206 } \
207  \
208 TEMPLATE \
209 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
210 ( \
211  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
212  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
213 ) \
214 { \
215  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
216  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
217  \
218  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
219  ( \
220  reuseTmpTmpDimensionedField<ReturnType, Type1, Type2, GeoMesh>::New \
221  ( \
222  tdf1, \
223  tdf2, \
224  #Func "(" + df1.name() + ',' + df2.name() + ')', \
225  Func(df1.dimensions(), df2.dimensions()) \
226  ) \
227  ); \
228  \
229  Func(tRes.ref().field(), df1.field(), df2.field()); \
230  \
231  tdf1.clear(); \
232  tdf2.clear(); \
233  \
234  return tRes; \
235 }
236 
237 
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 
240 #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
241  \
242 TEMPLATE \
243 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
244 ( \
245  const dimensioned<Type1>& dt1, \
246  const DimensionedField<Type2, GeoMesh>& df2 \
247 ) \
248 { \
249  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
250  ( \
251  DimensionedField<ReturnType, GeoMesh>::New \
252  ( \
253  #Func "(" + dt1.name() + ',' + df2.name() + ')', \
254  df2.mesh(), \
255  Func(dt1.dimensions(), df2.dimensions()) \
256  ) \
257  ); \
258  \
259  Func(tRes.ref().field(), dt1.value(), df2.field()); \
260  \
261  return tRes; \
262 } \
263  \
264 TEMPLATE \
265 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
266 ( \
267  const Type1& t1, \
268  const DimensionedField<Type2, GeoMesh>& df2 \
269 ) \
270 { \
271  return Func(dimensioned<Type1>(t1), df2); \
272 } \
273  \
274  \
275 TEMPLATE \
276 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
277 ( \
278  const dimensioned<Type1>& dt1, \
279  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
280 ) \
281 { \
282  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
283  \
284  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
285  ( \
286  reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::New \
287  ( \
288  tdf2, \
289  #Func "(" + dt1.name() + ',' + df2.name() + ')', \
290  Func(dt1.dimensions(), df2.dimensions()) \
291  ) \
292  ); \
293  \
294  Func(tRes.ref().field(), dt1.value(), df2.field()); \
295  \
296  tdf2.clear(); \
297  \
298  return tRes; \
299 } \
300  \
301 TEMPLATE \
302 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
303 ( \
304  const Type1& t1, \
305  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
306 ) \
307 { \
308  return Func(dimensioned<Type2>(t1), tdf2); \
309 }
310 
311 
312 #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \
313  \
314 TEMPLATE \
315 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
316 ( \
317  const DimensionedField<Type1, GeoMesh>& df1, \
318  const dimensioned<Type2>& dt2 \
319 ) \
320 { \
321  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
322  ( \
323  DimensionedField<ReturnType, GeoMesh>::New \
324  ( \
325  #Func "(" + df1.name() + ',' + dt2.name() + ')', \
326  df1.mesh(), \
327  Func(df1.dimensions(), dt2.dimensions()) \
328  ) \
329  ); \
330  \
331  Func(tRes.ref().field(), df1.field(), dt2.value()); \
332  \
333  return tRes; \
334 } \
335  \
336 TEMPLATE \
337 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
338 ( \
339  const DimensionedField<Type1, GeoMesh>& df1, \
340  const Type2& t2 \
341 ) \
342 { \
343  return Func(df1, dimensioned<Type2>(t2)); \
344 } \
345  \
346  \
347 TEMPLATE \
348 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
349 ( \
350  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
351  const dimensioned<Type2>& dt2 \
352 ) \
353 { \
354  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
355  \
356  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
357  ( \
358  reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::New \
359  ( \
360  tdf1, \
361  #Func "(" + df1.name() + ',' + dt2.name() + ')', \
362  Func(df1.dimensions(), dt2.dimensions()) \
363  ) \
364  ); \
365  \
366  Func(tRes.ref().field(), df1.field(), dt2.value()); \
367  \
368  tdf1.clear(); \
369  \
370  return tRes; \
371 } \
372  \
373 TEMPLATE \
374 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
375 ( \
376  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
377  const Type2& t2 \
378 ) \
379 { \
380  return Func(tdf1, dimensioned<Type2>(t2)); \
381 }
382 
383 
384 #define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func) \
385  BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
386  BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
387 
388 
389 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
390 
391 #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc) \
392  \
393 TEMPLATE \
394 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
395 ( \
396  const DimensionedField<Type1, GeoMesh>& df1, \
397  const DimensionedField<Type2, GeoMesh>& df2 \
398 ) \
399 { \
400  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
401  ( \
402  DimensionedField<ReturnType, GeoMesh>::New \
403  ( \
404  '(' + df1.name() + OpName + df2.name() + ')', \
405  df1.mesh(), \
406  df1.dimensions() Op df2.dimensions() \
407  ) \
408  ); \
409  \
410  Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \
411  \
412  return tRes; \
413 } \
414  \
415 TEMPLATE \
416 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
417 ( \
418  const DimensionedField<Type1, GeoMesh>& df1, \
419  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
420 ) \
421 { \
422  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
423  \
424  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
425  ( \
426  reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::New \
427  ( \
428  tdf2, \
429  '(' + df1.name() + OpName + df2.name() + ')', \
430  df1.dimensions() Op df2.dimensions() \
431  ) \
432  ); \
433  \
434  Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \
435  \
436  tdf2.clear(); \
437  \
438  return tRes; \
439 } \
440  \
441 TEMPLATE \
442 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
443 ( \
444  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
445  const DimensionedField<Type2, GeoMesh>& df2 \
446 ) \
447 { \
448  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
449  \
450  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
451  ( \
452  reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::New \
453  ( \
454  tdf1, \
455  '(' + df1.name() + OpName + df2.name() + ')', \
456  df1.dimensions() Op df2.dimensions() \
457  ) \
458  ); \
459  \
460  Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \
461  \
462  tdf1.clear(); \
463  \
464  return tRes; \
465 } \
466  \
467 TEMPLATE \
468 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
469 ( \
470  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
471  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
472 ) \
473 { \
474  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
475  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
476  \
477  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
478  ( \
479  reuseTmpTmpDimensionedField<ReturnType, Type1, Type2, GeoMesh>::New \
480  ( \
481  tdf1, \
482  tdf2, \
483  '(' + df1.name() + OpName + df2.name() + ')', \
484  df1.dimensions() Op df2.dimensions() \
485  ) \
486  ); \
487  \
488  Foam::OpFunc(tRes.ref().field(), df1.field(), df2.field()); \
489  \
490  tdf1.clear(); \
491  tdf2.clear(); \
492  \
493  return tRes; \
494 }
495 
496 
497 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
498 
499 #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc) \
500  \
501 TEMPLATE \
502 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
503 ( \
504  const dimensioned<Type1>& dt1, \
505  const DimensionedField<Type2, GeoMesh>& df2 \
506 ) \
507 { \
508  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
509  ( \
510  DimensionedField<ReturnType, GeoMesh>::New \
511  ( \
512  '(' + dt1.name() + OpName + df2.name() + ')', \
513  df2.mesh(), \
514  dt1.dimensions() Op df2.dimensions() \
515  ) \
516  ); \
517  \
518  Foam::OpFunc(tRes.ref().field(), dt1.value(), df2.field()); \
519  \
520  return tRes; \
521 } \
522  \
523 TEMPLATE \
524 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
525 ( \
526  const Type1& t1, \
527  const DimensionedField<Type2, GeoMesh>& df2 \
528 ) \
529 { \
530  return dimensioned<Type1>(t1) Op df2; \
531 } \
532  \
533  \
534 TEMPLATE \
535 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
536 ( \
537  const dimensioned<Type1>& dt1, \
538  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
539 ) \
540 { \
541  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
542  \
543  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
544  ( \
545  reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::New \
546  ( \
547  tdf2, \
548  '(' + dt1.name() + OpName + df2.name() + ')', \
549  dt1.dimensions() Op df2.dimensions() \
550  ) \
551  ); \
552  \
553  Foam::OpFunc(tRes.ref().field(), dt1.value(), tdf2().field()); \
554  \
555  tdf2.clear(); \
556  \
557  return tRes; \
558 } \
559  \
560 TEMPLATE \
561 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
562 ( \
563  const Type1& t1, \
564  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
565 ) \
566 { \
567  return dimensioned<Type1>(t1) Op tdf2; \
568 }
569 
570 
571 #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) \
572  \
573 TEMPLATE \
574 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
575 ( \
576  const DimensionedField<Type1, GeoMesh>& df1, \
577  const dimensioned<Type2>& dt2 \
578 ) \
579 { \
580  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
581  ( \
582  DimensionedField<ReturnType, GeoMesh>::New \
583  ( \
584  '(' + df1.name() + OpName + dt2.name() + ')', \
585  df1.mesh(), \
586  df1.dimensions() Op dt2.dimensions() \
587  ) \
588  ); \
589  \
590  Foam::OpFunc(tRes.ref().field(), df1.field(), dt2.value()); \
591  \
592  return tRes; \
593 } \
594  \
595 TEMPLATE \
596 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
597 ( \
598  const DimensionedField<Type1, GeoMesh>& df1, \
599  const Type2& t2 \
600 ) \
601 { \
602  return df1 Op dimensioned<Type2>(t2); \
603 } \
604  \
605  \
606 TEMPLATE \
607 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
608 ( \
609  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
610  const dimensioned<Type2>& dt2 \
611 ) \
612 { \
613  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
614  \
615  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
616  ( \
617  reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::New \
618  ( \
619  tdf1, \
620  '(' + df1.name() + OpName + dt2.name() + ')', \
621  df1.dimensions() Op dt2.dimensions() \
622  ) \
623  ); \
624  \
625  Foam::OpFunc(tRes.ref().field(), tdf1().field(), dt2.value()); \
626  \
627  tdf1.clear(); \
628  \
629  return tRes; \
630 } \
631  \
632 TEMPLATE \
633 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
634 ( \
635  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
636  const Type2& t2 \
637 ) \
638 { \
639  return tdf1 Op dimensioned<Type2>(t2); \
640 }
641 
642 #define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc) \
643  BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc) \
644  BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc)
645 
646 
647 // ************************************************************************* //