AGX Dynamics  2.38.0.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 RealValarray& z,
49  const SparseRangeReal& bounds,
50  const Real* iterativeSolutionContacts,
51  const Real* iterativeSolutionBinaryConstraints,
52  const Real* iterativeSolutionManyBodyConstraints,
53  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 
68  const RealValarray& z;
74  };
75 
76  public:
82  virtual Bool initialize( const NlmcpCallback::Args& args ) = 0;
83 
87  virtual Real calculateResidual( const NlmcpCallback::Args& args ) const = 0;
88 
92  virtual void update( const NlmcpCallback::Args& args ) const = 0;
93 
97  virtual void postIterativeSolve( const NlmcpCallback::Args& args ) const = 0;
98 
102  UInt getDirectRow() const;
103 
109  void setDirectRow( UInt directRow );
110 
114  UInt getIterativeRow() const;
115 
121  void setIterativeRow( UInt iterativeRow );
122 
126  UInt getSparseBoundsIndex() const;
127 
133  void setSparseBoundsIndex( UInt sparseBoundsIndex );
134 
138  UInt getNumRows() const;
139 
145  void setNumRows( UInt numRows );
146 
147  protected:
151  NlmcpCallback();
152 
156  virtual ~NlmcpCallback();
157 
158  private:
159  UInt m_directRow;
160  UInt m_iterativeRow;
161  UInt m_sparseBoundsIndex;
162  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 ConstraintImplementation* getContext() const;
253 
257  UInt getContextDirectRow() const;
258 
262  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  UInt m_contextDirectRow;
284  UInt m_contextIterativeRow;
285  };
286 
288 } // namespace agx
agx::UInt
uint64_t UInt
Definition: Integer.h:27
agx::Real
double Real
Definition: Real.h:42
Vector.h
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:51
agx::NlmcpCallback::Args::iterativeSolutionManyBodyConstraints
const Real * iterativeSolutionManyBodyConstraints
Definition: NlmcpCallback.h:72
agx::NlmcpCallback::Args::iterativeSolutionContacts
const Real * iterativeSolutionContacts
Definition: NlmcpCallback.h:70
agx::ConstraintImplementation
Definition: ConstraintImplementation.h:100
agx_valarray_types.h
agx::Physics::RigidBodyPtr
Pointer to a entity instance of type Physics.RigidBody.
Definition: RigidBodyEntity.h:371
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agx::NlmcpCallback::Args::z
const RealValarray & z
Definition: NlmcpCallback.h:68
agx::INlSolveDataH5
Definition: NlSolveDataH5.h:26
Vec3.h
agx::ref_ptr
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agx::NlmcpCallback::getSparseBoundsIndex
UInt getSparseBoundsIndex() const
Definition: NlmcpCallback.h:177
agx::NlmcpCallbackSolverData::rigidBody
const Physics::RigidBodyData & rigidBody
Global rigid body data.
Definition: NlmcpCallback.h:193
agx::ConstraintNlmcpCallback
Constraint solver callback interface with context and start rows for context.
Definition: NlmcpCallback.h:246
agx::NlmcpCallback::getDirectRow
UInt getDirectRow() const
Definition: NlmcpCallback.h:167
agx::Index
UInt32 Index
Definition: Integer.h:44
Range.h
agx::RealValarray
std::valarray< agx::Real > RealValarray
For this module, vectors are defined using valarray.
Definition: agx_valarray_types.h:27
agx::DirectSolverData
Definition: DirectSolverData.h:92
agx::NlmcpCallback::Args::bounds
const SparseRangeReal & bounds
Definition: NlmcpCallback.h:69
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:119
agx::NlmcpCallback::Args::iterativeSolutionBinaryConstraints
const Real * iterativeSolutionBinaryConstraints
Definition: NlmcpCallback.h:71
agx::Bool
bool Bool
Definition: Integer.h:40
agx::NlmcpCallback::Args
Definition: NlmcpCallback.h:45
agx::NlmcpCallback::getNumRows
UInt getNumRows() const
Definition: NlmcpCallback.h:182
agx::NlmcpCallbackSolverData
Data from the solver the ConstraintNlmcpCallback is part of.
Definition: NlmcpCallback.h:191
agx::NlmcpCallbackSolverData::directSolverData
const DirectSolverData & directSolverData
Direct solver data the ConstraintNlmcpCallback constraint is part of.
Definition: NlmcpCallback.h:194
agx::NlmcpCallback::Args::q
RealValarray & q
Definition: NlmcpCallback.h:67
agx::NlmcpCallback::Args::Args
Args(RealValarray &q, const RealValarray &z, const SparseRangeReal &bounds, const Real *iterativeSolutionContacts, const Real *iterativeSolutionBinaryConstraints, const Real *iterativeSolutionManyBodyConstraints, INlSolveDataH5 *solveDataH5)
Definition: NlmcpCallback.h:47
agx::UInt32
uint32_t UInt32
Definition: Integer.h:32
agx::NlmcpCallback::Args::solveDataH5
INlSolveDataH5 * solveDataH5
Definition: NlmcpCallback.h:73
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agx::SparseRangeReal
Essentially a sparse array of bounds.
Definition: SparseTypes.h:73
agx::NlmcpCallback
Interface class for solver callbacks.
Definition: NlmcpCallback.h:42
agx::NlmcpCallback::getIterativeRow
UInt getIterativeRow() const
Definition: NlmcpCallback.h:172