#include <matrixsparse.hpp>
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.
Public Types | |
typedef boost::shared_ptr < datamap_type > | datamap_ptrtype |
typedef DataMap | datamap_type |
typedef boost::shared_ptr < graph_type > | graph_ptrtype |
typedef GraphCSR | graph_type |
typedef type_traits< T >::real_type | real_type |
typedef T | value_type |
typedef boost::shared_ptr < Vector< T > > | vector_ptrtype |
typedef Vector< T > | vector_type |
Public Member Functions | |
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) |
void | checkProperties () const |
virtual void | clear ()=0 |
virtual void | close () const =0 |
virtual bool | closed () const =0 |
WorldComm const & | comm () const |
virtual void | createSubmatrix (MatrixSparse< T > &submatrix, const std::vector< size_type > &rows, const std::vector< size_type > &cols) const |
virtual void | diagonal (Vector< T > &dest) const =0 |
void | diagonal (boost::shared_ptr< Vector< T > > &dest) 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 |
graph_ptrtype const & | graph () const |
bool | hasGraph () const |
bool | haveConsistentProperties () const |
std::vector< std::vector < size_type > > | indexSplit () const |
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 |
bool | isDense () const |
bool | isHermitian () const |
bool | isHermitianPositiveDefinite () const |
virtual bool | isInitialized () const |
bool | isNonHermitian () const |
bool | isPositiveDefinite () const |
bool | isSingular () const |
virtual real_type | l1Norm () const =0 |
virtual real_type | linftyNorm () const =0 |
datamap_type const & | mapCol () const |
datamap_ptrtype const & | mapColPtr () const |
datamap_type const & | mapRow () const |
datamap_ptrtype const & | mapRowPtr () const |
MatrixSparse () | |
MatrixSparse (datamap_ptrtype const &dmRow, datamap_ptrtype const &dmCol, WorldComm const &worldComm=Environment::worldComm()) | |
void | multAddVector (const Vector< T > &arg, Vector< T > &dest) const |
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 |
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) |
void | print (std::ostream &os=std::cout) const |
virtual void | printMatlab (const std::string name="NULL") const |
virtual void | printPersonal (std::ostream &=std::cout) const |
virtual void | reinitSubmatrix (MatrixSparse< T > &submatrix, const std::vector< size_type > &rows, const std::vector< size_type > &cols) const |
virtual size_type | rowStart () const =0 |
virtual size_type | rowStop () const =0 |
virtual void | scale (const T)=0 |
virtual void | set (const size_type i, const size_type j, const value_type &value)=0 |
void | setGraph (graph_ptrtype const &graph) |
virtual void | setIndexSplit (std::vector< std::vector< size_type > > const &_indexSplit) |
void | setInitialized (bool _init) |
void | setMapCol (datamap_ptrtype const &d) |
void | setMapRow (datamap_ptrtype const &d) |
void | setMatrixProperties (size_type p) |
virtual size_type | size1 () const =0 |
virtual size_type | size2 () const =0 |
virtual void | symmetricPart (MatrixSparse< value_type > &Ms) const |
void | symmetricPart (boost::shared_ptr< MatrixSparse< value_type > > &Ms) 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 | updateBlockMat (boost::shared_ptr< MatrixSparse< T > > m, std::vector< size_type > start_i, std::vector< size_type > start_j)=0 |
virtual void | updateSparsityPattern (const std::vector< std::vector< size_type > > &) |
virtual void | zero ()=0 |
virtual void | zero (size_type start1, size_type size1, size_type start2, size_type size2)=0 |
virtual void | zeroRows (std::vector< int > const &rows, Vector< value_type > const &values, Vector< value_type > &rhs, Context const &on_context)=0 |
virtual | ~MatrixSparse () |
Protected Member Functions | |
virtual void | _get_submatrix (MatrixSparse< T > &, const std::vector< size_type > &, const std::vector< size_type > &, const bool) const |
Protected Attributes | |
graph_ptrtype | M_graph |
std::vector< std::vector < size_type > > | M_IndexSplit |
bool | M_is_initialized |
datamap_ptrtype | M_mapCol |
datamap_ptrtype | M_mapRow |
Context | M_mprop |
WorldComm | M_worldComm |
mpi communicator | |
Friends | |
template<typename U > | |
std::ostream & | operator<< (std::ostream &os, const MatrixSparse< U > &m) |
|
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
(...).
|
inlinevirtual |
Destructor. Free all memory, but do not release the memory of the sparsity structure.
|
inlineprotectedvirtual |
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!
|
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::MatrixBlockBase< T >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
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 >.
|
pure virtual |
Add the full matrix to the Sparse matrix. This is useful for adding an element matrix at assembly time
Implemented in Feel::MatrixEigenSparse< T >, Feel::MatrixEigenDense< T >, and Feel::MatrixBlockBase< T >.
|
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 >.
|
pure virtual |
Add a Sparse matrix _X
, scaled with _a
, to this
, stores the result in this:
.
Implemented in Feel::MatrixEigenSparse< T >, Feel::MatrixEigenDense< T >, and Feel::MatrixBlockBase< T >.
|
inline |
Add a Sparse matrix _X
, scaled with _a
, to this
, stores the result in this:
.
References Feel::MatrixSparse< T >::addMatrix().
|
pure virtual |
Release all memory and return to a state just like after having called the default constructor.
Implemented in Feel::MatrixEigenSparse< T >, Feel::MatrixEigenDense< T >, and Feel::MatrixBlockBase< T >.
|
pure virtual |
Call the Sparse assemble routines. sends necessary messages to other processors
Implemented in Feel::MatrixBlockBase< T >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
pure virtual |
see if Sparse matrix has been closed and fully assembled yet
Implemented in Feel::MatrixBlockBase< T >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
inline |
References Feel::MatrixSparse< T >::M_worldComm.
|
inlinevirtual |
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().
|
pure virtual |
Copies the diagonal part of the matrix into dest
.
Implemented in Feel::MatrixBlockBase< T >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
inline |
Copies the diagonal part of the matrix into dest
.
References Feel::MatrixSparse< T >::diagonal().
|
pure virtual |
compute the A scalar product
u | a vector |
v | a vector |
transpose | true to compute ![]() |
Implemented in Feel::MatrixBlockBase< T >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
inline |
Compute the scalar product
u | a vector |
v | a vector |
transpose | true to compute ![]() |
References Feel::MatrixSparse< T >::energy().
|
inline |
|
inline |
|
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::MatrixEigenSparse< T >, Feel::MatrixEigenDense< T >, and Feel::MatrixBlockBase< T >.
|
pure virtual |
Initialize using sparsity structure computed by dof_map
.
Implemented in Feel::MatrixEigenSparse< T >, Feel::MatrixEigenDense< T >, and Feel::MatrixBlockBase< T >.
|
inline |
References Feel::HERMITIAN.
|
inline |
References Feel::HERMITIAN, and Feel::POSITIVE_DEFINITE.
|
inlinevirtual |
Reimplemented in Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
References Feel::MatrixSparse< T >::M_is_initialized.
|
inline |
References Feel::NON_HERMITIAN.
|
inline |
References Feel::POSITIVE_DEFINITE.
|
inline |
References Feel::SINGULAR.
|
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::MatrixEigenSparse< T >, Feel::MatrixEigenDense< T >, and Feel::MatrixBlockBase< T >.
|
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::MatrixEigenSparse< T >, Feel::MatrixEigenDense< T >, and Feel::MatrixBlockBase< T >.
|
inline |
Return datamap for cols
|
inline |
Return datamap for cols
|
inline |
Return datamap for rows
References Feel::MatrixSparse< T >::M_mapRow.
|
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().
|
inline |
Multiplies the matrix with arg
and stores the result in dest
.
References Feel::MatrixSparse< T >::multVector().
|
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 >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
inline |
Print the contents of the matrix to the screen in a uniform style, regardless of matrix/solver package being used.
|
inlinevirtual |
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::MatrixBlockBase< T >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
inlinevirtual |
Print the contents of the matrix to the screen in a package-personalized style, if available.
Reimplemented in Feel::MatrixBlockBase< T >.
|
inlinevirtual |
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().
|
pure virtual |
return row_start, the index of the first matrix row stored on this processor
Implemented in Feel::MatrixBlockBase< T >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
pure virtual |
return row_stop, the index of the last matrix row (+1) stored on this processor
Implemented in Feel::MatrixBlockBase< T >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
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::MatrixEigenSparse< T >, Feel::MatrixEigenDense< T >, and Feel::MatrixBlockBase< T >.
|
inline |
set the graph associated to the sparse matrix
References Feel::MatrixSparse< T >::graph().
|
inline |
set initialized only for subclasses
References Feel::MatrixSparse< T >::M_is_initialized.
|
inline |
set matrix properties,
|
pure virtual |
m
, the row-dimension of the matrix where the marix is Implemented in Feel::MatrixBlockBase< T >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
pure virtual |
n
, the column-dimension of the matrix where the marix is Implemented in Feel::MatrixBlockBase< T >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
inlinevirtual |
Returns the symmetric part of the matrix
|
inline |
Returns the symmetric part of the matrix
References Feel::MatrixSparse< T >::symmetricPart().
|
pure virtual |
Returns the transpose of a matrix
Mt | the matrix transposed |
Implemented in Feel::MatrixEigenSparse< T >, Feel::MatrixEigenDense< T >, and Feel::MatrixBlockBase< T >.
|
inline |
|
inline |
Returns the transpose of a matrix
M | the matrix to transpose |
Mt | the matrix transposed |
References Feel::MatrixSparse< T >::transpose().
|
pure virtual |
update a block matrix
Implemented in Feel::MatrixBlockBase< T >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
inlinevirtual |
Updates the matrix sparsity pattern. When your MatrixSparse<T>
implementation does not need this data simply do not overload this method.
|
pure virtual |
Set all entries to 0.
Implemented in Feel::MatrixEigenSparse< T >, Feel::MatrixEigenDense< T >, and Feel::MatrixBlockBase< T >.
|
pure virtual |
Set entries between to 0.
Implemented in Feel::MatrixEigenSparse< T >, Feel::MatrixEigenDense< T >, and Feel::MatrixBlockBase< T >.
|
pure virtual |
eliminate rows without change pattern, and put 1 on the diagonal entry
Implemented in Feel::MatrixBlockBase< T >, Feel::MatrixEigenSparse< T >, and Feel::MatrixEigenDense< T >.
|
friend |
Same as the print method above, but allows you to print to a stream in the standard syntax.
|
protected |
Flag indicating whether or not the matrix has been initialized.
|
protected |
data distribution map of the vector over the processors