Class BlockMatrix

Defined in Program listing for file kernel/src/utils/SiconosAlgebra/BlockMatrix.hpp

class BlockMatrix : public SiconosMatrix

“Block” matrix, ie container of matrices

A BlockMatrix is a boost::ublas::compressed_matrix of SP::SiconosMatrix.

The blocks positions are given by two Index objects, tabRow and tabCol.

If block 1 is n1xm1, block2 n2xm2, block3 n3xm3 …, then:

tabRow = [ n1 n1+n2 n1+n2+n3 …]

tabCol = [ m1 m1+m2 m1+m2+m3 …]

Public Functions

BlockMatrix(const SiconosMatrix &m)

copy constructor

Parameters
  • m: a SiconosMatrix

BlockMatrix(const BlockMatrix &m)

copy constructor

Parameters

BlockMatrix(const std::vector<SP::SiconosMatrix> &m, unsigned int row, unsigned int col)

constructor with a list of pointer to SiconosMatrix (!links with pointer, no copy!)

Parameters
  • m: a vector of SiconosMatrix

  • row: number of blocks in a row

  • col: number of col in a row

BlockMatrix(SP::SiconosMatrix A, SP::SiconosMatrix B, SP::SiconosMatrix C, SP::SiconosMatrix D)

contructor with a list of 4 pointer to SiconosMatrix (!links with pointer, no copy!)

Parameters
  • A: block (0,0)

  • B: block (0,1)

  • C: block (1,0)

  • D: block (1,1)

~BlockMatrix(void)

destructor

ACCEPT_STD_VISITORS()

visitors hook

void addSimple(unsigned int &i, unsigned int &j, const SiconosMatrix &m)

add a part of the input matrix (starting from (i,j) pos) to the current matrix

Parameters
  • i: an unsigned int i (in-out)

  • j: an unsigned int j (in-out)

  • m: a SiconosMatrix (in-out)

BandedMat *banded(unsigned int row = 0, unsigned int col = 0) const

get a pointer on BandedMat matrix

Return

a BandedMat*

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

SP::SiconosMatrix block(unsigned int row = 0, unsigned int col = 0)

get block at position row-col

Return

SP::SiconosMatrix the requested block

Parameters
  • row: unsigned int

  • col: unsigned int

SPC::SiconosMatrix block(unsigned int row = 0, unsigned int col = 0) const

get block at position row-col

Return

SP::SiconosMatrix the requested block

Parameters
  • row: unsigned int

  • col: unsigned int

DenseMat *dense(unsigned int row = 0, unsigned int col = 0) const

get a pointer on DenseMat matrix

Return

a DenseMat*

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

void display() const

display data on standard output

void displayExpert(bool brief = true) const

display data on standard output

void eye()

set an identity matrix

double *getArray(unsigned int row = 0, unsigned int col = 0) const

return the address of the array of double values of the matrix

Return

double* : the pointer on the double array

Parameters
  • row: position for the required block ->useless for SimpleMatrix

  • col: position for the required block ->useless for SimpleMatrix

const BandedMat getBanded(unsigned int row = 0, unsigned int col = 0) const

get BandedMat matrix

Return

a BandedMat

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

void getCol(unsigned int c, SiconosVector &v) const

get column index of current matrix and save it into vOut

Parameters
  • c: index of required column

  • [out] v: a vector

const DenseMat getDense(unsigned int row = 0, unsigned int col = 0) const

get DenseMat matrix

Return

a DenseMat

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

const IdentityMat getIdentity(unsigned int row = 0, unsigned int col = 0) const

get getIdentity matrix

Return

an IdentityMat

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

void getRow(unsigned int r, SiconosVector &v) const

get row index of current matrix and save it in v

Parameters
  • r: index of required line

  • [out] v: a vector

const SparseMat getSparse(unsigned int row = 0, unsigned int col = 0) const

get SparseMat matrix

Return

a SparseMat

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

const SparseCoordinateMat getSparseCoordinate(unsigned int row = 0, unsigned int col = 0) const

get SparseCoordinateMat matrix

Return

a SparseCoordinateMat

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

const SymMat getSym(unsigned int row = 0, unsigned int col = 0) const

get SymMat matrix

Return

a SymMat

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

Index getTabCol() const

get the vector tabCol

Return

a vector of int

Index getTabRow() const

get the vector tabRow

Return

a vector of int

const TriangMat getTriang(unsigned int row = 0, unsigned int col = 0) const

get TriangMat matrix

Return

a TriangMat

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

double getValue(unsigned int i, unsigned int j) const

return the element matrix[i,j]

Return

a double

Parameters
  • i: an unsigned int

  • j: an unsigned int

const ZeroMat getZero(unsigned int row = 0, unsigned int col = 0) const

get ZeroMat matrix

Return

a ZeroMat

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

IdentityMat *identity(unsigned int row = 0, unsigned int col = 0) const

get a pointer on Identity matrix

Return

an IdentityMat*

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

virtual size_t nnz(double tol = 1.e-14)

number of non-zero in the matrix

Parameters
  • tol: the tolerance under which a number is considered zero

double normInf() const

compute the infinite norm of the Block matrix

Return

a double

unsigned int numberOfBlocks(unsigned int i) const

get the number of block (i=0, row, i=1 col)

Return

an unsigned int

Parameters
  • i: unsigned int(i=0, row, i=1 col)

double &operator()(unsigned int i, unsigned int j)

get or set the element matrix[i,j]

Return

the element matrix[i,j]

