00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <OpenFOAM/FieldM.H>
00027 #include <OpenFOAM/FieldReuseFunctions.H>
00028
00029
00030
00031 #define UNARY_FUNCTION(ReturnType, Type, Func) \
00032 \
00033 TEMPLATE \
00034 void Func(Field<ReturnType>& res, const UList<Type>& f) \
00035 { \
00036 TFOR_ALL_F_OP_FUNC_F(ReturnType, res, =, ::Foam::Func, Type, f) \
00037 } \
00038 \
00039 TEMPLATE \
00040 tmp<Field<ReturnType> > Func(const UList<Type>& f) \
00041 { \
00042 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f.size())); \
00043 Func(tRes(), f); \
00044 return tRes; \
00045 } \
00046 \
00047 TEMPLATE \
00048 tmp<Field<ReturnType> > Func(const tmp<Field<Type> >& tf) \
00049 { \
00050 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type>::New(tf); \
00051 Func(tRes(), tf()); \
00052 reuseTmp<ReturnType, Type>::clear(tf); \
00053 return tRes; \
00054 }
00055
00056
00057
00058
00059 #define UNARY_OPERATOR(ReturnType, Type, Op, OpFunc) \
00060 \
00061 TEMPLATE \
00062 void OpFunc(Field<ReturnType>& res, const UList<Type>& f) \
00063 { \
00064 TFOR_ALL_F_OP_OP_F(ReturnType, res, =, Op, Type, f) \
00065 } \
00066 \
00067 TEMPLATE \
00068 tmp<Field<ReturnType> > operator Op(const UList<Type>& f) \
00069 { \
00070 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f.size())); \
00071 OpFunc(tRes(), f); \
00072 return tRes; \
00073 } \
00074 \
00075 TEMPLATE \
00076 tmp<Field<ReturnType> > operator Op(const tmp<Field<Type> >& tf) \
00077 { \
00078 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type>::New(tf); \
00079 OpFunc(tRes(), tf()); \
00080 reuseTmp<ReturnType, Type>::clear(tf); \
00081 return tRes; \
00082 }
00083
00084
00085
00086
00087 #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \
00088 \
00089 TEMPLATE \
00090 void Func \
00091 ( \
00092 Field<ReturnType>& res, \
00093 const UList<Type1>& f1, \
00094 const UList<Type2>& f2 \
00095 ) \
00096 { \
00097 TFOR_ALL_F_OP_FUNC_F_F \
00098 ( \
00099 ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, f2 \
00100 ) \
00101 } \
00102 \
00103 TEMPLATE \
00104 tmp<Field<ReturnType> > Func \
00105 ( \
00106 const UList<Type1>& f1, \
00107 const UList<Type2>& f2 \
00108 ) \
00109 { \
00110 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
00111 Func(tRes(), f1, f2); \
00112 return tRes; \
00113 } \
00114 \
00115 TEMPLATE \
00116 tmp<Field<ReturnType> > Func \
00117 ( \
00118 const UList<Type1>& f1, \
00119 const tmp<Field<Type2> >& tf2 \
00120 ) \
00121 { \
00122 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
00123 Func(tRes(), f1, tf2()); \
00124 reuseTmp<ReturnType, Type2>::clear(tf2); \
00125 return tRes; \
00126 } \
00127 \
00128 TEMPLATE \
00129 tmp<Field<ReturnType> > Func \
00130 ( \
00131 const tmp<Field<Type1> >& tf1, \
00132 const UList<Type2>& f2 \
00133 ) \
00134 { \
00135 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
00136 Func(tRes(), tf1(), f2); \
00137 reuseTmp<ReturnType, Type1>::clear(tf1); \
00138 return tRes; \
00139 } \
00140 \
00141 TEMPLATE \
00142 tmp<Field<ReturnType> > Func \
00143 ( \
00144 const tmp<Field<Type1> >& tf1, \
00145 const tmp<Field<Type2> >& tf2 \
00146 ) \
00147 { \
00148 tmp<Field<ReturnType> > tRes = \
00149 reuseTmpTmp<ReturnType, Type1, Type1, Type2>::New(tf1, tf2); \
00150 Func(tRes(), tf1(), tf2()); \
00151 reuseTmpTmp<ReturnType, Type1, Type1, Type2>::clear(tf1, tf2); \
00152 return tRes; \
00153 }
00154
00155
00156
00157
00158 #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
00159 \
00160 TEMPLATE \
00161 void Func \
00162 ( \
00163 Field<ReturnType>& res, \
00164 const Type1& s1, \
00165 const UList<Type2>& f2 \
00166 ) \
00167 { \
00168 TFOR_ALL_F_OP_FUNC_S_F \
00169 ( \
00170 ReturnType, res, =, ::Foam::Func, Type1, s1, Type2, f2 \
00171 ) \
00172 } \
00173 \
00174 TEMPLATE \
00175 tmp<Field<ReturnType> > Func \
00176 ( \
00177 const Type1& s1, \
00178 const UList<Type2>& f2 \
00179 ) \
00180 { \
00181 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f2.size())); \
00182 Func(tRes(), s1, f2); \
00183 return tRes; \
00184 } \
00185 \
00186 TEMPLATE \
00187 tmp<Field<ReturnType> > Func \
00188 ( \
00189 const Type1& s1, \
00190 const tmp<Field<Type2> >& tf2 \
00191 ) \
00192 { \
00193 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
00194 Func(tRes(), s1, tf2()); \
00195 reuseTmp<ReturnType, Type2>::clear(tf2); \
00196 return tRes; \
00197 }
00198
00199
00200 #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \
00201 \
00202 TEMPLATE \
00203 void Func \
00204 ( \
00205 Field<ReturnType>& res, \
00206 const UList<Type1>& f1, \
00207 const Type2& s2 \
00208 ) \
00209 { \
00210 TFOR_ALL_F_OP_FUNC_F_S \
00211 ( \
00212 ReturnType, res, =, ::Foam::Func, Type1, f1, Type2, s2 \
00213 ) \
00214 } \
00215 \
00216 TEMPLATE \
00217 tmp<Field<ReturnType> > Func \
00218 ( \
00219 const UList<Type1>& f1, \
00220 const Type2& s2 \
00221 ) \
00222 { \
00223 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
00224 Func(tRes(), f1, s2); \
00225 return tRes; \
00226 } \
00227 \
00228 TEMPLATE \
00229 tmp<Field<ReturnType> > Func \
00230 ( \
00231 const tmp<Field<Type1> >& tf1, \
00232 const Type2& s2 \
00233 ) \
00234 { \
00235 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
00236 Func(tRes(), tf1(), s2); \
00237 reuseTmp<ReturnType, Type1>::clear(tf1); \
00238 return tRes; \
00239 }
00240
00241
00242 #define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func) \
00243 BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \
00244 BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
00245
00246
00247
00248
00249 #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
00250 \
00251 TEMPLATE \
00252 void OpFunc \
00253 ( \
00254 Field<ReturnType>& res, \
00255 const UList<Type1>& f1, \
00256 const UList<Type2>& f2 \
00257 ) \
00258 { \
00259 TFOR_ALL_F_OP_F_OP_F(ReturnType, res, =, Type1, f1, Op, Type2, f2) \
00260 } \
00261 \
00262 TEMPLATE \
00263 tmp<Field<ReturnType> > operator Op \
00264 ( \
00265 const UList<Type1>& f1, \
00266 const UList<Type2>& f2 \
00267 ) \
00268 { \
00269 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
00270 OpFunc(tRes(), f1, f2); \
00271 return tRes; \
00272 } \
00273 \
00274 TEMPLATE \
00275 tmp<Field<ReturnType> > operator Op \
00276 ( \
00277 const UList<Type1>& f1, \
00278 const tmp<Field<Type2> >& tf2 \
00279 ) \
00280 { \
00281 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
00282 OpFunc(tRes(), f1, tf2()); \
00283 reuseTmp<ReturnType, Type2>::clear(tf2); \
00284 return tRes; \
00285 } \
00286 \
00287 TEMPLATE \
00288 tmp<Field<ReturnType> > operator Op \
00289 ( \
00290 const tmp<Field<Type1> >& tf1, \
00291 const UList<Type2>& f2 \
00292 ) \
00293 { \
00294 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
00295 OpFunc(tRes(), tf1(), f2); \
00296 reuseTmp<ReturnType, Type1>::clear(tf1); \
00297 return tRes; \
00298 } \
00299 \
00300 TEMPLATE \
00301 tmp<Field<ReturnType> > operator Op \
00302 ( \
00303 const tmp<Field<Type1> >& tf1, \
00304 const tmp<Field<Type2> >& tf2 \
00305 ) \
00306 { \
00307 tmp<Field<ReturnType> > tRes = \
00308 reuseTmpTmp<ReturnType, Type1, Type1, Type2>::New(tf1, tf2); \
00309 OpFunc(tRes(), tf1(), tf2()); \
00310 reuseTmpTmp<ReturnType, Type1, Type1, Type2>::clear(tf1, tf2); \
00311 return tRes; \
00312 }
00313
00314
00315
00316
00317 #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
00318 \
00319 TEMPLATE \
00320 void OpFunc \
00321 ( \
00322 Field<ReturnType>& res, \
00323 const Type1& s1, \
00324 const UList<Type2>& f2 \
00325 ) \
00326 { \
00327 TFOR_ALL_F_OP_S_OP_F(ReturnType, res, =, Type1, s1, Op, Type2, f2) \
00328 } \
00329 \
00330 TEMPLATE \
00331 tmp<Field<ReturnType> > operator Op \
00332 ( \
00333 const Type1& s1, \
00334 const UList<Type2>& f2 \
00335 ) \
00336 { \
00337 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f2.size())); \
00338 OpFunc(tRes(), s1, f2); \
00339 return tRes; \
00340 } \
00341 \
00342 TEMPLATE \
00343 tmp<Field<ReturnType> > operator Op \
00344 ( \
00345 const Type1& s1, \
00346 const tmp<Field<Type2> >& tf2 \
00347 ) \
00348 { \
00349 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type2>::New(tf2); \
00350 OpFunc(tRes(), s1, tf2()); \
00351 reuseTmp<ReturnType, Type2>::clear(tf2); \
00352 return tRes; \
00353 }
00354
00355
00356 #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc) \
00357 \
00358 TEMPLATE \
00359 void OpFunc \
00360 ( \
00361 Field<ReturnType>& res, \
00362 const UList<Type1>& f1, \
00363 const Type2& s2 \
00364 ) \
00365 { \
00366 TFOR_ALL_F_OP_F_OP_S(ReturnType, res, =, Type1, f1, Op, Type2, s2) \
00367 } \
00368 \
00369 TEMPLATE \
00370 tmp<Field<ReturnType> > operator Op \
00371 ( \
00372 const UList<Type1>& f1, \
00373 const Type2& s2 \
00374 ) \
00375 { \
00376 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(f1.size())); \
00377 OpFunc(tRes(), f1, s2); \
00378 return tRes; \
00379 } \
00380 \
00381 TEMPLATE \
00382 tmp<Field<ReturnType> > operator Op \
00383 ( \
00384 const tmp<Field<Type1> >& tf1, \
00385 const Type2& s2 \
00386 ) \
00387 { \
00388 tmp<Field<ReturnType> > tRes = reuseTmp<ReturnType, Type1>::New(tf1); \
00389 OpFunc(tRes(), tf1(), s2); \
00390 reuseTmp<ReturnType, Type1>::clear(tf1); \
00391 return tRes; \
00392 }
00393
00394
00395 #define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpFunc) \
00396 BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpFunc) \
00397 BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpFunc)
00398
00399
00400