Simbody  3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SimTK::AssemblyCondition Class Reference

Define an assembly condition consisting of a scalar goal and/or a related set of assembly error equations (that is, an objective and/or some constraints). More...

+ Inheritance diagram for SimTK::AssemblyCondition:

Public Member Functions

 AssemblyCondition (const String &name)
 Base class constructor just takes the assembly condition name and saves it. More...
 
virtual ~AssemblyCondition ()
 Destructor is virtual for use by derived classes. More...
 
virtual int initializeCondition () const
 This is called whenever the Assembler is initialized in case this assembly condition wants to do some internal work before getting started. More...
 
virtual void uninitializeCondition () const
 This is called whenever the containing Assembler is uninitialized in case this assembly condition has some cleanup to do. More...
 
virtual int calcErrors (const State &state, Vector &err) const
 Calculate the amount by which this assembly condition is violated by the q values in the given state, with one scalar error per assembly equation returned in err. More...
 
virtual int calcErrorJacobian (const State &state, Matrix &jacobian) const
 Override to supply an analytic Jacobian for the assembly errors returned by calcErrors(). More...
 
virtual int getNumErrors (const State &state) const
 Override to supply an efficient method for determining how many errors will be returned by calcErrors(). More...
 
virtual int calcGoal (const State &state, Real &goal) const
 Calculate the current contribution (>= 0) of this assembly condition to the goal value that is being minimized. More...
 
virtual int calcGoalGradient (const State &state, Vector &gradient) const
 Override to supply an analytic gradient for this assembly condition's goal. More...
 
const char * getName () const
 Return the name assigned to this AssemblyCondition on construction. More...
 
bool isInAssembler () const
 Test whether this AssemblyCondition has already been adopted by an Assembler. More...
 
const AssemblergetAssembler () const
 Return the Assembler that has adopted this AssemblyCondition. More...
 
AssemblyConditionIndex getAssemblyConditionIndex () const
 Return the AssemblyConditionIndex of this concrete AssemblyCondition within the Assembler that has adopted it. More...
 

Protected Member Functions

int getNumFreeQs () const
 Ask the assembler how many free q's there are; only valid after initialization but does not invoke initialization. More...
 
QIndex getQIndexOfFreeQ (Assembler::FreeQIndex fx) const
 Ask the assembler where to find the actual q in the State that corresponds to a given free q; only valid after initialization but does not invoke initialization. More...
 
Assembler::FreeQIndex getFreeQIndexOfQ (QIndex qx) const
 Ask the assembler where to find the free q (if any) that corresponds to a given q in the State; only valid after initialization but does not invoke initialization. More...
 
const MultibodySystemgetMultibodySystem () const
 Ask the assembler for the MultibodySystem with which it is associated. More...
 
const SimbodyMatterSubsystemgetMatterSubsystem () const
 Ask the assembler for the MultibodySystem with which it is associated and extract the SimbodyMatterSubsystem contained therein. More...
 
void initializeAssembler () const
 Call this method before doing anything that logically requires the Assembler, or at least this AssemblyCondition, to have been initialized. More...
 
void uninitializeAssembler () const
 Call this when modifying any parameter of the concrete AssemblyCondition that would require reinitialization of the Assembler or the AssemblyCondition. More...
 

Friends

class Assembler
 

Detailed Description

Define an assembly condition consisting of a scalar goal and/or a related set of assembly error equations (that is, an objective and/or some constraints).

Whether the goal or error is used depends on the weighting assigned to this AssemblyCondition. A finite weight indicates that the goal should be used (and combined with other goals); an infinite weighting means that each error must independently be satisfied to tolerance.

Constructor & Destructor Documentation

SimTK::AssemblyCondition::AssemblyCondition ( const String name)
inlineexplicit

Base class constructor just takes the assembly condition name and saves it.

virtual SimTK::AssemblyCondition::~AssemblyCondition ( )
inlinevirtual

Destructor is virtual for use by derived classes.

Member Function Documentation

virtual int SimTK::AssemblyCondition::initializeCondition ( ) const
inlinevirtual

This is called whenever the Assembler is initialized in case this assembly condition wants to do some internal work before getting started.

None of the other virtual methods will be called until this one has been, except possibly the destructor. The set of free q's and the internal State are valid at this point and can be retrieved from the Assembler stored in the base class.

Reimplemented in SimTK::OrientationSensors, and SimTK::Markers.

virtual void SimTK::AssemblyCondition::uninitializeCondition ( ) const
inlinevirtual

This is called whenever the containing Assembler is uninitialized in case this assembly condition has some cleanup to do.

Reimplemented in SimTK::OrientationSensors, and SimTK::Markers.

virtual int SimTK::AssemblyCondition::calcErrors ( const State state,
Vector err 
) const
inlinevirtual

Calculate the amount by which this assembly condition is violated by the q values in the given state, with one scalar error per assembly equation returned in err.