Parameters
  • i: an unsigned int

  • j: an unsigned int

Exceptions

double operator()(unsigned int i, unsigned int j) const

get or set the element matrix[i,j]

Return

the element matrix[i,j]

Parameters
  • i: an unsigned int

  • j: an unsigned int

Exceptions

BlockMatrix &operator+=(const SiconosMatrix &m)

operator +=

Return

BlockMatrix&

Parameters
  • m: the matrix to add

BlockMatrix &operator-=(const SiconosMatrix &m)

operator -=

Return

BlockMatrix&

Parameters
  • m: the matrix to subtract

BlockMatrix &operator=(const SiconosMatrix &m)

assignment

Return

BlockMatrix&

Parameters
  • m: the matrix to be copied

BlockMatrix &operator=(const BlockMatrix &m)

assignment

Return

BlockMatrix&

Parameters
  • m: the matrix to be copied

BlockMatrix &operator=(const DenseMat &m)

assignment

Return

BlockMatrix&

Parameters
  • m: the matrix to be copied

void PLUFactorizationInPlace()

computes an LU factorization of a general M-by-N matrix using partial pivoting with row interchanges.

The result is returned in this (InPlace). Based on Blas dgetrf function.

void PLUForwardBackwardInPlace(SiconosMatrix &B)

solves a system of linear equations A * X = B (A=this) with a general N-by-N matrix A using the LU factorization computed by PLUFactorizationInPlace.

Based on Blas dgetrs function.

Parameters
  • [inout] B: on input the RHS matrix b; on output: the result x

void PLUForwardBackwardInPlace(SiconosVector &B)

solves a system of linear equations A * X = B (A=this) with a general N-by-N matrix A using the LU factorization computed by PLUFactorizationInPlace.

Based on Blas dgetrs function.

Parameters
  • [inout] B: on input the RHS matrix b; on output: the result x

void PLUInverseInPlace()

compute inverse of this thanks to LU factorization with Partial pivoting.

This method inverts U and then computes inv(A) by solving the system inv(A)*L = inv(U) for inv(A). The result is returned in this (InPlace). Based on Blas dgetri function.

void randomize()

Initialize the matrix with random values.

void randomize_sym()

Initialize a symmetric matrix with random values.

void resize(unsigned int nbrow, unsigned int nbcol, unsigned int lower = 0, unsigned int upper = 0, bool b = true)

resize the matrix with nbrow rows and nbcol columns, lower and upper are useful only for SparseMat.The existing elements of the Block matrix are preseved when specified.

Parameters
  • nbrow:

  • nbcol:

  • lower:

  • upper:

  • b:

void setCol(unsigned int c, const SiconosVector &v)

set column col of the current matrix with vector

Parameters
  • c: index of required column

  • v: a vector

void setRow(unsigned int r, const SiconosVector &v)

set line row of the current matrix with vector v

Parameters
  • r: index of required line

  • v: a vector

void setValue(unsigned int i, unsigned int j, double value)

set the element matrix[i,j]

Parameters
  • i: an unsigned int i

  • j: an unsigned int j

  • value:

unsigned int size(unsigned int index) const

get the number of rows or columns of the matrix

Return

an int

Parameters
  • index: 0 for rows, 1 for columns

SparseMat *sparse(unsigned int row = 0, unsigned int col = 0) const

get a pointer on SparseMat matrix

Return

a SparseMat*

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

SparseCoordinateMat *sparseCoordinate(unsigned int row = 0, unsigned int col = 0) const

get a pointer on SparseCoordinateMat matrix

Return

a SparseCoordinateMat*

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

void subSimple(unsigned int &i, unsigned int &j, const SiconosMatrix &m)

subtract a part of the input matrix (starting from (i,j) pos) to the current matrix

Parameters
  • i: an unsigned int i (in-out)

  • j: an unsigned int j (in-out)

  • m: a SiconosMatrix (in-out)

SymMat *sym(unsigned int row = 0, unsigned int col = 0) const

get a pointer on SymMat matrix

Return

a SymMat*

Parameters
  • row: an unsigned int, position of the block (row)

  • col: `an unsigned int, position of the block (column)

const SP::Index tabCol() const

get the vector tabCol

Return

a pointer to vector of int

const SP::Index tabRow() const

get the vector tabRow

Return

a pointer to vector of int

std::string toString() const

put data of the matrix into a std::string

Return

std::string

void trans()

transpose in place: x->trans() is x = transpose of x.

void trans(const SiconosMatrix &m)

transpose a matrix: x->trans(m) is x = transpose of m.

Parameters
  • m: the matrix to be transposed.

TriangMat *triang(unsigned int row = 0, unsigned int col = 0) const

get a pointer on TriangMat matrix

Return

a TriangMat*

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

void zero()

sets all the values of the matrix to 0.0

ZeroMat *zero_mat(unsigned int row = 0, unsigned int col = 0) const

get a pointer on ZeroMat matrix

Return

a ZeroMat*

Parameters
  • row: an unsigned int, position of the block (row)

  • col: an unsigned int, position of the block (column)

Friends

std::ostream &operator<<(std::ostream &os, const BlockMatrix &bm)

send data of the matrix to an ostream

Return

The same output stream

Parameters

void scal(double a, const SiconosMatrix &A, SiconosMatrix &B, bool)

multiplication of a matrix by a scalar, B = a*A (init = true) or B += a*A (init = false)

Parameters
  • a: a double

  • A: a SiconosMatrix

  • [inout] B: a SiconosMatrix

  • init: a bool