AGX Dynamics  2.38.0.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:
270  };
271 
273 }
274 
275 #endif
agx::DirectSolverData::ContactGroupsRef
agx::ref_ptr< ContactGroups > ContactGroupsRef
Definition: DirectSolverData.h:126
agx::DirectSolverData::ContactGroups::getBuffer
const GroupsContainer & getBuffer(Buffers buffer) const
Definition: DirectSolverData.h:114
agx::UInt
uint64_t UInt
Definition: Integer.h:27
agx::DirectSolverData::m_strongInteractionTable
StrongInteractionTable m_strongInteractionTable
Definition: DirectSolverData.h:268
agx::LogicalStructure::finalize
void finalize()
Definition: DirectSolverData.h:70
agx::DirectSolverData::ContactGroups::Buffers
Buffers
Definition: DirectSolverData.h:105
agx::LogicalStructure::insertBlock
void insertBlock(size_t colIndex)
Definition: DirectSolverData.h:62
agx::DirectSolverData::ContactGroups::SPLIT
@ SPLIT
Definition: DirectSolverData.h:105
agx::Physics::SolveIslandPtr
Pointer to a entity instance of type Physics.SolveIsland.
Definition: SolveIslandEntity.h:185
agx::SparseMatrix
agx::SparseMatrix holds a matrix representation which contains the data.
Definition: SparseMatrix.h:85
agx::DirectSolverData::m_nlmcp
NlMixedCpRef m_nlmcp
Definition: DirectSolverData.h:263
agx::LogicalStructure::ciPtr
unsigned int * ciPtr()
Definition: DirectSolverData.h:78
StrongInteractionEntity.h
agxAssert
#define agxAssert(expr)
Definition: debug.h:143
SolveIslandEntity.h
Array.h
MixedLCP.h
agx::VectorPOD< agx::Index >
agx::DirectSolverData::ContactGroups::GroupsContainer
agx::VectorPOD< agx::Index > GroupsContainer
Definition: DirectSolverData.h:104
StabilityReport.h
agx::LogicalStructure
Definition: DirectSolverData.h:35
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxData::Array< agx::Index >
Solver.h
RigidBodyState.h
agx::DirectSolverData::m_nlSolveDataH5
INlSolveDataH5 * m_nlSolveDataH5
Definition: DirectSolverData.h:269
agx::INlSolveDataH5
Definition: NlSolveDataH5.h:26
agx::ref_ptr< ContactGroups >
agx::LogicalStructure::resize
void resize(size_t riSize, size_t ciSize, size_t dimSize)
Definition: DirectSolverData.h:42
agx::DirectSolverData::m_numBlockRows
UInt m_numBlockRows
Definition: DirectSolverData.h:261
agx::DirectSolverData::ContactGroups::ContactGroups
ContactGroups()
Definition: DirectSolverData.h:107
agx::LogicalStructure::newRow
void newRow(size_t dim)
Definition: DirectSolverData.h:53
agx::LinearProbingHashTable
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: LinearProbingHashTable.h:926
agx::DirectSolverData::ContactGroups
Class that handles the grouping.
Definition: DirectSolverData.h:101
agx::RealValarray
std::valarray< agx::Real > RealValarray
For this module, vectors are defined using valarray.
Definition: agx_valarray_types.h:27
agx::IndexSet
Definition: IndexSet.h:30
agx::LogicalStructure::riPtr
unsigned int * riPtr()
Definition: DirectSolverData.h:77
agx::DirectSolverData::m_logicalStructure
LogicalStructure m_logicalStructure
Definition: DirectSolverData.h:264
agx::LogicalStructure::operator==
bool operator==(const LogicalStructure &rhs) const
agx::DirectSolverData
Definition: DirectSolverData.h:92
agx::DirectSolverData::m_contactGroups
ContactGroupsRef m_contactGroups
Definition: DirectSolverData.h:265
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:119
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agx::Bool
bool Bool
Definition: Integer.h:40
agx::DirectSolverData::m_numSolves
UInt m_numSolves
Definition: DirectSolverData.h:266
agx::StabilityReport
Definition: StabilityReport.h:36
agx::DirectSolverData::m_numEquations
UInt m_numEquations
Definition: DirectSolverData.h:260
agx::DirectSolverData::m_numBlocks
UInt m_numBlocks
Definition: DirectSolverData.h:262
agx::DirectSolverData::m_stabilityReport
StabilityReportRef m_stabilityReport
Definition: DirectSolverData.h:267
agx::Physics::InteractionGroupPtr
Pointer to a entity instance of type Physics.InteractionGroup.
Definition: InteractionGroupEntity.h:163
agx::NlMixedCp::McpAlgorithm
Interface class for algorithm to solve general mixed complementarity problem.
Definition: MixedLCP.h:114
agx::LogicalStructure::LogicalStructure
LogicalStructure()
Definition: DirectSolverData.h:40
agx::DirectSolverData::ContactGroups::~ContactGroups
virtual ~ContactGroups()
Definition: DirectSolverData.h:117
agx_vector_types.h
agx::DirectSolverData::StrongInteractionTable
agx::HashTable< agx::UInt, agx::UIntVector > StrongInteractionTable
Definition: DirectSolverData.h:95
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agx::LogicalStructure::UIntContainer
std::valarray< unsigned int > UIntContainer
Definition: DirectSolverData.h:38
agx::SparseRangeReal
Essentially a sparse array of bounds.
Definition: SparseTypes.h:73
agx::LogicalStructure::dimPtr
unsigned int * dimPtr()
Definition: DirectSolverData.h:79