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-2024 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().primitiveFieldRef(), df1.primitiveField()); \
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().primitiveFieldRef(), df1.primitiveField()); \
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().primitiveFieldRef(), df1.primitiveField()); \
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().primitiveFieldRef(), df1.primitiveField()); \
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 \
152  ( \
153  tRes.ref().primitiveFieldRef(), \
154  df1.primitiveField(), \
155  df2.primitiveField() \
156  ); \
157  \
158  return tRes; \
159 } \
160  \
161 TEMPLATE \
162 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
163 ( \
164  const DimensionedField<Type1, GeoMesh>& df1, \
165  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
166 ) \
167 { \
168  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
169  \
170  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
171  ( \
172  reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::New \
173  ( \
174  tdf2, \
175  #Func "(" + df1.name() + ',' + df2.name() + ')', \
176  Func(df1.dimensions(), df2.dimensions()) \
177  ) \
178  ); \
179  \
180  Func \
181  ( \
182  tRes.ref().primitiveFieldRef(), \
183  df1.primitiveField(), \
184  df2.primitiveField() \
185  ); \
186  \
187  tdf2.clear(); \
188  \
189  return tRes; \
190 } \
191  \
192 TEMPLATE \
193 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
194 ( \
195  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
196  const DimensionedField<Type2, GeoMesh>& df2 \
197 ) \
198 { \
199  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
200  \
201  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
202  ( \
203  reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::New \
204  ( \
205  tdf1, \
206  #Func "(" + df1.name() + ',' + df2.name() + ')', \
207  Func(df1.dimensions(), df2.dimensions()) \
208  ) \
209  ); \
210  \
211  Func \
212  ( \
213  tRes.ref().primitiveFieldRef(), \
214  df1.primitiveField(), \
215  df2.primitiveField() \
216  ); \
217  \
218  tdf1.clear(); \
219  \
220  return tRes; \
221 } \
222  \
223 TEMPLATE \
224 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
225 ( \
226  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
227  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
228 ) \
229 { \
230  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
231  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
232  \
233  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
234  ( \
235  reuseTmpTmpDimensionedField<ReturnType, Type1, Type2, GeoMesh>::New \
236  ( \
237  tdf1, \
238  tdf2, \
239  #Func "(" + df1.name() + ',' + df2.name() + ')', \
240  Func(df1.dimensions(), df2.dimensions()) \
241  ) \
242  ); \
243  \
244  Func \
245  ( \
246  tRes.ref().primitiveFieldRef(), \
247  df1.primitiveField(), \
248  df2.primitiveField() \
249  ); \
250  \
251  tdf1.clear(); \
252  tdf2.clear(); \
253  \
254  return tRes; \
255 }
256 
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
261  \
262 TEMPLATE \
263 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
264 ( \
265  const dimensioned<Type1>& dt1, \
266  const DimensionedField<Type2, GeoMesh>& df2 \
267 ) \
268 { \
269  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
270  ( \
271  DimensionedField<ReturnType, GeoMesh>::New \
272  ( \
273  #Func "(" + dt1.name() + ',' + df2.name() + ')', \
274  df2.mesh(), \
275  Func(dt1.dimensions(), df2.dimensions()) \
276  ) \
277  ); \
278  \
279  Func(tRes.ref().primitiveFieldRef(), dt1.value(), df2.primitiveField()); \
280  \
281  return tRes; \
282 } \
283  \
284 TEMPLATE \
285 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
286 ( \
287  const Type1& t1, \
288  const DimensionedField<Type2, GeoMesh>& df2 \
289 ) \
290 { \
291  return Func(dimensioned<Type1>(t1), df2); \
292 } \
293  \
294  \
295 TEMPLATE \
296 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
297 ( \
298  const dimensioned<Type1>& dt1, \
299  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
300 ) \
301 { \
302  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
303  \
304  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
305  ( \
306  reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::New \
307  ( \
308  tdf2, \
309  #Func "(" + dt1.name() + ',' + df2.name() + ')', \
310  Func(dt1.dimensions(), df2.dimensions()) \
311  ) \
312  ); \
313  \
314  Func(tRes.ref().primitiveFieldRef(), dt1.value(), df2.primitiveField()); \
315  \
316  tdf2.clear(); \
317  \
318  return tRes; \
319 } \
320  \
321 TEMPLATE \
322 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
323 ( \
324  const Type1& t1, \
325  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
326 ) \
327 { \
328  return Func(dimensioned<Type2>(t1), tdf2); \
329 }
330 
331 
332 #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \
333  \
334 TEMPLATE \
335 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
336 ( \
337  const DimensionedField<Type1, GeoMesh>& df1, \
338  const dimensioned<Type2>& dt2 \
339 ) \
340 { \
341  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
342  ( \
343  DimensionedField<ReturnType, GeoMesh>::New \
344  ( \
345  #Func "(" + df1.name() + ',' + dt2.name() + ')', \
346  df1.mesh(), \
347  Func(df1.dimensions(), dt2.dimensions()) \
348  ) \
349  ); \
350  \
351  Func(tRes.ref().primitiveFieldRef(), df1.primitiveField(), dt2.value()); \
352  \
353  return tRes; \
354 } \
355  \
356 TEMPLATE \
357 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
358 ( \
359  const DimensionedField<Type1, GeoMesh>& df1, \
360  const Type2& t2 \
361 ) \
362 { \
363  return Func(df1, dimensioned<Type2>(t2)); \
364 } \
365  \
366  \
367 TEMPLATE \
368 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
369 ( \
370  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
371  const dimensioned<Type2>& dt2 \
372 ) \
373 { \
374  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
375  \
376  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
377  ( \
378  reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::New \
379  ( \
380  tdf1, \
381  #Func "(" + df1.name() + ',' + dt2.name() + ')', \
382  Func(df1.dimensions(), dt2.dimensions()) \
383  ) \
384  ); \
385  \
386  Func(tRes.ref().primitiveFieldRef(), df1.primitiveField(), dt2.value()); \
387  \
388  tdf1.clear(); \
389  \
390  return tRes; \
391 } \
392  \
393 TEMPLATE \
394 tmp<DimensionedField<ReturnType, GeoMesh>> Func \
395 ( \
396  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
397  const Type2& t2 \
398 ) \
399 { \
400  return Func(tdf1, dimensioned<Type2>(t2)); \
401 }
402 
403 
404 #define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func) \
405  BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
406  BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
407 
408 
409 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410 
411 #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc) \
412  \
413 TEMPLATE \
414 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
415 ( \
416  const DimensionedField<Type1, GeoMesh>& df1, \
417  const DimensionedField<Type2, GeoMesh>& df2 \
418 ) \
419 { \
420  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
421  ( \
422  DimensionedField<ReturnType, GeoMesh>::New \
423  ( \
424  '(' + df1.name() + OpName + df2.name() + ')', \
425  df1.mesh(), \
426  df1.dimensions() Op df2.dimensions() \
427  ) \
428  ); \
429  \
430  Foam::OpFunc \
431  ( \
432  tRes.ref().primitiveFieldRef(), \
433  df1.primitiveField(), \
434  df2.primitiveField() \
435  ); \
436  \
437  return tRes; \
438 } \
439  \
440 TEMPLATE \
441 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
442 ( \
443  const DimensionedField<Type1, GeoMesh>& df1, \
444  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
445 ) \
446 { \
447  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
448  \
449  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
450  ( \
451  reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::New \
452  ( \
453  tdf2, \
454  '(' + df1.name() + OpName + df2.name() + ')', \
455  df1.dimensions() Op df2.dimensions() \
456  ) \
457  ); \
458  \
459  Foam::OpFunc \
460  ( \
461  tRes.ref().primitiveFieldRef(), \
462  df1.primitiveField(), \
463  df2.primitiveField() \
464  ); \
465  \
466  tdf2.clear(); \
467  \
468  return tRes; \
469 } \
470  \
471 TEMPLATE \
472 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
473 ( \
474  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
475  const DimensionedField<Type2, GeoMesh>& df2 \
476 ) \
477 { \
478  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
479  \
480  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
481  ( \
482  reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::New \
483  ( \
484  tdf1, \
485  '(' + df1.name() + OpName + df2.name() + ')', \
486  df1.dimensions() Op df2.dimensions() \
487  ) \
488  ); \
489  \
490  Foam::OpFunc \
491  ( \
492  tRes.ref().primitiveFieldRef(), \
493  df1.primitiveField(), \
494  df2.primitiveField() \
495  ); \
496  \
497  tdf1.clear(); \
498  \
499  return tRes; \
500 } \
501  \
502 TEMPLATE \
503 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
504 ( \
505  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
506  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
507 ) \
508 { \
509  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
510  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
511  \
512  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
513  ( \
514  reuseTmpTmpDimensionedField<ReturnType, Type1, Type2, GeoMesh>::New \
515  ( \
516  tdf1, \
517  tdf2, \
518  '(' + df1.name() + OpName + df2.name() + ')', \
519  df1.dimensions() Op df2.dimensions() \
520  ) \
521  ); \
522  \
523  Foam::OpFunc \
524  ( \
525  tRes.ref().primitiveFieldRef(), \
526  df1.primitiveField(), \
527  df2.primitiveField() \
528  ); \
529  \
530  tdf1.clear(); \
531  tdf2.clear(); \
532  \
533  return tRes; \
534 }
535 
536 
537 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
538 
539 #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc) \
540  \
541 TEMPLATE \
542 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
543 ( \
544  const dimensioned<Type1>& dt1, \
545  const DimensionedField<Type2, GeoMesh>& df2 \
546 ) \
547 { \
548  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
549  ( \
550  DimensionedField<ReturnType, GeoMesh>::New \
551  ( \
552  '(' + dt1.name() + OpName + df2.name() + ')', \
553  df2.mesh(), \
554  dt1.dimensions() Op df2.dimensions() \
555  ) \
556  ); \
557  \
558  Foam::OpFunc \
559  ( \
560  tRes.ref().primitiveFieldRef(), \
561  dt1.value(), \
562  df2.primitiveField() \
563  ); \
564  \
565  return tRes; \
566 } \
567  \
568 TEMPLATE \
569 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
570 ( \
571  const Type1& t1, \
572  const DimensionedField<Type2, GeoMesh>& df2 \
573 ) \
574 { \
575  return dimensioned<Type1>(t1) Op df2; \
576 } \
577  \
578  \
579 TEMPLATE \
580 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
581 ( \
582  const dimensioned<Type1>& dt1, \
583  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
584 ) \
585 { \
586  const DimensionedField<Type2, GeoMesh>& df2 = tdf2(); \
587  \
588  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
589  ( \
590  reuseTmpDimensionedField<ReturnType, Type2, GeoMesh>::New \
591  ( \
592  tdf2, \
593  '(' + dt1.name() + OpName + df2.name() + ')', \
594  dt1.dimensions() Op df2.dimensions() \
595  ) \
596  ); \
597  \
598  Foam::OpFunc \
599  ( \
600  tRes.ref().primitiveFieldRef(), \
601  dt1.value(), \
602  tdf2().primitiveField() \
603  ); \
604  \
605  tdf2.clear(); \
606  \
607  return tRes; \
608 } \
609  \
610 TEMPLATE \
611 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
612 ( \
613  const Type1& t1, \
614  const tmp<DimensionedField<Type2, GeoMesh>>& tdf2 \
615 ) \
616 { \
617  return dimensioned<Type1>(t1) Op tdf2; \
618 }
619 
620 
621 #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) \
622  \
623 TEMPLATE \
624 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
625 ( \
626  const DimensionedField<Type1, GeoMesh>& df1, \
627  const dimensioned<Type2>& dt2 \
628 ) \
629 { \
630  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
631  ( \
632  DimensionedField<ReturnType, GeoMesh>::New \
633  ( \
634  '(' + df1.name() + OpName + dt2.name() + ')', \
635  df1.mesh(), \
636  df1.dimensions() Op dt2.dimensions() \
637  ) \
638  ); \
639  \
640  Foam::OpFunc \
641  ( \
642  tRes.ref().primitiveFieldRef(), \
643  df1.primitiveField(), \
644  dt2.value() \
645  ); \
646  \
647  return tRes; \
648 } \
649  \
650 TEMPLATE \
651 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
652 ( \
653  const DimensionedField<Type1, GeoMesh>& df1, \
654  const Type2& t2 \
655 ) \
656 { \
657  return df1 Op dimensioned<Type2>(t2); \
658 } \
659  \
660  \
661 TEMPLATE \
662 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
663 ( \
664  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
665  const dimensioned<Type2>& dt2 \
666 ) \
667 { \
668  const DimensionedField<Type1, GeoMesh>& df1 = tdf1(); \
669  \
670  tmp<DimensionedField<ReturnType, GeoMesh>> tRes \
671  ( \
672  reuseTmpDimensionedField<ReturnType, Type1, GeoMesh>::New \
673  ( \
674  tdf1, \
675  '(' + df1.name() + OpName + dt2.name() + ')', \
676  df1.dimensions() Op dt2.dimensions() \
677  ) \
678  ); \
679  \
680  Foam::OpFunc \
681  ( \
682  tRes.ref().primitiveFieldRef(), \
683  tdf1().primitiveField(), \
684  dt2.value() \
685  ); \
686  \
687  tdf1.clear(); \
688  \
689  return tRes; \
690 } \
691  \
692 TEMPLATE \
693 tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \
694 ( \
695  const tmp<DimensionedField<Type1, GeoMesh>>& tdf1, \
696  const Type2& t2 \
697 ) \
698 { \
699  return tdf1 Op dimensioned<Type2>(t2); \
700 }
701 
702 #define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc) \
703  BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc) \
704  BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc)
705 
706 
707 // ************************************************************************* //