17 #ifndef AGX_SPARSE_MATRIX_H 18 #define AGX_SPARSE_MATRIX_H 37 virtual agx::Real* getBlock(
int i,
int j,
bool& writeTransposed,
unsigned int& lda) = 0;
39 virtual void reset() = 0;
41 virtual void factor() = 0;
44 virtual size_t unitSolve(
agx::Real*,
int = -1 );
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 );
61 virtual unsigned int getNumRows()
const = 0;
62 virtual unsigned int getNumColumns()
const = 0;
66 virtual bool saveH5(
void* group,
const agx::String& name )
const;
67 virtual bool loadH5(
void* group,
const agx::String& name );
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 ];
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 );
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 )
363 m_rep->setLogicalStructure(n,pointers, indices, dimensions, flags, numThreads);
368 return m_rep->getBlock(i, j, writeTransposed, leadingDimension);
388 return m_rep->unitSolve( rhs, startRow );
393 m_rep->multiply(x,r);
398 m_rep->multiplyAdd(x, r);
403 m_rep->multiplyAdd(alpha, x, beta, r );
408 return m_rep->getBlockPermutedStartRowIndex( blockIndex );
413 return m_rep->permuteRowIndex( rowIndex );
418 return m_rep->invPermuteRowIndex( permutedRowIndex );
423 return m_rep->getNumRows();
428 return m_rep->getNumColumns();
433 return m_rep->print();
438 return m_rep->saveH5( group, name );
443 return m_rep->loadH5( group, name );
448 m_rep->setNumBodies( num );
Class that stores rows and columns of the matrix.
AGXCORE_EXPORT Type * getType(const agx::String &name)
bool saveH5(void *group, const agx::String &name) const
Stores the matrix in HDF5 format.
void solve(agx::Real *)
Solve, the right hand side is overwritten with the result.
virtual void setNumBodies(size_t)
agx::UInt invPermuteRowIndex(agx::UInt permutedRowIndex) const
virtual agx::Real getFactorTime() const
void reset()
Clears the matrix.
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
void multiply(const agx::Real *x, agx::Real *r)
Calculates r = A x.
agx::UInt permuteRowIndex(agx::UInt rowIndex) const
agx::UInt getBlockPermutedStartRowIndex(agx::UInt blockIndex) const
Base class providing referencing counted objects.
agx::Real * getBlock(int i, int j, bool &writeTransposed, unsigned int &leadingDimension)
Fetches the location for a block of the matrix.
void setNumBodies(int num)
Sets the number of bodies, can be used by the representation to help making the permutation.
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.
void multiplyAdd(const agx::Real *x, agx::Real *r)
Calculates r = Ax + r.
const RealValarray & getOrCreateRow(UInt row)
unsigned int getNumRows() const
virtual ~SparseMatrixRep()
unsigned int getNumColumns() const
virtual void print() const
ColumnStorage(const SparseMatrix &matrix, const RealValarray &signs)
A class to distinguish between various types of matrices, both in terms of storage properties...
const RealValarray & getOrCreateColumn(UInt col)
Inheritance with partial specialization due to bug with ref_ptr containers.
size_t unitSolve(agx::Real *, int=-1)
Solve, the right hand side is overwritten with the result.
agx::SparseMatrix holds a matrix representation which contains the data.
virtual agx::Real getSolveTime() const
bool loadH5(void *group, const agx::String &name)
Loads the matrix.
void factor()
Factors the matrix.
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.
BlockFlags
Flags that can be used to tag blocks so that the matrix representation can optimize the calculations...