chrono::ChMapMatrix Class Reference

Description

This class defines a sparse matrix, implemented using unordered_maps for each row.

#include <ChMapMatrix.h>

Inheritance diagram for chrono::ChMapMatrix:
Collaboration diagram for chrono::ChMapMatrix:

Public Member Functions

 ChMapMatrix (int nrows=1, int ncols=1)
 Create a sparse matrix with given dimensions.
 
 ChMapMatrix (const ChMatrix<> &mat)
 Create a sparse matrix from a given dense matrix.
 
 ChMapMatrix (const ChMapMatrix &other)
 Copy constructor.
 
 ~ChMapMatrix ()
 Destructor.
 
virtual bool Resize (int nrows, int ncols, int nonzeros=0) override
 Resize this matrix.
 
virtual void Reset (int nrows, int ncols, int nonzeros=0) override
 Reset to null matrix and (if needed) changes the size.
 
virtual void SetElement (int row, int col, double elem, bool overwrite=true) override
 Set/update the specified matrix element.
 
virtual double GetElement (int row, int col) const override
 Get the element at the specified location.
 
virtual int * GetCSR_LeadingIndexArray () const override
 Return the row index array in the CSR representation of this matrix.
 
virtual int * GetCSR_TrailingIndexArray () const override
 Return the column index array in the CSR representation of this matrix.
 
virtual double * GetCSR_ValueArray () const override
 Return the array of matrix values in the CSR representation of this matrix.
 
void ConvertToDense (ChMatrixDynamic< double > &mat)
 Convert to dense matrix.
 
void ConvertToCSR (std::vector< int > &ia, std::vector< int > &ja, std::vector< double > &a) const
 Convert to CSR arrays.
 
void StreamOUTsparseMatlabFormat (ChStreamOutAscii &mstream)
 Method to allow serializing transient data into in ASCII stream (e.g., a file) as a Matlab sparse matrix format; each row in file has three elements: {row, column, value}. More...
 
void StreamOUT (ChStreamOutAscii &mstream)
 Write first few rows and columns to the console. More...
 
- Public Member Functions inherited from 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. 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 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 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)
 

Additional Inherited Members

- Public Types inherited from chrono::ChSparseMatrix
enum  SymmetryType { GENERAL, SYMMETRIC_POSDEF, SYMMETRIC_INDEF, STRUCTURAL_SYMMETRIC }
 
- Protected Attributes inherited from chrono::ChSparseMatrix
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 Function Documentation

void chrono::ChMapMatrix::StreamOUT ( ChStreamOutAscii mstream)

Write first few rows and columns to the console.

Method to allow serializing transient data into in ASCII format.

void chrono::ChMapMatrix::StreamOUTsparseMatlabFormat ( ChStreamOutAscii mstream)

Method to allow serializing transient data into in ASCII stream (e.g., a file) as a Matlab sparse matrix format; each row in file has three elements: {row, column, value}.

Note: the row and column indexes start from 1.