Simbody
Public Member Functions | Protected Member Functions | Friends

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...

#include <Assembler.h>

Inheritance diagram for SimTK::AssemblyCondition:

List of all members.

Public Member Functions

 AssemblyCondition (const String &name)
 Base class constructor just takes the assembly condition name and saves it.
virtual ~AssemblyCondition ()
 Destructor is virtual for use by derived classes.
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.
virtual void uninitializeCondition () const
 This is called whenever the containing Assembler is uninitialized in case this assembly condition has some cleanup to do.
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.
virtual int calcErrorJacobian (const State &state, Matrix &jacobian) const
 Override to supply an analytic Jacobian for the assembly errors returned by calcErrors().
virtual int getNumErrors (const State &state) const
 Override to supply an efficient method for determining how many errors will be returned by calcErrors().
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.
virtual int calcGoalGradient (const State &state, Vector &gradient) const
 Override to supply an analytic gradient for this assembly condition's goal.
const char * getName () const
 Return the name assigned to this AssemblyCondition on construction.
bool isInAssembler () const
 Test whether this AssemblyCondition has already been adopted by an Assembler.
const AssemblergetAssembler () const
 Return the Assembler that has adopted this AssemblyCondition.
AssemblyConditionIndex getAssemblyConditionIndex () const
 Return the AssemblyConditionIndex of this concrete AssemblyCondition within the Assembler that has adopted it.

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.
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.
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.
const MultibodySystemgetMultibodySystem () const
 Ask the assembler for the MultibodySystem with which it is associated.
const SimbodyMatterSubsystemgetMatterSubsystem () const
 Ask the assembler for the MultibodySystem with which it is associated and extract the SimbodyMatterSubsystem contained therein.
void initializeAssembler () const
 Call this method before doing anything that logically requires the Assembler, or at least this AssemblyCondition, to have been initialized.
void uninitializeAssembler () const
 Call this when modifying any parameter of the concrete AssemblyCondition that would require reinitialization of the Assembler or the AssemblyCondition.

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) [inline, explicit]

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

virtual SimTK::AssemblyCondition::~AssemblyCondition ( ) [inline, virtual]

Destructor is virtual for use by derived classes.


Member Function Documentation

virtual int SimTK::AssemblyCondition::initializeCondition ( ) const [inline, virtual]

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::Markers.

virtual void SimTK::AssemblyCondition::uninitializeCondition ( ) const [inline, virtual]

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

Reimplemented in SimTK::Markers.

virtual int SimTK::AssemblyCondition::calcErrors ( const State state,
Vector err 
) const [inline, virtual]

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::QValue, and SimTK::Markers.

virtual int SimTK::AssemblyCondition::calcErrorJacobian ( const State state,
Matrix jacobian 
) const [inline, virtual]

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::QValue, and SimTK::Markers.

virtual int SimTK::AssemblyCondition::getNumErrors ( const State state) const [inline, virtual]

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::Markers.

virtual int SimTK::AssemblyCondition::calcGoal ( const State state,
Real &  goal 
) const [inline, virtual]

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::QValue, and SimTK::Markers.

virtual int SimTK::AssemblyCondition::calcGoalGradient ( const State state,
Vector gradient 
) const [inline, virtual]

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::QValue, and SimTK::Markers.

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 [inline, protected]

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 [inline, protected]

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 [inline, protected]

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 [inline, protected]

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

const SimbodyMatterSubsystem& SimTK::AssemblyCondition::getMatterSubsystem ( ) const [inline, protected]

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

void SimTK::AssemblyCondition::initializeAssembler ( ) const [inline, protected]

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 [inline, protected]

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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines