SOFA API  ca665544
Open source framework for multi-physics simuation
sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy > Class Template Reference

#include <CompressedRowSparseMatrixConstraint.h>

Inheritance diagram for sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >:

Classes

class  ColConstIterator
 Row Sparse Matrix columns constant Iterator to match with constraint matrix manipulation. More...
 
class  RowConstIterator
 
class  RowType
 
class  RowWriteAccessor
 

Static Public Attributes

static constexpr Index s_invalidIndex = std::is_signed_v<Index> ? std::numeric_limits<Index>::lowest() : std::numeric_limits<Index>::max()
 
static constexpr sofa::Index NL = CRSMatrix::NL
 Number of rows of a block. More...
 
static constexpr sofa::Index NC = CRSMatrix::NC
 Number of columns of a block. More...
 
- Static Public Attributes inherited from sofa::linearalgebra::CompressedRowSparseMatrixGeneric< TBlock, CRSConstraintPolicy >
static constexpr sofa::Index NL
 Number of rows of a block. More...
 
static constexpr sofa::Index NC
 Number of columns of a block. More...
 
static constexpr Index s_invalidIndex
 
- Static Public Attributes inherited from sofa::linearalgebra::CRSConstraintPolicy
static constexpr bool AutoSize = true
 
static constexpr bool AutoCompress = true
 
static constexpr bool CompressZeros = false
 
static constexpr bool ClearByZeros = false
 
static constexpr bool OrderedInsertion = false
 
static constexpr int matrixType = 2
 
- Static Public Attributes inherited from sofa::linearalgebra::CRSDefaultPolicy
static constexpr bool IsAlwaysSquare = false
 Set to true if this matrix is always square (must be true for symmetric) More...
 
static constexpr bool IsAlwaysSymmetric = false
 Set to true if this matrix is always symmetric (IsAlwaysSquare should be true) More...
 
static constexpr bool AutoSize = false
 Set to true if the size of the matrix should be automatically increased when new blocks are added. More...
 
static constexpr bool AutoCompress = true
 Set to true if the matrix should be automatically compressed (easier to use, but might cause issues in multithreading) More...
 
static constexpr bool CompressZeros = true
 Set to true if the blocks that are all zeros should be removed from the matrix when compressing (expensive) More...
 
static constexpr bool ClearByZeros = true
 Set to true if clear methods will put all concerned value to zero instead of clearing vectors (CompressZeros should be true) More...
 
static constexpr bool OrderedInsertion = false
 Set to true if insertion in matrix are in most case at last line index or last col index. More...
 
static constexpr bool StoreLowerTriangularBlock = true
 Set to false to disable storage of blocks on the lower triangular part (IsAlwaysSymmetric must be true) More...
 
static constexpr int matrixType = 0
 Do not change this value, has to be overrided for all derivated class. More...
 

Public Member Functions

 CompressedRowSparseMatrixConstraint ()
 
 CompressedRowSparseMatrixConstraint (Index nbRow, Index nbCol)
 
bool empty () const
 
RowConstIterator begin () const
 Get the iterator corresponding to the beginning of the rows of blocks. More...
 
RowConstIterator end () const
 Get the iterator corresponding to the end of the rows of blocks. More...
 
RowConstIterator cbegin () const
 Get the iterator corresponding to the beginning of the rows of blocks. More...
 
RowConstIterator cend () const
 Get the iterator corresponding to the end of the rows of blocks. More...
 
size_t size () const
 Get the number of constraint. More...
 
RowConstIterator readLine (Index lIndex) const
 
RowWriteAccessor writeLine (Index lIndex)
 
void setLine (Index lIndex, RowType row)
 
void addLine (Index lIndex, RowType row)
 
template<class VecDeriv >
void multTransposeBaseVector (VecDeriv &res, const sofa::linearalgebra::BaseVector *lambda) const
 
void prettyPrint (std::ostream &out=std::cout) const
 write into output stream (default is standard output) More...
 
- Public Member Functions inherited from sofa::linearalgebra::CompressedRowSparseMatrixGeneric< TBlock, CRSConstraintPolicy >
 CompressedRowSparseMatrixGeneric ()
 
 CompressedRowSparseMatrixGeneric (Index nbBlockRow, Index nbBlockCol)
 
virtual ~CompressedRowSparseMatrixGeneric ()=default
 
Index rowBSize () const
 
Index colBSize () const
 
const VecIndexgetRowIndex () const
 
const VecIndexgetRowBegin () const
 
Range getRowRange (Index id) const
 Returns the range of indices from the column indices corresponding to the id-th row. More...
 
const VecIndexgetColsIndex () const
 
const VecBlockgetColsValue () const
 
virtual void resizeBlock (Index nbBRow, Index nbBCol)
 
void resizeBloc (Index nbBRow, Index nbBCol)
 
void compress ()
 
void swap (Matrix &m)
 
void fullRows ()
 Make sure all rows have an entry even if they are empty. More...
 
