17 #ifndef AGX_SPARSE_MATRIX_H
18 #define AGX_SPARSE_MATRIX_H
52 virtual void setLogicalStructure(
size_t n,
const unsigned int* pointers,
const unsigned int* indices,
const unsigned int* dimensions,
const int* flags,
unsigned int numThreads );
123 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 );
160 agx::Real* getBlock(
int i,
int j,
bool& writeTransposed,
unsigned int& leadingDimension);
181 size_t unitSolve(
agx::Real*,
int = -1 );
186 unsigned int getNumRows()
const;
191 unsigned int getNumColumns()
const;
242 bool saveH5(
void* group,
const agx::String& name )
const;
250 bool loadH5(
void* group,
const agx::String& name );
256 void setNumBodies(
int num );
287 : m_matrix( matrix ), m_signs( signs ) {}
291 return getOrCreateColRow( col )->column;
296 return getOrCreateColRow( row )->asRow( m_signs );
308 if ( column.size() == 0 )
311 if ( row.size() == column.size() )
314 row.resize( column.size() );
318 for (
UInt i = 0, numRows = row.size(); i < numRows; ++i )
319 row[ i ] *=
sign * signs[ i ];
324 typedef ref_ptr< ColRow > ColRowRef;
327 typedef HashTable< UInt, ColRowRef > ColRowContainer;
332 ColRowRef getOrCreateColRow(
UInt col )
334 ColRowContainer::iterator it = m_colRowStorage.
find( col );
335 if ( it == m_colRowStorage.
end() ) {
336 it = m_colRowStorage.
insert( col,
new ColRow() );
337 m_matrix.
getColumn( col, it->second->column, it->second->signFlip );
344 const SparseMatrix& m_matrix;
346 ColRowContainer m_colRowStorage;
360 size_t n,
const unsigned int* pointers,
const unsigned int* indices,
361 const unsigned int* dimensions,
const int* flags,
unsigned int numThreads )
368 return m_rep->
getBlock(i, j, writeTransposed, leadingDimension);
388 return m_rep->
unitSolve( rhs, startRow );
433 return m_rep->
print();
438 return m_rep->
saveH5( group, name );
443 return m_rep->
loadH5( group, name );
#define AGX_DECLARE_POINTER_TYPES(type)
#define AGXPHYSICS_EXPORT
Class that stores rows and columns of the matrix.
ColumnStorage(const SparseMatrix &matrix, const RealValarray &signs)
const RealValarray & getOrCreateRow(UInt row)
const RealValarray & getOrCreateColumn(UInt col)
iterator end()
Iterator marking end of hash table.
insert_iterator insert(const KeyT &key, const ValueT value)
Insert a key/value pair into the hash table.
iterator find(const KeyT &key)
Find a key/value pair in the hash table given a key.
A class to distinguish between various types of matrices, both in terms of storage properties,...
Base class providing referencing counted objects.
virtual void print() const
virtual agx::Real * getBlock(int i, int j, bool &writeTransposed, unsigned int &lda)=0
virtual void solve(agx::Real *)=0
virtual size_t unitSolve(agx::Real *, int=-1)
virtual ~SparseMatrixRep()
virtual void setLogicalStructure(size_t n, const unsigned int *pointers, const unsigned int *indices, const unsigned int *dimensions, const int *flags, unsigned int numThreads)
virtual agx::Real getFactorTime() const
virtual unsigned int getNumColumns() const =0
virtual agx::Real getSolveTime() const
virtual agx::UInt permuteRowIndex(agx::UInt rowIndex) const
virtual bool loadH5(void *group, const agx::String &name)
virtual void setNumBodies(size_t)
virtual void multiplyAdd(const agx::Real *x, agx::Real *r)=0
virtual void multiply(const agx::Real *x, agx::Real *r)=0
virtual bool saveH5(void *group, const agx::String &name) const
virtual agx::Bool getColumn(agx::UInt colNumber, agx::RealValarray &retCol, agx::Bool &signFlip) const =0
virtual agx::Bool getRow(agx::UInt rowNumber, const agx::RealValarray &signs, agx::RealValarray &retRow) const =0
virtual unsigned int getNumRows() const =0
virtual agx::UInt getBlockPermutedStartRowIndex(agx::UInt blockIndex) const =0
virtual agx::UInt invPermuteRowIndex(agx::UInt permutedRowIndex) const
virtual void multiplyAdd(const agx::Real &alpha, const agx::Real *x, const agx::Real &beta, agx::Real *r)=0
agx::SparseMatrix holds a matrix representation which contains the data.
bool loadH5(void *group, const agx::String &name)
Loads the matrix.
agx::UInt invPermuteRowIndex(agx::UInt permutedRowIndex) const
void setRep(SparseMatrixRep *rep)
Replace the Sparse Matrix Representation.
agx::Real * getBlock(int i, int j, bool &writeTransposed, unsigned int &leadingDimension)
Fetches the location for a block of the matrix.
size_t unitSolve(agx::Real *, int=-1)
Solve, the right hand side is overwritten with the result.
BlockFlags
Flags that can be used to tag blocks so that the matrix representation can optimize the calculations.
void solve(agx::Real *)
Solve, the right hand side is overwritten with the result.
agx::Bool getColumn(agx::UInt colNumber, agx::RealValarray &retCol) const
Extract a column from the matrix.
agx::Real getFactorTime() const
agx::UInt getBlockPermutedStartRowIndex(agx::UInt blockIndex) const
agx::UInt permuteRowIndex(agx::UInt rowIndex) const
SparseMatrixRep * getRep()
agx::Real getSolveTime() const
void reset()
Clears the matrix.
~SparseMatrix()
Destructor.
bool saveH5(void *group, const agx::String &name) const
Stores the matrix in HDF5 format.
agx::Bool getColumn(agx::UInt colNumber, agx::RealValarray &retCol, agx::Bool &signFlip) const
Extract a column from the matrix.
const SparseMatrixRep * getRep() const
unsigned int getNumRows() const
SparseMatrix(MatrixType type=MatrixType(), SparseMatrixRep *rep=0)
Constructor.
void multiplyAdd(const agx::Real *x, agx::Real *r)
Calculates r = Ax + r.
unsigned int getNumColumns() const
void setNumBodies(int num)
Sets the number of bodies, can be used by the representation to help making the permutation.
agx::Bool getRow(agx::UInt rowNumber, const agx::RealValarray &signs, agx::RealValarray &retRow) const
Extract a row from the matrix.
void factor()
Factors the matrix.
void multiply(const agx::Real *x, agx::Real *r)
Calculates r = A x.
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.
AGXCORE_EXPORT Type * getType(const agx::String &name)
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
std::valarray< agx::Real > RealValarray
For this module, vectors are defined using valarray.