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
val.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: 2007-07-02
7 
8  Copyright (C) 2007-2011 Université Joseph Fourier (Grenoble I)
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 3.0 of the License, or (at your option) any later version.
14 
15  This library 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
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
29 #if !defined( FEELPP_VF_VAL_HPP )
30 #define FEELPP_VF_VAL_HPP 1
31 
32 # include <boost/preprocessor/comparison/less.hpp>
33 # include <boost/preprocessor/logical/and.hpp>
34 # include <boost/preprocessor/control/if.hpp>
35 # include <boost/preprocessor/list/at.hpp>
36 # include <boost/preprocessor/list/cat.hpp>
37 # include <boost/preprocessor/list/for_each_product.hpp>
38 # include <boost/preprocessor/logical/or.hpp>
39 # include <boost/preprocessor/tuple/to_list.hpp>
40 # include <boost/preprocessor/tuple/eat.hpp>
41 # include <boost/preprocessor/facilities/empty.hpp>
42 # include <boost/preprocessor/punctuation/comma.hpp>
43 # include <boost/preprocessor/facilities/identity.hpp>
44 
46 #include <feel/feelcore/traits.hpp>
48 
49 
50 #if defined( FEELPP_HAS_QD_H ) && defined(FEELPP_HAS_MPFR)
51 # define VF_CHECK_ARITHMETIC_TYPE() \
52  BOOST_STATIC_ASSERT( (::boost::is_arithmetic<value_1_type>::value || \
53  ::boost::is_same<value_1_type, std::complex<float> >::value || \
54  ::boost::is_same<value_1_type, std::complex<double> >::value || \
55  ::boost::is_same<value_1_type,mp_type>::value || \
56  ::boost::is_same<value_1_type,dd_real>::value || \
57  ::boost::is_same<value_1_type,qd_real>::value) ); \
58 
59 #elif defined( FEELPP_HAS_QD_H )
60 # define VF_CHECK_ARITHMETIC_TYPE() \
61  BOOST_STATIC_ASSERT( (::boost::is_arithmetic<value_1_type>::value || \
62  ::boost::is_same<value_1_type, std::complex<float> >::value || \
63  ::boost::is_same<value_1_type, std::complex<double> >::value || \
64  ::boost::is_same<value_1_type,dd_real>::value || \
65  ::boost::is_same<value_1_type,qd_real>::value) ); \
66 
67 #elif defined( FEELPP_HAS_MPFR )
68 # define VF_CHECK_ARITHMETIC_TYPE() \
69  BOOST_STATIC_ASSERT( (::boost::is_arithmetic<value_1_type>::value || \
70  ::boost::is_same<value_1_type, std::complex<float> >::value || \
71  ::boost::is_same<value_1_type, std::complex<double> >::value || \
72  ::boost::is_same<value_1_type,mp_type>::value) ); \
73 
74 #else
75 # define VF_CHECK_ARITHMETIC_TYPE() \
76  BOOST_STATIC_ASSERT( ( ::boost::is_arithmetic<value_1_type>::value || \
77  ::boost::is_same<value_1_type, std::complex<float> >::value || \
78  ::boost::is_same<value_1_type, std::complex<double> >::value ) \
79  ); \
80 
81 #endif
82 
83 namespace Feel
84 {
85 namespace vf
86 {
87 
88 template < typename ExprT1 >
89 class Val
90  :
91 public UnaryFunctor<typename ExprT1::value_type>
92 {
93 public:
94 
95  static const size_type context = ExprT1::context;
96  static const bool is_terminal = ExprT1::is_terminal;
97 
98  static const uint16_type imorder = ExprT1::imorder;
99  static const bool imIsPoly = ExprT1::imIsPoly;
100 
101  template<typename Func>
102  struct HasTestFunction
103  {
104  static const bool result = false;
105  };
106 
107  template<typename Func>
108  struct HasTrialFunction
109  {
110  static const bool result = false;
111  };
112 
113  typedef UnaryFunctor<typename ExprT1::value_type> super;
114  typedef typename super::functordomain_type functordomain_type;
115  typedef typename super::functordomain_ptrtype functordomain_ptrtype;
116  typedef ExprT1 expression_1_type;
117  typedef Val<ExprT1> this_type;
118  typedef typename expression_1_type::value_type value_1_type;
119  typedef value_1_type value_type;
120 
121  VF_CHECK_ARITHMETIC_TYPE()
122 
123  explicit Val( expression_1_type const& __expr1 )
124  :
125  super( "value", functordomain_ptrtype( new UnboundedDomain<value_type>() ) ),
126  M_expr_1( __expr1 )
127  {
128  DVLOG(2) << "Val::Val default constructorn";
129  }
130 
131  Val( Val const& __vfp )
132  :
133  super( "value", functordomain_ptrtype( new UnboundedDomain<value_type>() ) ),
134  M_expr_1( __vfp.M_expr_1 )
135  {
136  DVLOG(2) << "Val::Val copy constructorn";
137  }
138 
139  bool isSymetric() const
140  {
141  return false;
142  }
143 
144  void eval( int nx, value_type const* x, value_type* f ) const
145  {
146  for ( int i = 0; i < nx; ++i )
147  f[i] = x[i];
148  }
149 
150  expression_1_type const& expression() const
151  {
152  return M_expr_1;
153  }
154 
155  template<typename Geo_t, typename Basis_i_t, typename Basis_j_t = Basis_i_t>
156  struct tensor
157  {
158  typedef this_type expression_type;
159  //typedef typename expression_1_type::template tensor<Geo_t, Basis_i_t,Basis_j_t> tensor2_expr_type;
160  typedef typename expression_1_type::template tensor<Geo_t> tensor2_expr_type;
161  typedef typename tensor2_expr_type::value_type value_type;
162  typedef typename mpl::if_<fusion::result_of::has_key<Geo_t,vf::detail::gmc<0> >,
163  mpl::identity<vf::detail::gmc<0> >,
164  mpl::identity<vf::detail::gmc<1> > >::type::type key_type;
165  typedef typename fusion::result_of::value_at_key<Geo_t,key_type>::type::element_type* gmc_ptrtype;
166  typedef typename fusion::result_of::value_at_key<Geo_t,key_type>::type::element_type gmc_type;
167  typedef typename tensor2_expr_type::shape shape;
168 
169  struct is_zero
170  {
171  static const bool value = tensor2_expr_type::is_zero::value;
172  };
173 
174  template<typename ExprT>
175  tensor( ExprT const& expr, Geo_t const& geom, Basis_i_t const& /*fev*/, Basis_j_t const& /*feu*/ )
176  :
177  M_expr( expr.expression(), geom ),
178  M_gmc( fusion::at_key<key_type>( geom ).get() ),
179  M_loc( boost::extents[M_gmc->nPoints()][shape::M][shape::N] )
180  {
181  update( geom );
182  }
183  template<typename ExprT>
184  tensor( ExprT const& expr,Geo_t const& geom, Basis_i_t const& /*fev*/ )
185  :
186  M_expr( expr.expression(), geom ),
187  M_gmc( fusion::at_key<key_type>( geom ).get() ),
188  M_loc( boost::extents[M_gmc->nPoints()][shape::M][shape::N] )
189  {
190  update( geom );
191  }
192  template<typename ExprT>
193  tensor( ExprT const& expr, Geo_t const& geom )
194  :
195  M_expr( expr.expression(), geom ),
196  M_gmc( fusion::at_key<key_type>( geom ).get() ),
197  M_loc( boost::extents[M_gmc->nPoints()][shape::M][shape::N] )
198  {
199  update( geom );
200  }
201  template<typename IM>
202  void init( IM const& im )
203  {
204  M_expr.init( im );
205  }
206  void update( Geo_t const& geom, Basis_i_t const& /*fev*/, Basis_j_t const& /*feu*/ )
207  {
208  update( geom );
209  }
210  void update( Geo_t const& geom, Basis_i_t const& /*fev*/ )
211  {
212  update( geom );
213  }
214  void update( Geo_t const& geom )
215  {
216  M_expr.update( geom );
217 
218  for ( int q = 0; q < M_gmc->nPoints(); ++q )
219  for ( int c1 = 0; c1 < shape::M; ++c1 )
220  for ( int c2 = 0; c2 < shape::N; ++c2 )
221  {
222  M_loc[q][c1][c2] = M_expr.evalq( c1, c2, q );
223  }
224  }
225  void update( Geo_t const& geom, uint16_type face )
226  {
227  M_expr.update( geom, face );
228 
229  for ( int q = 0; q < M_gmc->nPoints(); ++q )
230  for ( int c1 = 0; c1 < shape::M; ++c1 )
231  for ( int c2 = 0; c2 < shape::N; ++c2 )
232  {
233  M_loc[q][c1][c2] = M_expr.evalq( c1, c2, q );
234  }
235  }
236 
237  value_type
238  evalijq( uint16_type /*i*/, uint16_type /*j*/, uint16_type c1, uint16_type c2, uint16_type q ) const
239  {
240  return evalq( c1, c2, q );
241  }
242  template<int PatternContext>
243  value_type
244  evalijq( uint16_type /*i*/, uint16_type /*j*/, uint16_type c1, uint16_type c2, uint16_type q,
245  mpl::int_<PatternContext> ) const
246  {
247  return evalq( c1, c2, q );
248  }
249 
250  value_type
251  evaliq( uint16_type /*i*/, uint16_type c1, uint16_type c2, uint16_type q ) const
252  {
253  return evalq( c1, c2, q );
254  }
255  value_type
256  evalq( uint16_type c1, uint16_type c2, uint16_type q ) const
257  {
258  return evalq( c1, c2, q, mpl::int_<shape::rank>() );
259  }
260  private:
261  value_type
262  evalq( uint16_type c1, uint16_type c2, uint16_type q, mpl::int_<0> ) const
263  {
264  Feel::detail::ignore_unused_variable_warning( c1 );
265  Feel::detail::ignore_unused_variable_warning( c2 );
266  return M_loc[q][0][0];
267  }
268  value_type
269  evalq( uint16_type c1, uint16_type c2, uint16_type q, mpl::int_<1> ) const
270  {
271  if ( shape::M > shape::N )
272  return M_loc[q][c1][0];
273 
274  return M_loc[q][0][c2];
275  }
276  value_type
277  evalq( uint16_type c1, uint16_type c2, uint16_type q, mpl::int_<2> ) const
278  {
279  return M_loc[q][c1][c2];
280  }
281  private:
282  tensor2_expr_type M_expr;
283  gmc_ptrtype M_gmc;
284  boost::multi_array<value_type,3> M_loc;
285  };
286 
287 protected:
288  Val() {}
289 
290  expression_1_type M_expr_1;
291 };
293 
299 template<typename ExprT1>
300 inline
301 Expr< Val<typename mpl::if_<boost::is_arithmetic<ExprT1>,
302  mpl::identity<Cst<ExprT1> >,
303  mpl::identity<ExprT1> >::type::type > >
304  val( ExprT1 const& __e1 )
305 {
306  typedef typename mpl::if_<boost::is_arithmetic<ExprT1>,
307  mpl::identity<Cst<ExprT1> >,
308  mpl::identity<ExprT1> >::type::type t1;
309  typedef Val<t1> expr_t;
310  return Expr< expr_t >( expr_t( t1( __e1 ) ) );
311 }
312 } // vf
313 } // Feel
314 #endif /* FEELPP_VF_VAL_HPP */

Generated on Fri Oct 25 2013 14:24:26 for Feel++ by doxygen 1.8.4