LifeV
ExpressionDot.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 dot product between expressions are defined.
30 
31  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
32 
33  @date 07-2011
34  */
35 
36 #ifndef EXPRESSION_DOT_HPP
37 #define EXPRESSION_DOT_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 
45 namespace LifeV
46 {
47 
48 namespace ExpressionAssembly
49 {
50 
51 //! class ExpressionDot Class for representing a dot product between two expressions.
52 /*!
53  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
54 
55  This class represents the dot product in the expression tree.
56 
57  <b> Template parameters </b>
58 
59  <i>LExpressionType</i>: The expression on the left side of the dot product.
60 
61  <i>RExpressionType</i>: The expression on the right side of the dot product.
62 
63  <b> Template requirements </b>
64 
65  <i>LExpressionType</i>: Copiable, static display method
66 
67  <i>RExpressionType</i>: Copiable, static display method
68 
69 */
70 template <typename LExpressionType, typename RExpressionType>
71 class ExpressionDot : public ExpressionBase< ExpressionDot<LExpressionType, RExpressionType> >
72 {
73 public:
74 
75  //! @name Public Types
76  //@{
77 
78  // No real need, just for ease of coding
79  typedef ExpressionBase< ExpressionDot <LExpressionType, RExpressionType> > base_Type;
80 
81  //@}
82 
83 
84  //! @name Constructors & Destructor
85  //@{
86 
87  //! Full constructor, with the two expressions.
88  ExpressionDot (const LExpressionType& l, const RExpressionType& r)
89  : base_Type(), M_l (l), M_r (r) {}
90 
91  //! Copy constructor
92  ExpressionDot (const ExpressionDot<LExpressionType, RExpressionType>& expression)
93  : base_Type(), M_l (expression.M_l), M_r (expression.M_r) {}
94 
95  //! Destructor
96  ~ExpressionDot() {}
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 << " dot ";
109  RExpressionType::display (out);
110  }
111 
112  //@}
113 
114 
115  //! @name Get Methods
116  //@{
117 
118  //! Getter for the left hand side of the dot product
119  const LExpressionType& left() const
120  {
121  return M_l;
122  }
123 
124  //! Getter for the right hand side of the dot product
125  const RExpressionType& right() const
126  {
127  return M_r;
128  }
129 
130  //@}
131 
132 private:
133 
134  //! @name Private Methods
135  //@{
136 
137  //! No default constructor
138  ExpressionDot();
139 
140  //@}
141 
142  // Left hand side
143  LExpressionType M_l;
144 
145  // Right hand side
146  RExpressionType M_r;
147 };
148 
149 
150 //! dot The generic function for the dot product between expressions.
151 /*!
152  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
153 
154  Function used in construction of the expression tree. To avoid shadowing
155  other functions, 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 dot product.
161 
162  <i>RExpressionType</i>: The expression on the right side of the dot product.
163 
164  <b> Template requirements </b>
165 
166  <i>LExpressionType</i>: Same as in LifeV::ExpressionDot
167 
168  <i>RExpressionType</i>: Same as in LifeV::ExpressionDot
169 
170 */
171 template< typename LExpressionType, typename RExpressionType >
172 ExpressionDot<LExpressionType, RExpressionType>
173 dot (const ExpressionBase<LExpressionType>& l, const ExpressionBase<RExpressionType>& r)
174 {
175  return ExpressionDot<LExpressionType, RExpressionType> (l.cast(), r.cast() );
176 }
177 
178 // Specialization for the real constants
179 template< typename LExpressionType >
180 ExpressionDot<LExpressionType, ExpressionScalar >
181 dot (const ExpressionBase<LExpressionType>& l, const Real& r)
182 {
183  return ExpressionDot<LExpressionType, ExpressionScalar> (l.cast(), ExpressionScalar (r) );
184 }
185 
186 template< typename RExpressionType >
187 ExpressionDot<ExpressionScalar, RExpressionType>
188 dot (const Real& l, const ExpressionBase<RExpressionType>& r)
189 {
190  return ExpressionDot<ExpressionScalar, RExpressionType> (ExpressionScalar (l), r.cast() );
191 }
192 
193 // Specialization for the vectorial constants
194 template< typename RExpressionType , UInt Vdim>
195 ExpressionDot<ExpressionVector<Vdim>, RExpressionType>
196 dot (const VectorSmall<Vdim>& l, const ExpressionBase<RExpressionType>& r)
197 {
198  return ExpressionDot<ExpressionVector<Vdim>, RExpressionType> (ExpressionVector<Vdim> (l), r.cast() );
199 }
200 
201 template< typename LExpressionType, UInt Vdim >
202 ExpressionDot<LExpressionType, ExpressionVector<Vdim> >
203 dot (const ExpressionBase<LExpressionType>& l, const VectorSmall<Vdim>& r)
204 {
205  return ExpressionDot<LExpressionType, ExpressionVector<Vdim> > (l.cast(), ExpressionVector<Vdim> (r) );
206 }
207 
208 
209 } // Namespace ExpressionAssembly
210 
211 } // Namespace LifeV
212 #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