void shiftIndices (Index base)
 
const Blockblock (Index i, Index j) const
 Get block method. More...
 
const Blockbloc (Index i, Index j) const
 
Blockwblock (Index i, Index j, bool create=false)
 Write block method. More...
 
Blockwblock (Index i, Index j, Index &rowId, Index &colId, bool create=false)
 Write block method when rowId and colId are known, this is an optimized wblock specification. More...
 
Blockwbloc (Index i, Index j, bool create=false)
 
const BlockgetBlock (Index i, Index j) const
 
const BlockTranspose getSymBlock (Index i, Index j) const
 
void setBlock (Index i, Index j, const Block &v)
 
void setBlock (Index i, Index j, Index &rowId, Index &colId, const Block &v)
 
void addBlock (Index i, Index j, const Block &v)
 
void addBlock (Index i, Index j, Index &rowId, Index &colId, const Block &v)
 
BlockgetWBlock (Index i, Index j, bool create=false)
 
void clearRowBlock (Index i)
 Clear row block method. Clear all col of this line. More...
 
void clearColBlock (Index j)
 Clear col block method. Clear this col in all row of matrix. More...
 
std::size_t countEmptyBlocks () const
 
void clearRowColBlock (Index i)
 Clear both row i and column i in a square matrix. More...
 
void clear ()
 Completely clear the matrix. More...
 
bool check_matrix ()
 
std::ostream & write (std::ostream &os) const
 
std::istream & read (std::istream &is)
 
void add (unsigned int bi, unsigned int bj, const Block &b)
 
void add (unsigned int bi, unsigned int bj, int &rowId, int &colId, const Block &b)
 
void addDBlock (unsigned int bi, unsigned int bj, const DBlock &b)
 
void addDValue (unsigned int bi, unsigned int bj, const Real b)
 
void addDValue (unsigned int bi, unsigned int bj, int &rowId, int &colId, const Real b)
 
void addDiag (unsigned int bi, const Block &b)
 
void addDiag (unsigned int bi, int &rowId, int &colId, const Block &b)
 
void addDiagDBlock (unsigned int bi, const DBlock &b)
 
void addDiagDValue (unsigned int bi, const Real b)
 
void addDiagDValue (unsigned int bi, int &rowId, int &colId, const Real b)
 
void addSym (unsigned int bi, unsigned int bj, const Block &b)
 
void addSym (unsigned int bi, unsigned int bj, int &rowId, int &colId, int &rowIdT, int &colIdT, const Block &b)
 
void addSymDBlock (unsigned int bi, unsigned int bj, const DBlock &b)
 
void addSymDValue (unsigned int bi, unsigned int bj, const Real b)
 
void addSymDValue (unsigned int bi, unsigned int bj, int &rowId, int &colId, int &rowIdT, int &colIdT, Real b)
 
void transposeFullRows (CompressedRowSparseMatrixGeneric< TBlock2, TPolicy2 > &res) const
 Transpose the matrix into res, works only for 3 array variant ("full rows") matrices, ie which can be expressed using the rowBegin, colsIndex and colsValue arrays solely. More...
 
void mul (CompressedRowSparseMatrixGeneric< RB, RP > &res, const CompressedRowSparseMatrixGeneric< MB, MP > &m) const
 
void mulTranspose (CompressedRowSparseMatrixGeneric< RB, RP > &res, const CompressedRowSparseMatrixGeneric< MB, MP > &m) const
 

Static Public Member Functions

static const charName ()
 
- Static Public Member Functions inherited from sofa::linearalgebra::CompressedRowSparseMatrixGeneric< TBlock, CRSConstraintPolicy >
static bool sortedFind (const VecIndex &v, Range in, Index val, Index &result)
 
static bool sortedFind (const VecIndex &v, Index val, Index &result)
 
static const charName ()
 
static bool check_matrix (Index nzmax, Index m, Index n, Index *a_p, Index *a_i, Block *a_x)
 
static auto blockMultTranspose (const TBlock &blockA, const TBlock &blockB)
 

Friends

std::ostream & operator<< (std::ostream &out, const CompressedRowSparseMatrixConstraint< TBlock, Policy > &sc)
 write to an output stream More...
 
std::istream & operator>> (std::istream &in, CompressedRowSparseMatrixConstraint< TBlock, Policy > &sc)
 read from an input stream More...
 

Additional Inherited Members

- Public Attributes inherited from sofa::linearalgebra::CompressedRowSparseMatrixGeneric< TBlock, CRSConstraintPolicy >
Index nBlockRow
 Size. More...
 
Index nBlockCol
 Mathematical size of the matrix, in blocks. More...
 
VecIndex rowIndex
 Compressed sparse data structure. More...
 
VecIndex rowBegin
 column indices of non-empty blocks in each row. The column indices of the non-empty block within the i-th non-empty row are all the colsIndex[j], j in [rowBegin[i],rowBegin[i+1]) More...
 