The functional return should be zero if successful; negative values are reserved with -1 meaning "not implemented"; return a positive value if your implementation is unable to evaluate the error at the current state. If this method is not implemented then you must implement calcGoal() and this assembly condition may only be used as a goal, not a requirement.

Reimplemented in SimTK::OrientationSensors, SimTK::Markers, and SimTK::QValue.

virtual int SimTK::AssemblyCondition::calcErrorJacobian ( const State state,
Matrix jacobian 
) const
inlinevirtual

Override to supply an analytic Jacobian for the assembly errors returned by calcErrors().

The returned Jacobian must be nErr X nFreeQs; that is, if there is only one assembly error equation the returned matrix is a single row (that's the transpose of the gradient). The functional return should be zero if this succeeds; negative values are reserved with the default implementation returning -1 which indicates that the Jacobian must be calculated numerically using the calcErrors() method. Return a positive value if your implementation is unable to evaluate the Jacobian at the current state.

Reimplemented in SimTK::OrientationSensors, SimTK::Markers, and SimTK::QValue.

virtual int SimTK::AssemblyCondition::getNumErrors ( const State state) const
inlinevirtual

Override to supply an efficient method for determining how many errors will be returned by calcErrors().

Otherwise the default implementation determines this by making a call to calcErrors() and returning the size of the returned error vector. The functional return should be zero if this succeeds; negative values are reserved; return a positive value if your implementation of this method can't determine the number of errors with the given state (unlikely!).

Reimplemented in SimTK::OrientationSensors, and SimTK::Markers.

virtual int SimTK::AssemblyCondition::calcGoal ( const State state,
Real goal 
) const
inlinevirtual

Calculate the current contribution (>= 0) of this assembly condition to the goal value that is being minimized.

If this isn't overridden we'll generate it by combining the m errors returned by calcErrors() in a mean sum of squares: goal = err^2/m.

Reimplemented in SimTK::OrientationSensors, SimTK::Markers, and SimTK::QValue.

virtual int SimTK::AssemblyCondition::calcGoalGradient ( const State state,
Vector gradient 
) const
inlinevirtual

Override to supply an analytic gradient for this assembly condition's goal.

The returned gradient must be nFreeQ X 1; that is, it is a column vector giving the partial derivative of the goal with respect to each of the free q's in order. The functional return should be zero if this succeeds. The default implementation return -1 which indicates that the gradient must be calculated numerically using the calcGoal() method.

Reimplemented in SimTK::OrientationSensors, SimTK::Markers, and SimTK::QValue.

const char* SimTK::AssemblyCondition::getName ( ) const
inline

Return the name assigned to this AssemblyCondition on construction.

bool SimTK::AssemblyCondition::isInAssembler ( ) const
inline

Test whether this AssemblyCondition has already been adopted by an Assembler.

const Assembler& SimTK::AssemblyCondition::getAssembler ( ) const
inline

Return the Assembler that has adopted this AssemblyCondition.

This will throw an exception if there is no such Assembler; use isInAssembler() first if you're not sure.

AssemblyConditionIndex SimTK::AssemblyCondition::getAssemblyConditionIndex ( ) const
inline

Return the AssemblyConditionIndex of this concrete AssemblyCondition within the Assembler that has adopted it.

This returned index will be invalid if this AssemblyCondition has not yet been adopted.

int SimTK::AssemblyCondition::getNumFreeQs ( ) const
inlineprotected

Ask the assembler how many free q's there are; only valid after initialization but does not invoke initialization.

QIndex SimTK::AssemblyCondition::getQIndexOfFreeQ ( Assembler::FreeQIndex  fx) const
inlineprotected

Ask the assembler where to find the actual q in the State that corresponds to a given free q; only valid after initialization but does not invoke initialization.

Assembler::FreeQIndex SimTK::AssemblyCondition::getFreeQIndexOfQ ( QIndex  qx) const
inlineprotected

Ask the assembler where to find the free q (if any) that corresponds to a given q in the State; only valid after initialization but does not invoke initialization.

const MultibodySystem& SimTK::AssemblyCondition::getMultibodySystem ( ) const
inlineprotected

Ask the assembler for the MultibodySystem with which it is associated.

const SimbodyMatterSubsystem& SimTK::AssemblyCondition::getMatterSubsystem ( ) const
inlineprotected

Ask the assembler for the MultibodySystem with which it is associated and extract the SimbodyMatterSubsystem contained therein.

void SimTK::AssemblyCondition::initializeAssembler ( ) const
inlineprotected

Call this method before doing anything that logically requires the Assembler, or at least this AssemblyCondition, to have been initialized.

void SimTK::AssemblyCondition::uninitializeAssembler ( ) const
inlineprotected

Call this when modifying any parameter of the concrete AssemblyCondition that would require reinitialization of the Assembler or the AssemblyCondition.

Friends And Related Function Documentation

friend class Assembler
friend

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