Geophysical Inversion and Modelling Library  v1.5.0
GIMLI::SparseMatrix< ValueType > Class Template Reference

Sparse matrix in compressed row storage (CRS) form. More...

+ Inheritance diagram for GIMLI::SparseMatrix< ValueType >:
+ Collaboration diagram for GIMLI::SparseMatrix< ValueType >:

Public Member Functions

 SparseMatrix ()
 
 SparseMatrix (const SparseMatrix< ValueType > &S)
 
 SparseMatrix (const SparseMapMatrix< ValueType, Index > &S)
 
 SparseMatrix (const IndexArray &colPtr, const IndexArray &rowIdx, const Vector< ValueType > vals, int stype=0)
 
 SparseMatrix (const std::vector< int > &colPtr, const std::vector< int > &rowIdx, const Vector< ValueType > vals, int stype=0)
 
virtual ~SparseMatrix ()
 
SparseMatrix< ValueType > & operator= (const SparseMatrix< ValueType > &S)
 
SparseMatrix< ValueType > & operator= (const SparseMapMatrix< ValueType, Index > &S)
 
SparseMatrix< ValueType > & operator+= (const SparseMatrix< ValueType > &A)
 
SparseMatrix< ValueType > & operator-= (const SparseMatrix< ValueType > &A)
 
SparseMatrix< ValueType > & operator+= (const ElementMatrix< double > &A)
 
virtual uint rtti () const
 
virtual Vector< ValueType > mult (const Vector< ValueType > &a) const
 
virtual Vector< ValueType > transMult (const Vector< ValueType > &a) const
 
void add (const ElementMatrix< double > &A)
 
void add (const ElementMatrix< double > &A, ValueType scale)
 
void add (const ElementMatrix< double > &A, const Pos &scale)
 
void add (const ElementMatrix< double > &A, const Matrix< ValueType > &scale)
 
void clean ()
 
void clear ()
 
void setVal (int i, int j, ValueType val)
 
ValueType getVal (int i, int j, bool warn=true) const
 
void cleanRow (int row)
 
void cleanCol (int col)
 
void copy_ (const SparseMapMatrix< double, Index > &S)
 
void copy_ (const SparseMapMatrix< Complex, Index > &S)
 
void buildSparsityPattern (const Mesh &mesh)
 
void fillStiffnessMatrix (const Mesh &mesh)
 
void fillStiffnessMatrix (const Mesh &mesh, const RVector &a)
 
void fillMassMatrix (const Mesh &mesh)
 
void fillMassMatrix (const Mesh &mesh, const RVector &a)
 
int stype () const
 
int * colPtr ()
 
const int & colPtr () const
 
const std::vector< int > & vecColPtr () const
 
int * rowIdx ()
 
const int & rowIdx () const
 
const std::vector< int > & vecRowIdx () const
 
ValueType * vals ()
 
const Vector< ValueType > & vecVals () const
 
Vector< ValueType > & vecVals ()
 
Index size () const
 
Index nVals () const
 
Index cols () const
 
Index rows () const
 
Index nCols () const
 
Index nRows () const
 
void save (const std::string &fileName) const
 
bool valid () const
 
void copy_ (const SparseMapMatrix< double, Index > &S)
 
void copy_ (const SparseMapMatrix< Complex, Index > &S)
 
void add (const ElementMatrix< double > &A, double scale)
 
void add (const ElementMatrix< double > &A, const Pos &scale)
 
void add (const ElementMatrix< double > &A, const Matrix< double > &scale)
 
void add (const ElementMatrix< double > &A, Complex scale)
 
void add (const ElementMatrix< double > &A, const Pos &scale)
 
void add (const ElementMatrix< double > &A, const CMatrix &scale)
 
DLLEXPORT void copy_ (const SparseMapMatrix< double, Index > &S)
 
DLLEXPORT void copy_ (const SparseMapMatrix< Complex, Index > &S)
 
DLLEXPORT void add (const ElementMatrix< double > &A, double scale)
 
DLLEXPORT void add (const ElementMatrix< double > &A, const Pos &scale)
 
DLLEXPORT void add (const ElementMatrix< double > &A, const RMatrix &scale)
 
DLLEXPORT void add (const ElementMatrix< double > &A, Complex scale)
 
DLLEXPORT void add (const ElementMatrix< double > &A, const Pos &scale)
 
DLLEXPORT void add (const ElementMatrix< double > &A, const CMatrix &scale)
 
- Public Member Functions inherited from GIMLI::MatrixBase
 MatrixBase (bool verbose=false)
 
virtual ~MatrixBase ()
 
void setVerbose (bool verbose)
 
bool verbose () const
 
Index size () const
 
virtual void resize (Index rows, Index cols)
 
virtual RVector dot (const RVector &a) const
 
virtual RVector mult (const RVector &a) const
 
virtual CVector mult (const CVector &a) const
 
virtual RVector mult (const RVector &b, Index startI, Index endI) const
 
virtual CVector mult (const CVector &b, Index startI, Index endI) const
 
virtual RVector transMult (const RVector &a) const
 
virtual CVector transMult (const CVector &a) const
 

