Caribou
Public Types | Public Member Functions | List of all members
SofaCaribou::Algebra::EigenMatrix< Derived, CLASS_REQUIRES(std::is_base_of_v< Eigen::SparseMatrixBase< std::decay_t< Derived >>, std::decay_t< Derived >>)> Class Template Reference

Detailed Description

template<typename Derived>
class SofaCaribou::Algebra::EigenMatrix< Derived, CLASS_REQUIRES(std::is_base_of_v< Eigen::SparseMatrixBase< std::decay_t< Derived >>, std::decay_t< Derived >>)>

SparseMatrix specialization ///.

#include <EigenMatrix.h>

Inheritance diagram for SofaCaribou::Algebra::EigenMatrix< Derived, CLASS_REQUIRES(std::is_base_of_v< Eigen::SparseMatrixBase< std::decay_t< Derived >>, std::decay_t< Derived >>)>:

Public Types

using EigenType = std::remove_cv_t< std::remove_reference_t< Derived > >
 
using Base = sofa::defaulttype::BaseMatrix
 
using Index = Base::Index
 
using Real = SReal
 

Public Member Functions

 EigenMatrix (std::remove_reference_t< Derived > &eigen_matrix)
 Construct the class using another Eigen matrix. More...
 
 EigenMatrix (Eigen::Index rows, Eigen::Index cols)
 Construct a new rows x cols Eigen matrix of type Derived. More...
 
Index rowSize () const final
 
Index colSize () const final
 
bool symmetric () const
 States if the matrix is symmetric. More...
 
void set_symmetric (bool is_symmetric)
 Explicitly states if this matrix is symmetric.
 
Real element (Index i, Index j) const final
 Return the matrix entry (i,j). More...
 
void resize (Index nbRow, Index nbCol) final
 Resize the matrix to nbRow x nbCol dimensions. More...
 
void clear () final
 Set all entries to zero. More...
 
void set (Index i, Index j, double v) final
 Set this value of the matrix entry (i, j) to the value of v. More...
 
void add (Index i, Index j, double v) final
 Adds v to the value of the matrix entry (i, j). More...
 
void compress () final
 Compress the matrix. More...
 
void add (Index i, Index j, const sofa::defaulttype::Mat3x3d &m) override
 
void add (Index i, Index j, const sofa::defaulttype::Mat3x3f &m) override
 
void add (Index i, Index j, const sofa::defaulttype::Mat2x2d &m) override
 
void add (Index i, Index j, const sofa::defaulttype::Mat2x2f &m) override
 
void clearRow (Index row_id) final
 Sets the entire row i to zero.
 
void clearRows (Index imin, Index imax) final
 Sets the rows from index imin to index imax (inclusively) to zero.
 
void clearCol (Index col_id) final
 Sets the entire columns i to zero.
 
void clearCols (Index imin, Index imax) final
 Sets the columns from index imin to index imax (inclusively) to zero.
 
void clearRowCol (Index i) final
 Sets the entire row i and column i to zero.
 
const Derived & matrix () const
 Get a const reference to the underlying Eigen matrix

 

Constructor & Destructor Documentation

◆ EigenMatrix() [1/2]

template<typename Derived >
SofaCaribou::Algebra::EigenMatrix< Derived, CLASS_REQUIRES(std::is_base_of_v< Eigen::SparseMatrixBase< std::decay_t< Derived >>, std::decay_t< Derived >>)>::EigenMatrix ( std::remove_reference_t< Derived > &  eigen_matrix)
inlineexplicit

Construct the class using another Eigen matrix.

Depending on the template parameter used for the class, this constructor will either create a new Eigen matrix and copy its content from the parameter eigen_matrix, or it will simply store a reference to this external matrix.

Parameters
eigen_matrixThe external matrix

◆ EigenMatrix() [2/2]

template<typename Derived >
SofaCaribou::Algebra::EigenMatrix< Derived, CLASS_REQUIRES(std::is_base_of_v< Eigen::SparseMatrixBase< std::decay_t< Derived >>, std::decay_t< Derived >>)>::EigenMatrix ( Eigen::Index  rows,
Eigen::Index  cols 
)
inline

Construct a new rows x cols Eigen matrix of type Derived.

Parameters
rowsNumber of rows.
colsNumber of columns.

Member Function Documentation

◆ add()

template<typename Derived >
void SofaCaribou::Algebra::EigenMatrix< Derived, CLASS_REQUIRES(std::is_base_of_v< Eigen::SparseMatrixBase< std::decay_t< Derived >>, std::decay_t< Derived >>)>::add ( Index  i,
Index  j,
double  v 
)
inlinefinal

Adds v to the value of the matrix entry (i, j).

Warning
If this method is called after the matrix has been initialized, the matrix will become uncompressed.

◆ clear()

template<typename Derived >
void SofaCaribou::Algebra::EigenMatrix< Derived, CLASS_REQUIRES(std::is_base_of_v< Eigen::SparseMatrixBase< std::decay_t< Derived >>, std::decay_t< Derived >>)>::clear ( )
inlinefinal

Set all entries to zero.

Keeps the current matrix dimensions.

◆ compress()

template<typename Derived >
void SofaCaribou::Algebra::EigenMatrix< Derived, CLASS_REQUIRES(std::is_base_of_v< Eigen::SparseMatrixBase< std::decay_t< Derived >>, std::decay_t< Derived >>)>::compress ( )
inlinefinal

Compress the matrix.

If it is the first time that this method is called, then the matrix is built from a list of triplets (i, j, value) accumulated during the calls of the methodes 'add' and 'set'.

◆ element()

template<typename Derived >
Real SofaCaribou::Algebra::EigenMatrix< Derived, CLASS_REQUIRES(std::is_base_of_v< Eigen::SparseMatrixBase< std::decay_t< Derived >>, std::decay_t< Derived >>)>::element ( Index  i,
Index  j 
) const
inlinefinal

Return the matrix entry (i,j).

Warning
If the matrix hasn't been initialized by calling compress() or set(), this method will always return 0.

◆ resize()

template<typename Derived >
void SofaCaribou::Algebra::EigenMatrix< Derived, CLASS_REQUIRES(std::is_base_of_v< Eigen::SparseMatrixBase< std::decay_t< Derived >>, std::decay_t< Derived >>)>::resize ( Index  nbRow,
Index  nbCol 
)
inlinefinal

Resize the matrix to nbRow x nbCol dimensions.

This method resets to zero all entries.

◆ set()

template<typename Derived >
void SofaCaribou::Algebra::EigenMatrix< Derived, CLASS_REQUIRES(std::is_base_of_v< Eigen::SparseMatrixBase< std::decay_t< Derived >>, std::decay_t< Derived >>)>::set ( Index  i,
Index  j,
double  v 
)
inlinefinal

Set this value of the matrix entry (i, j) to the value of v.

Warning
When the matrix hasn't been initialized yet, this method will have to do it. This means that further calls to set or add will be much slower and generate an uncompressed matrix. If you have to use the set method, make sure that all calls to add has been made beforehand.

◆ symmetric()

template<typename Derived >
bool SofaCaribou::Algebra::EigenMatrix< Derived, CLASS_REQUIRES(std::is_base_of_v< Eigen::SparseMatrixBase< std::decay_t< Derived >>, std::decay_t< Derived >>)>::symmetric ( ) const
inline

States if the matrix is symmetric.

Note that this value isn't set automatically, the user must explicitly specify it using set_symmetric(true). When it is true, some optimizations will be enabled.


The documentation for this class was generated from the following file: