AGX Dynamics  2.35.0.1
agx::GenericElementaryConstraint Class Reference

Generic elementary constraint with minimal amount of user callbacks to reduce development/prototype time and trivially exported using SWIG to e.g., Python or C#. More...

#include <GenericElementaryConstraint.h>

+ Inheritance diagram for agx::GenericElementaryConstraint:

Public Member Functions

 GenericElementaryConstraint (agx::UInt numRows)
 Construct given the number of rows in this elementary constraint. More...
 
 GenericElementaryConstraint (agx::UInt numRows, agx::Bool enable)
 Construct given the number of rows in this elementary constraint and default enable flag. More...
 
void fetchData ()
 Performing callbacks and collecting data in serial. More...
 
const agx::AttachmentPair * getAttachmentPair () const
 
agx::UInt getBounds (agx::RangeReal *bounds, agx::UInt row, agx::Real h) const override
 Returns the bounds of the Lagrange Multipliers (default (-inf, +inf)). More...
 
agx::Bool getEnableMultiTangentNlCallback () const
 
agx::UInt getJacobian (agx::Jacobian6DOFElement *G, agx::UInt numBlocks, agx::UInt row, agx::GWriteState::Enum writeState) override
 Returns the Jacobian of this elementary constraint. More...
 
agx::ConstraintNlmcpCallback * getNlCallback () const override
 
agx::UInt getVelocity (agx::Real *v, agx::UInt row) const override
 Returns the velocity of this elementary constraint (extra, driving term on the right hand side). More...
 
agx::UInt getViolation (agx::Real *g, agx::UInt row) override
 Returns the violation of this elementary constraint. More...
 
agx::Bool isActive () const override
 An elementary constraint is defined to be active if enabled. More...
 
agx::Bool isImpacting () const override
 
virtual agx::Bool onPrepare ()
 Callback when the elementary constraints in the constraint receives the prepare call. More...
 
virtual void onWriteData (agx::GenericConstraintBodyData *rb1Data, agx::GenericConstraintBodyData *rb2Data, agx::GenericConstraintData *constraintData)
 Callback when to write Jacobian and constraint data if this elementary constraint is active. More...
 
void prepare () override
 Prepare call. More...
 
void setAttachmentPair (const agx::AttachmentPair *ap) override
 Call for elementary constraints dependent on attachment pairs. More...
 
void setEnableMultiTangentNlCallback (agx::Bool enable, agx::Real primaryFrictionCoefficient, agx::Real secondaryFrictionCoefficient, const agx::Vec3 &contactPointPosition)
 
- Public Member Functions inherited from agx::ElementaryConstraint
 AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE (agx::ElementaryConstraint)
 
void copyRowFrom (const ElementaryConstraint *source, agx::UInt sourceRow, agx::UInt destRow)
 Copy configuration row from the given ElementaryConstraint into this. More...
 
agx::Real getCompliance (agx::UInt row=0) const
 
virtual agx::Real getCurrentForce (const agx::UInt row=0) const
 Returns the force applied last time step by this elementary constraint. More...
 
const agx::Real * getCurrentForces () const
 
agx::Real getDamping (agx::UInt row=0) const
 
agx::Real getElasticity (agx::UInt row=0) const
 
virtual agx::Bool getEnable () const
 
agx::RangeReal & getForceRange (const agx::UInt row=0)
 
const agx::RangeReal & getForceRange (const agx::UInt row=0) const
 
const agx::ElementaryConstraint::NameType & getName () const
 
agx::UInt getNumRows () const
 
agx::RegularizationParameters * getRegularizationParameters (const agx::UInt row=0)
 
const agx::RegularizationParameters * getRegularizationParameters (const agx::UInt row=0) const
 
virtual void linearizeCompliance (const agx::Real *violations, agx::Real *epsilons, agx::Real minPerturbation) const
 Modify epsilon so that this ElementaryConstraint appear to be linear in the "normal" deformantion space instead any other space that the ElementaryConstraint may be using. More...
 
virtual agx::UInt postSolveCallback (const agx::Real *solution, agx::UInt row, agx::Real h)
 Callback after solve, with the solution. More...
 
void reset ()
 Reset call. More...
 
