File kernel/src/simulationTools/OSNSMatrix.hpp#
Go to the source code of this file
Specific storage for matrices used in OneStepNSProblem
-
class OSNSMatrix
- #include <OSNSMatrix.hpp>
Interface to some specific storage types for matrices used in OneStepNSProblem.
This class is used to define an interface for various storage methods used for matrices in OneStepNSProblem. Its aim is to fill the Numerics structure NumericsMatrix, required in many XXX_problem structures of Numerics as input argument for drivers.
The idea is to remove all matrix storage management problems from OSNS classes (LCP …) and to leave it into this class.
Two main functions:
fill(indexSet, interactionBlocks): fill the matrix using a list of “active” Interaction, in indexSet, and a MapOfMapOfInteractionMatrices, interactionBlocks, which determines which Interaction are connected or not (ie have common DynamicalSystem).
convert(): fill the NumericsMatrix structure (indeed only pointers links to the components of the present class)
Note that OSNSMatrix are square.
For example, if in a LCP, constraints of interest are indexSet={inter2,inter3,inter8,inter12}, whith common DynamicalSystem between 2 and 3, 2 and 8 and 8 and 12.
interactionBlocks contains matrices for all (interi,interj) which have common DS, for (interi,interj) in I0, the set of all Interaction.
(for details on how interactionBlocks is computed see OneStepNSProblem.h).
We denote interactionBlocks[interi][interj] = mij.
Then, a call to fill(indexSet, interactionBlock) results in a matrix which looks like:
\[\begin{split} M=\left\lbrace\begin{array}{cccc} m22 & m23 & m28 & 0 \\ m32 & m33 & 0 & 0 \\ 0 & 0 & m88 & m812 \\ 0 & 0 & m128& m1212 \end{array}\right. \end{split}\]Note: at the time the available storage types are:
full matrix in a SiconosMatrix (_storageType = NM_DENSE). In this case, for each call to fill(), the SiconosMatrix M is resized according to the sizes of the Interaction present in indexSet and then all the required interactionBlocks mij are COPIED into M.
Sparse Block Storage (_storageType = NM_SPARSE_BLOCK): corresponds to SparseBlockStructuredMatrix structure of Numerics. Only non-null interactionBlocks are saved in the matrix M and there is no copy of sub-interactionBlocks, only links thanks to pointers.
Sparse matrix (_storageType = NM_SPARSE): at the time of writting, only csc (compressed-sparse column). Could also be triplet (coo or coordinate) or csr (compressed-sparse row).
Subclassed by OSNSMatrixProjectOnConstraints
Public Functions
-
OSNSMatrix()
Default constructor -> empty matrix.
-
OSNSMatrix(unsigned int n, NM_types stor)
Constructor with _dimRow.
of the matrix
- Parameters:
n – size of the square matrix
stor – storage type (NM_DENSE or NM_SPARSE_BLOCK)
-
OSNSMatrix(unsigned int n, unsigned int m, NM_types stor)
Constructor with _dimRow and DimColumn of the matrix.
- Parameters:
n – row sizes of the rectangle matrix
m – column size of the rectangle matrix
stor – storage type (NM_DENSE or NM_SPARSE_BLOCK)
-
OSNSMatrix(InteractionsGraph &indexSet, NM_types stor)
Constructor from index set and map.
- Parameters:
indexSet – InteractionsGraph* the index set of the active constraints
stor – storage type
-
OSNSMatrix(const SiconosMatrix &MSource)
Constructor with copy of a SiconosMatrix => _storageType = NM_DENSE.
- Parameters:
MSource – matrix to be copied
-
inline virtual ~OSNSMatrix()
destructor
-
inline unsigned int size() const
get dimension of the square matrix
- Returns:
unsigned int
-
inline void setSize(unsigned int size)
get dimension of the square matrix
- Returns:
unsigned int
-
inline unsigned int sizeColumn() const
get dimension of the square matrix
- Returns:
unsigned int
-
inline NM_types storagetype() const
get the type of storage for current matrix
- Returns:
unsigned int
-
inline void setStorageType(NM_types i)
set which type of storage will be used for current matrix
- Parameters:
i – the type of storage
-
inline SP::NumericsMatrix numericsMatrix()
get the numerics-readable structure
- Returns:
SP::NumericsMatrix
-
inline SP::SiconosMatrix defaultMatrix()
get the matrix used for default storage
- Returns:
SP::NumericsMatrix
-
virtual void fillM(InteractionsGraph &indexSet, bool update = true)
fill the current class using an index set
- Parameters:
indexSet – the index set of the active constraints
update – if true update the size of the Matrix (default true)
-
void computeM(SP::NumericsMatrix Winverse, SP::NumericsMatrix H)
Compute the M matrix given the inverse of W and H.
- Parameters:
Winverse – the NumericsMatrix that contains the inverse of W
Winverse – the NumericsMatrix that contains H
-
virtual void fillW(DynamicalSystemsGraph &DSG, bool update = true)
fill the current class using an index set with the W matrix of DS
- Parameters:
DSG – the index set of the dynamicalSystems
update – if true update the size of the Matrix (default true)
-
virtual void fillWinverse(DynamicalSystemsGraph &DSG, bool update = true)
fill the current class using an index set with the inverse of W matrix of DS
- Parameters:
DSG – the index set of the dynamicalSystems
update – if true update the size of the Matrix (default true)
-
virtual void fillH(DynamicalSystemsGraph &DSG, InteractionsGraph &indexSet, bool update = true)
fill the current class using an index set
- Parameters:
DSG – the index set of the dynamicalSystems
indexSet – the index set of the Interactions
update – if true update the size of the Matrix (default true)
-
virtual void fillHtrans(DynamicalSystemsGraph &DSG, InteractionsGraph &indexSet, bool update = true)
fill the current class using an index set
- Parameters:
DSG – the index set of the dynamicalSystems
indexSet – the index set of the Interactions
update – if true update the size of the Matrix (default true)
-
void convert()
fill the numerics structure _numericsMatSparse using MBlockCSR
-
void display() const
display the current matrix
Protected Functions
-
ACCEPT_SERIALIZATION(OSNSMatrix)#
-
virtual unsigned updateSizeAndPositions(InteractionsGraph &indexSet)#
For each Interaction in the graph, compute its absolute position.
- Parameters:
indexSet – the index set ot the concerned interactios.
- Returns:
the dimension of the problem (or size of the matrix), computed as the sum of the nslaw of all the Interaction in indexSet
-
virtual unsigned updateSizeAndPositions(DynamicalSystemsGraph &DSG)#
For each DynamicalSystem in the graph, compute its absolute position.
- Parameters:
DSG – the index set of the dynamical systems
- Returns:
the dimension of the problem (or size of the matrix), computed as the sum of the nslaw of all the Interaction in indexSet
Protected Attributes
-
unsigned int _dimRow#
number of rows
-
unsigned int _dimColumn#
number of columns
-
size_t _triplet_nzmax#
_triplet_nzmax for memory allocation of NM_SPARSE
Private Functions
-
OSNSMatrix(const OSNSMatrix&)#
Private copy constructor => no copy nor pass by value.
-
OSNSMatrix &operator=(const OSNSMatrix&)#
Private assignment -> forbidden.
- Returns: