Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
operators3.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2005-01-17
7 
8  Copyright (C) 2005,2006 EPFL
9  Copyright (C) 2006,2007 Universite Joseph Fourier (Grenoble I)
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
30 #if !defined( __FEELPP_VF_OPERATORS3_HPP )
31 #define __FEELPP_VF_OPERATORS3_HPP 1
32 
33 # include <boost/preprocessor/stringize.hpp>
34 
35 namespace Feel
36 {
37 namespace vf
38 {
40 template <typename LeftExprType, typename RightExprType>
41 class OpDot
42 {
43 public:
44 
45  static const size_type context = LeftExprType::context|RightExprType::context;
46 
47  static const uint16_type imorder = LeftExprType::imorder + RightExprType::imorder;
48  static const bool imIsPoly = LeftExprType::imIsPoly && RightExprType::imIsPoly;
49 
50  typedef LeftExprType left_expression_type;
51  typedef RightExprType right_expression_type;
52  typedef OpDot<LeftExprType, RightExprType> this_type;
53  typedef this_type self_type;
54  typedef typename mpl::if_<mpl::greater<mpl::sizeof_<typename left_expression_type::value_type>,
55  mpl::sizeof_<typename right_expression_type::value_type> >,
56  mpl::identity<typename left_expression_type::value_type>,
57  mpl::identity<typename right_expression_type::value_type> >::type::type value_type;
58 
59  OpDot ( left_expression_type const& left,
60  right_expression_type const& right )
61  :
62  M_left ( left ),
63  M_right ( right )
64  {
65  DVLOG(2) << "[" BOOST_PP_STRINGIZE( OpDot ) "] default constructor\n";
66 
67  }
68  OpDot( OpDot const& op )
69  :
70  M_left ( op.M_left ),
71  M_right ( op.M_right )
72  {
73  DVLOG(2) << "[" BOOST_PP_STRINGIZE( OpDot ) "] copy constructor\n";
74 
75  }
76 
77  left_expression_type const& left() const
78  {
79  return M_left;
80  }
81  right_expression_type const& right() const
82  {
83  return M_right;
84  }
85 
86  template<typename Geo_t, typename Basis_i_t, typename Basis_j_t = Basis_i_t>
87  struct tensor
88  {
89  typedef this_type expression_type;
90  typedef typename LeftExprType::template tensor<Geo_t, Basis_i_t, Basis_j_t> l_type;
91  typedef typename RightExprType::template tensor<Geo_t, Basis_i_t, Basis_j_t> r_type;
92  typedef typename strongest_numeric_type<typename l_type::value_type,
93  typename r_type::value_type>::type value_type;
94  BOOST_STATIC_ASSERT( ( boost::is_same<typename l_type::return_value_type,
95  typename r_type::return_value_type>::value ) );
96 
97  typedef typename l_type::return_value_type return_value_type;
98 
99  static const uint16_type rank = return_value_type::rank+1;
100  static const uint16_type nComponents = return_value_type::nComponents;
101  static const bool do_reduction = ( !boost::is_same<return_value_type,typename Basis_i_t::polyset_type>::value||
102  !boost::is_same<return_value_type,typename Basis_j_t::polyset_type>::value );
103  tensor( this_type const& expr,
104  Geo_t const& geom,
105  Basis_i_t const& fev,
106  Basis_j_t const& feu )
107  :
108  M_left( expr.left(), geom, fev, feu ),
109  M_right( expr.right(), geom, fev, feu )
110  {}
111 
112  void update( Geo_t const& geom, Basis_i_t const& fev, Basis_j_t const& feu )
113  {
114  M_left.update( geom, fev, feu );
115  M_right.update( geom, fev, feu );
116  }
117  void update( Geo_t const& geom, Basis_i_t const& fev )
118  {
119  M_left.update( geom, fev );
120  M_right.update( geom, fev );
121  }
122  void update( Geo_t const& geom )
123  {
124  M_left.update( geom );
125  M_right.update( geom );
126  }
127 
128 
129  value_type
130  operator()( uint16_type i,
131  uint16_type j,
132  int q ) const
133  {
134  return this->operator()( i, j, q, mpl::bool_<do_reduction>() );
135  }
136 
137  private:
138 
139  value_type
140  operator()( uint16_type i,
141  uint16_type j,
142  int q,
143  mpl::bool_<true> ) const
144  {
145  value_type res( 0 );
146 #if 0
147  std::cout << "[dot] rank = "<< rank << " nc=" << return_value_type::nComponentsLast << "\n"
148  << "[dot] ranki= "<< uint16_type::rank << " rankj = "<< uint16_type::rank << "\n";
149 #endif
150  typename Basis_i_t::template Index<rank> i_up ( i );
151  typename Basis_i_t::template Index<rank> j_up ( j );
152 
153  // fail for g++ 4.2
154 #if 0
155  BOOST_MPL_ASSERT_MSG( rank == uint16_type::rank+1, INVALID_INDEX_RANK, ( mpl::int_<uint16_type::rank>, mpl::int_<rank> ) );
156  BOOST_MPL_ASSERT_MSG( rank == uint16_type::rank+1, INVALID_INDEX_RANK, ( mpl::int_<uint16_type::rank>, mpl::int_<rank> ) );
157 #endif
158 
159  for ( int c = 0; c < return_value_type::nComponentsLast; ++c )
160  {
161  i_up.setIndex( rank-1, c );
162  j_up.setIndex( rank-1, c );
163  res += M_left( i_up, j_up, q ) * M_right( i_up, j_up, q );
164  }
165 
166  return res;
167  }
168 
169  value_type
170  operator()( uint16_type i,
171  uint16_type j,
172  int q,
173  mpl::bool_<false> ) const
174  {
175  return M_left( i, j, q ) * M_right( i, j, q );
176  }
177  private:
178  l_type M_left;
179  r_type M_right;
180 
181  };
182 
183 protected:
184  OpDot () {}
185 
186 
187 private:
188  left_expression_type const& M_left;
189  right_expression_type const& M_right;
190 };
191 template <class LeftExprType, typename RightExprType>
192 inline Expr< OpDot< LeftExprType, RightExprType> >
193 dot( LeftExprType const& left, RightExprType const& right )
194 {
195  typedef OpDot<LeftExprType, RightExprType> expr_t;
196  return Expr< expr_t >( expr_t( left, right ) );
197 }
198 // template <class LeftExprType, typename RightExprType>
199 // inline Expr< OpDot< LeftExprType, RightExprType> >
200 // operator,( LeftExprType const& left, RightExprType const& right )
201 // {
202 // typedef OpDot<LeftExprType, RightExprType> expr_t;
203 // return Expr< expr_t >( expr_t(left, right) );
204 // }
206 } // vf
207 } // feel
208 
209 #endif /* __FEELPP_VF_OPERATORS2_HPP */
size_t size_type
Indices (starting from 0)
Definition: feelcore/feel.hpp:319

Generated on Sun Dec 22 2013 13:11:10 for Feel++ by doxygen 1.8.5