AGX Dynamics  2.35.0.1
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:
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;
201 
207 
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:
253 
258 
263 
264  protected:
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
#define AGXPHYSICS_EXPORT
Constraint solver callback interface with context and start rows for context.
const agx::ConstraintImplementation * getContext() const
virtual void onSetContext(const NlmcpCallbackSolverData &solverData)
Called when context constraint has been set and all data is valid.
agx::UInt getContextIterativeRow() const
agx::UInt getContextDirectRow() const
Interface class for solver callbacks.
Definition: NlmcpCallback.h:43
agx::UInt getIterativeRow() const
agx::UInt getDirectRow() const
virtual void update(const agx::NlmcpCallback::Args &args) const =0
Update call when bounds and/or q may be updated given the current solution z.
virtual agx::Real calculateResidual(const agx::NlmcpCallback::Args &args) const =0
Calculate residual given current solution.
agx::UInt getNumRows() const
virtual ~NlmcpCallback()
Protected destructor, reference counted object.
NlmcpCallback()
Default constructor.
void setSparseBoundsIndex(agx::UInt sparseBoundsIndex)
virtual void postIterativeSolve(const agx::NlmcpCallback::Args &args) const =0
Before direct solve, after iterative solve.
agx::UInt getSparseBoundsIndex() const
virtual agx::Bool initialize(const agx::NlmcpCallback::Args &args)=0
This method is a test for the non-linear solver if this callback is active for non-linear solve.
void setDirectRow(agx::UInt directRow)
void setIterativeRow(agx::UInt iterativeRow)
void setNumRows(agx::UInt numRows)
Pointer to a entity instance of type Physics.RigidBody.
Base class providing referencing counted objects.
Definition: Referenced.h:114
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
Essentially a sparse array of bounds.
Definition: SparseTypes.h:74
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:40
bool Bool
Definition: Integer.h:48
uint32_t UInt
Definition: Integer.h:34
double Real
Definition: Real.h:42
std::valarray< agx::Real > RealValarray
For this module, vectors are defined using valarray.
UInt32 Index
Definition: Integer.h:52
Data from the solver the ConstraintNlmcpCallback is part of.
UInt32 getRigidBodyNumRows(Index globalIndex) const
Finds number of rows the given rigid body index has allocated in the solver.
UInt32 getPermutedDirectStartRow(const RigidBody *rb) const
const Physics::RigidBodyData & rigidBody
Global rigid body data.
UInt32 getNumRows(const RigidBody *rb) const
Finds number of rows the given rigid body has allocated in the solver.
NlmcpCallbackSolverData(const NlmcpCallbackSolverData &)=delete
UInt32 getPermutedDirectStartRow(const Physics::RigidBodyPtr &entity) const
UInt32 getNumRows(const Physics::RigidBodyPtr &entity) const
Finds number of rows the given rigid body entity has allocated in the solver.
const DirectSolverData & directSolverData
Direct solver data the ConstraintNlmcpCallback constraint is part of.
UInt32 getRigidBodyPermutedDirectStartRow(Index globalIndex) const
const agx::Real * iterativeSolutionContacts
Definition: NlmcpCallback.h:70
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::INlSolveDataH5 * solveDataH5
Definition: NlmcpCallback.h:73
const agx::Real * iterativeSolutionBinaryConstraints
Definition: NlmcpCallback.h:71
const agx::Real * iterativeSolutionManyBodyConstraints
Definition: NlmcpCallback.h:72
const agx::RealValarray & z
Definition: NlmcpCallback.h:68
const agx::SparseRangeReal & bounds
Definition: NlmcpCallback.h:69
Args(const Args &)=delete
agx::RealValarray & q
Definition: NlmcpCallback.h:67