AGXDynamics  2.35.0.3
NlmcpCallback.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 #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
agx::NlmcpCallback::Args::iterativeSolutionManyBodyConstraints
const agx::Real * iterativeSolutionManyBodyConstraints
Definition: NlmcpCallback.h:72
agx::Real
double Real
Definition: Real.h:42
Vector.h
agx::NlmcpCallback::Args::q
agx::RealValarray & q
Definition: NlmcpCallback.h:67
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
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::getSparseBoundsIndex
agx::UInt getSparseBoundsIndex() const
Definition: NlmcpCallback.h:177
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::Args::iterativeSolutionContacts
const agx::Real * iterativeSolutionContacts
Definition: NlmcpCallback.h:70
agx::NlmcpCallback::getDirectRow
agx::UInt getDirectRow() const
Definition: NlmcpCallback.h:167
agx::NlmcpCallbackSolverData::rigidBody
const Physics::RigidBodyData & rigidBody
Global rigid body data.
Definition: NlmcpCallback.h:193
agx::NlmcpCallback::getNumRows
agx::UInt getNumRows() const
Definition: NlmcpCallback.h:182
agx::ConstraintNlmcpCallback
Constraint solver callback interface with context and start rows for context.
Definition: NlmcpCallback.h:246
agx::Index
UInt32 Index
Definition: Integer.h:52
Range.h
agx::RealValarray
std::valarray< agx::Real > RealValarray
For this module, vectors are defined using valarray.
Definition: agx_valarray_types.h:27
agx::NlmcpCallback::Args::solveDataH5
agx::INlSolveDataH5 * solveDataH5
Definition: NlmcpCallback.h:73
agx::DirectSolverData
Definition: DirectSolverData.h:92
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
agx::UInt
uint32_t UInt
Definition: Integer.h:34
agx::Bool
bool Bool
Definition: Integer.h:48
agx::NlmcpCallback::Args
Definition: NlmcpCallback.h:45
agx::NlmcpCallback::Args::bounds
const agx::SparseRangeReal & bounds
Definition: NlmcpCallback.h:69
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::getIterativeRow
agx::UInt getIterativeRow() const
Definition: NlmcpCallback.h:172
agx::NlmcpCallback::Args::Args
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
agx::NlmcpCallback::Args::iterativeSolutionBinaryConstraints
const agx::Real * iterativeSolutionBinaryConstraints
Definition: NlmcpCallback.h:71
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agx::NlmcpCallback::Args::z
const agx::RealValarray & z
Definition: NlmcpCallback.h:68
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