1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "FieldReuseFunctions.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 #define UNARY_FUNCTION(ReturnType, Type, Func) \
35 void Func(Field<ReturnType>& res, const UList<Type>& f) \
37 TFOR_ALL_F_OP_FUNC_F(ReturnType, res, =, ::Foam::Func, Type, f) \
41 tmp<Field<ReturnType> > Func(const UList<Type>& f) \
43 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f.size())); \
49 tmp<Field<ReturnType> > Func(const tmp<Field<Type> >& tf) \
51 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type>::New(tf); \
53 reuseTmp<ReturnType, Type>::clear(tf); \
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 #define UNARY_OPERATOR(ReturnType, Type, Op, OpFunc) \
63 void OpFunc(Field<ReturnType>& res, const UList<Type>& f) \
65 TFOR_ALL_F_OP_OP_F(ReturnType, res, =, Op, Type, f) \
69 tmp<Field<ReturnType> > operator Op(const UList<Type>& f) \
71 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f.size())); \
77 tmp<Field<ReturnType> > operator Op(const tmp<Field<Type> >& tf) \
79 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type>::New(tf); \
80 OpFunc(tRes(), tf()); \
81 reuseTmp<ReturnType, Type>::clear(tf); \
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
88 #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \
93 Field<ReturnType>& res, \
94 const UList<Type1>& f1, \
95 const UList<Type2>& f2 \
98 TFOR_ALL_F_OP_FUNC_F_F \
100 ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, f2 \
105 tmp<Field<ReturnType> > Func \
107 const UList<Type1>& f1, \
108 const UList<Type2>& f2 \
111 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
112 Func(tRes(), f1, f2); \
117 tmp<Field<ReturnType> > Func \
119 const UList<Type1>& f1, \
120 const tmp<Field<Type2> >& tf2 \
123 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
124 Func(tRes(), f1, tf2()); \
125 reuseTmp<ReturnType, Type2>::clear(tf2); \
130 tmp<Field<ReturnType> > Func \
132 const tmp<Field<Type1> >& tf1, \
133 const UList<Type2>& f2 \
136 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
137 Func(tRes(), tf1(), f2); \
138 reuseTmp<ReturnType, Type1>::clear(tf1); \
143 tmp<Field<ReturnType> > Func \
145 const tmp<Field<Type1> >& tf1, \
146 const tmp<Field<Type2> >& tf2 \
149 tmp<Field<ReturnType> > tRes = \
150 reuseTmpTmp<ReturnType, Type1, Type1, Type2>::New(tf1, tf2); \
151 Func(tRes(), tf1(), tf2()); \
152 reuseTmpTmp<ReturnType, Type1, Type1, Type2>::clear(tf1, tf2); \
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
164 Field<ReturnType>& res, \
166 const UList<Type2>& f2 \
169 TFOR_ALL_F_OP_FUNC_S_F \
171 ReturnType, res, =, ::Foam::Func, Type1, s1, Type2, f2 \
176 tmp<Field<ReturnType> > Func \
179 const UList<Type2>& f2 \
182 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f2.size())); \
183 Func(tRes(), s1, f2); \
188 tmp<Field<ReturnType> > Func \
191 const tmp<Field<Type2> >& tf2 \
194 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
195 Func(tRes(), s1, tf2()); \
196 reuseTmp<ReturnType, Type2>::clear(tf2); \
201 #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \
206 Field<ReturnType>& res, \
207 const UList<Type1>& f1, \
211 TFOR_ALL_F_OP_FUNC_F_S \
213 ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, s2 \
218 tmp<Field<ReturnType> > Func \
220 const UList<Type1>& f1, \
224 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
225 Func(tRes(), f1, s2); \
230 tmp<Field<ReturnType> > Func \
232 const tmp<Field<Type1> >& tf1, \
236 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
237 Func(tRes(), tf1(), s2); \
238 reuseTmp<ReturnType, Type1>::clear(tf1); \
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)
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
255 Field<ReturnType>& res, \
256 const UList<Type1>& f1, \
257 const UList<Type2>& f2 \
260 TFOR_ALL_F_OP_F_OP_F(ReturnType, res, =, Type1, f1, Op, Type2, f2) \
264 tmp<Field<ReturnType> > operator Op \
266 const UList<Type1>& f1, \
267 const UList<Type2>& f2 \
270 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
271 OpFunc(tRes(), f1, f2); \
276 tmp<Field<ReturnType> > operator Op \
278 const UList<Type1>& f1, \
279 const tmp<Field<Type2> >& tf2 \
282 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
283 OpFunc(tRes(), f1, tf2()); \
284 reuseTmp<ReturnType, Type2>::clear(tf2); \
289 tmp<Field<ReturnType> > operator Op \
291 const tmp<Field<Type1> >& tf1, \
292 const UList<Type2>& f2 \
295 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
296 OpFunc(tRes(), tf1(), f2); \
297 reuseTmp<ReturnType, Type1>::clear(tf1); \
302 tmp<Field<ReturnType> > operator Op \
304 const tmp<Field<Type1> >& tf1, \
305 const tmp<Field<Type2> >& tf2 \
308 tmp<Field<ReturnType> > tRes = \
309 reuseTmpTmp<ReturnType, Type1, Type1, Type2>::New(tf1, tf2); \
310 OpFunc(tRes(), tf1(), tf2()); \
311 reuseTmpTmp<ReturnType, Type1, Type1, Type2>::clear(tf1, tf2); \
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
318 #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
323 Field<ReturnType>& res, \
325 const UList<Type2>& f2 \
328 TFOR_ALL_F_OP_S_OP_F(ReturnType, res, =, Type1, s1, Op, Type2, f2) \
332 tmp<Field<ReturnType> > operator Op \
335 const UList<Type2>& f2 \
338 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f2.size())); \
339 OpFunc(tRes(), s1, f2); \
344 tmp<Field<ReturnType> > operator Op \
347 const tmp<Field<Type2> >& tf2 \
350 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
351 OpFunc(tRes(), s1, tf2()); \
352 reuseTmp<ReturnType, Type2>::clear(tf2); \
357 #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc) \
362 Field<ReturnType>& res, \
363 const UList<Type1>& f1, \
367 TFOR_ALL_F_OP_F_OP_S(ReturnType, res, =, Type1, f1, Op, Type2, s2) \
371 tmp<Field<ReturnType> > operator Op \
373 const UList<Type1>& f1, \
377 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
378 OpFunc(tRes(), f1, s2); \
383 tmp<Field<ReturnType> > operator Op \
385 const tmp<Field<Type1> >& tf1, \
389 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
390 OpFunc(tRes(), tf1(), s2); \
391 reuseTmp<ReturnType, Type1>::clear(tf1); \
396 #define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
397 BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
398 BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc)
401 // ************************************************************************* //