AGX Dynamics 2.42.2.1
Loading...
Searching...
No Matches
ConstraintImplementation.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGX_CONSTRAINT_IMPLEMENTATION_H
18#define AGX_CONSTRAINT_IMPLEMENTATION_H
19
21
23#include <agx/Constraint.h>
24
25#include <agx/agx_hash_types.h>
27
29
31
32#ifdef _MSC_VER
33# pragma warning(push)
34# pragma warning( disable : 4251 ) // class X needs to have dll-interface to be used by clients of class Y
35#endif
36
37#define DEFAULT_COMPLIANCE 1.0E-8
38
39#define CONSTRAINT_SUCCESS( success ) \
40 if ( !(success) ) { \
41 LOGGER_WARNING() << "Unable to create constraint. Constraint cleared." << std::endl << LOGGER_END(); \
42 m_bodies.clear(); \
43 m_localState.remove( VALID ); \
44 return; \
45 }
46
47#define CONSTRAINT_SUCCESS_RETURN_BOOL( success ) \
48 if ( !(success) ) { \
49 LOGGER_WARNING() << "Unable to create constraint. Constraint cleared." << std::endl << LOGGER_END(); \
50 m_bodies.clear(); \
51 m_localState.remove( VALID ); \
52 return false; \
53 }
54
55namespace agx
56{
57 // Forward declaration
58 class ElementaryConstraint;
59 class Constraint;
60 class RegularizationParameters;
61 class SparseRangeReal;
62 class LSquareComplianceMatrix;
63 struct NlmcpCallbackSolverData;
64
66 typedef std::pair< Real, Real > RealPair;
67
69 {
70 public:
73 : m_numBlocks( 0 ), m_numRows( 0 ), m_numDynBlocks( 0 ) {}
74
75 AGX_FORCE_INLINE void setNumBlocks( BlockType numBlocks ) { m_numBlocks = numBlocks; }
76 AGX_FORCE_INLINE void setNumRows( BlockType numRows ) { m_numRows = numRows; }
77
78 AGX_FORCE_INLINE BlockType getNumBlocks() const { return m_numBlocks; }
79 AGX_FORCE_INLINE BlockType getNumRows() const { return m_numRows; }
80
81 AGX_FORCE_INLINE BlockType& blocks() { return m_numBlocks; }
82 AGX_FORCE_INLINE BlockType& rows() { return m_numRows; }
83 AGX_FORCE_INLINE BlockType blocks() const { return m_numBlocks; }
84 AGX_FORCE_INLINE BlockType rows() const { return m_numRows; }
85
86 AGX_FORCE_INLINE BlockType& dynBlocks() { return m_numDynBlocks; }
87 AGX_FORCE_INLINE BlockType dynBlocks() const { return m_numDynBlocks; }
88 AGX_FORCE_INLINE BlockType kinBlocks() const { return (BlockType)(m_numBlocks - m_numDynBlocks); }
89
90 AGX_FORCE_INLINE void reset() { m_numBlocks = m_numRows = m_numDynBlocks = 0; }
91
92 private:
93 BlockType m_numBlocks;
94 BlockType m_numRows;
95 BlockType m_numDynBlocks;
96 };
97
99 {
100 public:
101 enum Tags
102 {
103 NONE = 0,
104 MANY_BODY = (1<<0),
105 DEFAULT_BINARY_TAG = NONE,
106 DEFAULT_MANY_BODY_TAG = MANY_BODY
107 };
108
113 {
114 public:
119 {
120 public:
122
126 agx::UInt& numDynamicBodies();
127
131 agx::UInt numDynamicBodies() const;
132
136 agx::UInt& numNonStaticBodies();
137
141 agx::UInt numNonStaticBodies() const;
142
143 private:
144 agx::UInt m_numDynamicBodies;
145 agx::UInt m_numNonStaticBodies;
146 };
147
148 public:
153
158 void reset( agx::UInt numBodies );
159
165
171
175 const BodiesInfo& getOriginalInfo() const;
176
180 const BodiesInfo& getSolverInfo() const;
181
185 const agx::Int32Vector& getPermutation() const;
186
190 agx::Int32Vector& getPermutation();
191
195 const agx::Int32Vector& getBodyIndices() const;
196
200 agx::Int32Vector& getBodyIndices();
201
205 const agx::ConstraintRigidBodyContainer& getSolverBodies() const;
206
215
216 private:
217 BodiesInfo m_originalInfo;
218 BodiesInfo m_solverInfo;
220 Int32Vector m_permutation;
221 Int32Vector m_bodyIndices;
222 UInt m_numRecurrentMergedBodies;
223 };
224
229 #if !defined(SWIGPYTHON)
231 {
232 public:
238
242 BodyView( const BodyView& other );
243
247 agx::UInt getNumDynamicBodies() const;
248
252 agx::UInt getNumNonStaticBodies() const;
253
257 agx::UInt getNumBodies() const;
258
262 agx::RigidBody* getBodyAt( agx::UInt i );
263
267 const agx::RigidBody* getBodyAt( agx::UInt i ) const;
268
272 const ConstraintRigidBodyContainer& getBodies() const;
273
277 BodyView& operator = ( const BodyView& ) = delete;
278
279 private:
281 const ConstraintRigidBodyContainer& m_bodies;
282 };
283
285 {
286 public:
292
296 SolverBodyView( const SolverBodyView& other );
297
301 const ConstrainedBodiesState& getState() const;
302
306 ConstrainedBodiesState& getState();
307
311 agx::RigidBody* getPermutedBodyAt( agx::UInt i );
312
316 const agx::RigidBody* getPermutedBodyAt( agx::UInt i ) const;
317
318 private:
322 inline SolverBodyView& operator = ( const SolverBodyView& ) { agxAbort(); return *this; }
323
324 private:
325 ConstrainedBodiesState& m_state;
326 };
327 #endif
328
329 public:
335
340
344 #if !defined(SWIGPYTHON)
346
351 #endif
352
353 // ****************************************************************************
354 // Callbacks from solvers *****************************************************
355 // ****************************************************************************
356
364 virtual bool updateValid();
365
372 virtual void prepare();
373
380 virtual size_t updateJacobian( agx::Jacobian6DOFElement* jacobians );
381
388 virtual int getViolation( agx::Real* g, int row );
389
395 virtual void getEpsilon( agx::Real* epsilon, agx::Real h );
396
400 virtual void getParameters( agx::Real* violation,
401 agx::Real* epsilon,
402 agx::Real* damping,
403 bool* holonomic,
404 agx::Real* velocity,
405 agx::RangeReal* bounds,
406 int8_t* indexSetState,
407 agx::Real h,
408 agx::Real minPerturbation = agx::Real( 1E-10 ) );
409
417 virtual int getConstraintVelocity( agx::Real* v, int row );
418
426 virtual void getBounds( agx::RangeReal* bounds, agx::Real dt ) const;
427
437
441 void onDirectComplianceMatrix( Real* data, unsigned int ld ) const;
442
449 virtual void postSolveCallback( const agx::Jacobian6DOFElement* jacobians, const agx::Real* solution, agx::Real dt );
450
455 void postSolveIndexSetCallback( const int8_t* state );
456
463 virtual void preSystemCallback( DynamicsSystem* system );
464
470 virtual void postSystemCallback( DynamicsSystem* system );
471
477 void sort();
478
482 void reset();
483
487 virtual void addNlCallbacks( agx::SparseRangeReal& sparseRangeReal, const NlmcpCallbackSolverData& solverData ) const;
488
489 // ****************************************************************************
490
491 // ****************************************************************************
492 // Methods used by the solvers ************************************************
493 // ****************************************************************************
494
498 AGX_FORCE_INLINE agx::UInt getJacobianRowUsage() const { return m_numRows; }
499
503 AGX_FORCE_INLINE const BlockStructure& getBlockStructure() const { return m_blockStructure; }
504
509 AGX_FORCE_INLINE void setBlockRowIndex( agx::UInt blockRowIndex ) { m_blockRowIndex = blockRowIndex; }
510
514 AGX_FORCE_INLINE agx::UInt getBlockRowIndex() const { return m_blockRowIndex; }
515
520 AGX_FORCE_INLINE bool getSolveIterative() const { return m_solveType == Constraint::ITERATIVE; }
521
525 AGX_FORCE_INLINE bool getSolveBoth() const { return m_solveType == Constraint::DIRECT_AND_ITERATIVE; }
526
530 AGX_FORCE_INLINE void setSolveType( Constraint::SolveType type ) { m_solveType = type; }
531
536
540 AGX_FORCE_INLINE bool isImpacting() const { return m_localState.Is( IMPACTING ); }
541
546 AGX_FORCE_INLINE void incrementConstraintCount( RigidBody* rb ) const { agxAssert( rb ); if (rb) rb->incrementNumConstraints(); }
547
551 AGX_FORCE_INLINE int getTag() const { return m_tag; }
552
553#ifndef SWIG
555#endif
556
557 // ****************************************************************************
558
559 // ****************************************************************************
560 // Callbacks from the simulation during add and remove of this constraint *****
561 // ****************************************************************************
562
566 virtual void addNotification() {}
567
571 virtual void removeNotification() {}
572
573 // ****************************************************************************
574
575 // ****************************************************************************
576 // Methods used by non-implementation constraints but not the 'end user' ******
577 // ****************************************************************************
578
584
590
595 AGX_FORCE_INLINE const ConstraintImplPtrVector& getSubConstraints() const { return m_subConstraints; }
596
597 // ****************************************************************************
598 // Methods used by 'the user' *************************************************
599 // ****************************************************************************
600
608 virtual bool rebind() { return false; }
609
614 virtual AGX_FORCE_INLINE bool getEnable() const { return m_enable; }
615
620 virtual void setEnable(bool enable);
621
625 AGX_FORCE_INLINE bool getActive() const { return m_enable && m_localState.Is( VALID ); }
626
630 AGX_FORCE_INLINE bool isValid() const { return m_localState.Is( VALID ); }
631
632 // ****************************************************************************
633
634 // ****************************************************************************
635 // Methods for user API, these should not be used internally ******************
636 // ****************************************************************************
637
644
652
659 virtual void setEnableComputeForces( agx::Bool enable );
660
665
685 virtual agx::Bool getLastForce( agx::UInt bodyIndex, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const;
686
705 virtual agx::Bool getLastForce( const agx::RigidBody* rb, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const;
706
725 virtual agx::Bool getLastLocalForce( agx::UInt bodyIndex, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const;
726
744 virtual agx::Bool getLastLocalForce( const agx::RigidBody* rb, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const;
745
752 void setEnableLinearization(bool enable);
753
758
762 virtual agx::Attachment* userAPIgetAttachment( const agx::RigidBody* /*rb*/ ) const { return nullptr; }
763
767 virtual agx::Attachment* userAPIgetAttachment( agx::UInt /*index*/ ) const { return nullptr; }
768
772 virtual agx::AttachmentPair* getAttachmentPair() const { return nullptr; }
773
780 virtual bool addElementaryConstraint( const agx::String& name, agx::ElementaryConstraint* elementaryConstraint );
781
788 virtual bool addSecondaryConstraint( const agx::String& name, agx::ElementaryConstraint* secondaryConstraint );
789
795 virtual bool removeElementaryConstraint( agx::ElementaryConstraint* elementaryConstraint );
796
802 virtual bool removeSecondaryConstraint( agx::ElementaryConstraint* secondaryConstraint );
803
809 virtual bool removeElementaryConstraint( const agx::String& name );
810
816 virtual bool removeSecondaryConstraint( const agx::String& name );
817
823
829
835
841
845 template< typename T >
846 T* findSecondaryConstraintGivenType( const agx::UInt count = 0 ) const;
847
851 agx::Motor1D* getMotor1D( agx::UInt number = 0 ) const;
852
856 agx::Lock1D* getLock1D( agx::UInt number = 0 ) const;
857
861 agx::Range1D* getRange1D( agx::UInt number = 0 ) const;
862
867
872 virtual agx::Real getAngle( agx::UInt /*dof*/ = 0 ) const { return 0; }
873
879 virtual agx::Real getCurrentSpeed( agx::UInt /*dof*/ = 0 ) const { return 0; }
880
888
893
899 void userAPIsetCompliance( agx::Real compliance, int dof );
900
905
911 void userAPIsetDamping( agx::Real damping, int dof );
912
920
928
937
945
946
947 // **************************************************************************
948
950
951
956 agx::RealValarray getCompliance() const;
957
961 agx::Referenced* getInternalData() const;
962
966 void setInternalData( agx::Referenced* data );
967
973 void clearRigidBodies();
974
982 void setRigidBodies( agx::RigidBody* rb1, agx::RigidBody* rb2 = nullptr );
983
991 void setRigidBodies( std::initializer_list<agx::RigidBody*> bodies );
992
999 void addRigidBody( agx::RigidBody* rb );
1000
1004 AGX_FORCE_INLINE agxSDK::SimulationProxy* getSimulationProxy() { return m_simulationProxy; }
1005 AGX_FORCE_INLINE const agxSDK::SimulationProxy* getSimulationProxy() const { return m_simulationProxy; }
1006
1007 agx::Physics::ConstraintForcesPtr getForceData();
1008 void setForceData(agx::Physics::ConstraintForcesPtr forceData);
1009
1010 virtual void storeLightData( agxStream::StorageStream& ) const {}
1011 virtual void restoreLightData( agxStream::StorageStream& ) {}
1012
1014
1015 protected:
1017 {
1018 VALID = 1 << 0, // Replaces m_valid.
1019 IMPACTING = 1 << 1, // Replaces m_impactState.
1020 SUPPORTS_COMPLIANCE_MATRIX = 1 << 2 // Set if this constraint supports write access to the compliance matrix
1021 // allocated in the system matrix.
1023
1024 using LocalState = agx::BitState<State, Int32>;
1025
1026 protected:
1027 friend class Constraint;
1033
1040 void setSupportsComplianceMatrix( Bool supportsComplianceMatrix );
1041
1042 protected:
1052 int m_tag;
1054 private:
1055 agxSDK::SimulationProxyRef m_simulationProxy;
1056 Physics::ConstraintForcesPtr m_forceData;
1057 ref_ptr<Referenced> m_internalData;
1058
1059 protected:
1064 };
1065
1067 {
1068 public:
1071
1079 virtual bool updateValid() override;
1080
1087 virtual void prepare() override;
1088
1094 virtual size_t updateJacobian( agx::Jacobian6DOFElement* jacobians ) override;
1095
1102 virtual void postSolveCallback( const agx::Jacobian6DOFElement* jacobians, const agx::Real* solution, agx::Real dt ) override;
1103
1111 virtual bool rebind() override;
1112
1117 virtual void computeForces( const agx::Jacobian6DOFElement* jacobians );
1118
1129 virtual agx::Bool computeForces( const agx::Jacobian6DOFElement* jacobians, agx::Vec3Vector& result ) const;
1130
1137 virtual void setEnableComputeForces( agx::Bool enable ) override;
1138
1142 virtual agx::Bool getEnableComputeForces() const override;
1143
1163 virtual agx::Bool getLastForce( agx::UInt bodyIndex, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const override;
1164
1183 virtual agx::Bool getLastForce( const RigidBody* rb, Vec3& retForce, Vec3& retTorque, agx::Bool giveForceAtCm = false ) const override;
1184
1203 virtual agx::Bool getLastLocalForce( agx::UInt bodyIndex, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const override;
1204
1222 virtual agx::Bool getLastLocalForce( const agx::RigidBody* rb, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const override;
1223
1224 // **************************************************************************
1225 // Internal utility methods for one or two body constraints *****************
1226 // **************************************************************************
1227
1228 typedef agx::Bool (*CreateElementaryConstraintsFunction)( HighLevelConstraintImplementation* );
1229
1230 bool construct( RigidBody* rb1, Frame* rb1AttachmentFrame, RigidBody* rb2, Frame* rb2AttachmentFrame, CreateElementaryConstraintsFunction = nullptr );
1232 bool validateRigidBodiesAndAttachments( RigidBody* rb1, Frame* rb1AttachmentFrame, RigidBody* rb2, Frame* rb2AttachmentFrame );
1233
1237 virtual agx::Attachment* userAPIgetAttachment( const agx::RigidBody* rb ) const override;
1238
1242 virtual agx::Attachment* userAPIgetAttachment( agx::UInt index ) const override;
1243
1247 virtual agx::AttachmentPair* getAttachmentPair() const override;
1248
1253 virtual agx::Real getAngle( agx::UInt dof = 0 ) const override;
1254
1258 bool bodiesValid() const;
1259
1263 template< typename T >
1264 T* getAttachment( agx::UInt index );
1265
1269 template< typename T >
1270 const T* getAttachment( agx::UInt index ) const;
1271
1273
1274 virtual void restore( agxStream::InputArchive& in ) override;
1275 virtual void store( agxStream::OutputArchive& out ) const override;
1276
1277 virtual void storeLightData( agxStream::StorageStream& str ) const override;
1278 virtual void restoreLightData( agxStream::StorageStream& str ) override;
1279
1280 protected:
1283 };
1284
1286 {
1287 return m_numDynamicBodies;
1288 }
1289
1291 {
1292 return m_numDynamicBodies;
1293 }
1294
1296 {
1297 return m_numNonStaticBodies;
1298 }
1299
1301 {
1302 return m_numNonStaticBodies;
1303 }
1304
1306 {
1307 return m_originalInfo;
1308 }
1309
1311 {
1312 return m_solverInfo;
1313 }
1314
1316 {
1317 return m_permutation;
1318 }
1319
1321 {
1322 return m_permutation;
1323 }
1324
1326 {
1327 return m_bodyIndices;
1328 }
1329
1331 {
1332 return m_bodyIndices;
1333 }
1334
1336 {
1337 return m_bodies;
1338 }
1339#if !defined(SWIGPYTHON)
1341 {
1342 }
1343
1345 {
1346 }
1347
1349 {
1350 return m_info.numDynamicBodies();
1351 }
1352
1354 {
1355 return m_info.numNonStaticBodies();
1356 }
1357
1359 {
1360 return m_bodies.size();
1361 }
1363 {
1364 agxAssert( i < getNumBodies() ); return m_bodies[ i ];
1365 }
1366
1368 {
1369 agxAssert( i < getNumBodies() ); return m_bodies[ i ];
1370 }
1371
1373 {
1374 return m_bodies;
1375 }
1376
1378 : BodyView( state.getSolverInfo(), state.getSolverBodies() ), m_state( state )
1379 {
1380 }
1381
1383 : BodyView( other.m_state.getSolverInfo(), other.m_state.getSolverBodies() ), m_state( other.m_state )
1384 {
1385 }
1386
1388 {
1389 return m_state;
1390 }
1391
1393 {
1394 return m_state;
1395 }
1396
1398 {
1399 agxAssert( i < m_state.getPermutation().size() );
1400 UInt permutedIndex = (UInt)m_state.getPermutation()[ i ];
1401 agxAssert( permutedIndex < getNumBodies() );
1402 return getBodyAt( permutedIndex );
1403 }
1404
1406 {
1407 agxAssert( i < m_state.getPermutation().size() );
1408 UInt permutedIndex = (UInt)m_state.getPermutation()[ i ];
1409 agxAssert( permutedIndex < getNumBodies() );
1410 return getBodyAt( permutedIndex );
1411 }
1412#endif
1413 template< typename T >
1415 {
1416 UInt currentNumber = 0;
1417 for ( UInt i = 0, num = m_sc.size(); i < num; ++i ) {
1418 T* ec = dynamic_cast< T* >( m_sc[ i ].get() );
1419 if ( ec != nullptr && currentNumber == count )
1420 return ec;
1421 currentNumber += ec != nullptr;
1422 }
1423
1424 return nullptr;
1425 }
1426
1428
1430
1432 {
1433 return const_cast< AttachmentPair* >( &m_attachmentPair );
1434 }
1435
1436 template< typename T >
1438 {
1439 return m_attachmentPair[ index ] != nullptr ? m_attachmentPair[ index ]->as< T >() : nullptr;
1440 }
1441
1442 template< typename T >
1444 {
1445 return m_attachmentPair[ index ] != nullptr ? m_attachmentPair[ index ]->as< T >() : nullptr;
1446 }
1447
1449 {
1450 return m_attachmentPair[ 0 ] != nullptr && !m_attachmentPair[ 0 ]->objectDeleted() &&
1451 m_attachmentPair[ 1 ] != nullptr && !m_attachmentPair[ 1 ]->objectDeleted();
1452 }
1453
1457 AGX_FORCE_INLINE Real getAngle( const Vec3& a, const Vec3& b, const Vec3& c )
1458 {
1459 return std::atan2( c * b, c * a );
1460 }
1461
1466
1471} // namespace agx
1472
1473#ifdef _MSC_VER
1474# pragma warning(pop)
1475#endif
1476
1477
1478#endif /* _CONSTRAINTIMPLEMENTATION_H_ */
#define AGXPHYSICS_EXPORT
Interface class used by internal objects running in parallel.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:49
Constraint angle class.
Constraint attachment pair class.
Constraint attachment base class for any type of frame.
void setNumRows(BlockType numRows)
BlockType getNumBlocks() const
BlockType getNumRows() const
void setNumBlocks(BlockType numBlocks)
Interface to the bodies, either user or solver, since these bodies can differ when e....
const ConstraintRigidBodyContainer & getBodies() const
BodyView(const ConstrainedBodiesState::BodiesInfo &info, const ConstraintRigidBodyContainer &bodies)
Internal, use ConstriantImplementation::getUserView().
Info with number of dynamic and non-static body counters.
Object that holds the state seen from the user and from the solver.
const agx::ConstraintRigidBodyContainer & getSolverBodies() const
agx::Bool finalize(agx::Bool valid)
Finalize given state of constraint.
void reset(agx::UInt numBodies)
Resets all data and allocates for a maximum of numBodies.
agx::Bool increment(agx::RigidBody *rb)
Increments data given a rigid body.
agx::UInt getNumRecurrentMergedBodies() const
Counter that increments each time a merged body already has been registered and comes back.
const ConstrainedBodiesState & getState() const
SolverBodyView(ConstrainedBodiesState &state)
Internal, use ConstriantImplementation::getSolverView().
void reset()
Reset the solution vectors of the primary and secondary elementary constraints in the implementation.
virtual agx::ElementaryConstraint * getElementaryConstraint(const agx::String &name) const
Constraint::SolveType m_solveType
Only for supported solvers.
virtual int getViolation(agx::Real *g, int row)
Calculates and pushes the constraint values into array given current row.
virtual bool addElementaryConstraint(const agx::String &name, agx::ElementaryConstraint *elementaryConstraint)
Add elementary constraint (like Spherical, Dot1, Dot2 etc) given name.
agx::ElementaryConstraint::RefContainer & getElementaryConstraints()
virtual agx::Real getAngle(agx::UInt=0) const
If the constraint supports angle calculations and 'dof' is in range, this method returns the angle of...
virtual void postSystemCallback(DynamicsSystem *system)
Last in the dynamics system step forward loop, this constraint gets a call with the main system.
bool m_enable
User controlled enable flag, constraint ignored by solver if false.
BlockStructure m_blockStructure
The block structure; number of block, rows, dynamic blocks etc.
void setSupportsComplianceMatrix(Bool supportsComplianceMatrix)
Enable/disable compliance matrix callbacks from the direct solver where read/write access to the comp...
virtual void setEnableComputeForces(agx::Bool enable)
Enable (or disable) computation of the forces applied to the dynamic bodies in this constraint.
virtual agx::ElementaryConstraint * getSecondaryConstraint(const agx::String &name) const
virtual bool removeSecondaryConstraint(agx::ElementaryConstraint *secondaryConstraint)
Remove secondary constraint.
agx::UInt calculateNumActiveRows() const
Calculates the current number of active rows, including both elementary and secondary constraints.
void sort()
This method will sort this constraint by global indexing of the bodies.
virtual agx::Attachment * userAPIgetAttachment(const agx::RigidBody *) const
const agx::ElementaryConstraint::RefContainer & getSecondaryConstraints() const
void * customData
Custom data for the solvers to store data into.
virtual bool removeSecondaryConstraint(const agx::String &name)
Remove secondary constraint.
virtual void addNotification()
Callback when this constraint is added to Simulation.
virtual ~ConstraintImplementation()
Destructor.
int m_tag
Tag for this constraint.
ElementaryConstraint::RefContainer m_sc
Vector of secondary constraints.
const BlockStructure & getBlockStructure() const
agx::RegularizationParameters * userAPIgetRegularizationParameters(agx::UInt i) const
Get the regularization parameter i, i.e., the regularization parameter for equation i which is constr...
agx::FrictionController * getFrictionController(agx::UInt number=0) const
virtual size_t updateJacobian(agx::Jacobian6DOFElement *jacobians)
Updated storing of Jacobian matrices.
virtual void getBounds(agx::RangeReal *bounds, agx::Real dt) const
Calculates and pushes the bounds into a sparse range data structure.
UInt m_numRows
Number of rows used by this constraint.
virtual agx::ElementaryConstraint * getElementaryConstraint(const agx::UInt index) const
const agx::ElementaryConstraint::RefContainer & getElementaryConstraints() const
virtual CALLABLE_IGNORE void updateComplianceMatrix(LSquareComplianceMatrix matrix) const
Callback with read/write access to the compliance matrix of this constraint in the direct solver.
void incrementConstraintCount(RigidBody *rb) const
Increment the number of constraints connection to rb.
RealVector calculateCurrentViolation() const
Calculates the current violation of the ordinary degrees of freedom of this constraint,...
agx::Motor1D * getMotor1D(agx::UInt number=0) const
virtual agx::Attachment * userAPIgetAttachment(agx::UInt) const
void onDirectComplianceMatrix(Real *data, unsigned int ld) const
Internal callback from the direct solver with perturbation matrix data.
void setSimulation(agxSDK::Simulation *simulation)
Set the Simulation this constraint belongs to.
void userAPIsetDamping(agx::Real damping, int dof)
Set the damping for constraint row i of this constraint.
void postSolveIndexSetCallback(const int8_t *state)
Callback after the solver is done about the state of each equation in the constraint.
ConstraintImplPtrVector m_subConstraints
Vector with sub-constraints.
virtual void removeNotification()
Callback when this constraint is removed from Simulation.
ConstraintRigidBodyContainer m_bodies
Vector with observer pointers to bodies.
virtual void postSolveCallback(const agx::Jacobian6DOFElement *jacobians, const agx::Real *solution, agx::Real dt)
Peak at the solution after the solver is done.
void setSolveType(Constraint::SolveType type)
Set solve type, either DIRECT, ITERATIVE or DIRECT_AND_ITERATIVE.
virtual agx::Bool getLastForce(agx::UInt bodyIndex, agx::Vec3 &retForce, agx::Vec3 &retTorque, agx::Bool giveForceAtCm=false) const
If 'compute forces' is enabled, returns the last force and torque applied by this constraint on the b...
virtual bool removeElementaryConstraint(agx::ElementaryConstraint *elementaryConstraint)
Remove elementary constraint.
void setBlockRowIndex(agx::UInt blockRowIndex)
Sets the global start index for this constraint in the global, non-permuted matrix.
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.
BodyView getUserView() const
Bodies as viewed from the user.
Constraint::SolveType getSolveType() const
virtual void setEnable(bool enable)
Sets the enable flag.
ConstraintImplPtrVector & getSubConstraints()
void userAPIsetForceRange(agx::RangeReal forceRange, agx::Int dof)
Assign force range, of an elementary constraint, for a given DOF.
virtual agx::Bool getLastForce(const agx::RigidBody *rb, agx::Vec3 &retForce, agx::Vec3 &retTorque, agx::Bool giveForceAtCm=false) const
If 'compute forces' is enabled, returns the last force and torque applied by this constraint on the b...
agx::Real userAPIgetCompliance(agx::UInt dof) const
ConstraintImplementation()
Default constructor.
agx::ElementaryConstraint::RefContainer & getSecondaryConstraints()
agx::Real userAPIgetCurrentForce(agx::UInt dof) const
Consider using getLastForce instead.
agx::Lock1D * getLock1D(agx::UInt number=0) const
SolverBodyView getSolverView() const
Bodies as viewed from the solver.
virtual void preSystemCallback(DynamicsSystem *system)
Before prepare, and before the system writes to the data buffers, this constraint gets a call with th...
virtual bool removeElementaryConstraint(const agx::String &name)
Remove elementary constraint.
UInt m_blockRowIndex
Start block row for this constraint in the global matrix.
virtual void getEpsilon(agx::Real *epsilon, agx::Real h)
Writes regularization parameters for all active rows into epsilon.
virtual void addNlCallbacks(agx::SparseRangeReal &sparseRangeReal, const NlmcpCallbackSolverData &solverData) const
Interface for non-linear callback from solver.
ConstrainedBodiesState m_constrainedBodiesState
State of the included bodies, updated in updateValid.
virtual agx::ElementaryConstraint * getSecondaryConstraint(const agx::UInt index) const
bool m_enableLinearization
When necessary, tweak the values sent to the solver to make violation depend linearly on force or tor...
virtual void getParameters(agx::Real *violation, agx::Real *epsilon, agx::Real *damping, bool *holonomic, agx::Real *velocity, agx::RangeReal *bounds, int8_t *indexSetState, agx::Real h, agx::Real minPerturbation=agx::Real(1E-10))
Writes solver parameters such as damping and holonomic.
virtual int getConstraintVelocity(agx::Real *v, int row)
Calculates and pushes the constraint velocities into array given current row.
virtual agx::Bool getEnableComputeForces() const
virtual void prepare()
Prepares this constraint.
virtual agx::Bool getLastLocalForce(agx::UInt bodyIndex, agx::Vec3 &retForce, agx::Vec3 &retTorque, agx::Bool giveForceAtCm=false) const
If 'compute forces' is enabled, returns the last force and torque applied by this constraint on the b...
virtual bool updateValid()
Updates the valid conditions for this constraint.
agx::BitState< State, Int32 > LocalState
const ConstraintImplPtrVector & getSubConstraints() const
agx::Real userAPIgetDamping(agx::UInt dof) const
void userAPIsetCompliance(agx::Real compliance, int dof)
Set the compliance for constraint row i of this constraint.
virtual bool addSecondaryConstraint(const agx::String &name, agx::ElementaryConstraint *secondaryConstraint)
Add secondary constraint (like motor, range and/or lock etc) given name.
virtual bool rebind()
The general version of rebind takes the first attachment frame and moves the other attachment frame s...
agx::Real calculateViolationVectorAverageSize()
Gets the average size of the elements in getViolation() by calculating the magnitude and dividing by ...
virtual agx::Bool getLastLocalForce(const agx::RigidBody *rb, agx::Vec3 &retForce, agx::Vec3 &retTorque, agx::Bool giveForceAtCm=false) const
If 'compute forces' is enabled, returns the last force and torque applied by this constraint on the b...
agx::Range1D * getRange1D(agx::UInt number=0) const
virtual agx::AttachmentPair * getAttachmentPair() const
ElementaryConstraint::RefContainer m_ec
Vector of elementary constraints.
agx::RangeReal userAPIgetForceRange(agx::UInt dof) const
Get the force range for DOF dof.
LocalState m_localState
Current local state, updated all the time, not serialized.
void setEnableLinearization(bool enable)
Control whether or not linearization should be performed on the ElementaryConstraints that require it...
T * findSecondaryConstraintGivenType(const agx::UInt count=0) const
The base class for a constraint.
Definition: Constraint.h:89
SolveType
Specifies in what solvers the constraint will be solved.
Definition: Constraint.h:93
size_t size() const
Definition: Container.h:134
The complete physical system with bodies, interactions, data layout, time stepper,...
Elementary constraint base class with interface and global constraint functionality.
The object defining a frame of reference and providing transformations operations.
Definition: agx/Frame.h:68
Translational or rotational friction controller for Hinge, Prismatic and CylindricalJoint.
virtual void postSolveCallback(const agx::Jacobian6DOFElement *jacobians, const agx::Real *solution, agx::Real dt) override
Peak at the solution after the solver is done.
bool setupOneOrTwoBodySystem(RigidBodyAttachment *a1, RigidBodyAttachment *a2)
virtual void restore(agxStream::InputArchive &in) override
virtual agx::Bool getLastForce(const RigidBody *rb, Vec3 &retForce, Vec3 &retTorque, agx::Bool giveForceAtCm=false) const override
If 'compute forces' is enabled, returns the last force and torque applied by this constraint on the b...
bool construct(RigidBody *rb1, Frame *rb1AttachmentFrame, RigidBody *rb2, Frame *rb2AttachmentFrame, CreateElementaryConstraintsFunction=nullptr)
virtual agx::Bool getLastForce(agx::UInt bodyIndex, agx::Vec3 &retForce, agx::Vec3 &retTorque, agx::Bool giveForceAtCm=false) const override
If 'compute forces' is enabled, returns the last force and torque applied by this constraint on the b...
virtual agx::Real getAngle(agx::UInt dof=0) const override
If the constraint supports angle calculations and 'dof' is in range, this method returns the angle of...
virtual size_t updateJacobian(agx::Jacobian6DOFElement *jacobians) override
Updates the Jacobian matrices.
virtual void storeLightData(agxStream::StorageStream &str) const override
virtual agx::Bool computeForces(const agx::Jacobian6DOFElement *jacobians, agx::Vec3Vector &result) const
Computes forces on rb1 and rb2 given this constraint has been solved and all the elementary constrain...
virtual bool rebind() override
The general version of rebind takes the first attachment frame and moves the other attachment frame s...
virtual void computeForces(const agx::Jacobian6DOFElement *jacobians)
Computes the forces, if valid and enabled.
virtual agx::Attachment * userAPIgetAttachment(agx::UInt index) const override
virtual void restoreLightData(agxStream::StorageStream &str) override
virtual void prepare() override
Prepares this constraint.
virtual agx::Bool getLastLocalForce(agx::UInt bodyIndex, agx::Vec3 &retForce, agx::Vec3 &retTorque, agx::Bool giveForceAtCm=false) const override
If 'compute forces' is enabled, returns the last force and torque applied by this constraint on the b...
virtual agx::Attachment * userAPIgetAttachment(const agx::RigidBody *rb) const override
virtual agx::Bool getLastLocalForce(const agx::RigidBody *rb, agx::Vec3 &retForce, agx::Vec3 &retTorque, agx::Bool giveForceAtCm=false) const override
If 'compute forces' is enabled, returns the last force and torque applied by this constraint on the b...
virtual agx::AttachmentPair * getAttachmentPair() const override
virtual void store(agxStream::OutputArchive &out) const override
virtual void setEnableComputeForces(agx::Bool enable) override
Enable (or disable) computation of the forces applied to the dynamic bodies in this constraint.
bool validateRigidBodiesAndAttachments(RigidBody *rb1, Frame *rb1AttachmentFrame, RigidBody *rb2, Frame *rb2AttachmentFrame)
virtual bool updateValid() override
Updates the valid conditions for this constraint.
AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(agx::HighLevelConstraintImplementation)
virtual agx::Bool getEnableComputeForces() const override
Interface to the lower triangle of the compliance matrix block in the system matrix.
Elementary secondary constraint to keep constraint angle at a given target position.
Pointer to a entity instance of type Physics.ConstraintForces.
Elementary secondary constraint to keep constraint angle within two given values.
Base class providing referencing counted objects.
Definition: Referenced.h:120
All ghost variables have compliance and damping attributes.
Constraint attachment class for agx::RigidBody.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:49
Implementation of constraint angle ABOUT an axis.
Implementation of constraint angle ALONG an axis.
Essentially a sparse array of bounds.
Definition: SparseTypes.h:74
Elementary secondary constraint to drive something given target speed (translational or rotational).
Templated vector class.
Definition: agx/Vector.h:53
#define agxAbort()
Definition: debug.h:164
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define CALLABLE
Definition: macros.h:72
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
#define CALLABLE_IGNORE
Definition: macros.h:74
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint16_t UInt16
Definition: Integer.h:31
int32_t Int32
Definition: Integer.h:37
AGXPHYSICS_EXPORT void addSecondaryConstraints1DOF(agx::HighLevelConstraintImplementation *constraint, agx::Angle *angle)
Add secondary controllers with default name to the constraint.
bool Bool
Definition: Integer.h:40
Vector< RigidBody * > ConstraintRigidBodyContainer
uint64_t UInt
Definition: Integer.h:27
double Real
Definition: Real.h:41
std::pair< Real, Real > RealPair
AGXPHYSICS_EXPORT void addSecondaryConstraints2DOF(agx::HighLevelConstraintImplementation *constraint, agx::SeparationAngle *sepAngle, agx::RotationalAngle *rotAngle)
Add secondary controllers with default name to the constraint.
std::valarray< agx::Real > RealValarray
For this module, vectors are defined using valarray.
int64_t Int
Definition: Integer.h:28
STL namespace.
Data from the solver the ConstraintNlmcpCallback is part of.