17 #ifndef AGX_CONSTRAINT_IMPLEMENTATION_H
18 #define AGX_CONSTRAINT_IMPLEMENTATION_H
35 # pragma warning(push)
36 # pragma warning( disable : 4251 ) // class X needs to have dll-interface to be used by clients of class Y
39 #define DEFAULT_COMPLIANCE 1.0E-8
41 #define CONSTRAINT_SUCCESS( success ) \
43 LOGGER_WARNING() << "Unable to create constraint. Constraint cleared." << std::endl << LOGGER_END(); \
45 m_localState.remove( VALID ); \
49 #define CONSTRAINT_SUCCESS_RETURN_BOOL( success ) \
51 LOGGER_WARNING() << "Unable to create constraint. Constraint cleared." << std::endl << LOGGER_END(); \
53 m_localState.remove( VALID ); \
60 class ElementaryConstraint;
62 class RegularizationParameters;
63 class SparseRangeReal;
74 : m_numBlocks( 0 ), m_numRows( 0 ), m_numDynBlocks( 0 ) {}
106 DEFAULT_BINARY_TAG = NONE,
107 DEFAULT_MANY_BODY_TAG = MANY_BODY
215 agx::UInt getNumRecurrentMergedBodies()
const;
223 UInt m_numRecurrentMergedBodies;
230 #if !defined(SWIGPYTHON)
345 #if !defined(SWIGPYTHON)
365 virtual bool updateValid();
373 virtual void prepare();
389 virtual int getViolation(
agx::Real* g,
int row );
396 agx::Real calculateViolationVectorAverageSize();
408 virtual void getParameters(
agx::Real* violation,
414 int8_t* indexSetState,
425 virtual int getConstraintVelocity(
agx::Real* v,
int row );
449 void onDirectComplianceMatrix(
Real* data,
unsigned int ld )
const;
463 void postSolveIndexSetCallback(
const int8_t* state );
628 virtual void setEnable(
bool enable);
652 virtual void setEnableComputeForces(
agx::Bool enable );
657 virtual agx::Bool getEnableComputeForces()
const;
745 void setEnableLinearization(
bool enable);
750 bool getEnableLinearization()
const;
802 virtual bool removeElementaryConstraint(
const agx::String& name );
809 virtual bool removeSecondaryConstraint(
const agx::String& name );
838 template<
typename T >
839 T* findSecondaryConstraintGivenType(
const agx::UInt count = 0 )
const;
893 void userAPIsetCompliance(
agx::Real compliance,
int dof );
905 void userAPIsetDamping(
agx::Real damping,
int dof );
938 agx::UInt calculateNumActiveRows()
const;
960 void setInternalData( agx::
Referenced* data );
965 AGX_FORCE_INLINE agxSDK::SimulationProxy* getSimulationProxy() {
return m_simulationProxy; }
981 SUPPORTS_COMPLIANCE_MATRIX = 1 << 2
1001 void setSupportsComplianceMatrix(
Bool supportsComplianceMatrix );
1040 virtual bool updateValid()
override;
1048 virtual void prepare()
override;
1077 virtual bool rebind()
override;
1103 virtual void setEnableComputeForces(
agx::Bool enable )
override;
1108 virtual agx::Bool getEnableComputeForces()
const override;
1224 bool bodiesValid()
const;
1229 template<
typename T >
1235 template<
typename T >
1236 const T* getAttachment(
agx::UInt index )
const;
1253 return m_numDynamicBodies;
1258 return m_numDynamicBodies;
1263 return m_numNonStaticBodies;
1268 return m_numNonStaticBodies;
1273 return m_originalInfo;
1278 return m_solverInfo;
1283 return m_permutation;
1288 return m_permutation;
1293 return m_bodyIndices;
1298 return m_bodyIndices;
1305 #if !defined(SWIGPYTHON)
1316 return m_info.numDynamicBodies();
1321 return m_info.numNonStaticBodies();
1344 :
BodyView( state.getSolverInfo(), state.getSolverBodies() ), m_state( state )
1349 :
BodyView( other.m_state.getSolverInfo(), other.m_state.getSolverBodies() ), m_state( other.m_state )
1365 agxAssert( i < m_state.getPermutation().size() );
1366 UInt permutedIndex = (
UInt)m_state.getPermutation()[ i ];
1367 agxAssert( permutedIndex < getNumBodies() );
1368 return getBodyAt( permutedIndex );
1373 agxAssert( i < m_state.getPermutation().size() );
1374 UInt permutedIndex = (
UInt)m_state.getPermutation()[ i ];
1375 agxAssert( permutedIndex < getNumBodies() );
1376 return getBodyAt( permutedIndex );
1379 template<
typename T >
1382 UInt currentNumber = 0;
1384 T* ec =
dynamic_cast< T*
>(
m_sc[ i ].get() );
1385 if ( ec !=
nullptr && currentNumber == count )
1387 currentNumber += ec !=
nullptr;
1402 template<
typename T >
1405 return m_attachmentPair[ index ] !=
nullptr ? m_attachmentPair[ index ]->as< T >() :
nullptr;
1408 template<
typename T >
1411 return m_attachmentPair[ index ] !=
nullptr ? m_attachmentPair[ index ]->as< T >() :
nullptr;
1416 return m_attachmentPair[ 0 ] !=
nullptr && !m_attachmentPair[ 0 ]->objectDeleted() &&
1417 m_attachmentPair[ 1 ] !=
nullptr && !m_attachmentPair[ 1 ]->objectDeleted();
1425 return std::atan2( c * b, c * a );
1440 # pragma warning(pop)
std::pair< Real, Real > RealPair
agx::UInt getNumNonStaticBodies() const
BlockType getNumBlocks() const
const ConstrainedBodiesState & getState() const
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...
AGXPHYSICS_EXPORT void addSecondaryConstraints2DOF(agx::HighLevelConstraintImplementation *constraint, agx::SeparationAngle *sepAngle, agx::RotationalAngle *rotAngle)
Add secondary controllers with default name to the constraint.
agx::RigidBody * getBodyAt(agx::UInt i)
int m_tag
Tag for this constraint.
virtual void removeNotification()
Callback when this constraint is removed from Simulation.
Constraint::SolveType getSolveType() const
agx::UInt & numNonStaticBodies()
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.
const BodiesInfo & getOriginalInfo() const
UInt m_numRows
Number of rows used by this constraint.
const agx::ConstraintRigidBodyContainer & getSolverBodies() const
bool m_enable
User controlled enable flag, constraint ignored by solver if false.
bool getSolveIterative() const
virtual bool rebind()
The general version of rebind takes the first attachment frame and moves the other attachment frame s...
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...
BlockType dynBlocks() const
ConstraintRigidBodyContainer m_bodies
Vector with observer pointers to bodies.
#define AGXPHYSICS_EXPORT
The base class for a constraint.
ConstrainedBodiesState m_constrainedBodiesState
State of the included bodies, updated in updateValid.
agx::Bool(* CreateElementaryConstraintsFunction)(class HighLevelConstraintImplementation *)
virtual agx::AttachmentPair * getAttachmentPair() const
Object that holds the state seen from the user and from the solver.
Constraint attachment class for agx::RigidBody.
virtual void preSystemCallback(DynamicsSystem *system)
Before prepare, and before the system writes to the data buffers, this constraint gets a call with th...
Translational or rotational friction controller for Hinge, Prismatic and CylindricalJoint.
BlockType getNumRows() const
virtual bool getEnable() const
Implementation of constraint angle ALONG an axis.
agx::ElementaryConstraint::RefContainer & getElementaryConstraints()
virtual agx::AttachmentPair * getAttachmentPair() const override
virtual agx::Attachment * userAPIgetAttachment(agx::UInt) const
Base class providing referencing counted objects.
T * getAttachment(agx::UInt index)
Constraint::SolveType m_solveType
Only for supported solvers.
const ConstraintImplPtrVector & getSubConstraints() 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...
const agx::Int32Vector & getBodyIndices() const
Essentially a sparse array of bounds.
ConstraintImplPtrVector m_subConstraints
Vector with sub-constraints.
Constraint attachment pair class.
Constraint attachment base class for any type of frame.
Elementary secondary constraint to keep constraint angle within two given values. ...
agx::UInt getNumBodies() const
agx::UInt getNumDynamicBodies() const
agx::UInt getJacobianRowUsage() const
const agx::ElementaryConstraint::RefContainer & getElementaryConstraints() const
agx::BitState< State, Int32 > LocalState
const BlockStructure & getBlockStructure() const
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.
agx::UInt & numDynamicBodies()
Vector< RigidBody * > ConstraintRigidBodyContainer
ConstraintImplPtrVector & getSubConstraints()
agx::ElementaryConstraint::RefContainer & getSecondaryConstraints()
Interface to the bodies, either user or solver, since these bodies can differ when e...
agx::RigidBody * getPermutedBodyAt(agx::UInt i)
The rigid body class, combining a geometric model and a frame of reference.
ElementaryConstraint::RefContainer m_ec
Vector of elementary constraints.
const agx::ElementaryConstraint::RefContainer & getSecondaryConstraints() const
Interface to the lower triangle of the compliance matrix block in the system matrix.
const BodiesInfo & getSolverInfo() const
The complete physical system with bodies, interactions, data layout, time stepper, and solver.
T * findSecondaryConstraintGivenType(const agx::UInt count=0) const
Abstract base class for storing/restoring a line/drums with version control.
void incrementConstraintCount(RigidBody *rb) const
Increment the number of constraints connection to rb.
const agx::Int32Vector & getPermutation() const
All ghost variables have compliance and damping attributes.
SolveType
Specifies in what solvers the constraint will be solved.
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.
SolverBodyView(ConstrainedBodiesState &state)
Internal, use ConstriantImplementation::getSolverView().
UInt m_blockRowIndex
Start block row for this constraint in the global matrix.
AttachmentPair m_attachmentPair
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Elementary secondary constraint to drive something given target speed (translational or rotational)...
Class for writing serialized data in binary format to a stream.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Solved both in the ITERATIVE and the DIRECT solver.
agx::UInt getBlockRowIndex() const
void * customData
Custom data for the solvers to store data into.
virtual agx::Attachment * userAPIgetAttachment(const agx::RigidBody *) const
BlockType kinBlocks() const
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Implementation of constraint angle ABOUT an axis.
BodyView(const ConstrainedBodiesState::BodiesInfo &info, const ConstraintRigidBodyContainer &bodies)
Internal, use ConstriantImplementation::getUserView().
void setNumRows(BlockType numRows)
Interface class used by internal objects running in parallel.
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.
LocalState m_localState
Current local state, updated all the time, not serialized.
const ConstraintRigidBodyContainer & getBodies() const
bool getSolveBoth() const
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()
ElementaryConstraint::RefContainer m_sc
Vector of secondary constraints.
#define DOXYGEN_START_INTERNAL_BLOCK()
bool m_enableLinearization
When necessary, tweak the values sent to the solver to make violation depend linearly on force or tor...
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...
Pointer to a entity instance of type Physics.ConstraintForces.