VecIndex colsIndex
 column indices of all the non-empty blocks, sorted by increasing row index and column index More...
 
VecBlock colsValue
 values of the non-empty blocks, in the same order as in colsIndex More...
 
VecFlag touchedBlock
 boolean vector, i-th value is true if block has been touched since last compression. More...
 
VecIndexedBlock btemp
 Additional storage to make block insertion more efficient. More...
 
bool skipCompressZero
 
VecIndex oldRowIndex
 Temporary vectors used during compression. More...
 
VecIndex oldRowBegin
 
VecIndex oldColsIndex
 
VecBlock oldColsValue
 
- Protected Member Functions inherited from sofa::linearalgebra::CompressedRowSparseMatrixGeneric< TBlock, CRSConstraintPolicy >
bool registerNewCol (Index &colId, TBlock &bvalue)
 Add a new col into matrix. More...
 
std::pair< Index, IndexregisterBtempLine (typename VecIndexedBlock::const_iterator &itbtemp)
 Add a complete new line from btemp into matrix. More...
 
void fullyCompressBtemp ()
 Clear matrix and just add btemp array. More...
 
BlockinsertBtemp (const Index i, const Index j)
 Method to easy insert new block into btemp. More...
 
Index getMaxColIndex ()
 Method to easy have the max colIndex. Could only be used if AutoSize policy is activated. More...
 
void deleteRow (Index rowId)
 Method to easy delete row given position in rowIndex. More...
 
void compressBtemp ()
 Clear matrix and compute new triplet's arrays by combining old ones and btemp(VecIndexedBlock) array. More...
 
void compressCSR ()
 
void writeVector (const TVec &vec, std::ostream &os)
 
void readVector (TVec &vec, std::istream &in)
 

Attribute details

◆ NC

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
constexpr sofa::Index sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::NC = CRSMatrix::NC
staticconstexpr

Number of columns of a block.

◆ NL

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
constexpr sofa::Index sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::NL = CRSMatrix::NL
staticconstexpr

Number of rows of a block.

◆ s_invalidIndex

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
constexpr Index sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::s_invalidIndex = std::is_signed_v<Index> ? std::numeric_limits<Index>::lowest() : std::numeric_limits<Index>::max()
staticconstexpr

Constructor details

◆ CompressedRowSparseMatrixConstraint() [1/2]

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::CompressedRowSparseMatrixConstraint ( )
inline

◆ CompressedRowSparseMatrixConstraint() [2/2]

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::CompressedRowSparseMatrixConstraint ( Index  nbRow,
Index  nbCol 
)
inline

Function details

◆ addLine()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
void sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::addLine ( Index  lIndex,
RowType  row 
)
inline
Parameters
lIndexrow Index
rowconstraint itself If lindex doesn't exists, creates the row

◆ begin()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
RowConstIterator sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::begin ( ) const
inline

Get the iterator corresponding to the beginning of the rows of blocks.

◆ cbegin()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
RowConstIterator sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::cbegin ( ) const
inline

Get the iterator corresponding to the beginning of the rows of blocks.

◆ cend()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
RowConstIterator sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::cend ( ) const
inline

Get the iterator corresponding to the end of the rows of blocks.

◆ empty()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
bool sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::empty ( ) const
inline

◆ end()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
RowConstIterator sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::end ( ) const
inline

Get the iterator corresponding to the end of the rows of blocks.

◆ multTransposeBaseVector()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
template<class VecDeriv >
void sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::multTransposeBaseVector ( VecDeriv &  res,
const sofa::linearalgebra::BaseVector lambda 
) const
inline

◆ Name()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
static const char* sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::Name ( )
inlinestatic

◆ prettyPrint()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
void sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::prettyPrint ( std::ostream &  out = std::cout) const
inline

write into output stream (default is standard output)

◆ readLine()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
RowConstIterator sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::readLine ( Index  lIndex) const
inline
Returns
Constant Iterator on specified row
Parameters
lIndexrow index If lIndex row doesn't exist, returns end iterator

◆ setLine()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
void sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::setLine ( Index  lIndex,
RowType  row 
)
inline
Parameters
lIndexrow Index
rowconstraint itself If lindex already exists, overwrite existing constraint

◆ size()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
size_t sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::size ( void  ) const
inline

Get the number of constraint.

◆ writeLine()

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
RowWriteAccessor sofa::linearalgebra::CompressedRowSparseMatrixConstraint< TBlock, TPolicy >::writeLine ( Index  lIndex)
inline
Returns
Iterator on specified row
Parameters
lIndexrow index

Related details

◆ operator<<

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
std::ostream& operator<< ( std::ostream &  out,
const CompressedRowSparseMatrixConstraint< TBlock, Policy > &  sc 
)
friend

write to an output stream

◆ operator>>

template<typename TBlock , typename TPolicy = CRSConstraintPolicy>
std::istream& operator>> ( std::istream &  in,
CompressedRowSparseMatrixConstraint< TBlock, Policy > &  sc 
)
friend

read from an input stream