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

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