virtual void restore (agxStream::InputArchive &in) override
 Restore this object from stream. More...
 
virtual void restoreLightData (agxStream::StorageStream &str) override
 Restore structural independent data from stream. More...
 
void setCompliance (agx::Real compliance)
 
void setCompliance (agx::Real compliance, int row)
 Assign compliance for a given row, or all rows if row = -1 (default). More...
 
void setDamping (agx::Real damping)
 
void setDamping (agx::Real damping, int row)
 Assign damping for a given row, or all rows if row = -1 (default). More...
 
void setElasticity (agx::Real elasticity)
 
void setElasticity (agx::Real elasticity, int row)
 Assign elasticity for a given row, or all rows if row = -1 (default). More...
 
virtual void setEnable (agx::Bool enable)
 Enable/disable this elementary constraint. More...
 
void setForceRange (agx::RangeReal forceRange, const agx::UInt row=0)
 Assign force range to a given row. More...
 
void setForceRange (agx::Real lower, agx::Real upper, const agx::UInt row=0)
 Assign force range to a given row. More...
 
void setName (const agx::ElementaryConstraint::NameType &name)
 Name this elementary constraint. More...
 
virtual void store (agxStream::OutputArchive &out) const override
 Store this object to stream. More...
 
virtual void storeLightData (agxStream::StorageStream &str) const override
 Store structural independent data to stream. More...
 
- Public Member Functions inherited from agx::Referenced
 Referenced ()
 Default constructor. More...
 
 Referenced (const Referenced &)
 
template<typename T >
T * as ()
 Subclass casting. More...
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match. More...
 
template<typename T >
const T * asSafe () const
 
int getReferenceCount () const
 
template<typename T >
bool is () const
 Subclass test. More...
 
Referenced & operator= (const Referenced &)
 Assignment operator. Will increment the number of references to the referenced object. More...
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
- Public Member Functions inherited from agxStream::Serializable
virtual ~Serializable ()
 Destructor for normal C++ use but hidden from SWIG bindings. More...
 
virtual const char * getClassName () const
 
bool getEnableSerialization () const
 
bool getEnableUuidGeneration ()
 
agx::UInt32 getIndex () const
 This index is given at creation of this object. More...
 
virtual StorageAgent * getStorageAgent () const =0
 
agx::Uuid getUuid () const
 
bool isFinished () const
 
void setEnableSerialization (bool flag)
 Set to false to disable serialization of this object. More...
 
void setFinished ()
 Tells this class that it is restored correctly and should not be deleted during destruction of an Archive. More...
 
void setUuid (const agx::Uuid &uuid)
 Explicitly set a Uuid on a serializable object. More...
 

Protected Member Functions

virtual ~GenericElementaryConstraint ()
 
- Protected Member Functions inherited from agx::ElementaryConstraint
 ElementaryConstraint (agx::Bool enable, agx::UInt numRows, agx::RegularizationParameters *regParamsBuffer, agx::Real *lastForcesBuffer, agx::RangeReal *userBoundsBuffer)
 Construct given data. More...
 
virtual ~ElementaryConstraint ()
 Reference counted object, protected destructor. More...
 
- Protected Member Functions inherited from agx::Referenced
virtual ~Referenced ()
 Destructor. More...
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 
- Protected Member Functions inherited from agxStream::Serializable
 Serializable ()
 Default constructor. More...
 
 Serializable (const Serializable &other)
 Copy constructor. More...
 
void generateUuid ()
 

Additional Inherited Members

- Public Types inherited from agx::ElementaryConstraint
typedef agx::Name NameType
 
typedef agx::VectorPOD< agx::ElementaryConstraint * > PtrContainer
 
typedef agx::Vector< agx::ref_ptr< agx::ElementaryConstraint > > RefContainer
 
- Static Public Member Functions inherited from agx::Referenced
template<typename T >
static bool ValidateCast (const Referenced *object)
 
- Static Public Member Functions inherited from agxStream::Serializable
static void setEnableUuidGeneration (bool flag)
 Specify if there should be UUID:s generated for each new Serializable object. By default it is enabled. More...
 
- Static Protected Member Functions inherited from agx::Referenced
static DeleteHandler * getDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to. More...
 
