FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

FieldM.H

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Description
00025     High performance macro functions for Field<Type> algebra.  These expand
00026     using either array element access (for vector machines) or pointer
00027     dereferencing for scalar machines as appropriate.
00028 
00029 \*---------------------------------------------------------------------------*/
00030 
00031 #ifndef FieldM_H
00032 #define FieldM_H
00033 
00034 #include <OpenFOAM/error.H>
00035 #include <OpenFOAM/ListLoopM.H>
00036 
00037 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00038 
00039 namespace Foam
00040 {
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 #ifdef FULLDEBUG
00045 
00046 template<class Type1, class Type2>
00047 void checkFields
00048 (
00049     const UList<Type1>& f1,
00050     const UList<Type2>& f2,
00051     const char* op
00052 )
00053 {
00054     if (f1.size() != f2.size())
00055     {
00056         FatalErrorIn
00057         (
00058             "checkFields(const UList<Type1>&, "
00059             "const UList<Type2>&, const char*)"
00060         )   << "    incompatible fields"
00061             << " Field<"<<pTraits<Type1>::typeName<<"> f1("<<f1.size()<<')'
00062             << " and Field<"<<pTraits<Type2>::typeName<<"> f2("<<f2.size()<<')'
00063             << endl << " for operation " << op
00064             << abort(FatalError);
00065     }
00066 }
00067 
00068 template<class Type1, class Type2, class Type3>
00069 void checkFields
00070 (
00071     const UList<Type1>& f1,
00072     const UList<Type2>& f2,
00073     const UList<Type3>& f3,
00074     const char* op
00075 )
00076 {
00077     if (f1.size() != f2.size() || f1.size() != f3.size())
00078     {
00079         FatalErrorIn
00080         (
00081             "checkFields(const UList<Type1>&, "
00082             "const UList<Type2>&, const UList<Type3>&, "
00083             "const char*)"
00084         )   << "    incompatible fields"
00085             << " Field<"<<pTraits<Type1>::typeName<<"> f1("<<f1.size()<<')'
00086             << ", Field<"<<pTraits<Type2>::typeName<<"> f2("<<f2.size()<<')'
00087             << " and Field<"<<pTraits<Type3>::typeName<<"> f3("<<f3.size()<<')'
00088             << endl << "    for operation " << op
00089             << abort(FatalError);
00090     }
00091 }
00092 
00093 #else
00094 
00095 template<class Type1, class Type2>
00096 void checkFields
00097 (
00098     const UList<Type1>&,
00099     const UList<Type2>&,
00100     const char*
00101 )
00102 {}
00103 
00104 template<class Type1, class Type2, class Type3>
00105 void checkFields
00106 (
00107     const UList<Type1>&,
00108     const UList<Type2>&,
00109     const UList<Type3>&,
00110     const char*
00111 )
00112 {}
00113 
00114 #endif
00115 
00116 
00117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00118 
00119 // member function : this f1 OP fUNC f2
00120 
00121 #define TFOR_ALL_F_OP_FUNC_F(typeF1, f1, OP, FUNC, typeF2, f2)              \
00122                                                                             \
00123     /* check the two fields have same Field<Type> mesh */                   \
00124     checkFields(f1, f2, "f1 " #OP " " #FUNC "(f2)");                        \
00125                                                                             \
00126     /* set access to f1, f2 and f3 at end of each field */                  \
00127     List_ACCESS(typeF1, f1, f1P);                                           \
00128     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00129                                                                             \
00130     /* loop through fields performing f1 OP1 f2 OP2 f3 */                   \
00131     List_FOR_ALL(f1, i)                                                     \
00132         List_ELEM(f1, f1P, i) OP FUNC(List_ELEM(f2, f2P, i));               \
00133     List_END_FOR_ALL                                                        \
00134 
00135 
00136 #define TFOR_ALL_F_OP_F_FUNC(typeF1, f1, OP, typeF2, f2, FUNC)              \
00137                                                                             \
00138     /* check the two fields have same Field<Type> mesh */                   \
00139     checkFields(f1, f2, "f1 " #OP " f2" #FUNC);                             \
00140                                                                             \
00141     /* set access to f1, f2 and f3 at end of each field */                  \
00142     List_ACCESS(typeF1, f1, f1P);                                           \
00143     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00144                                                                             \
00145     /* loop through fields performing f1 OP1 f2 OP2 f3 */                   \
00146     List_FOR_ALL(f1, i)                                                     \
00147         List_ELEM(f1, f1P, i) OP List_ELEM(f2, f2P, i).FUNC();              \
00148     List_END_FOR_ALL                                                        \
00149 
00150 
00151 // member function : this field f1 OP fUNC f2, f3
00152 
00153 #define TFOR_ALL_F_OP_FUNC_F_F(typeF1, f1, OP, FUNC, typeF2, f2, typeF3, f3)\
00154                                                                             \
00155     /* check the three fields have same Field<Type> mesh */                 \
00156     checkFields(f1, f2, f3, "f1 " #OP " " #FUNC "(f2, f3)");                \
00157                                                                             \
00158     /* set access to f1, f2 and f3 at end of each field */                  \
00159     List_ACCESS(typeF1, f1, f1P);                                           \
00160     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00161     List_CONST_ACCESS(typeF3, f3, f3P);                                     \
00162                                                                             \
00163     /* loop through fields performing f1 OP1 f2 OP2 f3 */                   \
00164     List_FOR_ALL(f1, i)                                                     \
00165         List_ELEM(f1, f1P, i)                                               \
00166         OP FUNC(List_ELEM(f2, f2P, i), List_ELEM(f3, f3P, i));              \
00167     List_END_FOR_ALL                                                        \
00168 
00169 
00170 // member function : this field f1 OP fUNC f2, f3
00171 
00172 #define TFOR_ALL_S_OP_FUNC_F_F(typeS, s, OP, FUNC, typeF1, f1, typeF2, f2)  \
00173                                                                             \
00174     /* check the two fields have same Field<Type> mesh */                   \
00175     checkFields(f1, f2, "s " #OP " " #FUNC "(f1, f2)");                     \
00176                                                                             \
00177     /* set access to f1 and f2 at end of each field */                      \
00178     List_CONST_ACCESS(typeF1, f1, f1P);                                     \
00179     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00180                                                                             \
00181     /* loop through fields performing s OP FUNC(f1, f2) */                  \
00182     List_FOR_ALL(f1, i)                                                     \
00183         (s) OP FUNC(List_ELEM(f1, f1P, i), List_ELEM(f2, f2P, i));          \
00184     List_END_FOR_ALL                                                        \
00185 
00186 
00187 // member function : this f1 OP fUNC f2, s
00188 
00189 #define TFOR_ALL_F_OP_FUNC_F_S(typeF1, f1, OP, FUNC, typeF2, f2, typeS, s)  \
00190                                                                             \
00191     /* check the two fields have same Field<Type> mesh */                   \
00192     checkFields(f1, f2, "f1 " #OP " " #FUNC "(f2, s)");                     \
00193                                                                             \
00194     /* set access to f1, f2 and f3 at end of each field */                  \
00195     List_ACCESS(typeF1, f1, f1P);                                           \
00196     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00197                                                                             \
00198     /* loop through fields performing f1 OP1 f2 OP2 f3 */                   \
00199     List_FOR_ALL(f1, i)                                                     \
00200         List_ELEM(f1, f1P, i) OP FUNC(List_ELEM(f2, f2P, i), (s));          \
00201     List_END_FOR_ALL
00202 
00203 
00204 // member function : s1 OP fUNC f, s2
00205 
00206 #define TFOR_ALL_S_OP_FUNC_F_S(typeS1, s1, OP, FUNC, typeF, f, typeS2, s2)  \
00207                                                                             \
00208     /* set access to f at end of field */                                   \
00209     List_CONST_ACCESS(typeF, f, fP);                                        \
00210                                                                             \
00211     /* loop through fields performing f1 OP1 f2 OP2 f3 */                   \
00212     List_FOR_ALL(f, i)                                                      \
00213         (s1) OP FUNC(List_ELEM(f, fP, i), (s2));                            \
00214     List_END_FOR_ALL                                                        \
00215 
00216 
00217 // member function : this f1 OP fUNC s, f2
00218 
00219 #define TFOR_ALL_F_OP_FUNC_S_F(typeF1, f1, OP, FUNC, typeS, s, typeF2, f2)  \
00220                                                                             \
00221     /* check the two fields have same Field<Type> mesh */                   \
00222     checkFields(f1, f2, "f1 " #OP " " #FUNC "(s, f2)");                     \
00223                                                                             \
00224     /* set access to f1, f2 and f3 at end of each field */                  \
00225     List_ACCESS(typeF1, f1, f1P);                                           \
00226     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00227                                                                             \
00228     /* loop through fields performing f1 OP1 f2 OP2 f3 */                   \
00229     List_FOR_ALL(f1, i)                                                     \
00230         List_ELEM(f1, f1P, i) OP FUNC((s), List_ELEM(f2, f2P, i));          \
00231     List_END_FOR_ALL                                                        \
00232 
00233 
00234 // member function : this f1 OP fUNC s, f2
00235 
00236 #define TFOR_ALL_F_OP_FUNC_S_S(typeF1, f1, OP, FUNC, typeS1, s1, typeS2, s2)\
00237                                                                             \
00238     /* set access to f1 at end of field */                                  \
00239     List_ACCESS(typeF1, f1, f1P);                                           \
00240                                                                             \
00241     /* loop through fields performing f1 OP1 FUNC(s1, s2) */                \
00242     List_FOR_ALL(f1, i)                                                     \
00243         List_ELEM(f1, f1P, i) OP FUNC((s1), (s2));                          \
00244     List_END_FOR_ALL                                                        \
00245 
00246 
00247 // member function : this f1 OP1 f2 OP2 FUNC s
00248 
00249 #define TFOR_ALL_F_OP_F_FUNC_S(typeF1, f1, OP, typeF2, f2, FUNC, typeS, s)  \
00250                                                                             \
00251     /* check the two fields have same Field<Type> mesh */                   \
00252     checkFields(f1, f2, "f1 " #OP " f2 " #FUNC "(s)");                      \
00253                                                                             \
00254     /* set access to f1, f2 and f3 at end of each field */                  \
00255     List_ACCESS(typeF1, f1, f1P);                                           \
00256     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00257                                                                             \
00258     /* loop through fields performing f1 OP1 f2 OP2 f3 */                   \
00259     List_FOR_ALL(f1, i)                                                     \
00260         List_ELEM(f1, f1P, i) OP List_ELEM(f2, f2P, i) FUNC((s));           \
00261     List_END_FOR_ALL                                                        \
00262 
00263 
00264 // define high performance macro functions for Field<Type> operations
00265 
00266 // member operator : this field f1 OP1 f2 OP2 f3
00267 
00268 #define TFOR_ALL_F_OP_F_OP_F(typeF1, f1, OP1, typeF2, f2, OP2, typeF3, f3)  \
00269                                                                             \
00270     /* check the three fields have same Field<Type> mesh */                 \
00271     checkFields(f1, f2, f3, "f1 " #OP1 " f2 " #OP2 " f3");                  \
00272                                                                             \
00273     /* set access to f1, f2 and f3 at end of each field */                  \
00274     List_ACCESS(typeF1, f1, f1P);                                           \
00275     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00276     List_CONST_ACCESS(typeF3, f3, f3P);                                     \
00277                                                                             \
00278     /* loop through fields performing f1 OP1 f2 OP2 f3 */                   \
00279     List_FOR_ALL(f1, i)                                                     \
00280         List_ELEM(f1, f1P, i) OP1 List_ELEM(f2, f2P, i)                     \
00281                               OP2 List_ELEM(f3, f3P, i);                    \
00282     List_END_FOR_ALL                                                        \
00283 
00284 
00285 // member operator : this field f1 OP1 s OP2 f2
00286 
00287 #define TFOR_ALL_F_OP_S_OP_F(typeF1, f1, OP1, typeS, s, OP2, typeF2, f2)    \
00288                                                                             \
00289     /* check the two fields have same Field<Type> mesh */                   \
00290     checkFields(f1, f2, "f1 " #OP1 " s " #OP2 " f2");                       \
00291                                                                             \
00292     /* set access to f1 and f2 at end of each field */                      \
00293     List_ACCESS(typeF1, f1, f1P);                                           \
00294     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00295                                                                             \
00296     /* loop through fields performing f1 OP1 s OP2 f2 */                    \
00297     List_FOR_ALL(f1, i)                                                     \
00298         List_ELEM(f1, f1P, i) OP1 (s) OP2 List_ELEM(f2, f2P, i);            \
00299     List_END_FOR_ALL                                                        \
00300 
00301 
00302 // member operator : this field f1 OP1 f2 OP2 s
00303 
00304 #define TFOR_ALL_F_OP_F_OP_S(typeF1, f1, OP1, typeF2, f2, OP2, typeS, s)    \
00305                                                                             \
00306     /* check the two fields have same Field<Type> mesh */                   \
00307     checkFields(f1, f2, "f1 " #OP1 " f2 " #OP2 " s");                       \
00308                                                                             \
00309     /* set access to f1 and f2 at end of each field */                      \
00310     List_ACCESS(typeF1, f1, f1P);                                           \
00311     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00312                                                                             \
00313     /* loop through fields performing f1 OP1 s OP2 f2 */                    \
00314     List_FOR_ALL(f1, i)                                                     \
00315         List_ELEM(f1, f1P, i) OP1 List_ELEM(f2, f2P, i) OP2 (s);            \
00316     List_END_FOR_ALL                                                        \
00317 
00318 
00319 // member operator : this field f1 OP f2
00320 
00321 #define TFOR_ALL_F_OP_F(typeF1, f1, OP, typeF2, f2)                         \
00322                                                                             \
00323     /* check the two fields have same Field<Type> mesh */                   \
00324     checkFields(f1, f2, "f1 " #OP " f2");                                   \
00325                                                                             \
00326     /* set pointer to f1P at end of f1 and */                               \
00327     /* f2.p at end of f2 */                                                 \
00328     List_ACCESS(typeF1, f1, f1P);                                           \
00329     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00330                                                                             \
00331     /* loop through fields performing f1 OP f2 */                           \
00332     List_FOR_ALL(f1, i)                                                     \
00333         List_ELEM(f1, f1P, i) OP List_ELEM(f2, f2P, i);                     \
00334     List_END_FOR_ALL                                                        \
00335 
00336 // member operator : this field f1 OP1 OP2 f2
00337 
00338 #define TFOR_ALL_F_OP_OP_F(typeF1, f1, OP1, OP2, typeF2, f2)                \
00339                                                                             \
00340     /* check the two fields have same Field<Type> mesh */                   \
00341     checkFields(f1, f2, #OP1 " " #OP2 " f2");                               \
00342                                                                             \
00343     /* set pointer to f1P at end of f1 and */                               \
00344     /* f2.p at end of f2 */                                                 \
00345     List_ACCESS(typeF1, f1, f1P);                                           \
00346     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00347                                                                             \
00348     /* loop through fields performing f1 OP1 OP2 f2 */                      \
00349     List_FOR_ALL(f1, i)                                                     \
00350         List_ELEM(f1, f1P, i) OP1 OP2 List_ELEM(f2, f2P, i);                \
00351     List_END_FOR_ALL                                                        \
00352 
00353 
00354 // member operator : this field f OP s
00355 
00356 #define TFOR_ALL_F_OP_S(typeF, f, OP, typeS, s)                             \
00357                                                                             \
00358     /* set access to f at end of field */                                   \
00359     List_ACCESS(typeF, f, fP);                                              \
00360                                                                             \
00361     /* loop through field performing f OP s */                              \
00362     List_FOR_ALL(f, i)                                                      \
00363         List_ELEM(f, fP, i) OP (s);                                         \
00364     List_END_FOR_ALL                                                        \
00365 
00366 
00367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00368 // define high performance macro functions for Field<Type> friend functions
00369 
00370 // friend operator function : s OP f, allocates storage for s
00371 
00372 #define TFOR_ALL_S_OP_F(typeS, s, OP, typeF, f)                             \
00373                                                                             \
00374     /* set access to f at end of field */                                   \
00375     List_CONST_ACCESS(typeF, f, fP);                                        \
00376                                                                             \
00377     /* loop through field performing s OP f */                              \
00378     List_FOR_ALL(f, i)                                                      \
00379         (s) OP List_ELEM(f, fP, i);                                         \
00380     List_END_FOR_ALL
00381 
00382 
00383 // friend operator function : s OP1 f1 OP2 f2, allocates storage for s
00384 
00385 #define TFOR_ALL_S_OP_F_OP_F(typeS, s, OP1, typeF1, f1, OP2, typeF2, f2)    \
00386                                                                             \
00387     /* set access to f1 and f2 at end of each field */                      \
00388     List_CONST_ACCESS(typeF1, f1, f1P);                                     \
00389     List_CONST_ACCESS(typeF2, f2, f2P);                                     \
00390                                                                             \
00391     /* loop through field performing s OP f */                              \
00392     List_FOR_ALL(f1, i)                                                     \
00393         (s) OP1 List_ELEM(f1, f1P, i) OP2 List_ELEM(f2, f2P, i);            \
00394     List_END_FOR_ALL
00395 
00396 
00397 // friend operator function : s OP FUNC(f), allocates storage for s
00398 
00399 #define TFOR_ALL_S_OP_FUNC_F(typeS, s, OP, FUNC, typeF, f)                  \
00400                                                                             \
00401     /* set access to f at end of field */                                   \
00402     List_CONST_ACCESS(typeF, f, fP);                                        \
00403                                                                             \
00404     /* loop through field performing s OP f */                              \
00405     List_FOR_ALL(f, i)                                                      \
00406         (s) OP FUNC(List_ELEM(f, fP, i));                                   \
00407     List_END_FOR_ALL
00408 
00409 
00410 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00411 
00412 } // End namespace Foam
00413 
00414 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00415 
00416 #endif
00417 
00418 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines