AGX Dynamics  2.37.3.2
NlmcpCallback.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 #pragma once
18 
19 #include <agx/Vector.h>
20 #include <agx/Vec3.h>
21 #include <agx/Range.h>
22 #include <agx/agx_valarray_types.h>
23 
24 namespace agx
25 {
26  class FrictionModel;
27  class INlSolveDataH5;
28  class SparseRangeReal;
29  class ConstraintImplementation;
30  class DirectSolverData;
31  class RigidBody;
32 
33  namespace Physics
34  {
35  class RigidBodyData;
36  class RigidBodyPtr;
37  }
38 
43  {
44  public:
45  struct Args
46  {
48  const agx::RealValarray& z,
49  const agx::SparseRangeReal& bounds,
50  const agx::Real* iterativeSolutionContacts,
51  const agx::Real* iterativeSolutionBinaryConstraints,
52  const agx::Real* iterativeSolutionManyBodyConstraints,
53  agx::INlSolveDataH5* solveDataH5 )
54  : q( q ),
55  z( z ),
56  bounds( bounds ),
57  iterativeSolutionContacts( iterativeSolutionContacts ),
58  iterativeSolutionBinaryConstraints( iterativeSolutionBinaryConstraints ),
59  iterativeSolutionManyBodyConstraints( iterativeSolutionManyBodyConstraints ),
60  solveDataH5( solveDataH5 )
61  {
62  }
63 
64  Args( const Args& ) = delete;
65  Args& operator = ( const Args& ) = delete;
66 
74  };
75 
76  public:
82  virtual agx::Bool initialize( const agx::NlmcpCallback::Args& args ) = 0;
83 
87  virtual agx::Real calculateResidual( const agx::NlmcpCallback::Args& args ) const = 0;
88 
92  virtual void update( const agx::NlmcpCallback::Args& args ) const = 0;
93 
97  virtual void postIterativeSolve( const agx::NlmcpCallback::Args& args ) const = 0;
98 
102  agx::UInt getDirectRow() const;
103 
109  void setDirectRow( agx::UInt directRow );
110 
114  agx::UInt getIterativeRow() const;
115 
121  void setIterativeRow( agx::UInt iterativeRow );
122 
126  agx::UInt getSparseBoundsIndex() const;
127 
133  void setSparseBoundsIndex( agx::UInt sparseBoundsIndex );
134 
138  agx::UInt getNumRows() const;
139 
145  void setNumRows( agx::UInt numRows );
146 
147  protected:
151  NlmcpCallback();
152 
156  virtual ~NlmcpCallback();
157 
158  private:
159  agx::UInt m_directRow;
160  agx::UInt m_iterativeRow;
161  agx::UInt m_sparseBoundsIndex;
162  agx::UInt m_numRows;
163  };
164 
166 
168  {
169  return m_directRow;
170  }
171 
173  {
174  return m_iterativeRow;
175  }
176 
178  {
179  return m_sparseBoundsIndex;
180  }
181 
183  {
184  return m_numRows;
185  }
186 
192  {
193  const Physics::RigidBodyData& rigidBody;
200  UInt32 getPermutedDirectStartRow( const RigidBody* rb ) const;
201 
206  UInt32 getPermutedDirectStartRow( const Physics::RigidBodyPtr& entity ) const;
207 
212  UInt32 getRigidBodyPermutedDirectStartRow( Index globalIndex ) const;
213 
220  UInt32 getNumRows( const RigidBody* rb ) const;
221 
228  UInt32 getNumRows( const Physics::RigidBodyPtr& entity ) const;
229 
236  UInt32 getRigidBodyNumRows( Index globalIndex ) const;
237 
239  NlmcpCallbackSolverData& operator = ( const NlmcpCallbackSolverData& ) = delete;
240  };
241 
247  {
248  public:
252  const agx::ConstraintImplementation* getContext() const;
253 
257  agx::UInt getContextDirectRow() const;
258 
262  agx::UInt getContextIterativeRow() const;
263 
264  protected:
266  virtual ~ConstraintNlmcpCallback();
267 
272  virtual void onSetContext( const NlmcpCallbackSolverData& solverData );
273 
274  private:
276  void setContext( const ConstraintImplementation* context,
277  UInt contextDirectRow,
278  UInt contextIterativeRow,
279  const NlmcpCallbackSolverData& solverData );
280 
281  private:
282  const ConstraintImplementation* m_context;
283  agx::UInt m_contextDirectRow;
284  agx::UInt m_contextIterativeRow;
285  };
286 
288 } // namespace agx
const agx::Real * iterativeSolutionManyBodyConstraints
Definition: NlmcpCallback.h:72
agx::UInt getNumRows() const
agx::UInt getSparseBoundsIndex() const
bool Bool
Definition: Integer.h:48
const Physics::RigidBodyData & rigidBody
Global rigid body data.
agx::RealValarray & q
Definition: NlmcpCallback.h:67
#define AGXPHYSICS_EXPORT
agx::UInt getDirectRow() const
#define AGX_FORCE_INLINE
Definition: Object.h:59
Base class providing referencing counted objects.
Definition: Referenced.h:119
Interface class for solver callbacks.
Definition: NlmcpCallback.h:42
Essentially a sparse array of bounds.
Definition: SparseTypes.h:73
Pointer to a entity instance of type Physics.RigidBody.
Constraint solver callback interface with context and start rows for context.
uint32_t UInt
Definition: Integer.h:34
agx::UInt getIterativeRow() const
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.
UInt32 Index
Definition: Integer.h:52
const DirectSolverData & directSolverData
Direct solver data the ConstraintNlmcpCallback constraint is part of.
const agx::Real * iterativeSolutionContacts
Definition: NlmcpCallback.h:70
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agx::INlSolveDataH5 * solveDataH5
Definition: NlmcpCallback.h:73
Args(agx::RealValarray &q, const agx::RealValarray &z, const agx::SparseRangeReal &bounds, const agx::Real *iterativeSolutionContacts, const agx::Real *iterativeSolutionBinaryConstraints, const agx::Real *iterativeSolutionManyBodyConstraints, agx::INlSolveDataH5 *solveDataH5)
Definition: NlmcpCallback.h:47
Data from the solver the ConstraintNlmcpCallback is part of.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
const agx::Real * iterativeSolutionBinaryConstraints
Definition: NlmcpCallback.h:71
const agx::RealValarray & z
Definition: NlmcpCallback.h:68
double Real
Definition: Real.h:42
const agx::SparseRangeReal & bounds
Definition: NlmcpCallback.h:69
uint32_t UInt32
Definition: Integer.h:40