chrono::ChLinkedListMatrix Class Reference

Description

This class defines a sparse matrix, implemented using linked lists of non-zero elements in each row.

#include <ChLinkedListMatrix.h>

Inheritance diagram for chrono::ChLinkedListMatrix:
Collaboration diagram for chrono::ChLinkedListMatrix:

Public Member Functions

 ChLinkedListMatrix ()
 Default constructor.
 
 ChLinkedListMatrix (int nrows, int ncols, double fill_in=SPM_DEF_FULLNESS)
 Create a sparse matrix with given dimensions and fill-in.
 
 ChLinkedListMatrix (const ChMatrix<> &mat)
 Create a sparse matrix from a given dense matrix.
 
 ChLinkedListMatrix (const ChLinkedListMatrix &other)
 Copy constructor.
 
 ~ChLinkedListMatrix ()
 Destructor.
 
void CopyToMatrix (ChMatrix<> &mat)
 Copy this sparse matrix to a dense matrix.
 
ChMelementSetElement (int row, int col, double val, ChMelement *guess)
 Optimized SetElement, returning the fetched Melement*.
 
ChMelementGetElement (int row, int col, double *val, ChMelement *guess)
 Optimized GetElement, returning the fetched Melement*.
 
void MoreBuffer (double inflate)
 Add another buffer in buffer list, bigger of last (max total buffer size = col x rows) as in newbuffer = lastbuffer * inflate (use inflate >1, suggested 2) [mostly used internally].
 
virtual bool Resize (int nrows, int ncols, int nonzeros=0) override
 Overloadings of standard matrix functions.
 
void Reset ()
 Reset to null matrix.
 
virtual void Reset (int nrows, int ncols, int nonzeros=0) override
 Reset to null matrix and (if needed) changes the size.
 
void ResetBlocks (int nrows, int ncols)
 If size changes, is like the above, otherwise just sets the elements to zero.
 
virtual void SetElement (int row, int col, double elem, bool overwrite=true) override
 
virtual double GetElement (int row, int col) const override
 
virtual void PasteMatrix (const ChMatrix<> &matra, int insrow, int inscol, bool overwrite, bool transp) override
 Paste the specified matrix into this sparse matrix at (insrow,inscol).
 
virtual void PasteTranspMatrix (const ChMatrix<> &matra, int insrow, int inscol) override
 
virtual void PasteClippedMatrix (const ChMatrix<> &matra, int cliprow, int clipcol, int nrows, int ncolumns, int insrow, int inscol, bool overwrite) override
 Paste a clipped portion of the specified matrix into this sparse matrix at (insrow,inscol).
 
virtual void PasteSumClippedMatrix (const ChMatrix<> &matra, int cliprow, int clipcol, int nrows, int ncolumns, int insrow, int inscol) override
 
virtual void PasteSumMatrix (const ChMatrix<> &matra, int insrow, int inscol) override
 
virtual void PasteSumTranspMatrix (const ChMatrix<> &matra, int insrow, int inscol) override
 
void PasteMatrix (const ChLinkedListMatrix &matra, int insrow, int inscol)
 
void PasteTranspMatrix (const ChLinkedListMatrix &matra, int insrow, int inscol)
 
void MatrScale (double factor)
 
void Neg ()
 
int Setup_LU ()
 Perform in-place LU factorization with partial (row) pivoting. More...
 
void Solve_LU (const ChMatrix<> &b, ChMatrix<> &x)
 Solve the system A*x = b, using an existing LU factorization.
 
int SolveGeneral (const ChMatrix<> &b, ChMatrix<> &x)
 Solve the general system A*x = b. More...
 
int Setup_LDL ()
 Perform in-place LDL factorization with full pivoting. More...
 
void Solve_LDL (const ChMatrix<> &b, ChMatrix<> &x)
 Solve the symmetric system A*x=b, using an existing LDL factorization.
 
int SolveSymmetric (const ChMatrix<> &b, ChMatrix<> &x)
 Solve the symmetric system A*x = b. More...
 
const std::vector< int > & GetPivots () const
 Get the pivot indices after the last factorization.
 
double GetDeterminant () const
 Get matrix determinant. More...
 
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...
 
ChMelementGetElarrayDereferenced ()
 Used to convert to CSR3 format (ChEigenMatrix). More...
 
template<typename reserveSizeType >
void CountNonZeros (reserveSizeType &reserveSize, int offset=0)
 Used to convert to CSR3 format (ChEigenMatrix). 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 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.
 

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

template<typename reserveSizeType >
void chrono::ChLinkedListMatrix::CountNonZeros ( reserveSizeType &  reserveSize,
int  offset = 0 
)

Used to convert to CSR3 format (ChEigenMatrix).

Returns a pointer to an array/vector of type . reserveSizeType[i] gives the number of non-zero elements in the i-th row; must have the same row-dimension as ChLinkedListMatrix instance.

double chrono::ChLinkedListMatrix::GetDeterminant ( ) const

Get matrix determinant.

Available after a factorization.

ChMelement* chrono::ChLinkedListMatrix::GetElarrayDereferenced ( )

Used to convert to CSR3 format (ChEigenMatrix).

Returns the array to 1st column elements.

int chrono::ChLinkedListMatrix::Setup_LDL ( )

Perform in-place LDL factorization with full pivoting.

Note that this factorization can only be performed for symmetric matrices. During the factorization, only the upper triangular part of A is accessed.

int chrono::ChLinkedListMatrix::Setup_LU ( )

Perform in-place LU factorization with partial (row) pivoting.

The matrix determinant is calculated as a by-product of the factorization and can be obtained with GetDeterminant().

int chrono::ChLinkedListMatrix::SolveGeneral ( const ChMatrix<> &  b,
ChMatrix<> &  x 
)

Solve the general system A*x = b.

Note that the matrix is modified in-place to contain the LU factors.

int chrono::ChLinkedListMatrix::SolveSymmetric ( const ChMatrix<> &  b,
ChMatrix<> &  x 
)

Solve the symmetric system A*x = b.

Note that the matrix is modified in-place to contain the LU factors.

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

Write first few rows and columns to the console.

Method to allow serializing transient data into in ASCII format.

void chrono::ChLinkedListMatrix::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.