Feel++
0.91.4
|
#include <matrixsparse.hpp>
Public Types | |
typedef T | value_type |
typedef type_traits< T >::real_type | real_type |
typedef GraphCSR | graph_type |
typedef boost::shared_ptr < graph_type > | graph_ptrtype |
typedef Vector< T > | vector_type |
typedef boost::shared_ptr < Vector< T > > | vector_ptrtype |
Public Member Functions | |
MatrixSparse () | |
MatrixSparse (DataMap const &dmRow, DataMap const &dmCol, WorldComm const &worldComm=WorldComm()) | |
virtual | ~MatrixSparse () |
DataMap const & | mapRow () const |
DataMap const & | mapCol () const |
void | setMapRow (DataMap const &d) |
void | setMapCol (DataMap const &d) |
virtual bool | isInitialized () const |
virtual void | updateSparsityPattern (const std::vector< std::vector< size_type > > &) |
virtual void | init (const size_type m, const size_type n, const size_type m_l, const size_type n_l, const size_type nnz=30, const size_type noz=10)=0 |
virtual void | init (const size_type m, const size_type n, const size_type m_l, const size_type n_l, graph_ptrtype const &graph)=0 |
virtual void | setIndexSplit (std::vector< std::vector< int > > const &_indexSplit) |
std::vector< std::vector< int > > | indexSplit () const |
bool | hasGraph () const |
graph_ptrtype const & | graph () const |
void | setGraph (graph_ptrtype const &graph) |
void | setMatrixProperties (size_type p) |
bool | isHermitian () const |
bool | isNonHermitian () const |
bool | isHermitianPositiveDefinite () const |
bool | isSingular () const |
bool | isPositiveDefinite () const |
bool | haveConsistentProperties () const |
void | checkProperties () const |
WorldComm const & | comm () const |
virtual void | clear ()=0 |
virtual void | zero ()=0 |
virtual void | zero (size_type start1, size_type size1, size_type start2, size_type size2)=0 |
virtual void | close () const =0 |
virtual size_type | size1 () const =0 |
virtual size_type | size2 () const =0 |
virtual size_type | rowStart () const =0 |
virtual size_type | rowStop () const =0 |
virtual void | set (const size_type i, const size_type j, const value_type &value)=0 |
virtual void | add (const size_type i, const size_type j, const value_type &value)=0 |
virtual void | addMatrix (const ublas::matrix< value_type > &dm, const std::vector< size_type > &rows, const std::vector< size_type > &cols)=0 |
virtual void | addMatrix (int *rows, int nrows, int *cols, int ncols, value_type *data)=0 |
virtual void | addMatrix (const ublas::matrix< value_type > &dm, const std::vector< size_type > &dof_indices)=0 |
virtual void | addMatrix (const T, MatrixSparse< T > &)=0 |
void | addMatrix (const T &s, boost::shared_ptr< MatrixSparse< T > > &m) |
virtual void | scale (const T)=0 |
void | multVector (const Vector< T > &arg, Vector< T > &dest) const |
void | multVector (const boost::shared_ptr< Vector< T > > &arg, boost::shared_ptr< Vector< T > > &dest) const |
void | multAddVector (const Vector< T > &arg, Vector< T > &dest) const |
virtual T | operator() (const size_type i, const size_type j) const =0 |
virtual MatrixSparse< T > & | operator= (MatrixSparse< value_type > const &M)=0 |
MatrixSparse< T > & | operator= (boost::shared_ptr< MatrixSparse< value_type > > const &M) |
virtual void | diagonal (Vector< T > &dest) const =0 |
void | diagonal (boost::shared_ptr< Vector< T > > &dest) const |
virtual void | transpose (MatrixSparse< value_type > &Mt) const =0 |
boost::shared_ptr < MatrixSparse< T > > | transpose () const |
void | transpose (boost::shared_ptr< MatrixSparse< value_type > > &Mt) const |
virtual void | symmetricPart (MatrixSparse< value_type > &Ms) const |
void | symmetricPart (boost::shared_ptr< MatrixSparse< value_type > > &Ms) const |
virtual real_type | energy (vector_type const &v, vector_type const &u, bool transpose=false) const =0 |
real_type | energy (vector_ptrtype const &v, vector_ptrtype const &u, bool _transpose=false) const |
virtual real_type | l1Norm () const =0 |
virtual real_type | linftyNorm () const =0 |
virtual bool | closed () const =0 |
void | print (std::ostream &os=std::cout) const |
virtual void | printPersonal (std::ostream &=std::cout) const |
virtual void | printMatlab (const std::string name="NULL") const |
virtual void | createSubmatrix (MatrixSparse< T > &submatrix, const std::vector< size_type > &rows, const std::vector< size_type > &cols) const |
virtual void | reinitSubmatrix (MatrixSparse< T > &submatrix, const std::vector< size_type > &rows, const std::vector< size_type > &cols) const |
virtual void | zeroRows (std::vector< int > const &rows, std::vector< value_type > const &values, Vector< value_type > &rhs, Context const &on_context)=0 |
virtual void | updateBlockMat (boost::shared_ptr< MatrixSparse< T > > m, size_type start_i, size_type start_j)=0 |
void | setInitialized (bool _init) |
Protected Member Functions | |
virtual void | _get_submatrix (MatrixSparse< T > &, const std::vector< size_type > &, const std::vector< size_type > &, const bool) const |
Protected Attributes | |
WorldComm | M_worldComm |
mpi communicator | |
bool | _M_is_initialized |
graph_ptrtype | _M_graph |
Context | M_mprop |
std::vector< std::vector< int > > | M_IndexSplit |
DataMap | M_mapRow |
DataMap | M_mapCol |
Friends | |
template<typename U > | |
std::ostream & | operator<< (std::ostream &os, const MatrixSparse< U > &m) |
Generic sparse matrix. This class contains pure virtual members that must be overloaded in derived classes. Using a derived class allows for uniform access to sparse matrices from various different solver packages in different formats.
Feel::MatrixSparse< T >::MatrixSparse | ( | ) | [inline] |
Constructor; initializes the matrix to be empty, without any structure, i.e. the matrix is not usable at all. This constructor is therefore only useful for matrices which are members of a class. All other matrices should be created at a point in the data flow where all necessary information is available.
You have to initialize the matrix before usage with init
(...).
Feel::MatrixSparse< T >::~MatrixSparse | ( | ) | [inline, virtual] |
Destructor. Free all memory, but do not release the memory of the sparsity structure.
virtual void Feel::MatrixSparse< T >::_get_submatrix | ( | MatrixSparse< T > & | , |
const std::vector< size_type > & | , | ||
const std::vector< size_type > & | , | ||
const bool | |||
) | const [inline, protected, virtual] |
Protected implementation of the create_submatrix and reinit_submatrix routines. Note that this function must be redefined in derived classes for it to work properly!
Referenced by Feel::MatrixBlockBase< T >::createSubmatrix(), Feel::MatrixSparse< T >::createSubmatrix(), Feel::MatrixBlockBase< T >::reinitSubmatrix(), and Feel::MatrixSparse< T >::reinitSubmatrix().
virtual void Feel::MatrixSparse< T >::add | ( | const size_type | i, |
const size_type | j, | ||
const value_type & | value | ||
) | [pure virtual] |
Add value
to the element (i,j). Throws an error if the entry does not exist. Still, it is allowed to store zero values in non-existent fields.
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::addMatrix | ( | const ublas::matrix< value_type > & | dm, |
const std::vector< size_type > & | rows, | ||
const std::vector< size_type > & | cols | ||
) | [pure virtual] |
Add the full matrix to the Sparse matrix. This is useful for adding an element matrix at assembly time
Implemented in Feel::MatrixBlockBase< T >.
Referenced by Feel::MatrixSparse< T >::addMatrix().
virtual void Feel::MatrixSparse< T >::addMatrix | ( | int * | rows, |
int | nrows, | ||
int * | cols, | ||
int | ncols, | ||
value_type * | data | ||
) | [pure virtual] |
Add the full matrix to the Sparse matrix. This is useful for adding an element matrix at assembly time
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::addMatrix | ( | const ublas::matrix< value_type > & | dm, |
const std::vector< size_type > & | dof_indices | ||
) | [pure virtual] |
Same, but assumes the row and column maps are the same. Thus the matrix dm
must be square.
Implemented in Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::addMatrix | ( | const T | , |
MatrixSparse< T > & | |||
) | [pure virtual] |
Add a Sparse matrix _X
, scaled with _a
, to this
, stores the result in this:
.
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
void Feel::MatrixSparse< T >::addMatrix | ( | const T & | s, |
boost::shared_ptr< MatrixSparse< T > > & | m | ||
) | [inline] |
Add a Sparse matrix _X
, scaled with _a
, to this
, stores the result in this:
.
References Feel::MatrixSparse< T >::addMatrix().
virtual void Feel::MatrixSparse< T >::clear | ( | ) | [pure virtual] |
Release all memory and return to a state just like after having called the default constructor.
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::close | ( | ) | const [pure virtual] |
Call the Sparse assemble routines. sends necessary messages to other processors
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual bool Feel::MatrixSparse< T >::closed | ( | ) | const [pure virtual] |
see if Sparse matrix has been closed and fully assembled yet
Implemented in Feel::MatrixBlockBase< T >, and Feel::MatrixGmm< T, LayoutType >.
WorldComm const& Feel::MatrixSparse< T >::comm | ( | ) | const [inline] |
References Feel::MatrixSparse< T >::M_worldComm.
virtual void Feel::MatrixSparse< T >::createSubmatrix | ( | MatrixSparse< T > & | submatrix, |
const std::vector< size_type > & | rows, | ||
const std::vector< size_type > & | cols | ||
) | const [inline, virtual] |
This function creates a matrix called "submatrix" which is defined by the row and column indices given in the "rows" and "cols" entries. Currently this operation is only defined for the PetscMatrix type.
Reimplemented in Feel::MatrixBlockBase< T >.
References Feel::MatrixSparse< T >::_get_submatrix().
virtual void Feel::MatrixSparse< T >::diagonal | ( | Vector< T > & | dest | ) | const [pure virtual] |
Copies the diagonal part of the matrix into dest
.
Implemented in Feel::MatrixBlockBase< T >.
void Feel::MatrixSparse< T >::diagonal | ( | boost::shared_ptr< Vector< T > > & | dest | ) | const [inline] |
Copies the diagonal part of the matrix into dest
.
References Feel::MatrixSparse< T >::diagonal().
Referenced by Feel::MatrixSparse< T >::diagonal().
virtual real_type Feel::MatrixSparse< T >::energy | ( | vector_type const & | v, |
vector_type const & | u, | ||
bool | transpose = false |
||
) | const [pure virtual] |
compute the A scalar product
u | a vector |
v | a vector |
transpose | true to compute ![]() |
Referenced by Feel::MatrixSparse< T >::energy().
real_type Feel::MatrixSparse< T >::energy | ( | vector_ptrtype const & | v, |
vector_ptrtype const & | u, | ||
bool | _transpose = false |
||
) | const [inline] |
Compute the scalar product
u | a vector |
v | a vector |
transpose | true to compute ![]() |
References Feel::MatrixSparse< T >::energy().
graph_ptrtype const& Feel::MatrixSparse< T >::graph | ( | ) | const [inline] |
Referenced by Feel::MatrixSparse< T >::setGraph().
bool Feel::MatrixSparse< T >::hasGraph | ( | ) | const [inline] |
virtual void Feel::MatrixSparse< T >::init | ( | const size_type | m, |
const size_type | n, | ||
const size_type | m_l, | ||
const size_type | n_l, | ||
const size_type | nnz = 30 , |
||
const size_type | noz = 10 |
||
) | [pure virtual] |
Initialize a Sparse matrix that is of global dimension with local dimensions
.
nnz
is the number of on-processor nonzeros per row (defaults to 30). noz
is the number of on-processor nonzeros per row (defaults to 10).
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::init | ( | const size_type | m, |
const size_type | n, | ||
const size_type | m_l, | ||
const size_type | n_l, | ||
graph_ptrtype const & | graph | ||
) | [pure virtual] |
Initialize using sparsity structure computed by dof_map
.
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
bool Feel::MatrixSparse< T >::isHermitian | ( | ) | const [inline] |
References Feel::HERMITIAN.
bool Feel::MatrixSparse< T >::isHermitianPositiveDefinite | ( | ) | const [inline] |
References Feel::HERMITIAN.
virtual bool Feel::MatrixSparse< T >::isInitialized | ( | ) | const [inline, virtual] |
Reimplemented in Feel::MatrixGmm< T, LayoutType >.
References Feel::MatrixSparse< T >::_M_is_initialized.
bool Feel::MatrixSparse< T >::isNonHermitian | ( | ) | const [inline] |
References Feel::NON_HERMITIAN.
bool Feel::MatrixSparse< T >::isPositiveDefinite | ( | ) | const [inline] |
bool Feel::MatrixSparse< T >::isSingular | ( | ) | const [inline] |
virtual real_type Feel::MatrixSparse< T >::l1Norm | ( | ) | const [pure virtual] |
Return the l1-norm of the matrix, that is , (max. sum of columns).
This is the natural matrix norm that is compatible to the l1-norm for vectors, i.e. .
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual real_type Feel::MatrixSparse< T >::linftyNorm | ( | ) | const [pure virtual] |
Return the linfty-norm of the matrix, that is
,
(max. sum of rows). This is the natural matrix norm that is compatible to the linfty-norm of vectors, i.e. .
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
DataMap const& Feel::MatrixSparse< T >::mapCol | ( | ) | const [inline] |
Return datamap for cols
DataMap const& Feel::MatrixSparse< T >::mapRow | ( | ) | const [inline] |
Return datamap for rows
References Feel::MatrixSparse< T >::M_mapRow.
void Feel::MatrixSparse< T >::multAddVector | ( | const Vector< T > & | arg, |
Vector< T > & | dest | ||
) | const |
Multiplies the matrix with arg
and adds the result to dest
.
References Feel::Vector< T >::addVector().
void Feel::MatrixSparse< T >::multVector | ( | const Vector< T > & | arg, |
Vector< T > & | dest | ||
) | const |
Multiplies the matrix with arg
and stores the result in dest
.
References Feel::Vector< T >::zero().
Referenced by Feel::MatrixSparse< T >::multVector().
void Feel::MatrixSparse< T >::multVector | ( | const boost::shared_ptr< Vector< T > > & | arg, |
boost::shared_ptr< Vector< T > > & | dest | ||
) | const [inline] |
Multiplies the matrix with arg
and stores the result in dest
.
References Feel::MatrixSparse< T >::multVector().
virtual T Feel::MatrixSparse< T >::operator() | ( | const size_type | i, |
const size_type | j | ||
) | const [pure virtual] |
Return the value of the entry (i,j). This may be an expensive operation and you should always take care where to call this function. In order to avoid abuse, this function throws an exception if the required element does not exist in the matrix.
In case you want a function that returns zero instead (for entries that are not in the sparsity pattern of the matrix), use the el
function.
Implemented in Feel::MatrixBlockBase< T >, and Feel::MatrixGmm< T, LayoutType >.
void Feel::MatrixSparse< T >::print | ( | std::ostream & | os = std::cout | ) | const [inline] |
Print the contents of the matrix to the screen in a uniform style, regardless of matrix/solver package being used.
Reimplemented in Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::printMatlab | ( | const std::string | name = "NULL" | ) | const [inline, virtual] |
Print the contents of the matrix in Matlab's sparse matrix format. Optionally prints the matrix to the file named name
. If name
is not specified it is dumped to the screen.
Reimplemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::printPersonal | ( | std::ostream & | = std::cout | ) | const [inline, virtual] |
Print the contents of the matrix to the screen in a package-personalized style, if available.
Reimplemented in Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::reinitSubmatrix | ( | MatrixSparse< T > & | submatrix, |
const std::vector< size_type > & | rows, | ||
const std::vector< size_type > & | cols | ||
) | const [inline, virtual] |
This function is similar to the one above, but it allows you to reuse the existing sparsity pattern of "submatrix" instead of reallocating it again. This should hopefully be more efficient if you are frequently extracting submatrices of the same size.
Reimplemented in Feel::MatrixBlockBase< T >.
References Feel::MatrixSparse< T >::_get_submatrix().
virtual size_type Feel::MatrixSparse< T >::rowStart | ( | ) | const [pure virtual] |
return row_start, the index of the first matrix row stored on this processor
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual size_type Feel::MatrixSparse< T >::rowStop | ( | ) | const [pure virtual] |
return row_stop, the index of the last matrix row (+1) stored on this processor
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::set | ( | const size_type | i, |
const size_type | j, | ||
const value_type & | value | ||
) | [pure virtual] |
Set the element (i,j) to
value
. Throws an error if the entry does not exist. Still, it is allowed to store zero values in non-existent fields.
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
void Feel::MatrixSparse< T >::setGraph | ( | graph_ptrtype const & | graph | ) | [inline] |
set the graph associated to the sparse matrix
References Feel::MatrixSparse< T >::graph().
void Feel::MatrixSparse< T >::setInitialized | ( | bool | _init | ) | [inline] |
set initialized only for subclasses
References Feel::MatrixSparse< T >::_M_is_initialized.
void Feel::MatrixSparse< T >::setMatrixProperties | ( | size_type | p | ) | [inline] |
set matrix properties,
virtual size_type Feel::MatrixSparse< T >::size1 | ( | ) | const [pure virtual] |
m
, the row-dimension of the matrix where the marix is Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual size_type Feel::MatrixSparse< T >::size2 | ( | ) | const [pure virtual] |
n
, the column-dimension of the matrix where the marix is Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::symmetricPart | ( | MatrixSparse< value_type > & | Ms | ) | const [inline, virtual] |
Returns the symmetric part of the matrix
Referenced by Feel::MatrixSparse< T >::symmetricPart().
void Feel::MatrixSparse< T >::symmetricPart | ( | boost::shared_ptr< MatrixSparse< value_type > > & | Ms | ) | const [inline] |
Returns the symmetric part of the matrix
References Feel::MatrixSparse< T >::symmetricPart().
virtual void Feel::MatrixSparse< T >::transpose | ( | MatrixSparse< value_type > & | Mt | ) | const [pure virtual] |
Returns the transpose of a matrix
Mt | the matrix transposed |
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
boost::shared_ptr<MatrixSparse<T> > Feel::MatrixSparse< T >::transpose | ( | ) | const [inline] |
Referenced by Feel::MatrixSparse< T >::transpose().
void Feel::MatrixSparse< T >::transpose | ( | boost::shared_ptr< MatrixSparse< value_type > > & | Mt | ) | const [inline] |
Returns the transpose of a matrix
M | the matrix to transpose |
Mt | the matrix transposed |
References Feel::MatrixSparse< T >::transpose().
virtual void Feel::MatrixSparse< T >::updateBlockMat | ( | boost::shared_ptr< MatrixSparse< T > > | m, |
size_type | start_i, | ||
size_type | start_j | ||
) | [pure virtual] |
update a block matrix
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::updateSparsityPattern | ( | const std::vector< std::vector< size_type > > & | ) | [inline, virtual] |
Updates the matrix sparsity pattern. When your MatrixSparse<T>
implementation does not need this data simply do not overload this method.
virtual void Feel::MatrixSparse< T >::zero | ( | ) | [pure virtual] |
Set all entries to 0.
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::zero | ( | size_type | start1, |
size_type | size1, | ||
size_type | start2, | ||
size_type | size2 | ||
) | [pure virtual] |
Set entries between to 0.
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
virtual void Feel::MatrixSparse< T >::zeroRows | ( | std::vector< int > const & | rows, |
std::vector< value_type > const & | values, | ||
Vector< value_type > & | rhs, | ||
Context const & | on_context | ||
) | [pure virtual] |
eliminate rows without change pattern, and put 1 on the diagonal entry
Implemented in Feel::MatrixGmm< T, LayoutType >, and Feel::MatrixBlockBase< T >.
std::ostream& operator<< | ( | std::ostream & | os, |
const MatrixSparse< U > & | m | ||
) | [friend] |
Same as the print method above, but allows you to print to a stream in the standard syntax.
Reimplemented in Feel::MatrixBlockBase< T >.
bool Feel::MatrixSparse< T >::_M_is_initialized [protected] |
Flag indicating whether or not the matrix has been initialized.
Referenced by Feel::MatrixSparse< T >::isInitialized(), and Feel::MatrixSparse< T >::setInitialized().
DataMap Feel::MatrixSparse< T >::M_mapRow [protected] |
data distribution map of the vector over the processors
Referenced by Feel::MatrixSparse< T >::mapRow().