AGX Dynamics  2.37.3.2
DirectSolverData.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_DIRECTSOLVERDATA_H
18 #define AGX_DIRECTSOLVERDATA_H
19 
20 #include <agx/MixedLCP.h>
21 #include <agx/Solver.h>
22 #include <agx/RigidBodyState.h>
23 #include <agx/StabilityReport.h>
24 #include <agx/agx_vector_types.h>
25 
28 
29 #include <agxData/Array.h>
30 
31 #define to_permuted_matrix_index( lId ) matrix.getBlockPermutedStartRowIndex( lId )
32 
33 namespace agx
34 {
36  {
37  public:
38  typedef std::valarray< unsigned int > UIntContainer;
39  public:
40  LogicalStructure() : m_riCounter( 0 ), m_riIndex( 0 ), m_ciIndex( 0 ), m_dimIndex( 0 ) {}
41 
42  void resize( size_t riSize, size_t ciSize, size_t dimSize )
43  {
44  m_ri.resize( riSize, UIntContainer::value_type(-1) );
45  m_ci.resize( ciSize, UIntContainer::value_type(-1) );
46  m_dim.resize( dimSize, UIntContainer::value_type(-1) );
47  m_riCounter = 0;
48  m_riIndex = 0;
49  m_ciIndex = 0;
50  m_dimIndex = 0;
51  }
52 
53  inline void newRow( size_t dim )
54  {
55  agxAssert( m_riIndex < m_ri.size() );
56  m_ri[ m_riIndex ] = (UIntContainer::value_type)m_riCounter;
57  m_dim[ m_dimIndex ] = (UIntContainer::value_type)dim;
58  ++m_riIndex;
59  ++m_dimIndex;
60  }
61 
62  inline void insertBlock( size_t colIndex )
63  {
64  agxAssert( m_ciIndex < m_ci.size() );
65  m_ci[ m_ciIndex ] = (UIntContainer::value_type)colIndex;
66  ++m_ciIndex;
67  ++m_riCounter;
68  }
69 
70  void finalize()
71  {
72  agxAssert( m_riIndex == m_ri.size() - 1 );
73  agxAssert( m_ciIndex == m_ci.size() );
74  m_ri[ m_riIndex ] = (UIntContainer::value_type)m_riCounter;
75  }
76 
77  unsigned int* riPtr() { return &( m_ri[0]); }
78  unsigned int* ciPtr() { return &( m_ci[0]); }
79  unsigned int* dimPtr() { return &(m_dim[0]); }
80 
81  bool operator==(const LogicalStructure& rhs) const;
82  private:
83  UIntContainer m_ri;
84  UIntContainer m_ci;
85  UIntContainer m_dim;
86  size_t m_riCounter;
87  size_t m_riIndex;
88  size_t m_ciIndex;
89  size_t m_dimIndex;
90  };
91 
93  {
94  public:
96 
97  public:
102  {
103  public:
105  enum Buffers { SPLIT, DIRECT, DIRECT_AND_ITERATIVE, NUM_BUFFERS };
106 
108 
112  bool initialize( Physics::SolveIslandPtr& island );
113 
114  AGX_FORCE_INLINE const GroupsContainer& getBuffer( Buffers buffer ) const { return m_buffers[ buffer ]; }
115 
116  protected:
117  virtual ~ContactGroups() {}
118 
119  private:
120  ContactGroups( const ContactGroups& ) {}
121 
122  private:
123  GroupsContainer m_buffers[ NUM_BUFFERS ];
124  };
125 
127 
128  public:
137  DirectSolverData( agx::UInt numEquations,
138  agx::UInt numBlockRows,
139  agx::UInt numBlocks,
140  agx::Solver::NlMcpConfig nlMcpConfig,
141  agx::Bool gatherStatistics,
142  INlSolveDataH5* nlSolveDataH5 );
143 
148  void initialize();
149 
153  DirectSolverData* clone();
154 
160  void buildStrongInteractionTable( agx::Physics::InteractionGroupPtr islandGroup,
161  agx::Physics::StrongInteractionData& strongInteractions,
162  const agxData::IndexArray& globalToLocalIndexArray );
163 
167  agx::LogicalStructure& getLogicalStructure();
168  const agx::LogicalStructure& getLogicalStructure() const;
169 
173  agx::SparseMatrix& getMatrix();
174  const agx::SparseMatrix& getMatrix() const;
175 
179  agx::UInt getNumBlockRows() const;
180 
184  agx::RealValarray& getSigns();
185  const agx::RealValarray& getSigns() const;
186 
190  agx::SparseRangeReal& getSparseBounds();
191  const agx::SparseRangeReal& getSparseBounds() const;
192 
198  const agx::RealValarray& solve();
199 
203  agx::RealValarray& getQ();
204  const agx::RealValarray& getQ() const;
205 
209  agx::RealValarray& getSolution();
210  const agx::RealValarray& getSolution() const;
211 
215  agx::IndexSet& getIndexSet();
216 
220  agx::DirectSolverData::ContactGroups* getContactGroups() const;
221 
225  const agx::NlMixedCp::McpAlgorithm* getAlgorithm() const;
226 
230  agx::StabilityReport* getStabilityReport() const;
231 
235  const agx::DirectSolverData::StrongInteractionTable& getStrongInteractionTable() const;
236 
240  void setContactGroups( agx::DirectSolverData::ContactGroups* contactGroups );
241 
249  void commitVelocities( const agxData::IndexArray& indices,
250  agxData::Array< agx::Vec3 >& linearVelocities,
251  agxData::Array< agx::Vec3 >& angularVelocities,
252  const agxData::Array< agx::RigidBodyState >& states ) const;
253 
254  protected:
255  DirectSolverData() = delete;
256  virtual ~DirectSolverData();
257 
258 
259  protected:
265  ContactGroupsRef m_contactGroups;
268  StrongInteractionTable m_strongInteractionTable;
270  };
271 
273 }
274 
275 #endif
unsigned int * dimPtr()
agx::ref_ptr< ContactGroups > ContactGroupsRef
unsigned int * ciPtr()
agx::HashTable< agx::UInt, agx::UIntVector > StrongInteractionTable
const GroupsContainer & getBuffer(Buffers buffer) const
void insertBlock(size_t colIndex)
bool Bool
Definition: Integer.h:48
StrongInteractionTable m_strongInteractionTable
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
INlSolveDataH5 * m_nlSolveDataH5
agx::VectorPOD< agx::Index > GroupsContainer
Pointer to a entity instance of type Physics.SolveIsland.
Base class providing referencing counted objects.
Definition: Referenced.h:119
Essentially a sparse array of bounds.
Definition: SparseTypes.h:73
uint32_t UInt
Definition: Integer.h:34
LogicalStructure m_logicalStructure
void newRow(size_t dim)
void resize(size_t riSize, size_t ciSize, size_t dimSize)
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.
bool operator==(const LogicalStructure &rhs) const
#define agxAssert(expr)
Definition: debug.h:143
Pointer to a entity instance of type Physics.InteractionGroup.
Class that handles the grouping.
unsigned int * riPtr()
std::valarray< unsigned int > UIntContainer
StabilityReportRef m_stabilityReport
ContactGroupsRef m_contactGroups
Interface class for algorithm to solve general mixed complementarity problem.
Definition: MixedLCP.h:114
Inheritance with partial specialization due to bug with ref_ptr containers.
agx::SparseMatrix holds a matrix representation which contains the data.
Definition: SparseMatrix.h:85