- Protected Attributes inherited from agx::ElementaryConstraint
agx::Bool m_enable
 enabled More...
 
agx::ref_ptr< agx::Referenced > m_internalData
 custom, internal data More...
 
agx::Real * m_lfs
 last forces More...
 
agx::ElementaryConstraint::NameType m_name
 name More...
 
agx::UInt m_numRows
 number of rows More...
 
agx::RegularizationParameters * m_rps
 regularization parameters More...
 
agx::RangeReal * m_ubs
 user bounds
More...
 
- Protected Attributes inherited from agx::Referenced
Mutex m_mutex
 
ObserverContainer m_observers
 
AtomicValue m_refCount
 

Detailed Description

Generic elementary constraint with minimal amount of user callbacks to reduce development/prototype time and trivially exported using SWIG to e.g., Python or C#.

This elementary constraint is only valid for one or two body constraints.

Python example for elementary Dot1: class MyDot1(agx.GenericElementaryConstraint): def init(self, dir1, dir2): super().__init__( 1 ) self.dir1 = dir1 self.dir2 = dir2

def onWriteData(self, rb1Data: agx.GenericConstraintBodyData, rb2Data: agx.GenericConstraintBodyData, constraintData: agx.GenericConstraintData): a1 = self.getAttachmentPair().getAttachment1() # type: agx.Attachment a2 = self.getAttachmentPair().getAttachment2() # type: agx.Attachment v1 = a1.get( self.dir1 ) # type: agx.Vec3 v2 = a2.get( self.dir2 ) # type: agx.Vec3

rb1Data.setJacobian( 0, agx.Vec3(), v1.cross( v2 ) ) rb2Data.setJacobian( 0, agx.Vec3(), v2.cross( v1 ) ) constraintData.setViolation( 0, v1 * v2 )

myHinge.addElementaryConstraint( "D1_VN", MyDot1( agx.Attachment.V, agx.Attachment.N ) ) myHinge.addElementaryConstraint( "D1_UN", MyDot1( agx.Attachment.U, agx.Attachment.N ) )

Definition at line 53 of file GenericElementaryConstraint.h.

Constructor & Destructor Documentation

◆ GenericElementaryConstraint() [1/2]

agx::GenericElementaryConstraint::GenericElementaryConstraint ( agx::UInt  numRows)

Construct given the number of rows in this elementary constraint.

Note
Using this constructor the enable flag is set to true.
Parameters
numRows- number of rows in this elementary constraint

◆ GenericElementaryConstraint() [2/2]

agx::GenericElementaryConstraint::GenericElementaryConstraint ( agx::UInt  numRows,
agx::Bool  enable 
)

Construct given the number of rows in this elementary constraint and default enable flag.

Parameters
numRows- number of rows in this elementary constraint
enable- true to be enabled by default, false disabled

◆ ~GenericElementaryConstraint()

virtual agx::GenericElementaryConstraint::~GenericElementaryConstraint ( )
protectedvirtual

Member Function Documentation

◆ fetchData()

void agx::GenericElementaryConstraint::fetchData ( )

Performing callbacks and collecting data in serial.

◆ getAttachmentPair()

const agx::AttachmentPair* agx::GenericElementaryConstraint::getAttachmentPair ( ) const
Returns
the attachment pair in the constraint

◆ getBounds()

agx::UInt agx::GenericElementaryConstraint::getBounds ( agx::RangeReal *  bounds,
agx::UInt  row,
agx::Real  h 
) const
overridevirtual

Returns the bounds of the Lagrange Multipliers (default (-inf, +inf)).

Note that the bounds buffer has to be provided by the caller.

Note
Dimension of the Lagrange Multipliers are Force * Time (argument h = time step length).
Parameters
bounds- bounds buffer
row- start row in bounds buffer bounds
h- current time step length
Returns
the number of rows used (= elements written) in the bounds buffer

Reimplemented from agx::ElementaryConstraint.

◆ getEnableMultiTangentNlCallback()

agx::Bool agx::GenericElementaryConstraint::getEnableMultiTangentNlCallback ( ) const

◆ getJacobian()

