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
matrixeigendense.hpp
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-11-13
7 
8  Copyright (C) 2005,2006 EPFL
9  Copyright (C) 2007-2012 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 #ifndef __MatrixEigen_H
31 #define __MatrixEigen_H 1
32 
33 #include <set>
34 
35 #include <boost/version.hpp>
36 #if (BOOST_VERSION >= 103400)
37 #include <boost/none.hpp>
38 #else
39 #include <boost/none_t.hpp>
40 #endif /* BOOST_VERSION >= 103400 */
41 
42 #include <Eigen/Core>
43 
46 
47 
48 namespace Feel
49 {
50 template<typename T, typename Storage> class VectorUblas;
51 
70 template<typename T>
71 class MatrixEigenDense : public MatrixSparse<T>
72 {
73  typedef MatrixSparse<T> super;
74 public:
75 
76 
80 
81  typedef T value_type;
82  typedef typename type_traits<value_type>::real_type real_type;
83  typedef Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> matrix_type;
84  typedef typename super::graph_type graph_type;
85  typedef typename super::graph_ptrtype graph_ptrtype;
87 
91 
93 
95 
97 
99 
100 
102 
106 
107  MatrixEigenDense<T> & operator = ( MatrixSparse<value_type> const& M )
108  {
109  return *this;
110  }
111 
112 
113  value_type operator()( size_type i, size_type j ) const
114  {
115  return M_mat( i, j );
116  }
117 
119 
123 
128  size_type size1 () const
129  {
130  return M_mat.rows();
131  }
132 
137  size_type size2 () const
138  {
139  return M_mat.cols();
140  }
141 
145  size_type nnz() const
146  {
147  return M_mat.rows()*M_mat.cols();
148  }
149 
155  {
156  return 0;
157  }
158 
164  {
165  return 0;
166  }
167 
171  bool isInitialized() const
172  {
173  return M_is_initialized;
174  }
175 
180  void close () const;
181 
182 
187  bool closed() const
188  {
189  return M_is_closed;
190  }
191 
192 
196  matrix_type const& mat () const
197  {
198  return M_mat;
199  }
200 
204  matrix_type & mat ()
205  {
206  return M_mat;
207  }
208 
210 
214 
215 
217 
221 
230  void init ( const size_type m,
231  const size_type n,
232  const size_type m_l,
233  const size_type n_l,
234  const size_type nnz=30,
235  const size_type noz=10 );
236 
240  void init ( const size_type m,
241  const size_type n,
242  const size_type m_l,
243  const size_type n_l,
244  graph_ptrtype const& graph );
245 
252  void clear ()
253  {
254  //eigen::resize( M_mat, 0, 0 );
255  M_mat.setZero( M_mat.rows(), M_mat.cols() );
256  }
257 
262  void zero ()
263  {
264  M_mat.setZero( M_mat.rows(), M_mat.cols() );
265  }
266 
267  void zero ( size_type start1, size_type stop1, size_type start2, size_type stop2 )
268  {
269  }
270 
279  void add ( const size_type i,
280  const size_type j,
281  const value_type& value )
282  {
283  M_mat( i, j ) += value;
284  }
285 
294  void set ( const size_type i,
295  const size_type j,
296  const value_type& value )
297  {
298  M_mat( i, j ) = value;
299  }
300 
301 
308  void printMatlab( const std::string name="NULL" ) const;
309 
310 
311 
312  void resize( size_type nr, size_type nc, bool /*preserve*/ = false );
313 
317  void diagonal ( Vector<T>& dest ) const;
318 
322  value_type
323  energy( Vector<value_type> const& __v,
324  Vector<value_type> const& __u, bool transpose = false ) const;
325 
333  void zeroRows( std::vector<int> const& rows, Vector<value_type> const& values, Vector<value_type>& rhs, Context const& on_context );
334 
335  void init() {}
336 
343  void addMatrix( const ublas::matrix<T, ublas::row_major>&,
344  const std::vector<size_type>&,
345  const std::vector<size_type>& ) {}
346 
351  void addMatrix( const boost::numeric::ublas::matrix<T, ublas::row_major>&, const std::vector<size_type>& ) {}
352 
358  void addMatrix( value_type v, MatrixSparse<value_type>& _m );
359 
366  void addMatrix ( int* rows, int nrows,
367  int* cols, int ncols,
368  value_type* data );
369 
370  void scale( const T a );
371 
378  void transpose( MatrixSparse<value_type>& Mt ) const;
379 
387  real_type l1Norm() const
388  {
389  return real_type( 0 );
390  }
391 
402  real_type linftyNorm() const
403  {
404  return real_type( 0 );
405  }
406 
410  void updateBlockMat( boost::shared_ptr<MatrixSparse<value_type> > m, std::vector<size_type> start_i, std::vector<size_type> start_j );
411 
412 
414 
415 
416 
417 protected:
418 
419 private:
420 
421  bool M_is_initialized;
422  mutable bool M_is_closed;
423 
427  mutable matrix_type M_mat;
428 };
429 
430 
431 template<typename T>
432 void
433 MatrixEigenDense<T>::zeroRows( std::vector<int> const& rows,
434  Vector<value_type> const& vals,
435  Vector<value_type>& rhs,
436  Context const& on_context )
437 {
438  Feel::detail::ignore_unused_variable_warning( rhs );
439  Feel::detail::ignore_unused_variable_warning( vals );
440 
441  for ( size_type i = 0; i < rows.size(); ++i )
442  {
443  value_type value = 1.0;
444 
445  if ( on_context.test( ON_ELIMINATION_KEEP_DIAGONAL ) )
446  value = M_mat( rows[i], rows[i] );
447  M_mat.row( rows[i] ).setZero();
448  //M_mat.col( rows[i] ).setZero();
449  // set diagonal
450  M_mat( rows[i], rows[i] ) = value;
451 
452  // multiply rhs by value of the diagonal entry value
453  rhs.set( rows[i], value * vals(rows[i]) );
454  }
455 }
456 
457 } // Feel
458 #endif /* __MatrixEigenDense_H */
void zero()
Definition: matrixeigendense.hpp:262
void diagonal(Vector< T > &dest) const
Definition: matrixeigendense.cpp:146
Definition: solverlinear.hpp:33
bool isInitialized() const
Definition: matrixeigendense.hpp:171
boost::shared_ptr< MatrixSparse< T > > transpose() const
Definition: matrixsparse.hpp:543
void clear()
Definition: matrixeigendense.hpp:252
virtual void set(const size_type i, const value_type &value)=0
void zero(size_type start1, size_type stop1, size_type start2, size_type stop2)
Definition: matrixeigendense.hpp:267
void printMatlab(const std::string name="NULL") const
Definition: matrixeigendense.cpp:207
Definition: feelalg/enums.hpp:59
matrix_type & mat()
Definition: matrixeigendense.hpp:204
void set(const size_type i, const size_type j, const value_type &value)
Definition: matrixeigendense.hpp:294
graph_ptrtype const & graph() const
Definition: matrixsparse.hpp:262
value_type operator()(size_type i, size_type j) const
Definition: matrixeigendense.hpp:113
void zeroRows(std::vector< int > const &rows, Vector< value_type > const &values, Vector< value_type > &rhs, Context const &on_context)
Definition: matrixeigendense.hpp:433
size_type size1() const
Definition: matrixeigendense.hpp:128
interface to eigen sparse matrix
Definition: matrixeigendense.hpp:71
void add(const size_type i, const size_type j, const value_type &value)
Definition: matrixeigendense.hpp:279
real_type l1Norm() const
Definition: matrixeigendense.hpp:387
bool closed() const
Definition: matrixeigendense.hpp:187
void addMatrix(const ublas::matrix< T, ublas::row_major > &, const std::vector< size_type > &, const std::vector< size_type > &)
Definition: matrixeigendense.hpp:343
matrix_type const & mat() const
Definition: matrixeigendense.hpp:196
size_type rowStop() const
Definition: matrixeigendense.hpp:163
size_type nnz() const
Definition: matrixeigendense.hpp:145
size_type rowStart() const
Definition: matrixeigendense.hpp:154
value_type energy(Vector< value_type > const &__v, Vector< value_type > const &__u, bool transpose=false) const
Definition: matrixeigendense.cpp:155
void close() const
Definition: matrixeigendense.cpp:131
interface to vector
Definition: matrixeigendense.hpp:50
size_t size_type
Indices (starting from 0)
Definition: feelcore/feel.hpp:319
Definition: matrixsparse.hpp:76
Context class.
Definition: feelcore/context.hpp:63
void addMatrix(const boost::numeric::ublas::matrix< T, ublas::row_major > &, const std::vector< size_type > &)
Definition: matrixeigendense.hpp:351
size_type size2() const
Definition: matrixeigendense.hpp:137
void updateBlockMat(boost::shared_ptr< MatrixSparse< value_type > > m, std::vector< size_type > start_i, std::vector< size_type > start_j)
Definition: matrixeigendense.cpp:197
real_type linftyNorm() const
Definition: matrixeigendense.hpp:402
Graph representation of the Compressed Sparse Row format.
Definition: graphcsr.hpp:57

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