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 | Copyright (C) 2011 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(), 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(), tf()); \
52  reuseTmp<ReturnType, Type>::clear(tf); \
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(), 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(), tf()); \
80  reuseTmp<ReturnType, Type>::clear(tf); \
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(), 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(), f1, tf2()); \
124  reuseTmp<ReturnType, Type2>::clear(tf2); \
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(), tf1(), f2); \
137  reuseTmp<ReturnType, Type1>::clear(tf1); \
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(), tf1(), tf2()); \
151  reuseTmpTmp<ReturnType, Type1, Type1, Type2>::clear(tf1, tf2); \
152  return tRes; \
153 }
154 
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
159  \
160 TEMPLATE \
161 void Func \
162 ( \
163  Field<ReturnType>& res, \
164  const Type1& s1, \
165  const UList<Type2>& f2 \
166 ) \
167 { \
168  TFOR_ALL_F_OP_FUNC_S_F \
169  ( \
170  ReturnType, res, =, ::Foam::Func, Type1, s1, Type2, f2 \
171  ) \
172 } \
173  \
174 TEMPLATE \
175 tmp<Field<ReturnType> > Func \
176 ( \
177  const Type1& s1, \
178  const UList<Type2>& f2 \
179 ) \
180 { \
181  tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f2.size())); \
182  Func(tRes(), s1, f2); \
183  return tRes; \
184 } \
185  \
186 TEMPLATE \
187 tmp<Field<ReturnType> > Func \
188 ( \
189  const Type1& s1, \
190  const tmp<Field<Type2> >& tf2 \
191 ) \
192 { \
193  tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
194  Func(tRes(), s1, tf2()); \
195  reuseTmp<ReturnType, Type2>::clear(tf2); \
196  return tRes; \
197 }
198 
199 
200 #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \
201  \
202 TEMPLATE \
203 void Func \
204 ( \
205  Field<ReturnType>& res, \
206  const UList<Type1>& f1, \
207  const Type2& s2 \
208 ) \
209 { \
210  TFOR_ALL_F_OP_FUNC_F_S \
211  ( \
212  ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, s2 \
213  ) \
214 } \
215  \
216 TEMPLATE \
217 tmp<Field<ReturnType> > Func \
218 ( \
219  const UList<Type1>& f1, \
220  const Type2& s2 \
221 ) \
222 { \
223  tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
224  Func(tRes(), f1, s2); \
225  return tRes; \
226 } \
227  \
228 TEMPLATE \
229 tmp<Field<ReturnType> > Func \
230 ( \
231  const tmp<Field<Type1> >& tf1, \
232  const Type2& s2 \
233 ) \
234 { \
235  tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
236  Func(tRes(), tf1(), s2); \
237  reuseTmp<ReturnType, Type1>::clear(tf1); \
238  return tRes; \
239 }
240 
241 
242 #define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func) \
243  BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
244  BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
245 
246 
247 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 
249 #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
250  \
251 TEMPLATE \
252 void OpFunc \
253 ( \
254  Field<ReturnType>& res, \
255  const UList<Type1>& f1, \
256  const UList<Type2>& f2 \
257 ) \
258 { \
259  TFOR_ALL_F_OP_F_OP_F(ReturnType, res, =, Type1, f1, Op, Type2, f2) \
260 } \
261  \
262 TEMPLATE \
263 tmp<Field<ReturnType> > operator Op \
264 ( \
265  const UList<Type1>& f1, \
266  const UList<Type2>& f2 \
267 ) \
268 { \
269  tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
270  OpFunc(tRes(), f1, f2); \
271  return tRes; \
272 } \
273  \
274 TEMPLATE \
275 tmp<Field<ReturnType> > operator Op \
276 ( \
277  const UList<Type1>& f1, \
278  const tmp<Field<Type2> >& tf2 \
279 ) \
280 { \
281  tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
282  OpFunc(tRes(), f1, tf2()); \
283  reuseTmp<ReturnType, Type2>::clear(tf2); \
284  return tRes; \
285 } \
286  \
287 TEMPLATE \
288 tmp<Field<ReturnType> > operator Op \
289 ( \
290  const tmp<Field<Type1> >& tf1, \
291  const UList<Type2>& f2 \
292 ) \
293 { \
294  tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
295  OpFunc(tRes(), tf1(), f2); \
296  reuseTmp<ReturnType, Type1>::clear(tf1); \
297  return tRes; \
298 } \
299  \
300 TEMPLATE \
301 tmp<Field<ReturnType> > operator Op \
302 ( \
303  const tmp<Field<Type1> >& tf1, \
304  const tmp<Field<Type2> >& tf2 \
305 ) \
306 { \
307  tmp<Field<ReturnType> > tRes = \
308  reuseTmpTmp<ReturnType, Type1, Type1, Type2>::New(tf1, tf2); \
309  OpFunc(tRes(), tf1(), tf2()); \
310  reuseTmpTmp<ReturnType, Type1, Type1, Type2>::clear(tf1, tf2); \
311  return tRes; \
312 }
313 
314 
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 
317 #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
318  \
319 TEMPLATE \
320 void OpFunc \
321 ( \
322  Field<ReturnType>& res, \
323  const Type1& s1, \
324  const UList<Type2>& f2 \
325 ) \
326 { \
327  TFOR_ALL_F_OP_S_OP_F(ReturnType, res, =, Type1, s1, Op, Type2, f2) \
328 } \
329  \
330 TEMPLATE \
331 tmp<Field<ReturnType> > operator Op \
332 ( \
333  const Type1& s1, \
334  const UList<Type2>& f2 \
335 ) \
336 { \
337  tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f2.size())); \
338  OpFunc(tRes(), s1, f2); \
339  return tRes; \
340 } \
341  \
342 TEMPLATE \
343 tmp<Field<ReturnType> > operator Op \
344 ( \
345  const Type1& s1, \
346  const tmp<Field<Type2> >& tf2 \
347 ) \
348 { \
349  tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
350  OpFunc(tRes(), s1, tf2()); \
351  reuseTmp<ReturnType, Type2>::clear(tf2); \
352  return tRes; \
353 }
354 
355 
356 #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc) \
357  \
358 TEMPLATE \
359 void OpFunc \
360 ( \
361  Field<ReturnType>& res, \
362  const UList<Type1>& f1, \
363  const Type2& s2 \
364 ) \
365 { \
366  TFOR_ALL_F_OP_F_OP_S(ReturnType, res, =, Type1, f1, Op, Type2, s2) \
367 } \
368  \
369 TEMPLATE \
370 tmp<Field<ReturnType> > operator Op \
371 ( \
372  const UList<Type1>& f1, \
373  const Type2& s2 \
374 ) \
375 { \
376  tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
377  OpFunc(tRes(), f1, s2); \
378  return tRes; \
379 } \
380  \
381 TEMPLATE \
382 tmp<Field<ReturnType> > operator Op \
383 ( \
384  const tmp<Field<Type1> >& tf1, \
385  const Type2& s2 \
386 ) \
387 { \
388  tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
389  OpFunc(tRes(), tf1(), s2); \
390  reuseTmp<ReturnType, Type1>::clear(tf1); \
391  return tRes; \
392 }
393 
394 
395 #define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
396  BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
397  BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc)
398 
399 
400 // ************************************************************************* //
FieldM.H
High performance macro functions for Field<Type> algebra. These expand using either array element acc...
FieldReuseFunctions.H