OpenFOAM: API Guide
v2112
The open source CFD toolbox
FieldFunctionsM.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-2016 OpenFOAM Foundation
9
Copyright (C) 2019 OpenCFD Ltd.
10
-------------------------------------------------------------------------------
11
License
12
This file is part of OpenFOAM.
13
14
OpenFOAM is free software: you can redistribute it and/or modify it
15
under the terms of the GNU General Public License as published by
16
the Free Software Foundation, either version 3 of the License, or
17
(at your option) any later version.
18
19
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22
for more details.
23
24
You should have received a copy of the GNU General Public License
25
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27
\*---------------------------------------------------------------------------*/
28
29
#include "
FieldM.H
"
30
#include "
FieldReuseFunctions.H
"
31
32
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34
#define UNARY_FUNCTION(ReturnType, Type, Func) \
35
\
36
TEMPLATE \
37
void Func(Field<ReturnType>& res, const UList<Type>& f) \
38
{ \
39
TFOR_ALL_F_OP_FUNC_F(ReturnType, res, =, ::Foam::Func, Type, f) \
40
} \
41
\
42
TEMPLATE \
43
tmp<Field<ReturnType>> Func(const UList<Type>& f) \
44
{ \
45
auto tres = tmp<Field<ReturnType>>::New(f.size()); \
46
Func(tres.ref(), f); \
47
return tres; \
48
} \
49
\
50
TEMPLATE \
51
tmp<Field<ReturnType>> Func(const tmp<Field<Type>>& tf) \
52
{ \
53
auto tres = reuseTmp<ReturnType, Type>::New(tf); \
54
Func(tres.ref(), tf()); \
55
tf.clear(); \
56
return tres; \
57
}
58
59
60
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61
62
#define UNARY_OPERATOR(ReturnType, Type, Op, OpFunc) \
63
\
64
TEMPLATE \
65
void OpFunc(Field<ReturnType>& res, const UList<Type>& f) \
66
{ \
67
TFOR_ALL_F_OP_OP_F(ReturnType, res, =, Op, Type, f) \
68
} \
69
\
70
TEMPLATE \
71
tmp<Field<ReturnType>> operator Op(const UList<Type>& f) \
72
{ \
73
auto tres = tmp<Field<ReturnType>>::New(f.size()); \
74
OpFunc(tres.ref(), f); \
75
return tres; \
76
} \
77
\
78
TEMPLATE \
79
tmp<Field<ReturnType>> operator Op(const tmp<Field<Type>>& tf) \
80
{ \
81
auto tres = reuseTmp<ReturnType, Type>::New(tf); \
82
OpFunc(tres.ref(), tf()); \
83
tf.clear(); \
84
return tres; \
85
}
86
87
88
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
89
90
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \
91
\
92
TEMPLATE \
93
void Func \
94
( \
95
Field<ReturnType>& res, \
96
const UList<Type1>& f1, \
97
const UList<Type2>& f2 \
98
) \
99
{ \
100
TFOR_ALL_F_OP_FUNC_F_F \
101
( \
102
ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, f2 \
103
) \
104
} \
105
\
106
TEMPLATE \
107
tmp<Field<ReturnType>> Func \
108
( \
109
const UList<Type1>& f1, \
110
const UList<Type2>& f2 \
111
) \
112
{ \
113
auto tres = tmp<Field<ReturnType>>::New(f1.size()); \
114
Func(tres.ref(), f1, f2); \
115
return tres; \
116
} \
117
\
118
TEMPLATE \
119
tmp<Field<ReturnType>> Func \
120
( \
121
const UList<Type1>& f1, \
122
const tmp<Field<Type2>>& tf2 \
123
) \
124
{ \
125
auto tres = reuseTmp<ReturnType, Type2>::New(tf2); \
126
Func(tres.ref(), f1, tf2()); \
127
tf2.clear(); \
128
return tres; \
129
} \
130
\
131
TEMPLATE \
132
tmp<Field<ReturnType>> Func \
133
( \
134
const tmp<Field<Type1>>& tf1, \
135
const UList<Type2>& f2 \
136
) \
137
{ \
138
auto tres = reuseTmp<ReturnType, Type1>::New(tf1); \
139
Func(tres.ref(), tf1(), f2); \
140
tf1.clear(); \
141
return tres; \
142
} \
143
\
144
TEMPLATE \
145
tmp<Field<ReturnType>> Func \
146
( \
147
const tmp<Field<Type1>>& tf1, \
148
const tmp<Field<Type2>>& tf2 \
149
) \
150
{ \
151
auto tres = reuseTmpTmp<ReturnType, Type1, Type1, Type2>::New(tf1, tf2); \
152
Func(tres.ref(), tf1(), tf2()); \
153
tf1.clear(); \
154
tf2.clear(); \
155
return tres; \
156
}
157
158
159
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160
161
#define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
162
\
163
TEMPLATE \
164
void Func \
165
( \
166
Field<ReturnType>& res, \
167
const Type1& s1, \
168
const UList<Type2>& f2 \
169
) \
170
{ \
171
TFOR_ALL_F_OP_FUNC_S_F \
172
( \
173
ReturnType, res, =, ::Foam::Func, Type1, s1, Type2, f2 \
174
) \
175
} \
176
\
177
TEMPLATE \
178
tmp<Field<ReturnType>> Func \
179
( \
180
const Type1& s1, \
181
const UList<Type2>& f2 \
182
) \
183
{ \
184
auto tres = tmp<Field<ReturnType>>::New(f2.size()); \
185
Func(tres.ref(), s1, f2); \
186
return tres; \
187
} \
188
\
189
TEMPLATE \
190
tmp<Field<ReturnType>> Func \
191
( \
192
const Type1& s1, \
193
const tmp<Field<Type2>>& tf2 \
194
) \
195
{ \
196
auto tres = reuseTmp<ReturnType, Type2>::New(tf2); \
197
Func(tres.ref(), s1, tf2()); \
198
tf2.clear(); \
199
return tres; \
200
}
201
202
203
#define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \
204
\
205
TEMPLATE \
206
void Func \
207
( \
208
Field<ReturnType>& res, \
209
const UList<Type1>& f1, \
210
const Type2& s2 \
211
) \
212
{ \
213
TFOR_ALL_F_OP_FUNC_F_S \
214
( \
215
ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, s2 \
216
) \
217
} \
218
\
219
TEMPLATE \
220
tmp<Field<ReturnType>> Func \
221
( \
222
const UList<Type1>& f1, \
223
const Type2& s2 \
224
) \
225
{ \
226
auto tres = tmp<Field<ReturnType>>::New(f1.size()); \
227
Func(tres.ref(), f1, s2); \
228
return tres; \
229
} \
230
\
231
TEMPLATE \
232
tmp<Field<ReturnType>> Func \
233
( \
234
const tmp<Field<Type1>>& tf1, \
235
const Type2& s2 \
236
) \
237
{ \
238
auto tres = reuseTmp<ReturnType, Type1>::New(tf1); \
239
Func(tres.ref(), tf1(), s2); \
240
tf1.clear(); \
241
return tres; \
242
}
243
244
245
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func) \
246
BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
247
BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
248
249
250
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251
252
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
253
\
254
TEMPLATE \
255
void OpFunc \
256
( \
257
Field<ReturnType>& res, \
258
const UList<Type1>& f1, \
259
const UList<Type2>& f2 \
260
) \
261
{ \
262
TFOR_ALL_F_OP_F_OP_F(ReturnType, res, =, Type1, f1, Op, Type2, f2) \
263
} \
264
\
265
TEMPLATE \
266
tmp<Field<ReturnType>> operator Op \
267
( \
268
const UList<Type1>& f1, \
269
const UList<Type2>& f2 \
270
) \
271
{ \
272
auto tres = tmp<Field<ReturnType>>::New(f1.size()); \
273
OpFunc(tres.ref(), f1, f2); \
274
return tres; \
275
} \
276
\
277
TEMPLATE \
278
tmp<Field<ReturnType>> operator Op \
279
( \
280
const UList<Type1>& f1, \
281
const tmp<Field<Type2>>& tf2 \
282
) \
283
{ \
284
auto tres = reuseTmp<ReturnType, Type2>::New(tf2); \
285
OpFunc(tres.ref(), f1, tf2()); \
286
tf2.clear(); \
287
return tres; \
288
} \
289
\
290
TEMPLATE \
291
tmp<Field<ReturnType>> operator Op \
292
( \
293
const tmp<Field<Type1>>& tf1, \
294
const UList<Type2>& f2 \
295
) \
296
{ \
297
auto tres = reuseTmp<ReturnType, Type1>::New(tf1); \
298
OpFunc(tres.ref(), tf1(), f2); \
299
tf1.clear(); \
300
return tres; \
301
} \
302
\
303
TEMPLATE \
304
tmp<Field<ReturnType>> operator Op \
305
( \
306
const tmp<Field<Type1>>& tf1, \
307
const tmp<Field<Type2>>& tf2 \
308
) \
309
{ \
310
auto tres = reuseTmpTmp<ReturnType, Type1, Type1, Type2>::New(tf1, tf2); \
311
OpFunc(tres.ref(), tf1(), tf2()); \
312
tf1.clear(); \
313
tf2.clear(); \
314
return tres; \
315
}
316
317
318
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319
320
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
321
\
322
TEMPLATE \
323
void OpFunc \
324
( \
325
Field<ReturnType>& res, \
326
const Type1& s1, \
327
const UList<Type2>& f2 \
328
) \
329
{ \
330
TFOR_ALL_F_OP_S_OP_F(ReturnType, res, =, Type1, s1, Op, Type2, f2) \
331
} \
332
\
333
TEMPLATE \
334
tmp<Field<ReturnType>> operator Op \
335
( \
336
const Type1& s1, \
337
const UList<Type2>& f2 \
338
) \
339
{ \
340
auto tres = tmp<Field<ReturnType>>::New(f2.size()); \
341
OpFunc(tres.ref(), s1, f2); \
342
return tres; \
343
} \
344
\
345
TEMPLATE \
346
tmp<Field<ReturnType>> operator Op \
347
( \
348
const Type1& s1, \
349
const tmp<Field<Type2>>& tf2 \
350
) \
351
{ \
352
auto tres = reuseTmp<ReturnType, Type2>::New(tf2); \
353
OpFunc(tres.ref(), s1, tf2()); \
354
tf2.clear(); \
355
return tres; \
356
}
357
358
359
#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc) \
360
\
361
TEMPLATE \
362
void OpFunc \
363
( \
364
Field<ReturnType>& res, \
365
const UList<Type1>& f1, \
366
const Type2& s2 \
367
) \
368
{ \
369
TFOR_ALL_F_OP_F_OP_S(ReturnType, res, =, Type1, f1, Op, Type2, s2) \
370
} \
371
\
372
TEMPLATE \
373
tmp<Field<ReturnType>> operator Op \
374
( \
375
const UList<Type1>& f1, \
376
const Type2& s2 \
377
) \
378
{ \
379
auto tres = tmp<Field<ReturnType>>::New(f1.size()); \
380
OpFunc(tres.ref(), f1, s2); \
381
return tres; \
382
} \
383
\
384
TEMPLATE \
385
tmp<Field<ReturnType>> operator Op \
386
( \
387
const tmp<Field<Type1>>& tf1, \
388
const Type2& s2 \
389
) \
390
{ \
391
auto tres = reuseTmp<ReturnType, Type1>::New(tf1); \
392
OpFunc(tres.ref(), tf1(), s2); \
393
tf1.clear(); \
394
return tres; \
395
}
396
397
398
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
399
BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
400
BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc)
401
402
403
// ************************************************************************* //
FieldM.H
High performance macro functions for Field<Type> algebra. These expand using either array element acc...
FieldReuseFunctions.H
src
OpenFOAM
fields
Fields
Field
FieldFunctionsM.C
Generated by
1.8.17
OPENFOAM® is a registered
trademark
of OpenCFD Ltd.