AGXDynamics  2.35.0.2
SparseInverse.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_SPARSE_INVERSE_H
18 #define AGX_SPARSE_INVERSE_H
19 
20 #include <agx/agx_valarray_types.h>
21 #include <agx/IndexSet.h>
22 #include <agx/SparseMatrix.h>
23 #include <map>
24 
25 #include <agxSabre/DenseTypes.h>
26 
27 #ifdef _MSC_VER
28 # pragma warning(push)
29 // Disable warning about assignment operator could not be generated due to reference members.
30 #pragma warning( disable: 4512 )
31 #endif
32 
33 
34 namespace agx
35 {
36 
58  class RealEntry : public std::pair<int, Real> {
59  public:
60  RealEntry() : std::pair<int, Real>() {}
61  RealEntry(const int& i, const Real &x) : std::pair<int, Real> (i, x) {}
62  bool operator< (const RealEntry & e) { return first < e.first ; }
63  bool operator== (const RealEntry & e) { return first == e.first ; }
64  bool operator<= (const RealEntry & e) { return first <= e.first ; }
65  };
66 
72  class SparseVector : public Vector<RealEntry> {
73  public:
75  SparseVector(const RealValarray &x, const SparseRangeReal &bounds, Real threshold = 0 );
76  void extract_subvector(const IndexSet::IxSet& s, SparseVector &V ) const;
77  };
78 
79 
80  class SparseInverse {
81  private:
82  typedef std::map<UInt, SparseVector > ISVMap;
83  ISVMap m_map;
84  void update_inverse( SparseMatrix& sparseMatrix, const IndexSet::IxSet& s, const SparseRangeReal& bounds, const RealValarray& signs );
85  void build_submatrix( SparseMatrix& sparseMatrix, const IndexSet::IxSet &s, const SparseRangeReal& bounds, agxSabre::DenseMatrix<agx::Real> &m, const RealValarray& signs );
86  public:
89 
90  void clear();
91  void solve_subproblem( SparseMatrix& sparseMatrix, const IndexSet::IxSet& s, const SparseRangeReal& bounds, RealValarray &b, const RealValarray& signs );
92  };
93 
94 }
95 
96 #ifdef _MSC_VER
97 # pragma warning(pop)
98 #endif
99 
100 #endif
agx::SparseInverse::~SparseInverse
~SparseInverse()
agx::Real
double Real
Definition: Real.h:42
agx::Vector
Templated vector class.
Definition: Vector.h:52
agx::RealEntry::operator<
bool operator<(const RealEntry &e)
Definition: SparseInverse.h:62
agx::SparseMatrix
agx::SparseMatrix holds a matrix representation which contains the data.
Definition: SparseMatrix.h:85
agx::RealEntry::RealEntry
RealEntry()
Definition: SparseInverse.h:60
agx_valarray_types.h
SparseMatrix.h
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
IndexSet.h
agx::RealEntry::operator<=
bool operator<=(const RealEntry &e)
Definition: SparseInverse.h:64
agx::SparseInverse
Definition: SparseInverse.h:80
agx::SparseInverse::SparseInverse
SparseInverse()
Definition: SparseInverse.h:87
agx::RealValarray
std::valarray< agx::Real > RealValarray
For this module, vectors are defined using valarray.
Definition: agx_valarray_types.h:27
agx::RealEntry::operator==
bool operator==(const RealEntry &e)
Definition: SparseInverse.h:63
agx::SparseVector::extract_subvector
void extract_subvector(const IndexSet::IxSet &s, SparseVector &V) const
agx::SparseVector
A sparse vector here is an Vector of entries with a few additional operations for creation and sortin...
Definition: SparseInverse.h:72
agx::SparseInverse::clear
void clear()
agx::RealEntry
SparseInverse holds a subset of the columns of the inverse of a given sparse matrix.
Definition: SparseInverse.h:58
agx::RealEntry::RealEntry
RealEntry(const int &i, const Real &x)
Definition: SparseInverse.h:61
agx::SparseVector::SparseVector
SparseVector()
Definition: SparseInverse.h:74
agx::SparseRangeReal
Essentially a sparse array of bounds.
Definition: SparseTypes.h:73
agx::SparseInverse::solve_subproblem
void solve_subproblem(SparseMatrix &sparseMatrix, const IndexSet::IxSet &s, const SparseRangeReal &bounds, RealValarray &b, const RealValarray &signs)