AGX Dynamics  2.35.0.1
agx::SparseMatrix Class Reference

agx::SparseMatrix holds a matrix representation which contains the data. More...

#include <SparseMatrix.h>

Public Types

enum  BlockFlags { DENSE = 0 , DIAGONAL = 1 , LOWER_TRIANGULAR = 2 , UPPER_TRIANGULAR = 3 }
 Flags that can be used to tag blocks so that the matrix representation can optimize the calculations. More...
 

Public Member Functions

 SparseMatrix (MatrixType type=MatrixType(), SparseMatrixRep *rep=0)
 Constructor. More...
 
 ~SparseMatrix ()
 Destructor. More...
 
void factor ()
 Factors the matrix. More...
 
agx::Real * getBlock (int i, int j, bool &writeTransposed, unsigned int &leadingDimension)
 Fetches the location for a block of the matrix. More...
 
agx::UInt getBlockPermutedStartRowIndex (agx::UInt blockIndex) const
 
agx::Bool getColumn (agx::UInt colNumber, agx::RealValarray &retCol) const
 Extract a column from the matrix. More...
 
agx::Bool getColumn (agx::UInt colNumber, agx::RealValarray &retCol, agx::Bool &signFlip) const
 Extract a column from the matrix. More...
 
agx::Real getFactorTime () const
 
unsigned int getNumColumns () const
 
unsigned int getNumRows () const
 
SparseMatrixRep * getRep ()
 
const SparseMatrixRep * getRep () const
 
agx::Bool getRow (agx::UInt rowNumber, const agx::RealValarray &signs, agx::RealValarray &retRow) const
 Extract a row from the matrix. More...
 
agx::Real getSolveTime () const
 
MatrixType & getType ()
 
agx::UInt invPermuteRowIndex (agx::UInt permutedRowIndex) const
 
bool loadH5 (void *group, const agx::String &name)
 Loads the matrix. More...
 
void multiply (const agx::Real *x, agx::Real *r)
 Calculates r = A x. More...
 
void multiplyAdd (const agx::Real &alpha, const agx::Real *x, const agx::Real &beta, agx::Real *r)
 Calculates r = alpha A x + beta r. More...
 
void multiplyAdd (const agx::Real *x, agx::Real *r)
 Calculates r = Ax + r. More...
 
agx::UInt permuteRowIndex (agx::UInt rowIndex) const
 
void print () const
 
void reset ()
 Clears the matrix. More...
 
bool saveH5 (void *group, const agx::String &name) const
 Stores the matrix in HDF5 format. More...
 
void setLogicalStructure (size_t n, const unsigned int *pointers, const unsigned int *indices, const unsigned int *dimensions, const int *flags=nullptr, unsigned int numThreads=1)
 Sets the logical structure of the matrix. More...
 
void setNumBodies (int num)
 Sets the number of bodies, can be used by the representation to help making the permutation. More...
 
void setRep (SparseMatrixRep *rep)
 Replace the Sparse Matrix Representation. More...
 
void solve (agx::Real *)
 Solve, the right hand side is overwritten with the result. More...
 
size_t unitSolve (agx::Real *, int=-1)
 Solve, the right hand side is overwritten with the result. More...
 

Detailed Description

agx::SparseMatrix holds a matrix representation which contains the data.

Each solver wrapper (if it can handle the matrix format defined by MatrixType), uses this data and passes it in the correct format to the solver.

Definition at line 85 of file SparseMatrix.h.

Member Enumeration Documentation

◆ BlockFlags

Flags that can be used to tag blocks so that the matrix representation can optimize the calculations.

Enumerator
DENSE 
DIAGONAL 
LOWER_TRIANGULAR 
UPPER_TRIANGULAR 

Definition at line 93 of file SparseMatrix.h.

Constructor & Destructor Documentation

◆ SparseMatrix()

agx::SparseMatrix::SparseMatrix ( MatrixType  type = MatrixType(),
SparseMatrixRep *  rep = 0 
)

Constructor.