agx::UInt agx::GenericElementaryConstraint::getJacobian ( agx::Jacobian6DOFElement *  G,
agx::UInt  numBlocks,
agx::UInt  row,
agx::GWriteState::Enum  writeState 
)
overridevirtual

Returns the Jacobian of this elementary constraint.

Note that the Jacobian buffer has to be provided by the caller.

Parameters
G- Jacobian buffer
numBlocks- number of blocks in the global Jacobian (e.g., number of bodies in the main constraint)
row- start row in Jacobian buffer
writeState- state of the main constraint (the order in which the Jacobian is written defines this state)
Returns
the number of elements used in G

Reimplemented from agx::ElementaryConstraint.

◆ getNlCallback()

agx::ConstraintNlmcpCallback* agx::GenericElementaryConstraint::getNlCallback ( ) const
overridevirtual
Returns
solver callback instance if supported by this elementary constraint

Reimplemented from agx::ElementaryConstraint.

◆ getVelocity()

agx::UInt agx::GenericElementaryConstraint::getVelocity ( agx::Real *  v,
agx::UInt  row 
) const
overridevirtual

Returns the velocity of this elementary constraint (extra, driving term on the right hand side).

Note that the velocity buffer has to be provided by the caller.

Parameters
v- velocity buffer
row- start row in velocity buffer v
Returns
the number of rows used (= elements written) in velocity buffer

Reimplemented from agx::ElementaryConstraint.

◆ getViolation()

agx::UInt agx::GenericElementaryConstraint::getViolation ( agx::Real *  g,
agx::UInt  row 
)
overridevirtual

Returns the violation of this elementary constraint.

Note that the violation buffer has to be provided by the caller.

Parameters
g- violation buffer
row- start row in violation buffer g
Returns
the number of rows used (= elements written) in violation buffer

Reimplemented from agx::ElementaryConstraint.

◆ isActive()

agx::Bool agx::GenericElementaryConstraint::isActive ( ) const
overridevirtual

An elementary constraint is defined to be active if enabled.

Yet constraints can be enabled but not active (e.g., RangeController when the range isn't exceeded).

Returns
true if this elementary constraint is active - otherwise false

Reimplemented from agx::ElementaryConstraint.

◆ isImpacting()

agx::Bool agx::GenericElementaryConstraint::isImpacting ( ) const
overridevirtual
Returns
true of this elementary constraint is impacting

Reimplemented from agx::ElementaryConstraint.

◆ onPrepare()

virtual agx::Bool agx::GenericElementaryConstraint::onPrepare ( )
virtual

Callback when the elementary constraints in the constraint receives the prepare call.

The return value defines if this elementary constraint is active or not (regardless of the enable flag). When this elementary constraint isn't active, onWriteData won't be called.

Returns
true if this elementary constraint is active, false if inactive

◆ onWriteData()

virtual void agx::GenericElementaryConstraint::onWriteData ( agx::GenericConstraintBodyData *  rb1Data,
agx::GenericConstraintBodyData *  rb2Data,
agx::GenericConstraintData *  constraintData 
)
virtual

Callback when to write Jacobian and constraint data if this elementary constraint is active.

Parameters
rb1Data- constraint body data (Jacobian) for the first rigid body in the constraint
rb2Data- constraint body data (Jacobian) for the second rigid body in the constraint
constraintData- constraint data for this elementary constraint

◆ prepare()

void agx::GenericElementaryConstraint::prepare ( )
overridevirtual

Prepare call.

After this call the elementary constraint may be activated.

Reimplemented from agx::ElementaryConstraint.

◆ setAttachmentPair()

void agx::GenericElementaryConstraint::setAttachmentPair ( const agx::AttachmentPair *  ap)
overridevirtual

Call for elementary constraints dependent on attachment pairs.

Ignored by this base class.

Reimplemented from agx::ElementaryConstraint.

◆ setEnableMultiTangentNlCallback()

void agx::GenericElementaryConstraint::setEnableMultiTangentNlCallback ( agx::Bool  enable,
agx::Real  primaryFrictionCoefficient,
agx::Real  secondaryFrictionCoefficient,
const agx::Vec3 &  contactPointPosition 
)

The documentation for this class was generated from the following file: