OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

FieldFunctionsM.C

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