 |
AGXDynamics
2.35.0.2
|
Go to the documentation of this file.
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 ];
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 );
virtual agx::UInt getBlockPermutedStartRowIndex(agx::UInt blockIndex) const =0
virtual size_t unitSolve(agx::Real *, int=-1)
virtual void print() const
void solve(agx::Real *)
Solve, the right hand side is overwritten with the result.
virtual unsigned int getNumColumns() const =0
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)
agx::Bool getColumn(agx::UInt colNumber, agx::RealValarray &retCol) const
Extract a column from the matrix.
agx::SparseMatrix holds a matrix representation which contains the data.
const RealValarray & getOrCreateRow(UInt row)
A class to distinguish between various types of matrices, both in terms of storage properties,...
virtual ~SparseMatrixRep()
virtual agx::Real * getBlock(int i, int j, bool &writeTransposed, unsigned int &lda)=0
virtual void solve(agx::Real *)=0
void multiply(const agx::Real *x, agx::Real *r)
Calculates r = A x.
BlockFlags
Flags that can be used to tag blocks so that the matrix representation can optimize the calculations.
virtual agx::UInt permuteRowIndex(agx::UInt rowIndex) const
insert_iterator insert(const KeyT &key, const ValueT value)
Insert a key/value pair into the hash table.
iterator end()
Iterator marking end of hash table.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
#define AGXPHYSICS_EXPORT
void reset()
Clears the matrix.
iterator find(const KeyT &key)
Find a key/value pair in the hash table given a key.
agx::UInt getBlockPermutedStartRowIndex(agx::UInt blockIndex) const
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 unsigned int getNumRows() const =0
agx::UInt permuteRowIndex(agx::UInt rowIndex) const
virtual agx::Real getSolveTime() const
ColumnStorage(const SparseMatrix &matrix, const RealValarray &signs)
void setNumBodies(int num)
Sets the number of bodies, can be used by the representation to help making the permutation.
virtual void multiplyAdd(const agx::Real *x, agx::Real *r)=0
virtual agx::UInt invPermuteRowIndex(agx::UInt permutedRowIndex) const
void multiplyAdd(const agx::Real *x, agx::Real *r)
Calculates r = Ax + r.
Class that stores rows and columns of the matrix.
unsigned int getNumRows() const
std::valarray< agx::Real > RealValarray
For this module, vectors are defined using valarray.
size_t unitSolve(agx::Real *, int=-1)
Solve, the right hand side is overwritten with the result.
agx::UInt invPermuteRowIndex(agx::UInt permutedRowIndex) const
void factor()
Factors the matrix.
virtual bool saveH5(void *group, const agx::String &name) const
Base class providing referencing counted objects.
#define AGX_DECLARE_POINTER_TYPES(type)
virtual void setNumBodies(size_t)
virtual bool loadH5(void *group, const agx::String &name)
virtual agx::Real getFactorTime() const
virtual void multiply(const agx::Real *x, agx::Real *r)=0
unsigned int getNumColumns() const
agx::Real * getBlock(int i, int j, bool &writeTransposed, unsigned int &leadingDimension)
Fetches the location for a block of the matrix.
bool saveH5(void *group, const agx::String &name) const
Stores the matrix in HDF5 format.
bool loadH5(void *group, const agx::String &name)
Loads the matrix.
const RealValarray & getOrCreateColumn(UInt col)