LifeV
ExpressionSubstraction.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 substraction between expressions are defined.
30 
31  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
32 
33  @date 07-2011
34  */
35 
36 #ifndef EXPRESSION_SUBSTRACTION_HPP
37 #define EXPRESSION_SUBSTRACTION_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 ExpressionSubstraction Class for representing a difference between two expressions.
52 /*!
53  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
54 
55  This class represents the substraction in the expression tree.
56 
57  <b> Template parameters </b>
58 
59  <i>LExpressionType</i>: The expression on the left side of the substraction operation.
60 
61  <i>RExpressionType</i>: The expression on the right side of the substraction operation.
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 ExpressionSubstraction : public ExpressionBase< ExpressionSubstraction<LExpressionType, RExpressionType> >
72 {
73 public:
74 
75  //! @name Public Types
76  //@{
77 
78  // Not usefull, just for ease of coding
79  typedef ExpressionBase< ExpressionSubstraction <LExpressionType, RExpressionType> > base_Type;
80 
81  //@}
82 
83 
84  //! @name Constructors & Destructor
85  //@{
86 
87  //! Full constructor using the two expressions
88  ExpressionSubstraction (const LExpressionType& l, const RExpressionType& r)
89  : base_Type(), M_l (l), M_r (r) {}
90 
91  //! Copy constructor
92  ExpressionSubstraction (const ExpressionSubstraction<LExpressionType, RExpressionType>& expression)
93  : base_Type(), M_l (expression.M_l), M_r (expression.M_r) {}
94 
95  //! Destructor
96  ~ExpressionSubstraction() {}
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 Get Methods
116  //@{
117 
118  //! Getter for the left side of the substraction
119  const LExpressionType& left() const
120  {
121  return M_l;
122  }
123 
124  //! Getter for the right side of the substraction
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  ExpressionSubstraction();
139 
140  //@}
141 
142  // Left hand side
143  LExpressionType M_l;
144 
145  // Right hand side
146  RExpressionType M_r;
147 };
148 
149 //! operator- The generic operator for the substraction between expressions.
150 /*!
151  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
152 
153  Operator used in construction of the expression tree. To avoid shadowing
154  other operator-, it uses the ExpressionBase type to distinguish expressions
155  from other types.
156 
157  <b> Template parameters </b>
158 
159  <i>LExpressionType</i>: The expression on the left side of the substraction operation.
160 
161  <i>RExpressionType</i>: The expression on the right side of the substraction operation.
162 
163  <b> Template requirements </b>
164 
165  <i>LExpressionType</i>: Same as in LifeV::ExpressionSubstraction
166 
167  <i>RExpressionType</i>: Same as in LifeV::ExpressionSubstraction
168 
169 */
170 template< typename LExpressionType, typename RExpressionType >
171 ExpressionSubstraction<LExpressionType, RExpressionType>
172 operator- (const ExpressionBase<LExpressionType>& l, const ExpressionBase<RExpressionType>& r)
173 {
174  return ExpressionSubstraction<LExpressionType, RExpressionType> (l.cast(), r.cast() );
175 }
176 
177 // Specialization for the real constants
178 template< typename LExpressionType >
179 ExpressionSubstraction<LExpressionType, ExpressionScalar >
180 operator- (const ExpressionBase<LExpressionType>& l, const Real& r)
181 {
182  return ExpressionSubstraction<LExpressionType, ExpressionScalar> (l.cast(), ExpressionScalar (r) );
183 }
184 
185 template< typename RExpressionType >
186 ExpressionSubstraction<ExpressionScalar, RExpressionType>
187 operator- (const Real& l, const ExpressionBase<RExpressionType>& r)
188 {
189  return ExpressionSubstraction<ExpressionScalar, RExpressionType> (ExpressionScalar (l), r.cast() );
190 }
191 
192 // Specialization for the vectorial constants
193 template< typename RExpressionType , UInt Vdim>
194 ExpressionSubstraction<ExpressionVector<Vdim>, RExpressionType>
195 operator- (const VectorSmall<Vdim>& l, const ExpressionBase<RExpressionType>& r)
196 {
197  return ExpressionSubstraction<ExpressionVector<Vdim>, RExpressionType> (ExpressionVector<Vdim> (l), r.cast() );
198 }
199 
200 template< typename LExpressionType, UInt Vdim >
201 ExpressionSubstraction<LExpressionType, ExpressionVector<Vdim> >
202 operator- (const ExpressionBase<LExpressionType>& l, const VectorSmall<Vdim>& r)
203 {
204  return ExpressionSubstraction<LExpressionType, ExpressionVector<Vdim> > (l.cast(), ExpressionVector<Vdim> (r) );
205 }
206 
207 
208 } // Namespace ExpressionAssembly
209 
210 } // Namespace LifeV
211 
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