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
functionalset.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-10-11
7 
8  Copyright (C) 2005,2006 EPFL
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 #ifndef __FunctionalSet_H
30 #define __FunctionalSet_H 1
31 
32 #include <boost/numeric/ublas/vector.hpp>
33 #include <boost/numeric/ublas/vector_proxy.hpp>
34 #include <boost/numeric/ublas/matrix.hpp>
35 #include <boost/numeric/ublas/matrix_proxy.hpp>
36 #include <boost/numeric/ublas/lu.hpp>
37 #include <boost/numeric/ublas/io.hpp>
38 
39 
41 
42 namespace Feel
43 {
52 template<typename Space>
53 class FunctionalSet
54 {
55 public:
56 
57 
61 
62  typedef Space space_type;
63  typedef typename space_type::value_type value_type;
64 
65 
66  typedef FunctionalSet<Space> functionalset_type;
67  typedef functionalset_type self_type;
68  typedef Functional<Space> functional_type;
69 
70 
71  typedef typename space_type::matrix_type matrix_type;
72 
73  typedef std::vector<functional_type> fset_type;
74 
76 
80 
81  FunctionalSet()
82  :
83  M_space(),
84  M_fset(),
85  M_mat()
86  {}
87 
88  FunctionalSet( space_type const& s )
89  :
90  M_space( s ),
91  M_fset(),
92  M_mat()
93  {
94  }
95  FunctionalSet( space_type const& s, std::vector<functional_type> const& fset )
96  :
97  M_space( s ),
98  M_fset( fset ),
99  M_mat( space_type::nComponents*fset.size(), fset[0].coeff().size2() )
100  {
101  //std::cout << "FunctionalSet: " << fset[0].coeff() << "\n";
102  this->setFunctionalSet( fset );
103  }
104  FunctionalSet( FunctionalSet const & fset )
105  :
106  M_space( fset.M_space ),
107  M_fset( fset.M_fset ),
108  M_mat( fset.M_mat )
109  {}
110 
111  ~FunctionalSet()
112  {}
113 
115 
119 
120  self_type& operator=( self_type const& fset )
121  {
122  if ( this != fset )
123  {
124  M_space = fset.M_space;
125  M_fset = fset.M_fset;
126  M_mat = fset.M_mat;
127  }
128 
129  return *this;
130  }
131 
135  functional_type const& operator()( uint16_type i ) const
136  {
137  return M_fset[i];
138  }
139 
143  matrix_type operator()( space_type const& p ) const
144  {
145  //FEELPP_ASSERT( M_mat.size2() == ublas::trans(p.coeff()).size1() )( M_mat.size1() )( p.coeff().size1() ).error( "incompatible dimension between functional and polynomial.\n Is the space correctly defined?" );
146 
147  return ublas::prod( space_type::polyset_type::toMatrix( M_mat ),
148  ublas::trans( space_type::polyset_type::toMatrix( p.coeff() ) ) );
149  }
151 
155 
160  space_type const& functionSpace() const
161  {
162  return M_space;
163  }
164 
171  matrix_type const& rep() const
172  {
173  return M_mat;
174  }
175 
176 
178 
182 
186  void setFunctionSpace( space_type const& __space )
187  {
188  M_space = __space;
189  }
190 
194  void setFunctionalSet( std::vector<functional_type> const& fset )
195  {
196  M_fset = fset;
197 
198 
199  if ( space_type::is_scalar )
200  {
201  // update matrix associated with functionals applied to the
202  // basis of the function space
203  M_mat = ublas::zero_matrix<value_type>( fset.size(), fset[0].coeff().size2() );
204 
205  //std::cout << "mat size" << M_mat << "\n";
206  for ( uint16_type i = 0; i < fset.size(); ++i )
207  {
208  //std::cout << "Functional " << i << "=" << fset[i].coeff() << "\n";
209  ublas::row( M_mat, i ) = ublas::row( fset[i].coeff(), 0 );
210  }
211 
212  //std::cout << "mat size" << M_mat << "\n";
213 
214  }
215 
216  else
217  {
218  // update matrix associated with functionals applied to the
219  // basis of the function space
220  M_mat = ublas::zero_matrix<value_type>( space_type::nComponents*fset.size(), fset[0].coeff().size2() );
221 
222  for ( uint16_type i = 0; i < fset.size(); ++i )
223  {
224  ublas::project( M_mat,
225  ublas::range( i*space_type::nComponents, ( i+1 )*space_type::nComponents ),
226  ublas::range( 0, M_mat.size2() ) ) = ublas::scalar_matrix<value_type>( space_type::nComponents, M_mat.size2(), -1 );
227  ublas::project( M_mat,
228  ublas::range( i*space_type::nComponents, ( i+1 )*space_type::nComponents ),
229  ublas::range( 0, M_mat.size2() ) ) = fset[i].coeff();
230  }
231  }
232  }
233 
235 
239 
240 
242 
243 
244 
245 protected:
246 
247 private:
248  space_type M_space;
249  fset_type M_fset;
250  matrix_type M_mat;
251 };
252 } // Feel
253 #endif /* __FunctionalSet_H */

Generated on Sun Oct 20 2013 08:24:58 for Feel++ by doxygen 1.8.4