Parameters
typeMatrix type
repPointer to SparseMatrixRepresentation. The SparseMatrix takes ownership of the pointer.

◆ ~SparseMatrix()

agx::SparseMatrix::~SparseMatrix ( )

Destructor.

Member Function Documentation

◆ factor()

void agx::SparseMatrix::factor ( )

Factors the matrix.

Definition at line 376 of file SparseMatrix.h.

References agx::SparseMatrixRep::factor().

◆ getBlock()

agx::Real * agx::SparseMatrix::getBlock ( int  i,
int  j,
bool &  writeTransposed,
unsigned int &  leadingDimension 
)

Fetches the location for a block of the matrix.

The block can be 1x1 in size for non block matrix.

Parameters
iBlock row index.
jBlock column index.
leadingDimensionLeading dimension when writing the block data. Row major/column major depends on MatrixRep used.

Definition at line 366 of file SparseMatrix.h.

References agx::SparseMatrixRep::getBlock().

◆ getBlockPermutedStartRowIndex()

UInt agx::SparseMatrix::getBlockPermutedStartRowIndex ( agx::UInt  blockIndex) const
inline
Parameters
blockIndex- non-permuted block index
Returns
permuted start row

Definition at line 406 of file SparseMatrix.h.

References agx::SparseMatrixRep::getBlockPermutedStartRowIndex().

◆ getColumn() [1/2]

agx::Bool agx::SparseMatrix::getColumn ( agx::UInt  colNumber,
agx::RealValarray &  retCol 
) const

Extract a column from the matrix.

Parameters
colNumber- column number to extract
[out]retCol- result
Returns
true if successful

◆ getColumn() [2/2]

agx::Bool agx::SparseMatrix::getColumn ( agx::UInt  colNumber,
agx::RealValarray &  retCol,
agx::Bool &  signFlip 
) const

Extract a column from the matrix.

Parameters
colNumber- column number to extract
[out]retCol- result
[out]signFlip- depending on colNumber the sign has to be flipped when this column is transformed to a row
Returns
true if successful

◆ getFactorTime()

agx::Real agx::SparseMatrix::getFactorTime ( ) const

◆ getNumColumns()

unsigned int agx::SparseMatrix::getNumColumns ( ) const
Returns
Number of columns in the matrix.

Definition at line 426 of file SparseMatrix.h.

References agx::SparseMatrixRep::getNumColumns().

◆ getNumRows()

unsigned int agx::SparseMatrix::getNumRows ( ) const
Returns
Number of rows in the matrix.

Definition at line 421 of file SparseMatrix.h.

References agx::SparseMatrixRep::getNumRows().

◆ getRep() [1/2]

SparseMatrixRep* agx::SparseMatrix::getRep ( )

◆ getRep() [2/2]

const SparseMatrixRep* agx::SparseMatrix::getRep ( ) const

◆ getRow()

agx::Bool agx::SparseMatrix::getRow ( agx::UInt  rowNumber,
const agx::RealValarray &  signs,
agx::RealValarray &  retRow 
) const

Extract a row from the matrix.

Parameters
rowNumber- row number to extract
signs- sign array -1 for constraints, 1 for bodies
[out]retRow- result
Returns
true if successful

◆ getSolveTime()

agx::Real agx::SparseMatrix::getSolveTime ( ) const

◆ getType()

MatrixType & agx::SparseMatrix::getType ( )
Returns
Type information about the matrix

Definition at line 353 of file SparseMatrix.h.

◆ invPermuteRowIndex()

UInt agx::SparseMatrix::invPermuteRowIndex ( agx::UInt  permutedRowIndex) const
inline
Parameters
permutedRowIndex- permuted row index
Returns
non-permuted start row index

Definition at line 416 of file SparseMatrix.h.

References agx::SparseMatrixRep::invPermuteRowIndex().

◆ loadH5()

bool agx::SparseMatrix::loadH5 ( void *  group,
const agx::String &  name 
)
inline

Loads the matrix.

Parameters
groupPointer to H5::Group in which matrix should be stored
nameName to use when loading matrix
Returns
true if successful

