LifeV
ExpressionProduct.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 product between expressions are defined.
30 
31  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
32 
33  @date 07-2011
34  */
35 
36 #ifndef EXPRESSION_PRODUCT_HPP
37 #define EXPRESSION_PRODUCT_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 ExpressionProduct Class for representing a product between two expressions.
53 /*!
54  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
55 
56  This class represents the product in the expression tree.
57 
58  <b> Template parameters </b>
59 
60  <i>LExpressionType</i>: The expression on the left side of the product operation.
61 
62  <i>RExpressionType</i>: The expression on the right side of the product 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 ExpressionProduct : public ExpressionBase< ExpressionProduct<LExpressionType, RExpressionType> >
73 {
74 public:
75 
76  //! @name Public Types
77  //@{
78 
79  // No direct use, just ease of coding
80  typedef ExpressionBase< ExpressionProduct <LExpressionType, RExpressionType> > base_Type;
81 
82  //@}
83 
84  //! @name Constructors & Destructor
85  //@{
86 
87  //! Full constructor using the two expressions
88  ExpressionProduct (const LExpressionType& l, const RExpressionType& r)
89  : base_Type(), M_l (l), M_r (r) {}
90 
91  //! Copy constructor
92  ExpressionProduct (const ExpressionProduct<LExpressionType, RExpressionType>& expression)
93  : base_Type(), M_l (expression.M_l), M_r (expression.M_r) {}
94 
95  //! Destructor
96  ~ExpressionProduct() {}
97 
98  //@}
99 
100 
101  //! @name Methods
102  //@{
103 
104  //! Display method
105  static void display (std::ostream& out = std::cout)
106  {
107  LExpressionType::display (out);
108  out << " * ";
109  RExpressionType::display (out);
110  }
111 
112  //@}
113 
114 
115  //! @name Private Methods
116  //@{
117 
118  //! Getter for the left hand side
119  const LExpressionType& left() const
120  {
121  return M_l;
122  }
123 
124  //! Getter for the right hand side
125  const RExpressionType& right() const
126  {
127  return M_r;
128  }
129 
130  //@}
131 
132 private:
133 
134  //! @name Private Methods
135  //@{
136 
137  ExpressionProduct();
138 
139  //@}
140 
141 
142  // Left hand side
143  LExpressionType M_l;
144 
145  // Right hand side
146  RExpressionType M_r;
147 };
148 
149 
150 //! operator* The generic operator for the product between expressions.
151 /*!
152  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
153 
154  Operator used in construction of the expression tree. To avoid shadowing
155  other operator*, it uses the ExpressionBase type to distinguish expressions
156  from other types.
157 
158  <b> Template parameters </b>
159 
160  <i>LExpressionType</i>: The expression on the left side of the product operation.
161 
162  <i>RExpressionType</i>: The expression on the right side of the product operation.
163 
164  <b> Template requirements </b>
165 
166  <i>LExpressionType</i>: Same as in LifeV::ExpressionProduct
167 
168  <i>RExpressionType</i>: Same as in LifeV::ExpressionProduct
169 
170 */
171 template< typename LExpressionType, typename RExpressionType >
172 ExpressionProduct<LExpressionType, RExpressionType>
173 operator* (const ExpressionBase<LExpressionType>& l, const ExpressionBase<RExpressionType>& r)
174 {
175  return ExpressionProduct<LExpressionType, RExpressionType> (l.cast(), r.cast() );
176 }
177 
178 // "Specialization" for the case of a scalar
179 template< typename RExpressionType >
180 ExpressionProduct<ExpressionScalar, RExpressionType>
181 operator* (const Real& l, const ExpressionBase<RExpressionType>& r)
182 {
183  return ExpressionProduct<ExpressionScalar, RExpressionType> (ExpressionScalar (l), r.cast() );
184 }
185 
186 // "Specialization" for the case of a scalar
187 template< typename LExpressionType >
188 ExpressionProduct<LExpressionType, ExpressionScalar>
189 operator* (const ExpressionBase<LExpressionType>& l, const Real& r)
190 {
191  return ExpressionProduct<LExpressionType, ExpressionScalar> (l.cast(), ExpressionScalar (r) );
192 }
193 
194 // "Specialization" for the case of a vector
195 template< typename RExpressionType, UInt Vdim >
196 ExpressionProduct<ExpressionVector<Vdim>, RExpressionType>
197 operator* (const VectorSmall<Vdim>& l, const ExpressionBase<RExpressionType>& r)
198 {
199  return ExpressionProduct<ExpressionVector<Vdim>, RExpressionType> (ExpressionVector<Vdim> (l), r.cast() );
200 }
201 
202 // "Specialization" for the case of a vector
203 template< typename LExpressionType, UInt Vdim>
204 ExpressionProduct<LExpressionType, ExpressionVector<Vdim> >
205 operator* (const ExpressionBase<LExpressionType>& l, const VectorSmall<Vdim>& r)
206 {
207  return ExpressionProduct<LExpressionType, ExpressionVector<Vdim> > (l.cast(), ExpressionVector<Vdim> (r) );
208 }
209 
210 // "Specialization" for the case of a matrix
211 template< typename RExpressionType, UInt Dim1 , UInt Dim2 >
212 ExpressionProduct<ExpressionMatrix<Dim1, Dim2>, RExpressionType>
213 operator* (const MatrixSmall<Dim1, Dim2>& l, const ExpressionBase<RExpressionType>& r)
214 {
215  return ExpressionProduct<ExpressionMatrix<Dim1, Dim2>, RExpressionType> (ExpressionMatrix<Dim1, Dim2> (l), r.cast() );
216 }
217 
218 // "Specialization" for the case of a matrix
219 template< typename LExpressionType, UInt Dim1, UInt Dim2 >
220 ExpressionProduct<LExpressionType, ExpressionMatrix<Dim1, Dim2> >
221 operator* (const ExpressionBase<LExpressionType>& l, const MatrixSmall<Dim1, Dim2>& r)
222 {
223  return ExpressionProduct<LExpressionType, ExpressionMatrix<Dim1, Dim2> > (l.cast(), ExpressionMatrix<Dim1, Dim2> (r) );
224 }
225 
226 
227 
228 
229 
230 } // Namespace ExpressionAssembly
231 
232 } // Namespace LifeV
233 
234 #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