Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / OpenFOAM / primitives / ops / ops.H
blobd915dd464f6be6d6e8b6b76cd307b96feb86fcca
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 InClass
25     Foam::Pstream
27 Description
28     Combination-Reduction operation for a parallel run.
30     The information from all nodes is collected on the master node,
31     combined using the given combination function and the result is
32     broadcast to all nodes
34 \*---------------------------------------------------------------------------*/
36 #ifndef ops_H
37 #define ops_H
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 namespace Foam
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 #define EqOp(opName, op)                                                    \
47                                                                             \
48 template<class T1, class T2>                                                \
49 class opName##Op2                                                           \
50 {                                                                           \
51 public:                                                                     \
52                                                                             \
53     void operator()(T1& x, const T2& y) const                               \
54     {                                                                       \
55         op;                                                                 \
56     }                                                                       \
57 };                                                                          \
58                                                                             \
59 template<class T>                                                           \
60 class opName##Op                                                            \
61 {                                                                           \
62 public:                                                                     \
63                                                                             \
64     void operator()(T& x, const T& y) const                                 \
65     {                                                                       \
66         op;                                                                 \
67     }                                                                       \
70 EqOp(eq, x = y)
71 EqOp(plusEq, x += y)
72 EqOp(minusEq, x -= y)
73 EqOp(multiplyEq, x *= y)
74 EqOp(divideEq, x /= y)
75 EqOp(eqMag, x = mag(y))
76 EqOp(plusEqMagSqr, x += magSqr(y))
77 EqOp(maxEq, x = max(x, y))
78 EqOp(minEq, x = min(x, y))
79 EqOp(minMagSqrEq, x = (magSqr(x)<=magSqr(y) ? x : y))
80 EqOp(maxMagSqrEq, x = (magSqr(x)>=magSqr(y) ? x : y))
81 EqOp(andEq, x = (x && y))
82 EqOp(orEq, x  = (x || y))
84 EqOp(eqMinus, x = -y)
86 EqOp(nopEq, (void)x)
88 #undef EqOp
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93 #define Op(opName, op)                                                      \
94                                                                             \
95 template<class T, class T1, class T2>                                       \
96 class opName##Op3                                                           \
97 {                                                                           \
98 public:                                                                     \
99                                                                             \
100     T operator()(const T1& x, const T2& y) const                            \
101     {                                                                       \
102         return op;                                                          \
103     }                                                                       \
104 };                                                                          \
105                                                                             \
106 template<class T1, class T2>                                                \
107 class opName##Op2                                                           \
108 {                                                                           \
109 public:                                                                     \
110                                                                             \
111     T1 operator()(const T1& x, const T2& y) const                           \
112     {                                                                       \
113         return op;                                                          \
114     }                                                                       \
115 };                                                                          \
116                                                                             \
117 template<class T>                                                           \
118 class opName##Op                                                            \
119 {                                                                           \
120 public:                                                                     \
121                                                                             \
122     T operator()(const T& x, const T& y) const                              \
123     {                                                                       \
124         return op;                                                          \
125     }                                                                       \
128 Op(sum, x + y)
130 Op(plus, x + y)
131 Op(minus, x - y)
132 Op(multiply, x * y)
133 Op(divide, x / y)
134 Op(cmptMultiply, cmptMultiply(x, y))
135 Op(cmptDivide, cmptDivide(x, y))
136 Op(stabilise, stabilise(x, y))
137 Op(max, max(x, y))
138 Op(min, min(x, y))
139 Op(minMod, minMod(x, y))
140 Op(and, x && y)
141 Op(or, x || y)
142 Op(eqEq, x == y)
144 #undef Op
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 } // End namespace Foam
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 #endif
155 // ************************************************************************* //