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;
64 class LSquareComplianceMatrix;
75 : m_numBlocks( 0 ), m_numRows( 0 ), m_numDynBlocks( 0 ) {}
95 BlockType m_numBlocks;
97 BlockType m_numDynBlocks;
107 DEFAULT_BINARY_TAG = NONE,
108 DEFAULT_MANY_BODY_TAG = MANY_BODY
216 agx::UInt getNumRecurrentMergedBodies()
const;
221 ConstraintRigidBodyContainer m_bodies;
224 UInt m_numRecurrentMergedBodies;
231 #if !defined(SWIGPYTHON) 274 const ConstraintRigidBodyContainer& getBodies()
const;
283 const ConstraintRigidBodyContainer& m_bodies;
346 #if !defined(SWIGPYTHON) 366 virtual bool updateValid();
374 virtual void prepare();
390 virtual int getViolation(
agx::Real* g,
int row );
397 agx::Real calculateViolationVectorAverageSize();
409 virtual void getParameters(
agx::Real* violation,
415 int8_t* indexSetState,
426 virtual int getConstraintVelocity(
agx::Real* v,
int row );
450 void onDirectComplianceMatrix(
Real* data,
unsigned int ld )
const;
464 void postSolveIndexSetCallback(
const int8_t* state );
629 virtual void setEnable(
bool enable);
653 virtual void setEnableComputeForces(
agx::Bool enable );
658 virtual agx::Bool getEnableComputeForces()
const;
746 void setEnableLinearization(
bool enable);
751 bool getEnableLinearization()
const;
803 virtual bool removeElementaryConstraint(
const agx::String& name );
810 virtual bool removeSecondaryConstraint(
const agx::String& name );
839 template<
typename T >
840 T* findSecondaryConstraintGivenType(
const agx::UInt count = 0 )
const;
894 void userAPIsetCompliance(
agx::Real compliance,
int dof );
906 void userAPIsetDamping(
agx::Real damping,
int dof );
939 agx::UInt calculateNumActiveRows()
const;
982 SUPPORTS_COMPLIANCE_MATRIX = 1 << 2
1002 void setSupportsComplianceMatrix(
Bool supportsComplianceMatrix );
1041 virtual bool updateValid()
override;
1049 virtual void prepare()
override;
1073 virtual bool rebind()
override;
1099 virtual void setEnableComputeForces(
agx::Bool enable )
override;
1104 virtual agx::Bool getEnableComputeForces()
const override;
1220 bool bodiesValid()
const;
1225 template<
typename T >
1231 template<
typename T >
1232 const T* getAttachment(
agx::UInt index )
const;
1249 return m_numDynamicBodies;
1254 return m_numDynamicBodies;
1259 return m_numNonStaticBodies;
1264 return m_numNonStaticBodies;
1269 return m_originalInfo;
1274 return m_solverInfo;
1279 return m_permutation;
1284 return m_permutation;
1289 return m_bodyIndices;
1294 return m_bodyIndices;
1301 #if !defined(SWIGPYTHON) 1322 return m_bodies.
size();
1340 :
BodyView( state.getSolverInfo(), state.getSolverBodies() ), m_state( state )
1345 :
BodyView( other.m_state.getSolverInfo(), other.m_state.getSolverBodies() ), m_state( other.m_state )
1375 template<
typename T >
1378 UInt currentNumber = 0;
1380 T* ec =
dynamic_cast< T*
>(
m_sc[ i ].get() );
1381 if ( ec !=
nullptr && currentNumber == count )
1383 currentNumber += ec !=
nullptr;
1398 template<
typename T >
1401 return m_attachmentPair[ index ] !=
nullptr ? m_attachmentPair[ index ]->as< T >() :
nullptr;
1404 template<
typename T >
1407 return m_attachmentPair[ index ] !=
nullptr ? m_attachmentPair[ index ]->as< T >() :
nullptr;
1412 return m_attachmentPair[ 0 ] !=
nullptr && !m_attachmentPair[ 0 ]->objectDeleted() &&
1413 m_attachmentPair[ 1 ] !=
nullptr && !m_attachmentPair[ 1 ]->objectDeleted();
1421 return std::atan2( c * b, c * a );
1436 # pragma warning(pop)
std::pair< Real, Real > RealPair
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...
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...
const ConstrainedBodiesState & getState() const
agx::UInt getJacobianRowUsage() const
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.
agx::Bool(* CreateElementaryConstraintsFunction)(class HighLevelConstraintImplementation *)
agx::UInt & numNonStaticBodies()
const agx::ElementaryConstraint::RefContainer & getElementaryConstraints() const
Info with number of dynamic and non-static body counters.
virtual bool getEnable() const
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
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...
bool getSolveBoth() const
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.
Object that holds the state seen from the user and from the solver.
BlockType getNumBlocks() const
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.
Implementation of constraint angle ALONG an axis.
agx::ElementaryConstraint::RefContainer & getElementaryConstraints()
virtual agx::AttachmentPair * getAttachmentPair() const override
Base class providing referencing counted objects.
T * getAttachment(agx::UInt index)
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.
ConstraintImplPtrVector m_subConstraints
Vector with sub-constraints.
Constraint attachment pair class.
agx::UInt getNumNonStaticBodies() const
Constraint attachment base class for any type of frame.
Elementary secondary constraint to keep constraint angle within two given values. ...
BlockType kinBlocks() const
The agx namespace 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.
const agx::Int32Vector & getBodyIndices() const
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()
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...
const agx::Int32Vector & getPermutation() const
const BodiesInfo & getSolverInfo() const
agx::UInt getBlockRowIndex() const
agx::RigidBody * getPermutedBodyAt(agx::UInt i)
const BlockStructure & getBlockStructure() const
Data from the solver the ConstraintNlmcpCallback is part of.
The rigid body class, combining a geometric model and a frame of reference.
ElementaryConstraint::RefContainer m_ec
Vector of elementary constraints.
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
Abstract base class for storing/restoring a line/drums with version control.
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().
agx::UInt getNumBodies() const
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.
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...
const BodiesInfo & getOriginalInfo() const
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.
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.
agx::UInt getNumDynamicBodies() const
#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...
BlockType getNumRows() const
bool getSolveIterative() const
Pointer to a entity instance of type Physics.ConstraintForces.