30 #ifndef __MatrixBlock_H
31 #define __MatrixBlock_H 1
34 #include <boost/spirit/home/phoenix.hpp>
35 #include <boost/spirit/home/phoenix/core/argument.hpp>
46 template<
typename T>
class Backend;
48 template <
typename T=
double>
49 class BlocksBaseSparseMatrix :
public vf::BlocksBase<boost::shared_ptr<MatrixSparse<T> > >
52 typedef vf::BlocksBase<boost::shared_ptr<MatrixSparse<T> > > super_type;
53 typedef BlocksBaseSparseMatrix<T> self_type;
54 typedef boost::shared_ptr<MatrixSparse<T> > matrix_sparse_ptrtype;
56 BlocksBaseSparseMatrix(uint16_type nr,uint16_type nc)
61 BlocksBaseSparseMatrix(super_type
const & b)
67 operator<<( matrix_sparse_ptrtype
const& m )
const
69 return super_type::operator<<( m );
74 template <
int NR,
int NC,
typename T=
double>
75 class BlocksSparseMatrix :
public BlocksBaseSparseMatrix<T>
78 static const uint16_type NBLOCKROWS = NR;
79 static const uint16_type NBLOCKCOLS = NC;
81 typedef BlocksBaseSparseMatrix<T> super_type;
85 super_type(NBLOCKROWS,NBLOCKCOLS)
107 template<
typename T>
108 class MatrixBlockBase :
public MatrixSparse<T>
110 typedef MatrixSparse<T> super;
117 typedef MatrixBlockBase<T> self_type;
119 typedef typename super::value_type value_type;
120 typedef typename super::real_type real_type;
122 typedef Backend<value_type> backend_type;
123 typedef boost::shared_ptr<backend_type> backend_ptrtype;
125 typedef super matrix_type;
126 typedef boost::shared_ptr<matrix_type> matrix_ptrtype;
128 typedef std::vector<matrix_ptrtype> vector_matrix_ptrtype;
130 typedef typename super::graph_type graph_type;
131 typedef typename super::graph_ptrtype graph_ptrtype;
139 MatrixBlockBase( vf::BlocksBase<matrix_ptrtype >
const & blockSet,
140 backend_type &backend,
141 bool copy_values=
true,
142 bool diag_is_nonzero=
true );
144 MatrixBlockBase( vf::BlocksBase<graph_ptrtype>
const &
graph,
145 backend_type &backend,
146 bool diag_is_nonzero=
true );
148 MatrixBlockBase( MatrixBlockBase
const & mb )
163 MatrixBlockBase operator=( MatrixBlockBase
const& mb )
178 matrix_ptrtype getSparseMatrix()
217 graph_ptrtype
const&
graph );
276 const value_type& value );
288 const value_type& value );
296 void addMatrix (
const ublas::matrix<value_type> &dm,
297 const std::vector<size_type> &rows,
298 const std::vector<size_type> &cols );
307 int* cols,
int ncols,
315 const std::vector<size_type> &dof_indices )
317 this->
addMatrix ( dm, dof_indices, dof_indices );
328 void scale (
const value_type );
378 real_type
l1Norm ()
const;
403 void print( std::ostream& os=std::cout )
const;
409 template <
typename U>
410 friend std::ostream& operator << ( std::ostream& os, const MatrixSparse<U>& m );
418 std::cerr <<
"ERROR: Not Implemented in base class yet!" << std::endl;
419 FEELPP_ASSERT( 0 ).error(
"invalid call" );
428 void printMatlab(
const std::string name=
"NULL" )
const;
436 const std::vector<size_type>& rows,
437 const std::vector<size_type>& cols )
const
452 const std::vector<size_type>& rows,
453 const std::vector<size_type>& cols )
const
482 boost::shared_ptr<MatrixSparse<value_type> > M_mat;
486 template<
int NR,
int NC,
typename T>
487 class MatrixBlock :
public MatrixBlockBase<T>
489 typedef MatrixBlockBase<T> super_type;
493 static const uint16_type NBLOCKROWS = NR;
494 static const uint16_type NBLOCKCOLS = NC;
495 static const uint16_type NBLOCKSIZE = NR * NC;
497 typedef typename super_type::value_type value_type;
498 typedef typename super_type::matrix_ptrtype matrix_ptrtype;
499 typedef typename super_type::backend_type backend_type;
500 typedef vf::Blocks<NBLOCKROWS,NBLOCKCOLS,matrix_ptrtype > blocks_type;
501 typedef vf::BlocksBase<matrix_ptrtype> blocksbase_type;
502 MatrixBlock( blocksbase_type
const & blockSet,
503 backend_type &backend,
504 bool copy_values=
true,
505 bool diag_is_nonzero=
true )
507 super_type( blockSet,backend,copy_values,diag_is_nonzero )
510 MatrixBlock( MatrixBlock
const & mb )
515 MatrixBlock operator=( MatrixBlock
const& mb )
517 super_type::operator=( mb );
521 MatrixBlock & operator = ( matrix_ptrtype
const& M )
523 super_type::operator=( M );