Protected Attributes

std::vector< int > colPtr_
 
std::vector< int > rowIdx_
 
Vector< ValueType > vals_
 
bool valid_
 
int stype_
 
Index rows_
 
Index cols_
 
- Protected Attributes inherited from GIMLI::MatrixBase
bool verbose_
 

Detailed Description

template<class ValueType>
class GIMLI::SparseMatrix< ValueType >

Sparse matrix in compressed row storage (CRS) form.

Sparse matrix in compressed row storage (CRS) form. IF you need native CCS format you need to transpose CRS Symmetry type: 0 = nonsymmetric, -1 symmetric lower part, 1 symmetric upper part.

Constructor & Destructor Documentation

◆ SparseMatrix() [1/3]

template<class ValueType >
GIMLI::SparseMatrix< ValueType >::SparseMatrix ( )
inline

Default constructor. Builds invalid sparse matrix

◆ SparseMatrix() [2/3]

template<class ValueType >
GIMLI::SparseMatrix< ValueType >::SparseMatrix ( const SparseMatrix< ValueType > &  S)
inline

◆ SparseMatrix() [3/3]

template<class ValueType >
GIMLI::SparseMatrix< ValueType >::SparseMatrix ( const SparseMapMatrix< ValueType, Index > &  S)
inline

Copy constructor.

References GIMLI::SparseMatrix< ValueType >::copy_().

◆ ~SparseMatrix()

template<class ValueType >
virtual GIMLI::SparseMatrix< ValueType >::~SparseMatrix ( )
inlinevirtual

Destructor

Member Function Documentation

◆ clean()

template<class ValueType >
void GIMLI::SparseMatrix< ValueType >::clean ( )
inlinevirtual

Fill Vector with 0.0. Don't change size.

Reimplemented from GIMLI::MatrixBase.

◆ clear()

template<class ValueType >
void GIMLI::SparseMatrix< ValueType >::clear ( )
inlinevirtual

Clear the data, set size to zero and frees memory.

Reimplemented from GIMLI::MatrixBase.

◆ cols()

template<class ValueType >
Index GIMLI::SparseMatrix< ValueType >::cols ( ) const
inlinevirtual

◆ copy_()

template<typename ValueType >
void GIMLI::SparseMatrix< ValueType >::copy_ ( const SparseMapMatrix< double, Index > &  S)

SparseMatrix specialized type traits in sparsematrix.cpp

Referenced by GIMLI::SparseMatrix< ValueType >::SparseMatrix().

◆ getVal()

template<class ValueType >
ValueType GIMLI::SparseMatrix< ValueType >::getVal ( int  i,
int  j,
bool  warn = true 
) const
inline

Get matrix value at i,j. If i and j is not part of the matrix sparsity pattern return 0 and print a warning. This warning can be disabled by setting warn to false.

◆ mult()

template<class ValueType >
virtual Vector< ValueType > GIMLI::SparseMatrix< ValueType >::mult ( const Vector< ValueType > &  a) const
inlinevirtual

◆ operator=()

template<class ValueType >
SparseMatrix< ValueType >& GIMLI::SparseMatrix< ValueType >::operator= ( const SparseMatrix< ValueType > &  S)
inline

◆ rows()

template<class ValueType >
Index GIMLI::SparseMatrix< ValueType >::rows ( ) const
inlinevirtual

◆ rtti()

template<class ValueType >
virtual uint GIMLI::SparseMatrix< ValueType >::rtti ( ) const
inlinevirtual

Return entity rtti value.

Reimplemented from GIMLI::MatrixBase.

◆ save()

template<class ValueType >
void GIMLI::SparseMatrix< ValueType >::save ( const std::string &  filename) const
inlinevirtual

Brute force column separation fallback .. should be overwriten if you need performance for your onw matrix type.

Brute force row separation fallback .. should be overwriten if you need performance for your onw matrix type. ‍/ template< class ValueType > const Vector < ValueType > row(Index r) const{ __M ASSERT_RANGE(r, 0, rows()) Vector < ValueType > b(rows(), 0.0); b[r] = 1.0; return this->transMult(b); } these template function above will not work until MatrixBase is a non template function /! Brute force column separation fallback .. should be overwriten if you need performance for your onw matrix type.

Brute force row separation fallback .. should be overwriten if you need performance for your onw matrix type. *‍/ virtual const RVector row(Index r) const { __M ASSERT_RANGE(r, 0, rows()) RVector b(rows(), 0.0); b[r] = 1.0; return this->transMult(b); }

/*! Save this matrix into the file filename given. 

Reimplemented from GIMLI::MatrixBase.

◆ stype()

template<class ValueType >
int GIMLI::SparseMatrix< ValueType >::stype ( ) const
inline

symmetric type. 0 = nonsymmetric, -1 symmetric lower part, 1 symmetric upper part.

Referenced by GIMLI::SparseMatrix< ValueType >::operator=().

◆ transMult()

template<class ValueType >
virtual Vector< ValueType > GIMLI::SparseMatrix< ValueType >::transMult ( const Vector< ValueType > &  a) const
inlinevirtual