AGX Dynamics  2.37.2.0
SparseInverse.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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:
88  ~SparseInverse();
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
bool operator<=(const RealEntry &e)
Definition: SparseInverse.h:64
A sparse vector here is an Vector of entries with a few additional operations for creation and sortin...
Definition: SparseInverse.h:72
AGXTERRAIN_EXPORT void clear()
bool operator==(const RealEntry &e)
Definition: SparseInverse.h:63
RealEntry(const int &i, const Real &x)
Definition: SparseInverse.h:61
SparseInverse holds a subset of the columns of the inverse of a given sparse matrix.
Definition: SparseInverse.h:58
STL namespace.
Templated vector class.
Definition: Vector.h:52
Essentially a sparse array of bounds.
Definition: SparseTypes.h:73
bool operator<(const RealEntry &e)
Definition: SparseInverse.h:62
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.
double Real
Definition: Real.h:42
agx::SparseMatrix holds a matrix representation which contains the data.
Definition: SparseMatrix.h:85