1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
27 #include "FieldReuseFunctions.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 #define UNARY_FUNCTION(ReturnType, Type, Func) \
34 void Func(Field<ReturnType>& res, const UList<Type>& f) \
36 TFOR_ALL_F_OP_FUNC_F(ReturnType, res, =, ::Foam::Func, Type, f) \
40 tmp<Field<ReturnType> > Func(const UList<Type>& f) \
42 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f.size())); \
48 tmp<Field<ReturnType> > Func(const tmp<Field<Type> >& tf) \
50 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type>::New(tf); \
52 reuseTmp<ReturnType, Type>::clear(tf); \
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 #define UNARY_OPERATOR(ReturnType, Type, Op, OpFunc) \
62 void OpFunc(Field<ReturnType>& res, const UList<Type>& f) \
64 TFOR_ALL_F_OP_OP_F(ReturnType, res, =, Op, Type, f) \
68 tmp<Field<ReturnType> > operator Op(const UList<Type>& f) \
70 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f.size())); \
76 tmp<Field<ReturnType> > operator Op(const tmp<Field<Type> >& tf) \
78 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type>::New(tf); \
79 OpFunc(tRes(), tf()); \
80 reuseTmp<ReturnType, Type>::clear(tf); \
85 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
87 #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \
92 Field<ReturnType>& res, \
93 const UList<Type1>& f1, \
94 const UList<Type2>& f2 \
97 TFOR_ALL_F_OP_FUNC_F_F \
99 ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, f2 \
104 tmp<Field<ReturnType> > Func \
106 const UList<Type1>& f1, \
107 const UList<Type2>& f2 \
110 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
111 Func(tRes(), f1, f2); \
116 tmp<Field<ReturnType> > Func \
118 const UList<Type1>& f1, \
119 const tmp<Field<Type2> >& tf2 \
122 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
123 Func(tRes(), f1, tf2()); \
124 reuseTmp<ReturnType, Type2>::clear(tf2); \
129 tmp<Field<ReturnType> > Func \
131 const tmp<Field<Type1> >& tf1, \
132 const UList<Type2>& f2 \
135 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
136 Func(tRes(), tf1(), f2); \
137 reuseTmp<ReturnType, Type1>::clear(tf1); \
142 tmp<Field<ReturnType> > Func \
144 const tmp<Field<Type1> >& tf1, \
145 const tmp<Field<Type2> >& tf2 \
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); \
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
163 Field<ReturnType>& res, \
165 const UList<Type2>& f2 \
168 TFOR_ALL_F_OP_FUNC_S_F \
170 ReturnType, res, =, ::Foam::Func, Type1, s1, Type2, f2 \
175 tmp<Field<ReturnType> > Func \
178 const UList<Type2>& f2 \
181 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f2.size())); \
182 Func(tRes(), s1, f2); \
187 tmp<Field<ReturnType> > Func \
190 const tmp<Field<Type2> >& tf2 \
193 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
194 Func(tRes(), s1, tf2()); \
195 reuseTmp<ReturnType, Type2>::clear(tf2); \
200 #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \
205 Field<ReturnType>& res, \
206 const UList<Type1>& f1, \
210 TFOR_ALL_F_OP_FUNC_F_S \
212 ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, s2 \
217 tmp<Field<ReturnType> > Func \
219 const UList<Type1>& f1, \
223 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
224 Func(tRes(), f1, s2); \
229 tmp<Field<ReturnType> > Func \
231 const tmp<Field<Type1> >& tf1, \
235 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
236 Func(tRes(), tf1(), s2); \
237 reuseTmp<ReturnType, Type1>::clear(tf1); \
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)
247 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
254 Field<ReturnType>& res, \
255 const UList<Type1>& f1, \
256 const UList<Type2>& f2 \
259 TFOR_ALL_F_OP_F_OP_F(ReturnType, res, =, Type1, f1, Op, Type2, f2) \
263 tmp<Field<ReturnType> > operator Op \
265 const UList<Type1>& f1, \
266 const UList<Type2>& f2 \
269 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
270 OpFunc(tRes(), f1, f2); \
275 tmp<Field<ReturnType> > operator Op \
277 const UList<Type1>& f1, \
278 const tmp<Field<Type2> >& tf2 \
281 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
282 OpFunc(tRes(), f1, tf2()); \
283 reuseTmp<ReturnType, Type2>::clear(tf2); \
288 tmp<Field<ReturnType> > operator Op \
290 const tmp<Field<Type1> >& tf1, \
291 const UList<Type2>& f2 \
294 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
295 OpFunc(tRes(), tf1(), f2); \
296 reuseTmp<ReturnType, Type1>::clear(tf1); \
301 tmp<Field<ReturnType> > operator Op \
303 const tmp<Field<Type1> >& tf1, \
304 const tmp<Field<Type2> >& tf2 \
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); \
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317 #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
322 Field<ReturnType>& res, \
324 const UList<Type2>& f2 \
327 TFOR_ALL_F_OP_S_OP_F(ReturnType, res, =, Type1, s1, Op, Type2, f2) \
331 tmp<Field<ReturnType> > operator Op \
334 const UList<Type2>& f2 \
337 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f2.size())); \
338 OpFunc(tRes(), s1, f2); \
343 tmp<Field<ReturnType> > operator Op \
346 const tmp<Field<Type2> >& tf2 \
349 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
350 OpFunc(tRes(), s1, tf2()); \
351 reuseTmp<ReturnType, Type2>::clear(tf2); \
356 #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc) \
361 Field<ReturnType>& res, \
362 const UList<Type1>& f1, \
366 TFOR_ALL_F_OP_F_OP_S(ReturnType, res, =, Type1, f1, Op, Type2, s2) \
370 tmp<Field<ReturnType> > operator Op \
372 const UList<Type1>& f1, \
376 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
377 OpFunc(tRes(), f1, s2); \
382 tmp<Field<ReturnType> > operator Op \
384 const tmp<Field<Type1> >& tf1, \
388 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
389 OpFunc(tRes(), tf1(), s2); \
390 reuseTmp<ReturnType, Type1>::clear(tf1); \
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)
400 // ************************************************************************* //