# Class BlockCSRMatrix¶

class BlockCSRMatrix

Definition of a compressed sparse row matrix of SiconosMatrix, used in OneStepNSProblem to store the M matrix.

This class defines a specific compressed row sparse storage for blocks matrices, each block being a SiconosMatrix*.

It handles:

• a SparseMat (boost-ublas) of SiconosMatrix*

• a vector<SiconosMatrix*> which handles the non-null blocks

• three vector<int> (IndexInt) to save non-null blocks position in row, columns and the list of the sizes of diagonal blocks.

• two int, the number of blocks in a row and the number of non null blocks.

Each block of the current object represents the connection between two coupled Interactions,

(for example for Lagrangian systems, a single $$H W^{-1} H^t$$ block or for first order systems $$hCW^{-1}B$$ …).

This objects is built using an index set of SP::Interaction, that represents the “active” constraints in the OSNS problem and a map<SP::Interaction u1, <SP::Interaction u2, SP::SiconosMatrix block> >, block being the link between u1 and u2. Only Interaction present in the index set are picked out in the map.

A convert method is also implemented to create a SparseBlockStructuredMatrix which is Numerics-readable.

As an example, consider the index set I={u1, u3, u5, u8} and the map where non null blocks are (ui,ui), (u1,u3), (u1,u8), (u3,u1), (u8,u1). Each block being a pointer to a 3x3 matrix. Then the resulting matrix has 4 X 4 blocks, with 8 non-null blocks and looks like:

$\begin{split} M=\left\lbrace\begin{array}{cccc} b11 & b13 & 0 & b18 \\ b31 & b22 & 0 & 0 \\ 0 & 0 & b33&0 \\ b81 & 0 & 0 & b44 \end{array}\right. \end{split}$

with nc = 4, nbNonNullBlocks = 8, RowPos = [0 0 0 1 1 2 3 3], RowCol = [0 1 3 0 1 2 0 3] and _diagsize0 = [3 6 9 12].

We use std::vector (which may seems redundent with the double* of the numerics SparseBlockStructuredMatrix) because memory can be reserved during construction or initialized and then vectors are resized when the object is filled in. This avoid some call to malloc/free at each iteration.

Public Functions

BlockCSRMatrix()

Default constructor -> empty matrix.

BlockCSRMatrix(unsigned int n)

Constructor with dimension (number of blocks)

Parameters

n – number of blocks in a row/column (only square matrices allowed)

BlockCSRMatrix(InteractionsGraph &indexSet)

Constructor from index set.

Parameters

indexSet – the index set of the active constraints

~BlockCSRMatrix()

destructor

inline unsigned int numberOfBlocksInARow() const

get size (in block-components)

Returns

unsigned int NumberOfBlocksInARow

unsigned int getNbNonNullBlocks() const

get total number of non-null blocks

Returns

unsigned int

inline SP::SparseBlockStructuredMatrix getNumericsMatSparse()

Returns

SP::SparseBlockStructuredMatrix

inline SP::CompressedRowMat getMSparse()

get the ublas sparse mat

Returns

SP::CompressedRowMat

inline IndexInt::value_type getSizeOfDiagonalBlock(int i) const

get the dimension of the square-diagonal block number num

Parameters

i – block position

Returns

unsigned int

inline SP::IndexInt getPositionsIndex(bool i)

get the index of blocks position (i=0 -> rows, i=1 -> columns)

Parameters

i – unsigned int, 0 for rows, 1 for columns

Returns

SP::IndexInt

void fill(InteractionsGraph &indexSet)

fill the current class using an index set

Parameters

indexSet – set of the active constraints

void fillW(InteractionsGraph &indexSet)

fill the matrix with the Mass matrix

Warning

only for NewtonEulerDS

Parameters

indexSet – of the active constraints

void fillH(InteractionsGraph &indexSet)

fill the matrix with the H matrix

Warning

only for NewtonEuler3DR

Parameters

indexSet – of the active constraints

void convert()

fill the numerics structure _sparseBlockStructuredMatrix using _blockCSR

void display() const

display the current matrix