Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / primitives / ops / ops.H
bloba1375e296f9224e575e74fe075b218024ff4b256
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 InClass
26     Foam::Pstream
28 Description
29     Combination-Reduction operation for a parallel run.
31     The information from all nodes is collected on the master node,
32     combined using the given combination function and the result is
33     broadcast to all nodes
35 \*---------------------------------------------------------------------------*/
37 #ifndef ops_H
38 #define ops_H
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 namespace Foam
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 #define EqOp(opName, op)                                                    \
48                                                                             \
49 template<class T1, class T2>                                                \
50 class opName##Op2                                                           \
51 {                                                                           \
52 public:                                                                     \
53                                                                             \
54     void operator()(T1& x, const T2& y) const                               \
55     {                                                                       \
56         op;                                                                 \
57     }                                                                       \
58 };                                                                          \
59                                                                             \
60 template<class T>                                                           \
61 class opName##Op                                                            \
62 {                                                                           \
63 public:                                                                     \
64                                                                             \
65     void operator()(T& x, const T& y) const                                 \
66     {                                                                       \
67         op;                                                                 \
68     }                                                                       \
71 EqOp(eq, x = y)
72 EqOp(plusEq, x += y)
73 EqOp(minusEq, x -= y)
74 EqOp(multiplyEq, x *= y)
75 EqOp(divideEq, x /= y)
76 EqOp(eqMag, x = mag(y))
77 EqOp(plusEqMagSqr, x += magSqr(y))
78 EqOp(maxEq, x = max(x, y))
79 EqOp(minEq, x = min(x, y))
80 EqOp(andEq, x = (x && y))
81 EqOp(orEq, x  = (x || y))
83 EqOp(eqMinus, x = -y)
85 #undef EqOp
88 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
90 #define Op(opName, op)                                                      \
91                                                                             \
92 template<class T, class T1, class T2>                                       \
93 class opName##Op3                                                           \
94 {                                                                           \
95 public:                                                                     \
96                                                                             \
97     T operator()(const T1& x, const T2& y) const                            \
98     {                                                                       \
99         return op;                                                          \
100     }                                                                       \
101 };                                                                          \
102                                                                             \
103 template<class T1, class T2>                                                \
104 class opName##Op2                                                           \
105 {                                                                           \
106 public:                                                                     \
107                                                                             \
108     T1 operator()(const T1& x, const T2& y) const                           \
109     {                                                                       \
110         return op;                                                          \
111     }                                                                       \
112 };                                                                          \
113                                                                             \
114 template<class T>                                                           \
115 class opName##Op                                                            \
116 {                                                                           \
117 public:                                                                     \
118                                                                             \
119     T operator()(const T& x, const T& y) const                              \
120     {                                                                       \
121         return op;                                                          \
122     }                                                                       \
125 Op(sum, x + y)
127 Op(plus, x + y)
128 Op(minus, x - y)
129 Op(multiply, x * y)
130 Op(divide, x / y)
131 Op(cmptMultiply, cmptMultiply(x, y))
132 Op(cmptDivide, cmptDivide(x, y))
133 Op(stabilise, stabilise(x, y))
134 Op(max, max(x, y))
135 Op(min, min(x, y))
136 Op(minMod, minMod(x, y))
137 Op(and, x && y)
138 Op(or, x || y)
139 Op(eqEq, x == y)
141 #undef Op
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 } // End namespace Foam
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 #endif
152 // ************************************************************************* //