LifeV
ExpressionAddition.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief File where the structures for the addition between expressions are defined.
30 
31  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
32 
33  @date 07-2011
34  */
35 
36 #ifndef EXPRESSION_ADDITION_HPP
37 #define EXPRESSION_ADDITION_HPP
38 
39 #include <lifev/core/LifeV.hpp>
40 
41 #include <lifev/eta/expression/ExpressionBase.hpp>
42 #include <lifev/eta/expression/ExpressionScalar.hpp>
43 #include <lifev/eta/expression/ExpressionVector.hpp>
44 #include <lifev/eta/expression/ExpressionMatrix.hpp>
45 
46 namespace LifeV
47 {
48 
49 namespace ExpressionAssembly
50 {
51 
52 //! class ExpressionAddition Class for representing an addition between two expressions.
53 /*!
54  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
55 
56  This class represents the addition in the expression tree.
57 
58  <b> Template parameters </b>
59 
60  <i>LExpressionType</i>: The expression on the left side of the addition operation.
61 
62  <i>RExpressionType</i>: The expression on the right side of the addition operation.
63 
64  <b> Template requirements </b>
65 
66  <i>LExpressionType</i>: Copiable, static display method
67 
68  <i>RExpressionType</i>: Copiable, static display method
69 
70 */
71 template <typename LExpressionType, typename RExpressionType>
72 class ExpressionAddition : public ExpressionBase< ExpressionAddition<LExpressionType, RExpressionType> >
73 {
74 public:
75 
76  //! @name Public Types
77  //@{
78 
79  // Base class (no need, just for ease of coding this class)
80  typedef ExpressionBase< ExpressionAddition <LExpressionType, RExpressionType> > base_Type;
81 
82  //@}
83 
84 
85  //! @name Constructors & Destructor
86  //@{
87 
88  //! Complete constructor using the two expressions to be summed
89  ExpressionAddition (const LExpressionType& l, const RExpressionType& r)
90  : base_Type(), M_l (l), M_r (r) {}
91 
92  //! Copy constructor
93  ExpressionAddition (const ExpressionAddition<LExpressionType, RExpressionType>& expression)
94  : base_Type(), M_l (expression.M_l), M_r (expression.M_r) {}
95 
96  //! Destructor
97  ~ExpressionAddition() {}
98 
99  //@}
100 
101 
102  //! @name Methods
103  //@{
104 
105  //! Display method
106  static void display (std::ostream& out = std::cout)
107  {
108  LExpressionType::display (out);
109  out << " + ";
110  RExpressionType::display (out);
111  }
112 
113  //@}
114 
115 
116  //! @name Get Methods
117  //@{
118 
119  //! Getter for the expression on the left side of the addition
120  const LExpressionType& left() const
121  {
122  return M_l;
123  }
124 
125  //! Getter for the expression on the right side of the addition
126  const RExpressionType& right() const
127  {
128  return M_r;
129  }
130 
131  //@}
132 
133 private:
134 
135  //! @name Private Methods
136  //@{
137 
138  //! No default constructor
139  ExpressionAddition();
140 
141  //@}
142 
143  // Left side of the operation
144  LExpressionType M_l;
145 
146  // Right side of the operation
147  RExpressionType M_r;
148 };
149 
150 
151 //! operator+ The generic operator for the addition between expressions.
152 /*!
153  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
154 
155  Operator used in construction of the expression tree. To avoid shadowing
156  other operator+, it uses the ExpressionBase type to distinguish expressions
157  from other types.
158 
159  <b> Template parameters </b>
160 
161  <i>LExpressionType</i>: The expression on the left side of the addition operation.
162 
163  <i>RExpressionType</i>: The expression on the right side of the addition operation.
164 
165  <b> Template requirements </b>
166 
167  <i>LExpressionType</i>: Same as in LifeV::ExpressionAddition
168 
169  <i>RExpressionType</i>: Same as in LifeV::ExpressionAddition
170 
171 */
172 template< typename LExpressionType, typename RExpressionType >
173 ExpressionAddition<LExpressionType, RExpressionType>
174 operator+ (const ExpressionBase<LExpressionType>& l, const ExpressionBase<RExpressionType>& r)
175 {
176  return ExpressionAddition<LExpressionType, RExpressionType> (l.cast(), r.cast() );
177 }
178 
179 // Specialization for the real constants
180 template< typename LExpressionType >
181 ExpressionAddition<LExpressionType, ExpressionScalar >
182 operator+ (const ExpressionBase<LExpressionType>& l, const Real& r)
183 {
184  return ExpressionAddition<LExpressionType, ExpressionScalar> (l.cast(), ExpressionScalar (r) );
185 }
186 
187 template< typename RExpressionType >
188 ExpressionAddition<ExpressionScalar, RExpressionType>
189 operator+ (const Real& l, const ExpressionBase<RExpressionType>& r)
190 {
191  return ExpressionAddition<ExpressionScalar, RExpressionType> (ExpressionScalar (l), r.cast() );
192 }
193 
194 // Specialization for the vectorial constants
195 template< typename RExpressionType , UInt Vdim>
196 ExpressionAddition<ExpressionVector<Vdim>, RExpressionType>
197 operator+ (const VectorSmall<Vdim>& l, const ExpressionBase<RExpressionType>& r)
198 {
199  return ExpressionAddition<ExpressionVector<Vdim>, RExpressionType> (ExpressionVector<Vdim> (l), r.cast() );
200 }
201 
202 template< typename LExpressionType, UInt Vdim >
203 ExpressionAddition<LExpressionType, ExpressionVector<Vdim> >
204 operator+ (const ExpressionBase<LExpressionType>& l, const VectorSmall<Vdim>& r)
205 {
206  return ExpressionAddition<LExpressionType, ExpressionVector<Vdim> > (l.cast(), ExpressionVector<Vdim> (r) );
207 }
208 
209 // Specialization for the matrix constants
210 template< typename RExpressionType , UInt Dim1, UInt Dim2>
211 ExpressionAddition<ExpressionMatrix<Dim1, Dim2>, RExpressionType>
212 operator+ (const MatrixSmall<Dim1, Dim2>& l, const ExpressionBase<RExpressionType>& r)
213 {
214  return ExpressionAddition<ExpressionMatrix<Dim1, Dim2>, RExpressionType> (ExpressionMatrix<Dim1, Dim2> (l), r.cast() );
215 }
216 
217 template< typename LExpressionType, UInt Dim1, UInt Dim2 >
218 ExpressionAddition<LExpressionType, ExpressionMatrix<Dim1, Dim2> >
219 operator+ (const ExpressionBase<LExpressionType>& l, const MatrixSmall<Dim1, Dim2>& r)
220 {
221  return ExpressionAddition<LExpressionType, ExpressionMatrix<Dim1, Dim2> > (l.cast(), ExpressionMatrix<Dim1, Dim2> (r) );
222 }
223 
224 template< UInt Dim1, UInt Dim2 >
225 ExpressionAddition< ExpressionMatrix<Dim1, Dim2>, ExpressionMatrix<Dim1, Dim2> >
226 operator+ (const MatrixSmall<Dim1, Dim2>& l, const MatrixSmall<Dim1, Dim2>& r)
227 {
228  return ExpressionAddition< ExpressionMatrix<Dim1, Dim2>, ExpressionMatrix<Dim1, Dim2> > (ExpressionMatrix<Dim1, Dim2> (l), ExpressionMatrix<Dim1, Dim2> (r) );
229 }
230 
231 
232 } // Namespace ExpressionAssembly
233 
234 } // Namespace LifeV
235 #endif
void updateInverseJacobian(const UInt &iQuadPt)
double Real
Generic real data.
Definition: LifeV.hpp:175
class ExpressionBase Base class (static polymorphism, CRTP sense) for all the expressions used in ass...
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191