Definition at line 441 of file SparseMatrix.h.

References agx::SparseMatrixRep::loadH5().

◆ multiply()

void agx::SparseMatrix::multiply ( const agx::Real *  x,
agx::Real *  r 
)

Calculates r = A x.

Definition at line 391 of file SparseMatrix.h.

References agx::SparseMatrixRep::multiply().

◆ multiplyAdd() [1/2]

void agx::SparseMatrix::multiplyAdd ( const agx::Real &  alpha,
const agx::Real *  x,
const agx::Real &  beta,
agx::Real *  r 
)

Calculates r = alpha A x + beta r.

Definition at line 401 of file SparseMatrix.h.

References agx::SparseMatrixRep::multiplyAdd().

◆ multiplyAdd() [2/2]

void agx::SparseMatrix::multiplyAdd ( const agx::Real *  x,
agx::Real *  r 
)

Calculates r = Ax + r.

Definition at line 396 of file SparseMatrix.h.

References agx::SparseMatrixRep::multiplyAdd().

◆ permuteRowIndex()

UInt agx::SparseMatrix::permuteRowIndex ( agx::UInt  rowIndex) const
inline
Parameters
rowIndex- non-permuted rowIndex
Returns
permuted row index

Definition at line 411 of file SparseMatrix.h.

References agx::SparseMatrixRep::permuteRowIndex().

◆ print()

void agx::SparseMatrix::print ( ) const
inline

Definition at line 431 of file SparseMatrix.h.

References agx::SparseMatrixRep::print().

◆ reset()

void agx::SparseMatrix::reset ( )

Clears the matrix.

Definition at line 371 of file SparseMatrix.h.

References agx::SparseMatrixRep::reset().

◆ saveH5()

bool agx::SparseMatrix::saveH5 ( void *  group,
const agx::String &  name 
) const
inline

Stores the matrix in HDF5 format.

Parameters
groupPointer to H5::Group in which matrix should be stored
nameName to use when storing matrix
Returns
true if successful

Definition at line 436 of file SparseMatrix.h.

References agx::SparseMatrixRep::saveH5().

◆ setLogicalStructure()

void agx::SparseMatrix::setLogicalStructure ( size_t  n,
const unsigned int *  pointers,
const unsigned int *  indices,
const unsigned int *  dimensions,
const int *  flags = nullptr,
unsigned int  numThreads = 1 
)

Sets the logical structure of the matrix.

The method takes a matrix in packed row format.

Parameters
nNumber of (block) rows
pointersRow pointers
indicesColumn indices
dimensionsNumber of rows for each block row. If not blocked, each dimension[i] will be 1.
flagsPointer to flag for each block, if 0, all blocks are assumed to be dense.
numThreadsHint about maximum number of threads the factorizer can use.

Definition at line 359 of file SparseMatrix.h.

References agx::SparseMatrixRep::setLogicalStructure().

◆ setNumBodies()

void agx::SparseMatrix::setNumBodies ( int  num)

Sets the number of bodies, can be used by the representation to help making the permutation.

Definition at line 446 of file SparseMatrix.h.

References agx::SparseMatrixRep::setNumBodies().

◆ setRep()

void agx::SparseMatrix::setRep ( SparseMatrixRep *  rep)

Replace the Sparse Matrix Representation.

The SparseMatrix takes ownership of the SparseMatrixRep

This method is only needed in some very special use cases.

◆ solve()

void agx::SparseMatrix::solve ( agx::Real *  rhs)

Solve, the right hand side is overwritten with the result.

Definition at line 381 of file SparseMatrix.h.

References agx::SparseMatrixRep::solve().

◆ unitSolve()

size_t agx::SparseMatrix::unitSolve ( agx::Real *  rhs,
int  startRow = -1 
)

Solve, the right hand side is overwritten with the result.

The right hand side is contains one 1, the rest is 0.

Definition at line 386 of file SparseMatrix.h.

References agx::SparseMatrixRep::unitSolve().


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