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