AGX Dynamics  2.35.0.1
DirectSolverData.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_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 
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:
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 
154 
161  agx::Physics::StrongInteractionData& strongInteractions,
162  const agxData::IndexArray& globalToLocalIndexArray );
163 
169 
174  const agx::SparseMatrix& getMatrix() const;
175 
180 
185  const agx::RealValarray& getSigns() const;
186 
192 
199 
204  const agx::RealValarray& getQ() const;
205 
211 
216 
221 
226 
231 
236 
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
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXPHYSICS_EXPORT
Class that handles the grouping.
agx::VectorPOD< agx::Index > GroupsContainer
const GroupsContainer & getBuffer(Buffers buffer) const
bool initialize(Physics::SolveIslandPtr &island)
agx::RealValarray & getSolution()
agx::LogicalStructure & getLogicalStructure()
StrongInteractionTable m_strongInteractionTable
DirectSolverData * clone()
Clones solver data.
const agx::RealValarray & getQ() const
const agx::DirectSolverData::StrongInteractionTable & getStrongInteractionTable() const
agx::HashTable< agx::UInt, agx::UIntVector > StrongInteractionTable
const agx::SparseMatrix & getMatrix() const
agx::SparseMatrix & getMatrix()
void setContactGroups(agx::DirectSolverData::ContactGroups *contactGroups)
Assign new contact groups object.
void buildStrongInteractionTable(agx::Physics::InteractionGroupPtr islandGroup, agx::Physics::StrongInteractionData &strongInteractions, const agxData::IndexArray &globalToLocalIndexArray)
Builds table that maps a rigid body to the other bodies it interacts with.
const agx::RealValarray & getSigns() const
const agx::NlMixedCp::McpAlgorithm * getAlgorithm() const
agx::SparseRangeReal & getSparseBounds()
void initialize()
Initialize for a new solve.
LogicalStructure m_logicalStructure
void commitVelocities(const agxData::IndexArray &indices, agxData::Array< agx::Vec3 > &linearVelocities, agxData::Array< agx::Vec3 > &angularVelocities, const agxData::Array< agx::RigidBodyState > &states) const
Copy solution to velocity buffers.
virtual ~DirectSolverData()
DirectSolverData(agx::UInt numEquations, agx::UInt numBlockRows, agx::UInt numBlocks, agx::Solver::NlMcpConfig nlMcpConfig, agx::Bool gatherStatistics, INlSolveDataH5 *nlSolveDataH5)
Construct given total number of equations in the direct system, number of block rows and the total nu...
const agx::RealValarray & solve()
Solve the current configuration of the matrix, right hand side and bounds.
agx::DirectSolverData::ContactGroups * getContactGroups() const
const agx::RealValarray & getSolution() const
const agx::LogicalStructure & getLogicalStructure() const
agx::IndexSet & getIndexSet()
agx::ref_ptr< ContactGroups > ContactGroupsRef
agx::StabilityReport * getStabilityReport() const
INlSolveDataH5 * m_nlSolveDataH5
agx::UInt getNumBlockRows() const
StabilityReportRef m_stabilityReport
ContactGroupsRef m_contactGroups
const agx::SparseRangeReal & getSparseBounds() const
agx::RealValarray & getSigns()
agx::RealValarray & getQ()
Inheritance with partial specialization due to bug with ref_ptr containers.
std::valarray< unsigned int > UIntContainer
bool operator==(const LogicalStructure &rhs) const
unsigned int * dimPtr()
void insertBlock(size_t colIndex)
unsigned int * ciPtr()
void newRow(size_t dim)
unsigned int * riPtr()
void resize(size_t riSize, size_t ciSize, size_t dimSize)
Interface class for algorithm to solve general mixed complementarity problem.
Definition: MixedLCP.h:115
Pointer to a entity instance of type Physics.InteractionGroup.
Pointer to a entity instance of type Physics.SolveIsland.
Base class providing referencing counted objects.
Definition: Referenced.h:114
agx::SparseMatrix holds a matrix representation which contains the data.
Definition: SparseMatrix.h:86
Essentially a sparse array of bounds.
Definition: SparseTypes.h:74
#define agxAssert(expr)
Definition: debug.h:143
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool Bool
Definition: Integer.h:48
uint32_t UInt
Definition: Integer.h:34
std::valarray< agx::Real > RealValarray
For this module, vectors are defined using valarray.