chrono::ChSparseMatrix Class Referenceabstract

Description

Base class for all sparse matrices.

#include <ChSparseMatrix.h>

Inheritance diagram for chrono::ChSparseMatrix:

Public Types

enum  SymmetryType { GENERAL, SYMMETRIC_POSDEF, SYMMETRIC_INDEF, STRUCTURAL_SYMMETRIC }
 

Public Member Functions

 ChSparseMatrix (int nrows=0, int ncols=0, int nnz=0)
 Construct a sparse matrix with 'nrows' and 'ncols' and with 'nnz' non-zero elements. More...
 
 ChSparseMatrix (const ChSparseMatrix &other)
 
int GetNumRows () const
 Get the number of rows of this matrix.
 
int GetNumColumns () const
 Get the number of columns of this matrix.
 
virtual int GetNNZ () const
 Get the number of non-zero elements in this matrix.
 
void SetType (SymmetryType type)
 Set the symmetry type for this sparse matrix (default: GENERAL). More...
 
SymmetryType GetType () const
 Return the symnmetery type of this matrix.
 
void SetSparsityPatternLock (bool val)
 Enable/disable a lock on the matrix sparsity pattern (default: false).
 
virtual void LoadSparsityPattern (ChSparsityPatternLearner &sparsity_learner)
 (Optional) Force the update of the sparsity pattern More...
 
virtual void SetElement (int insrow, int inscol, double insval, bool overwrite=true)=0
 
virtual double GetElement (int row, int col) const =0
 
virtual void Reset (int row, int col, int nonzeros=0)=0
 
virtual bool Resize (int nrows, int ncols, int nonzeros=0)=0
 
virtual bool Compress ()
 Optional compression method, typically invoked after all elements have been inserted. More...
 
virtual void PasteMatrix (const ChMatrix<> &matra, int insrow, int inscol, bool overwrite=true, bool transp=false)
 Paste the specified matrix into this sparse matrix at (insrow,inscol).
 
virtual void PasteClippedMatrix (const ChMatrix<> &matra, int cliprow, int clipcol, int nrows, int ncolumns, int insrow, int inscol, bool overwrite=true)
 Paste a clipped portion of the specified matrix into this sparse matrix at (insrow,inscol).
 
virtual int * GetCSR_LeadingIndexArray () const
 Return the row index array in the CSR representation of this matrix.
 
virtual int * GetCSR_TrailingIndexArray () const
 Return the column index array in the CSR representation of this matrix.
 
virtual double * GetCSR_ValueArray () const
 Return the array of matrix values in the CSR representation of this matrix.
 
virtual void PasteTranspMatrix (const ChMatrix<> &matra, int insrow, int inscol)
 
virtual void PasteSumMatrix (const ChMatrix<> &matra, int insrow, int inscol)
 
virtual void PasteSumTranspMatrix (const ChMatrix<> &matra, int insrow, int inscol)
 
virtual void PasteSumClippedMatrix (const ChMatrix<> &matra, int cliprow, int clipcol, int nrows, int ncolumns, int insrow, int inscol)
 

Protected Attributes

int m_num_rows
 number of rows
 
int m_num_cols
 number of columns
 
int m_nnz
 number of non-zero elements
 
SymmetryType m_type = GENERAL
 matrix type
 
bool m_lock = false
 indicate whether or not the matrix sparsity pattern should be locked
 
bool m_update_sparsity_pattern = false
 let the matrix acquire the sparsity pattern
 

Member Enumeration Documentation

Enumerator
GENERAL 

unsymmetric matrix

SYMMETRIC_POSDEF 

symmetric positive definite

SYMMETRIC_INDEF 

symmetric indefinite

STRUCTURAL_SYMMETRIC 

structurally symmetric

Constructor & Destructor Documentation

chrono::ChSparseMatrix::ChSparseMatrix ( int  nrows = 0,
int  ncols = 0,
int  nnz = 0 
)

Construct a sparse matrix with 'nrows' and 'ncols' and with 'nnz' non-zero elements.

By default, the matrix type is GENERAL (i.e., unsymmetric) and the sparsity pattern is unlocked.

Member Function Documentation

virtual bool chrono::ChSparseMatrix::Compress ( )
virtual

Optional compression method, typically invoked after all elements have been inserted.

Depending on the internal data structures, a derived class may perform additional operations for improved space or speed performance. A typical implementation should respect the sparsity pattern lock status. This function should return true if it makes any modifications.

Reimplemented in chrono::ChCSR3Matrix.

virtual void chrono::ChSparseMatrix::LoadSparsityPattern ( ChSparsityPatternLearner sparsity_learner)
virtual

(Optional) Force the update of the sparsity pattern

Depending on the internal data structure, this can highly speed up the insertion of elements in the matrix. Suggested for matrix with dimension >1e5

Reimplemented in chrono::ChCSR3Matrix.

void chrono::ChSparseMatrix::SetType ( SymmetryType  type)

Set the symmetry type for this sparse matrix (default: GENERAL).

A derived class should always support GENERAL (i.e. unsymmetric matrices), but is free to perform optimizations for symmetric or structurally symmetric matrices.