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

ops.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 InClass
00025     Foam::Pstream
00026 
00027 Description
00028     Combination-Reduction operation for a parallel run.
00029 
00030     The information from all nodes is collected on the master node,
00031     combined using the given combination function and the result is
00032     broadcast to all nodes
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef ops_H
00037 #define ops_H
00038 
00039 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00040 
00041 namespace Foam
00042 {
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 #define EqOp(opName, op)                                                    \
00047                                                                             \
00048 template<class T1, class T2>                                                \
00049 class opName##Op2                                                           \
00050 {                                                                           \
00051 public:                                                                     \
00052                                                                             \
00053     void operator()(T1& x, const T2& y) const                               \
00054     {                                                                       \
00055         op;                                                                 \
00056     }                                                                       \
00057 };                                                                          \
00058                                                                             \
00059 template<class T>                                                           \
00060 class opName##Op                                                            \
00061 {                                                                           \
00062 public:                                                                     \
00063                                                                             \
00064     void operator()(T& x, const T& y) const                                 \
00065     {                                                                       \
00066         op;                                                                 \
00067     }                                                                       \
00068 };
00069 
00070 EqOp(eq, x = y)
00071 EqOp(plusEq, x += y)
00072 EqOp(minusEq, x -= y)
00073 EqOp(multiplyEq, x *= y)
00074 EqOp(divideEq, x /= y)
00075 EqOp(eqMag, x = mag(y))
00076 EqOp(plusEqMagSqr, x += magSqr(y))
00077 EqOp(maxEq, x = max(x, y))
00078 EqOp(minEq, x = min(x, y))
00079 EqOp(andEq, x = (x && y))
00080 EqOp(orEq, x  = (x || y))
00081 
00082 EqOp(eqMinus, x = -y)
00083 
00084 #undef EqOp
00085 
00086 
00087 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00088 
00089 #define Op(opName, op)                                                      \
00090                                                                             \
00091 template<class T, class T1, class T2>                                       \
00092 class opName##Op3                                                           \
00093 {                                                                           \
00094 public:                                                                     \
00095                                                                             \
00096     T operator()(const T1& x, const T2& y) const                            \
00097     {                                                                       \
00098         return op;                                                          \
00099     }                                                                       \
00100 };                                                                          \
00101                                                                             \
00102 template<class T1, class T2>                                                \
00103 class opName##Op2                                                           \
00104 {                                                                           \
00105 public:                                                                     \
00106                                                                             \
00107     T1 operator()(const T1& x, const T2& y) const                           \
00108     {                                                                       \
00109         return op;                                                          \
00110     }                                                                       \
00111 };                                                                          \
00112                                                                             \
00113 template<class T>                                                           \
00114 class opName##Op                                                            \
00115 {                                                                           \
00116 public:                                                                     \
00117                                                                             \
00118     T operator()(const T& x, const T& y) const                              \
00119     {                                                                       \
00120         return op;                                                          \
00121     }                                                                       \
00122 };
00123 
00124 Op(sum, x + y)
00125 
00126 Op(plus, x + y)
00127 Op(minus, x - y)
00128 Op(multiply, x * y)
00129 Op(divide, x / y)
00130 Op(cmptMultiply, cmptMultiply(x, y))
00131 Op(cmptDivide, cmptDivide(x, y))
00132 Op(stabilise, stabilise(x, y))
00133 Op(max, max(x, y))
00134 Op(min, min(x, y))
00135 Op(minMod, minMod(x, y))
00136 Op(and, x && y)
00137 Op(or, x || y)
00138 Op(eqEq, x == y)
00139 
00140 #undef Op
00141 
00142 
00143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00144 
00145 } // End namespace Foam
00146 
00147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00148 
00149 #endif
00150 
00151 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines