OpenFOAM
dev
The OpenFOAM Foundation
FieldFunctionsM.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
"
27
#include "
FieldReuseFunctions.H
"
28
29
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30
31
#define UNARY_FUNCTION(ReturnType, Type, Func) \
32
\
33
TEMPLATE \
34
void Func(Field<ReturnType>& res, const UList<Type>& f) \
35
{ \
36
TFOR_ALL_F_OP_FUNC_F(ReturnType, res, =, ::Foam::Func, Type, f) \
37
} \
38
\
39
TEMPLATE \
40
tmp<Field<ReturnType>> Func(const UList<Type>& f) \
41
{ \
42
tmp<Field<ReturnType>> tRes(new Field<ReturnType>(f.size())); \
43
Func(tRes.ref(), f); \
44
return tRes; \
45
} \
46
\
47
TEMPLATE \
48
tmp<Field<ReturnType>> Func(const tmp<Field<Type>>& tf) \
49
{ \
50
tmp<Field<ReturnType>> tRes = reuseTmp<ReturnType, Type>::New(tf); \
51
Func(tRes.ref(), tf()); \
52
tf.clear(); \
53
return tRes; \
54
}
55
56
57
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58
59
#define UNARY_OPERATOR(ReturnType, Type, Op, OpFunc) \
60
\
61
TEMPLATE \
62
void OpFunc(Field<ReturnType>& res, const UList<Type>& f) \
63
{ \
64
TFOR_ALL_F_OP_OP_F(ReturnType, res, =, Op, Type, f) \
65
} \
66
\
67
TEMPLATE \
68
tmp<Field<ReturnType>> operator Op(const UList<Type>& f) \
69
{ \
70
tmp<Field<ReturnType>> tRes(new Field<ReturnType>(f.size())); \
71
OpFunc(tRes.ref(), f); \
72
return tRes; \
73
} \
74
\
75
TEMPLATE \
76
tmp<Field<ReturnType>> operator Op(const tmp<Field<Type>>& tf) \
77
{ \
78
tmp<Field<ReturnType>> tRes = reuseTmp<ReturnType, Type>::New(tf); \
79
OpFunc(tRes.ref(), tf()); \
80
tf.clear(); \
81
return tRes; \
82
}
83
84
85
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
86
87
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \
88
\
89
TEMPLATE \
90
void Func \
91
( \
92
Field<ReturnType>& res, \
93
const UList<Type1>& f1, \
94
const UList<Type2>& f2 \
95
) \
96
{ \
97
TFOR_ALL_F_OP_FUNC_F_F \
98
( \
99
ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, f2 \
100
) \
101
} \
102
\
103
TEMPLATE \
104
tmp<Field<ReturnType>> Func \
105
( \
106
const UList<Type1>& f1, \
107
const UList<Type2>& f2 \
108
) \
109
{ \
110
tmp<Field<ReturnType>> tRes(new Field<ReturnType>(f1.size())); \
111
Func(tRes.ref(), f1, f2); \
112
return tRes; \
113
} \
114
\
115
TEMPLATE \
116
tmp<Field<ReturnType>> Func \
117
( \
118
const UList<Type1>& f1, \
119
const tmp<Field<Type2>>& tf2 \
120
) \
121
{ \
122
tmp<Field<ReturnType>> tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
123
Func(tRes.ref(), f1, tf2()); \
124
tf2.clear(); \
125
return tRes; \
126
} \
127
\
128
TEMPLATE \
129
tmp<Field<ReturnType>> Func \
130
( \
131
const tmp<Field<Type1>>& tf1, \
132
const UList<Type2>& f2 \
133
) \
134
{ \
135
tmp<Field<ReturnType>> tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
136
Func(tRes.ref(), tf1(), f2); \
137
tf1.clear(); \
138
return tRes; \
139
} \
140
\
141
TEMPLATE \
142
tmp<Field<ReturnType>> Func \
143
( \
144
const tmp<Field<Type1>>& tf1, \
145
const tmp<Field<Type2>>& tf2 \
146
) \
147
{ \
148
tmp<Field<ReturnType>> tRes = \
149
reuseTmpTmp<ReturnType, Type1, Type1, Type2>::New(tf1, tf2); \
150
Func(tRes.ref(), tf1(), tf2()); \
151
tf1.clear(); \
152
tf2.clear(); \
153
return tRes; \
154
}
155
156
157
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158
159
#define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
160
\
161
TEMPLATE \
162
void Func \
163
( \
164
Field<ReturnType>& res, \
165
const Type1& s1, \
166
const UList<Type2>& f2 \
167
) \
168
{ \
169
TFOR_ALL_F_OP_FUNC_S_F \
170
( \
171
ReturnType, res, =, ::Foam::Func, Type1, s1, Type2, f2 \
172
) \
173
} \
174
\
175
TEMPLATE \
176
tmp<Field<ReturnType>> Func \
177
( \
178
const Type1& s1, \
179
const UList<Type2>& f2 \
180
) \
181
{ \
182
tmp<Field<ReturnType>> tRes(new Field<ReturnType>(f2.size())); \
183
Func(tRes.ref(), s1, f2); \
184
return tRes; \
185
} \
186
\
187
TEMPLATE \
188
tmp<Field<ReturnType>> Func \
189
( \
190
const Type1& s1, \
191
const tmp<Field<Type2>>& tf2 \
192
) \
193
{ \
194
tmp<Field<ReturnType>> tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
195
Func(tRes.ref(), s1, tf2()); \
196
tf2.clear(); \
197
return tRes; \
198
}
199
200
201
#define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \
202
\
203
TEMPLATE \
204
void Func \
205
( \
206
Field<ReturnType>& res, \
207
const UList<Type1>& f1, \
208
const Type2& s2 \
209
) \
210
{ \
211
TFOR_ALL_F_OP_FUNC_F_S \
212
( \
213
ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, s2 \
214
) \
215
} \
216
\
217
TEMPLATE \
218
tmp<Field<ReturnType>> Func \
219
( \
220
const UList<Type1>& f1, \
221
const Type2& s2 \
222
) \
223
{ \
224
tmp<Field<ReturnType>> tRes(new Field<ReturnType>(f1.size())); \
225
Func(tRes.ref(), f1, s2); \
226
return tRes; \
227
} \
228
\
229
TEMPLATE \
230
tmp<Field<ReturnType>> Func \
231
( \
232
const tmp<Field<Type1>>& tf1, \
233
const Type2& s2 \
234
) \
235
{ \
236
tmp<Field<ReturnType>> tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
237
Func(tRes.ref(), tf1(), s2); \
238
tf1.clear(); \
239
return tRes; \
240
}
241
242
243
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func) \
244
BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
245
BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
246
247
248
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249
250
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
251
\
252
TEMPLATE \
253
void OpFunc \
254
( \
255
Field<ReturnType>& res, \
256
const UList<Type1>& f1, \
257
const UList<Type2>& f2 \
258
) \
259
{ \
260
TFOR_ALL_F_OP_F_OP_F(ReturnType, res, =, Type1, f1, Op, Type2, f2) \
261
} \
262
\
263
TEMPLATE \
264
tmp<Field<ReturnType>> operator Op \
265
( \
266
const UList<Type1>& f1, \
267
const UList<Type2>& f2 \
268
) \
269
{ \
270
tmp<Field<ReturnType>> tRes(new Field<ReturnType>(f1.size())); \
271
OpFunc(tRes.ref(), f1, f2); \
272
return tRes; \
273
} \
274
\
275
TEMPLATE \
276
tmp<Field<ReturnType>> operator Op \
277
( \
278
const UList<Type1>& f1, \
279
const tmp<Field<Type2>>& tf2 \
280
) \
281
{ \
282
tmp<Field<ReturnType>> tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
283
OpFunc(tRes.ref(), f1, tf2()); \
284
tf2.clear(); \
285
return tRes; \
286
} \
287
\
288
TEMPLATE \
289
tmp<Field<ReturnType>> operator Op \
290
( \
291
const tmp<Field<Type1>>& tf1, \
292
const UList<Type2>& f2 \
293
) \
294
{ \
295
tmp<Field<ReturnType>> tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
296
OpFunc(tRes.ref(), tf1(), f2); \
297
tf1.clear(); \
298
return tRes; \
299
} \
300
\
301
TEMPLATE \
302
tmp<Field<ReturnType>> operator Op \
303
( \
304
const tmp<Field<Type1>>& tf1, \
305
const tmp<Field<Type2>>& tf2 \
306
) \
307
{ \
308
tmp<Field<ReturnType>> tRes = \
309
reuseTmpTmp<ReturnType, Type1, Type1, Type2>::New(tf1, tf2); \
310
OpFunc(tRes.ref(), tf1(), tf2()); \
311
tf1.clear(); \
312
tf2.clear(); \
313
return tRes; \
314
}
315
316
317
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
318
319
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
320
\
321
TEMPLATE \
322
void OpFunc \
323
( \
324
Field<ReturnType>& res, \
325
const Type1& s1, \
326
const UList<Type2>& f2 \
327
) \
328
{ \
329
TFOR_ALL_F_OP_S_OP_F(ReturnType, res, =, Type1, s1, Op, Type2, f2) \
330
} \
331
\
332
TEMPLATE \
333
tmp<Field<ReturnType>> operator Op \
334
( \
335
const Type1& s1, \
336
const UList<Type2>& f2 \
337
) \
338
{ \
339
tmp<Field<ReturnType>> tRes(new Field<ReturnType>(f2.size())); \
340
OpFunc(tRes.ref(), s1, f2); \
341
return tRes; \
342
} \
343
\
344
TEMPLATE \
345
tmp<Field<ReturnType>> operator Op \
346
( \
347
const Type1& s1, \
348
const tmp<Field<Type2>>& tf2 \
349
) \
350
{ \
351
tmp<Field<ReturnType>> tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
352
OpFunc(tRes.ref(), s1, tf2()); \
353
tf2.clear(); \
354
return tRes; \
355
}
356
357
358
#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc) \
359
\
360
TEMPLATE \
361
void OpFunc \
362
( \
363
Field<ReturnType>& res, \
364
const UList<Type1>& f1, \
365
const Type2& s2 \
366
) \
367
{ \
368
TFOR_ALL_F_OP_F_OP_S(ReturnType, res, =, Type1, f1, Op, Type2, s2) \
369
} \
370
\
371
TEMPLATE \
372
tmp<Field<ReturnType>> operator Op \
373
( \
374
const UList<Type1>& f1, \
375
const Type2& s2 \
376
) \
377
{ \
378
tmp<Field<ReturnType>> tRes(new Field<ReturnType>(f1.size())); \
379
OpFunc(tRes.ref(), f1, s2); \
380
return tRes; \
381
} \
382
\
383
TEMPLATE \
384
tmp<Field<ReturnType>> operator Op \
385
( \
386
const tmp<Field<Type1>>& tf1, \
387
const Type2& s2 \
388
) \
389
{ \
390
tmp<Field<ReturnType>> tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
391
OpFunc(tRes.ref(), tf1(), s2); \
392
tf1.clear(); \
393
return tRes; \
394
}
395
396
397
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
398
BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
399
BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc)
400
401
402
// ************************************************************************* //
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.9.1