AGXDynamics  2.31.1.0
ConstraintImplementation.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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_CONSTRAINT_IMPLEMENTATION_H
18 #define AGX_CONSTRAINT_IMPLEMENTATION_H
19 
20 #include <agxSDK/SimulationProxy.h>
21 
22 #include <agx/FrictionModel.h>
23 #include <agx/RigidBody.h>
24 #include <agx/SVec.h>
25 #include <agxStream/Serializable.h>
26 #include <agx/agx_hash_types.h>
27 #include <agx/Constraint.h>
28 #include <agx/Jacobian.h>
31 #include <agx/BitState.h>
32 #include <agx/agx_valarray_types.h>
33 
34 #ifdef _MSC_VER
35 # pragma warning(push)
36 # pragma warning( disable : 4251 ) // class X needs to have dll-interface to be used by clients of class Y
37 #endif
38 
39 #define DEFAULT_COMPLIANCE 1.0E-8
40 
41 #define CONSTRAINT_SUCCESS( success ) \
42  if ( !(success) ) { \
43  LOGGER_WARNING() << "Unable to create constraint. Constraint cleared." << std::endl << LOGGER_END(); \
44  m_bodies.clear(); \
45  m_localState.remove( VALID ); \
46  return; \
47  }
48 
49 #define CONSTRAINT_SUCCESS_RETURN_BOOL( success ) \
50  if ( !(success) ) { \
51  LOGGER_WARNING() << "Unable to create constraint. Constraint cleared." << std::endl << LOGGER_END(); \
52  m_bodies.clear(); \
53  m_localState.remove( VALID ); \
54  return false; \
55  }
56 
57 namespace agx
58 {
59  // Forward declaration
60  class ElementaryConstraint;
61  class Constraint;
62  class RegularizationParameters;
63  class SparseRangeReal;
65 
67  typedef std::pair< Real, Real > RealPair;
68 
70  {
71  public:
72  typedef UInt16 BlockType;
74  : m_numBlocks( 0 ), m_numRows( 0 ), m_numDynBlocks( 0 ) {}
75 
76  AGX_FORCE_INLINE void setNumBlocks( BlockType numBlocks ) { m_numBlocks = numBlocks; }
77  AGX_FORCE_INLINE void setNumRows( BlockType numRows ) { m_numRows = numRows; }
78 
79  AGX_FORCE_INLINE BlockType getNumBlocks() const { return m_numBlocks; }
80  AGX_FORCE_INLINE BlockType getNumRows() const { return m_numRows; }
81 
82  AGX_FORCE_INLINE BlockType& blocks() { return m_numBlocks; }
83  AGX_FORCE_INLINE BlockType& rows() { return m_numRows; }
84  AGX_FORCE_INLINE BlockType blocks() const { return m_numBlocks; }
85  AGX_FORCE_INLINE BlockType rows() const { return m_numRows; }
86 
87  AGX_FORCE_INLINE BlockType& dynBlocks() { return m_numDynBlocks; }
88  AGX_FORCE_INLINE BlockType dynBlocks() const { return m_numDynBlocks; }
89  AGX_FORCE_INLINE BlockType kinBlocks() const { return (BlockType)(m_numBlocks - m_numDynBlocks); }
90 
91  AGX_FORCE_INLINE void reset() { m_numBlocks = m_numRows = m_numDynBlocks = 0; }
92 
93  private:
94  BlockType m_numBlocks;
95  BlockType m_numRows;
96  BlockType m_numDynBlocks;
97  };
98 
100  {
101  public:
102  enum Tags
103  {
104  NONE = 0,
105  MANY_BODY = (1<<0),
106  DEFAULT_BINARY_TAG = NONE,
107  DEFAULT_MANY_BODY_TAG = MANY_BODY
108  };
109 
114  {
115  public:
120  {
121  public:
122  BodiesInfo();
123 
127  agx::UInt& numDynamicBodies();
128 
132  agx::UInt numDynamicBodies() const;
133 
137  agx::UInt& numNonStaticBodies();
138 
142  agx::UInt numNonStaticBodies() const;
143 
144  private:
145  agx::UInt m_numDynamicBodies;
146  agx::UInt m_numNonStaticBodies;
147  };
148 
149  public:
154 
159  void reset( agx::UInt numBodies );
160 
165  agx::Bool increment( agx::RigidBody* rb );
166 
171  agx::Bool finalize( agx::Bool valid );
172 
176  const BodiesInfo& getOriginalInfo() const;
177 
181  const BodiesInfo& getSolverInfo() const;
182 
186  const agx::Int32Vector& getPermutation() const;
187 
191  agx::Int32Vector& getPermutation();
192 
196  const agx::Int32Vector& getBodyIndices() const;
197 
201  agx::Int32Vector& getBodyIndices();
202 
206  const agx::ConstraintRigidBodyContainer& getSolverBodies() const;
207 
215  agx::UInt getNumRecurrentMergedBodies() const;
216 
217  private:
218  BodiesInfo m_originalInfo;
219  BodiesInfo m_solverInfo;
220  ConstraintRigidBodyContainer m_bodies;
221  Int32Vector m_permutation;
222  Int32Vector m_bodyIndices;
223  UInt m_numRecurrentMergedBodies;
224  };
225 
230  #if !defined(SWIGPYTHON)
232  {
233  public:
238  BodyView( const ConstrainedBodiesState::BodiesInfo& info, const ConstraintRigidBodyContainer& bodies );
239 
243  BodyView( const BodyView& other );
244 
248  agx::UInt getNumDynamicBodies() const;
249 
253  agx::UInt getNumNonStaticBodies() const;
254 
258  agx::UInt getNumBodies() const;
259 
263  agx::RigidBody* getBodyAt( agx::UInt i );
264 
268  const agx::RigidBody* getBodyAt( agx::UInt i ) const;
269 
273  const ConstraintRigidBodyContainer& getBodies() const;
274 
278  BodyView& operator = ( const BodyView& ) = delete;
279 
280  private:
282  const ConstraintRigidBodyContainer& m_bodies;
283  };
284 
286  {
287  public:
293 
297  SolverBodyView( const SolverBodyView& other );
298 
302  const ConstrainedBodiesState& getState() const;
303 
307  ConstrainedBodiesState& getState();
308 
312  agx::RigidBody* getPermutedBodyAt( agx::UInt i );
313 
317  const agx::RigidBody* getPermutedBodyAt( agx::UInt i ) const;
318 
319  private:
323  inline SolverBodyView& operator = ( const SolverBodyView& ) { agxAbort(); return *this; }
324 
325  private:
326  ConstrainedBodiesState& m_state;
327  };
328  #endif
329 
330  public:
336 
340  virtual ~ConstraintImplementation();
341 
345  #if !defined(SWIGPYTHON)
346  BodyView getUserView() const;
347 
351  SolverBodyView getSolverView() const;
352  #endif
353 
354  // ****************************************************************************
355  // Callbacks from solvers *****************************************************
356  // ****************************************************************************
357 
365  virtual bool updateValid();
366 
373  virtual void prepare();
374 
381  virtual size_t updateJacobian( agx::Jacobian6DOFElement* jacobians );
382 
389  virtual int getViolation( agx::Real* g, int row );
390 
396  agx::Real calculateViolationVectorAverageSize();
397 
403  virtual void getEpsilon( agx::Real* epsilon, agx::Real h );
404 
408  virtual void getParameters( agx::Real* violation,
409  agx::Real* epsilon,
410  agx::Real* damping,
411  bool* holonomic,
412  agx::Real* velocity,
413  agx::RangeReal* bounds,
414  int8_t* indexSetState,
415  agx::Real h,
416  agx::Real minPerturbation = agx::Real( 1E-10 ) );
417 
425  virtual int getConstraintVelocity( agx::Real* v, int row );
426 
434  virtual void getBounds( agx::RangeReal* bounds, agx::Real dt ) const;
435 
444  virtual void updateComplianceMatrix( LSquareComplianceMatrix matrix ) const;
445 
449  void onDirectComplianceMatrix( Real* data, unsigned int ld ) const;
450 
457  virtual void postSolveCallback( const agx::Jacobian6DOFElement* jacobians, const agx::Real* solution, agx::Real dt );
458 
463  void postSolveIndexSetCallback( const int8_t* state );
464 
471  virtual void preSystemCallback( DynamicsSystem* system );
472 
478  virtual void postSystemCallback( DynamicsSystem* system );
479 
485  void sort();
486 
490  void reset();
491 
495  virtual void addNlCallbacks( agx::SparseRangeReal& sparseRangeReal ) const;
496 
497  // ****************************************************************************
498 
499  // ****************************************************************************
500  // Methods used by the solvers ************************************************
501  // ****************************************************************************
502 
506  AGX_FORCE_INLINE agx::UInt getJacobianRowUsage() const { return m_numRows; }
507 
511  AGX_FORCE_INLINE const BlockStructure& getBlockStructure() const { return m_blockStructure; }
512 
517  AGX_FORCE_INLINE void setBlockRowIndex( agx::UInt blockRowIndex ) { m_blockRowIndex = blockRowIndex; }
518 
522  AGX_FORCE_INLINE agx::UInt getBlockRowIndex() const { return m_blockRowIndex; }
523 
528  AGX_FORCE_INLINE bool getSolveIterative() const { return m_solveType == Constraint::ITERATIVE; }
529 
533  AGX_FORCE_INLINE bool getSolveBoth() const { return m_solveType == Constraint::DIRECT_AND_ITERATIVE; }
534 
539 
543  AGX_FORCE_INLINE Constraint::SolveType getSolveType() const { return m_solveType; }
544 
548  AGX_FORCE_INLINE bool isImpacting() const { return m_localState.Is( IMPACTING ); }
549 
554  AGX_FORCE_INLINE void incrementConstraintCount( RigidBody* rb ) const { agxAssert( rb ); if (rb) rb->incrementNumConstraints(); }
555 
559  AGX_FORCE_INLINE int getTag() const { return m_tag; }
560 
561 #ifndef SWIG
562  void* customData;
563 #endif
564 
565  // ****************************************************************************
566 
567  // ****************************************************************************
568  // Callbacks from the simulation during add and remove of this constraint *****
569  // ****************************************************************************
570 
574  virtual void addNotification() {}
575 
579  virtual void removeNotification() {}
580 
581  // ****************************************************************************
582 
583  // ****************************************************************************
584  // Methods used by non-implementation constraints but not the 'end user' ******
585  // ****************************************************************************
586 
592 
598 
603  AGX_FORCE_INLINE const ConstraintImplPtrVector& getSubConstraints() const { return m_subConstraints; }
604 
605  // ****************************************************************************
606  // Methods used by 'the user' *************************************************
607  // ****************************************************************************
608 
616  virtual bool rebind() { return false; }
617 
622  virtual AGX_FORCE_INLINE bool getEnable() const { return m_enable; }
623 
628  virtual void setEnable(bool enable);
629 
633  AGX_FORCE_INLINE bool getActive() const { return m_enable && m_localState.Is( VALID ); }
634 
638  AGX_FORCE_INLINE bool isValid() const { return m_localState.Is( VALID ); }
639 
640  // ****************************************************************************
641 
642  // ****************************************************************************
643  // Methods for user API, these should not be used internally ******************
644  // ****************************************************************************
645 
652  virtual void setEnableComputeForces( agx::Bool enable );
653 
657  virtual agx::Bool getEnableComputeForces() const;
658 
678  virtual agx::Bool getLastForce( agx::UInt bodyIndex, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const;
679 
698  virtual agx::Bool getLastForce( const agx::RigidBody* rb, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const;
699 
718  virtual agx::Bool getLastLocalForce( agx::UInt bodyIndex, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const;
719 
737  virtual agx::Bool getLastLocalForce( const agx::RigidBody* rb, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const;
738 
745  void setEnableLinearization(bool enable);
746 
750  bool getEnableLinearization() const;
751 
755  virtual agx::Attachment* userAPIgetAttachment( const agx::RigidBody* /*rb*/ ) const { return nullptr; }
756 
760  virtual agx::Attachment* userAPIgetAttachment( agx::UInt /*index*/ ) const { return nullptr; }
761 
765  virtual agx::AttachmentPair* getAttachmentPair() const { return nullptr; }
766 
773  virtual bool addElementaryConstraint( const agx::String& name, agx::ElementaryConstraint* elementaryConstraint );
774 
781  virtual bool addSecondaryConstraint( const agx::String& name, agx::ElementaryConstraint* secondaryConstraint );
782 
788  virtual bool removeElementaryConstraint( agx::ElementaryConstraint* elementaryConstraint );
789 
795  virtual bool removeSecondaryConstraint( agx::ElementaryConstraint* secondaryConstraint );
796 
802  virtual bool removeElementaryConstraint( const agx::String& name );
803 
809  virtual bool removeSecondaryConstraint( const agx::String& name );
810 
815  virtual agx::ElementaryConstraint* getElementaryConstraint( const agx::UInt index ) const;
816 
821  virtual agx::ElementaryConstraint* getElementaryConstraint( const agx::String& name ) const;
822 
827  virtual agx::ElementaryConstraint* getSecondaryConstraint( const agx::UInt index ) const;
828 
833  virtual agx::ElementaryConstraint* getSecondaryConstraint( const agx::String& name ) const;
834 
838  template< typename T >
839  T* findSecondaryConstraintGivenType( const agx::UInt count = 0 ) const;
840 
844  agx::Motor1D* getMotor1D( agx::UInt number = 0 ) const;
845 
849  agx::Lock1D* getLock1D( agx::UInt number = 0 ) const;
850 
854  agx::Range1D* getRange1D( agx::UInt number = 0 ) const;
855 
859  agx::FrictionController* getFrictionController( agx::UInt number = 0 ) const;
860 
865  virtual agx::Real getAngle( agx::UInt /*dof*/ = 0 ) const { return 0; }
866 
872  virtual agx::Real getCurrentSpeed( agx::UInt /*dof*/ = 0 ) const { return 0; }
873 
880  agx::RegularizationParameters* userAPIgetRegularizationParameters( agx::UInt i );
881  const agx::RegularizationParameters* userAPIgetRegularizationParameters( agx::UInt i ) const;
882 
886  agx::Real userAPIgetCompliance( agx::UInt dof ) const;
887 
893  void userAPIsetCompliance( agx::Real compliance, int dof );
894 
898  agx::Real userAPIgetDamping( agx::UInt dof ) const;
899 
905  void userAPIsetDamping( agx::Real damping, int dof );
906 
913  void userAPIsetForceRange( agx::RangeReal forceRange, agx::Int dof );
914 
921  agx::RangeReal userAPIgetForceRange( agx::UInt dof ) const;
922 
930  agx::Real userAPIgetCurrentForce( agx::UInt dof ) const;
931 
938  agx::UInt calculateNumActiveRows() const;
939 
940 
941  // **************************************************************************
942 
944 
945 
950  agx::RealValarray getCompliance() const;
951 
955  agx::Referenced* getInternalData() const;
956 
960  void setInternalData( agx::Referenced* data );
961 
965  AGX_FORCE_INLINE agxSDK::SimulationProxy* getSimulationProxy() { return m_simulationProxy; }
966  AGX_FORCE_INLINE const agxSDK::SimulationProxy* getSimulationProxy() const { return m_simulationProxy; }
967 
968  agx::Physics::ConstraintForcesPtr getForceData();
969  void setForceData(agx::Physics::ConstraintForcesPtr forceData);
970 
971  virtual void storeLightData( agxStream::StorageStream& ) const {}
972  virtual void restoreLightData( agxStream::StorageStream& ) {}
973 
975 
976  protected:
977  enum State : Int32
978  {
979  VALID = 1 << 0, // Replaces m_valid.
980  IMPACTING = 1 << 1, // Replaces m_impactState.
981  SUPPORTS_COMPLIANCE_MATRIX = 1 << 2 // Set if this constraint supports write access to the compliance matrix
982  // allocated in the system matrix.
983  };
984 
985  using LocalState = agx::BitState<State, Int32>;
986 
987  protected:
988  friend class Constraint;
993  void setSimulation( agxSDK::Simulation* simulation );
994 
1001  void setSupportsComplianceMatrix( Bool supportsComplianceMatrix );
1002 
1003  protected:
1007  ConstraintRigidBodyContainer m_bodies;
1013  int m_tag;
1015  private:
1016  agxSDK::SimulationProxyRef m_simulationProxy;
1017  Physics::ConstraintForcesPtr m_forceData;
1018  ref_ptr<Referenced> m_internalData;
1019 
1020  protected:
1022  bool m_enable;
1025  };
1026 
1028  {
1029  public:
1032 
1040  virtual bool updateValid() override;
1041 
1048  virtual void prepare() override;
1049 
1053  virtual void addNlCallbacks( agx::SparseRangeReal& sparseRangeReal ) const override;
1054 
1060  virtual size_t updateJacobian( agx::Jacobian6DOFElement* jacobians ) override;
1061 
1068  virtual void postSolveCallback( const agx::Jacobian6DOFElement* jacobians, const agx::Real* solution, agx::Real dt ) override;
1069 
1077  virtual bool rebind() override;
1078 
1083  virtual void computeForces( const agx::Jacobian6DOFElement* jacobians );
1084 
1095  virtual agx::Bool computeForces( const agx::Jacobian6DOFElement* jacobians, agx::Vec3Vector& result ) const;
1096 
1103  virtual void setEnableComputeForces( agx::Bool enable ) override;
1104 
1108  virtual agx::Bool getEnableComputeForces() const override;
1109 
1129  virtual agx::Bool getLastForce( agx::UInt bodyIndex, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const override;
1130 
1149  virtual agx::Bool getLastForce( const RigidBody* rb, Vec3& retForce, Vec3& retTorque, agx::Bool giveForceAtCm = false ) const override;
1150 
1169  virtual agx::Bool getLastLocalForce( agx::UInt bodyIndex, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const override;
1170 
1188  virtual agx::Bool getLastLocalForce( const agx::RigidBody* rb, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const override;
1189 
1190  // **************************************************************************
1191  // Internal utility methods for one or two body constraints *****************
1192  // **************************************************************************
1193 
1195 
1196  bool construct( RigidBody* rb1, Frame* rb1AttachmentFrame, RigidBody* rb2, Frame* rb2AttachmentFrame, CreateElementaryConstraintsFunction = nullptr );
1197  bool setupOneOrTwoBodySystem( RigidBodyAttachment* a1, RigidBodyAttachment* a2 );
1198  bool validateRigidBodiesAndAttachments( RigidBody* rb1, Frame* rb1AttachmentFrame, RigidBody* rb2, Frame* rb2AttachmentFrame );
1199 
1203  virtual agx::Attachment* userAPIgetAttachment( const agx::RigidBody* rb ) const override;
1204 
1208  virtual agx::Attachment* userAPIgetAttachment( agx::UInt index ) const override;
1209 
1213  virtual agx::AttachmentPair* getAttachmentPair() const override;
1214 
1219  virtual agx::Real getAngle( agx::UInt dof = 0 ) const override;
1220 
1224  bool bodiesValid() const;
1225 
1229  template< typename T >
1230  T* getAttachment( agx::UInt index );
1231 
1235  template< typename T >
1236  const T* getAttachment( agx::UInt index ) const;
1237 
1239 
1240  virtual void restore( agxStream::InputArchive& in ) override;
1241  virtual void store( agxStream::OutputArchive& out ) const override;
1242 
1243  virtual void storeLightData( agxStream::StorageStream& str ) const override;
1244  virtual void restoreLightData( agxStream::StorageStream& str ) override;
1245 
1246  protected:
1249  };
1250 
1252  {
1253  return m_numDynamicBodies;
1254  }
1255 
1257  {
1258  return m_numDynamicBodies;
1259  }
1260 
1262  {
1263  return m_numNonStaticBodies;
1264  }
1265 
1267  {
1268  return m_numNonStaticBodies;
1269  }
1270 
1272  {
1273  return m_originalInfo;
1274  }
1275 
1277  {
1278  return m_solverInfo;
1279  }
1280 
1282  {
1283  return m_permutation;
1284  }
1285 
1287  {
1288  return m_permutation;
1289  }
1290 
1292  {
1293  return m_bodyIndices;
1294  }
1295 
1297  {
1298  return m_bodyIndices;
1299  }
1300 
1301  inline const ConstraintRigidBodyContainer& ConstraintImplementation::ConstrainedBodiesState::getSolverBodies() const
1302  {
1303  return m_bodies;
1304  }
1305 #if !defined(SWIGPYTHON)
1306  AGX_FORCE_INLINE ConstraintImplementation::BodyView::BodyView(const ConstrainedBodiesState::BodiesInfo &info, const ConstraintRigidBodyContainer &bodies) : m_info(info), m_bodies(bodies)
1307  {
1308  }
1309 
1310  AGX_FORCE_INLINE ConstraintImplementation::BodyView::BodyView( const BodyView& other ) : m_info( other.m_info ), m_bodies( other.m_bodies )
1311  {
1312  }
1313 
1315  {
1316  return m_info.numDynamicBodies();
1317  }
1318 
1320  {
1321  return m_info.numNonStaticBodies();
1322  }
1323 
1325  {
1326  return m_bodies.size();
1327  }
1329  {
1330  agxAssert( i < getNumBodies() ); return m_bodies[ i ];
1331  }
1332 
1334  {
1335  agxAssert( i < getNumBodies() ); return m_bodies[ i ];
1336  }
1337 
1338  AGX_FORCE_INLINE const ConstraintRigidBodyContainer& ConstraintImplementation::BodyView::getBodies() const
1339  {
1340  return m_bodies;
1341  }
1342 
1344  : BodyView( state.getSolverInfo(), state.getSolverBodies() ), m_state( state )
1345  {
1346  }
1347 
1349  : BodyView( other.m_state.getSolverInfo(), other.m_state.getSolverBodies() ), m_state( other.m_state )
1350  {
1351  }
1352 
1354  {
1355  return m_state;
1356  }
1357 
1359  {
1360  return m_state;
1361  }
1362 
1364  {
1365  agxAssert( i < m_state.getPermutation().size() );
1366  UInt permutedIndex = (UInt)m_state.getPermutation()[ i ];
1367  agxAssert( permutedIndex < getNumBodies() );
1368  return getBodyAt( permutedIndex );
1369  }
1370 
1372  {
1373  agxAssert( i < m_state.getPermutation().size() );
1374  UInt permutedIndex = (UInt)m_state.getPermutation()[ i ];
1375  agxAssert( permutedIndex < getNumBodies() );
1376  return getBodyAt( permutedIndex );
1377  }
1378 #endif
1379  template< typename T >
1381  {
1382  UInt currentNumber = 0;
1383  for ( UInt i = 0, num = m_sc.size(); i < num; ++i ) {
1384  T* ec = dynamic_cast< T* >( m_sc[ i ].get() );
1385  if ( ec != nullptr && currentNumber == count )
1386  return ec;
1387  currentNumber += ec != nullptr;
1388  }
1389 
1390  return nullptr;
1391  }
1392 
1394 
1396 
1398  {
1399  return const_cast< AttachmentPair* >( &m_attachmentPair );
1400  }
1401 
1402  template< typename T >
1404  {
1405  return m_attachmentPair[ index ] != nullptr ? m_attachmentPair[ index ]->as< T >() : nullptr;
1406  }
1407 
1408  template< typename T >
1410  {
1411  return m_attachmentPair[ index ] != nullptr ? m_attachmentPair[ index ]->as< T >() : nullptr;
1412  }
1413 
1415  {
1416  return m_attachmentPair[ 0 ] != nullptr && !m_attachmentPair[ 0 ]->objectDeleted() &&
1417  m_attachmentPair[ 1 ] != nullptr && !m_attachmentPair[ 1 ]->objectDeleted();
1418  }
1419 
1423  AGX_FORCE_INLINE Real getAngle( const Vec3& a, const Vec3& b, const Vec3& c )
1424  {
1425  return std::atan2( c * b, c * a );
1426  }
1427 
1432 
1437 } // namespace agx
1438 
1439 #ifdef _MSC_VER
1440 # pragma warning(pop)
1441 #endif
1442 
1443 
1444 #endif /* _CONSTRAINTIMPLEMENTATION_H_ */
std::pair< Real, Real > RealPair
virtual agx::Real getAngle(agx::UInt=0) const
If the constraint supports angle calculations and &#39;dof&#39; is in range, this method returns the angle of...
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
const ConstrainedBodiesState & getState() const
AGXPHYSICS_EXPORT void addSecondaryConstraints2DOF(agx::HighLevelConstraintImplementation *constraint, agx::SeparationAngle *sepAngle, agx::RotationalAngle *rotAngle)
Add secondary controllers with default name to the constraint.
int m_tag
Tag for this constraint.
virtual void removeNotification()
Callback when this constraint is removed from Simulation.
#define CALLABLE_IGNORE
Definition: Object.h:79
agx::Bool(* CreateElementaryConstraintsFunction)(class HighLevelConstraintImplementation *)
const agx::ElementaryConstraint::RefContainer & getElementaryConstraints() const
Info with number of dynamic and non-static body counters.
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive...
Elementary constraint base class with interface and global constraint functionality.
UInt m_numRows
Number of rows used by this constraint.
T * findSecondaryConstraintGivenType(const agx::UInt count=0) const
int32_t Int32
Definition: Integer.h:45
bool Bool
Definition: Integer.h:48
virtual agx::AttachmentPair * getAttachmentPair() const
virtual agx::Attachment * userAPIgetAttachment(agx::UInt) const
bool m_enable
User controlled enable flag, constraint ignored by solver if false.
Constraint::SolveType getSolveType() const
virtual bool rebind()
The general version of rebind takes the first attachment frame and moves the other attachment frame s...
ConstraintRigidBodyContainer m_bodies
Vector with observer pointers to bodies.
#define AGXPHYSICS_EXPORT
The base class for a constraint.
Definition: Constraint.h:86
ConstrainedBodiesState m_constrainedBodiesState
State of the included bodies, updated in updateValid.
int32_t Int
Definition: Integer.h:35
#define agxAbort()
Definition: debug.h:164
Object that holds the state seen from the user and from the solver.
BlockType getNumBlocks() const
Constraint attachment class for agx::RigidBody.
Definition: Attachment.h:207
virtual void preSystemCallback(DynamicsSystem *system)
Before prepare, and before the system writes to the data buffers, this constraint gets a call with th...
#define AGX_FORCE_INLINE
Definition: Object.h:63
Translational or rotational friction controller for Hinge, Prismatic and CylindricalJoint.
Implementation of constraint angle ALONG an axis.
agx::ElementaryConstraint::RefContainer & getElementaryConstraints()
virtual agx::AttachmentPair * getAttachmentPair() const override
Base class providing referencing counted objects.
Definition: Referenced.h:113
const agx::ConstraintRigidBodyContainer & getSolverBodies() const
const ConstraintImplPtrVector & getSubConstraints() const
void incrementConstraintCount(RigidBody *rb) const
Increment the number of constraints connection to rb.
Constraint::SolveType m_solveType
Only for supported solvers.
const agx::ElementaryConstraint::RefContainer & getSecondaryConstraints() const
Elementary secondary constraint to keep constraint angle at a given target position.
virtual void postSystemCallback(DynamicsSystem *system)
Last in the dynamics system step forward loop, this constraint gets a call with the main system...
Essentially a sparse array of bounds.
Definition: SparseTypes.h:73
ConstraintImplPtrVector m_subConstraints
Vector with sub-constraints.
uint32_t UInt
Definition: Integer.h:34
Constraint attachment pair class.
Definition: Attachment.h:300
Constraint attachment base class for any type of frame.
Definition: Attachment.h:36
Elementary secondary constraint to keep constraint angle within two given values. ...
Namespace agx contains the dynamics/math part of the AGX Dynamics API.
agx::BitState< State, Int32 > LocalState
std::valarray< agx::Real > RealValarray
For this module, vectors are defined using valarray.
void setNumBlocks(BlockType numBlocks)
virtual void addNotification()
Callback when this constraint is added to Simulation.
BlockStructure m_blockStructure
The block structure; number of block, rows, dynamic blocks etc.
virtual agx::Real getCurrentSpeed(agx::UInt=0) const
If this method is implemented, a call to this method will return the current speed of the angle...
Vector< RigidBody *> ConstraintRigidBodyContainer
ConstraintImplPtrVector & getSubConstraints()
agx::ElementaryConstraint::RefContainer & getSecondaryConstraints()
Interface to the bodies, either user or solver, since these bodies can differ when e...
#define agxAssert(expr)
Definition: debug.h:143
Constraint angle class.
const BlockStructure & getBlockStructure() const
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
ElementaryConstraint::RefContainer m_ec
Vector of elementary constraints.
#define CALLABLE
Definition: Object.h:77
Interface to the lower triangle of the compliance matrix block in the system matrix.
virtual agx::Attachment * userAPIgetAttachment(const agx::RigidBody *) const
The complete physical system with bodies, interactions, data layout, time stepper, and solver.
const ConstraintRigidBodyContainer & getBodies() const
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:48
All ghost variables have compliance and damping attributes.
SolveType
Specifies in what solvers the constraint will be solved.
Definition: Constraint.h:90
void setSolveType(Constraint::SolveType type)
Set solve type, either DIRECT, ITERATIVE or DIRECT_AND_ITERATIVE.
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
SolverBodyView(ConstrainedBodiesState &state)
Internal, use ConstriantImplementation::getSolverView().
UInt m_blockRowIndex
Start block row for this constraint in the global matrix.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Elementary secondary constraint to drive something given target speed (translational or rotational)...
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
size_t size() const
Definition: Container.h:134
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:121
Solved both in the ITERATIVE and the DIRECT solver.
Definition: Constraint.h:94
void * customData
Custom data for the solvers to store data into.
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Definition: Serializable.h:220
Implementation of constraint angle ABOUT an axis.
BodyView(const ConstrainedBodiesState::BodiesInfo &info, const ConstraintRigidBodyContainer &bodies)
Internal, use ConstriantImplementation::getUserView().
uint16_t UInt16
Definition: Integer.h:39
void setNumRows(BlockType numRows)
Interface class used by internal objects running in parallel.
double Real
Definition: Real.h:42
AGXPHYSICS_EXPORT void addSecondaryConstraints1DOF(agx::HighLevelConstraintImplementation *constraint, agx::Angle *angle)
Add secondary controllers with default name to the constraint.
Solved only in the ITERATIVE solver.
Definition: Constraint.h:93
LocalState m_localState
Current local state, updated all the time, not serialized.
Real getAngle(const Vec3 &a, const Vec3 &b, const Vec3 &c)
a and b should be orthogonal
void setBlockRowIndex(agx::UInt blockRowIndex)
Sets the global start index for this constraint in the global, non-permuted matrix.
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:102
ElementaryConstraint::RefContainer m_sc
Vector of secondary constraints.
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:101
bool m_enableLinearization
When necessary, tweak the values sent to the solver to make violation depend linearly on force or tor...
BlockType getNumRows() const
GLenum type
Definition: gl.h:5539
Pointer to a entity instance of type Physics.ConstraintForces.