OpenSim Moco  0.4.0
Public Member Functions | List of all members
OpenSim::MocoProblemRep Class Reference

Description

The primary intent of this class is for use by MocoSolvers, but users can also use this class to apply parameter values to the model and evaluate cost terms.

This class also checks the MocoProblem for various errors. To get an instance of this class, use MocoProblem::createRep(). This interface currently supports only single-phase problems. This class stores a reference (not a copy) to the original MocoProblem from which it was created.

#include <Moco/Moco/MocoProblemRep.h>

Public Member Functions

 MocoProblemRep (const MocoProblemRep &)=delete
 
MocoProblemRepoperator= (const MocoProblemRep &)=delete
 
 MocoProblemRep (MocoProblemRep &&source)
 
MocoProblemRepoperator= (MocoProblemRep &&source)
 
const std::string & getName () const
 
const Model & getModelBase () const
 Get a reference to the copy of the model being used by this MocoProblemRep. More...
 
SimTK::State & updStateBase () const
 This is a state object that solvers can use along with ModelBase.
 
const Model & getModelDisabledConstraints () const
 Get a reference to a copy of the model being used by this MocoProblemRep, but with all constraints disabled and an additional DiscreteForces component. More...
 
SimTK::State & updStateDisabledConstraints (int index=0) const
 This is a state object that solvers can use with ModelDisabledConstraints. More...
 
const DiscreteForcesgetConstraintForces () const
 This is a component inside ModelDisabledConstraints that you can use to set the value of discrete forces, intended to hold the constraint forces obtained from ModelBase. More...
 
const AccelerationMotiongetAccelerationMotion () const
 This is a component inside ModelDisabledConstraints that you can use to set the value of generalized accelerations UDot, for use in implicit dynamics formulations. More...
 
int getNumStates () const
 
int getNumControls () const
 
int getNumParameters () const
 
int getNumCosts () const
 Get the number of goals in cost mode.
 
int getNumEndpointConstraints () const
 Get the number of goals in endpoint constraint mode.
 
int getNumKinematicConstraints () const
 
bool isPrescribedKinematics () const
 Does the model contain a PositionMotion to prescribe all generalized coordinates, speeds, and accelerations?
 
int getNumImplicitAuxiliaryResiduals () const
 
std::vector< std::string > createStateVariableNamesInSystemOrder (std::unordered_map< int, int > &yIndexMap) const
 This excludes generalized coordinate and speed states if isPrescribedKinematics() is true. More...
 
std::vector< std::string > createStateInfoNames () const
 Get the state names of all the state infos.
 
std::vector< std::string > createControlInfoNames () const
 Get the control names of all the control infos.
 
std::vector< std::string > createParameterNames () const
 Get the names of all the parameters.
 
std::vector< std::string > createCostNames () const
 Get the names of all the goals in cost mode.
 
std::vector< std::string > createEndpointConstraintNames () const
 Get the names of all the goals in endpoint constraint mode.
 
std::vector< std::string > createPathConstraintNames () const
 Get the names of all the MocoPathConstraints.
 
std::vector< std::string > createMultiplierInfoNames () const
 Get the names of all the Lagrange multiplier infos.
 
std::vector< std::string > createKinematicConstraintNames () const
 Get the constraint names of all the kinematic constraints. More...
 
std::vector< std::string > getKinematicConstraintEquationNames (bool includeDerivatives) const
 Get a vector of names for all kinematic constraint equations. More...
 
MocoInitialBounds getTimeInitialBounds () const
 
MocoFinalBounds getTimeFinalBounds () const
 
const MocoVariableInfogetStateInfo (const std::string &name) const
 Get information for state variables. See MocoPhase::setStateInfo().
 
const MocoVariableInfogetControlInfo (const std::string &name) const
 Get information for actuator controls. More...
 
const MocoParametergetParameter (const std::string &name) const
 
const MocoGoalgetCost (const std::string &name) const
 Get a cost by name. This returns a MocoGoal in cost mode.
 
const MocoGoalgetCostByIndex (int index) const
 Get a cost by index. More...
 
const MocoGoalgetEndpointConstraint (const std::string &name) const
 Get an endpoint constraint by name. More...
 
const MocoGoalgetEndpointConstraintByIndex (int index) const
 Get an endpoint constraint by index. More...
 
const MocoPathConstraintgetPathConstraint (const std::string &name) const
 Get a MocoPathConstraint. More...
 
const MocoPathConstraintgetPathConstraintByIndex (int index) const
 Get a path constraint by index. More...
 
int getNumPathConstraintEquations () const
 Get the number of scalar path constraints in the MocoProblem. More...
 
const std::vector< MocoVariableInfo > & getMultiplierInfos (const std::string &kinematicConstraintInfoName) const
 Given a kinematic constraint name, get a vector of MocoVariableInfos corresponding to the Lagrange multipliers for that kinematic constraint. More...
 
const MocoKinematicConstraintgetKinematicConstraint (const std::string &name) const
 Get a MocoKinematicConstraint from this MocoPhase. More...
 
int getNumKinematicConstraintEquations () const
 Get the number of scalar kinematic constraints in the MocoProblem. More...
 
void printDescription (std::ostream &stream=std::cout) const
 Print a description of this problem, including costs and variable bounds. More...
 
Interface for solvers

These functions are for use by MocoSolvers, but can also be called by users for debugging.

Calculate the errors in all the scalar path constraint equations in this phase.

void calcPathConstraintErrors (const SimTK::State &state, SimTK::Vector &errors) const
 
SimTK::Vector calcKinematicConstraintErrors (const SimTK::State &state) const
 Calculate the errors in all the scalar kinematic constraint equations in this phase. More...
 
void applyParametersToModelProperties (const SimTK::Vector &parameterValues, bool initSystemAndDisableConstraints=false) const
 Apply paramater values to the models created from the model passed to initialize() within the current MocoProblem. More...
 
const std::vector< SimTK::ReferencePtr< const Output< double > > > & getImplicitResidualReferencePtrs () const
 Get a vector of reference pointers to model outputs that return residual values for any components with dynamics in implicit forms. More...
 
const std::vector< std::pair< std::string, SimTK::ReferencePtr< const Component > > > & getImplicitComponentReferencePtrs () const
 Get reference pointers to components that enforce dynamics in implicit form. More...
 

Member Function Documentation

◆ applyParametersToModelProperties()

void OpenSim::MocoProblemRep::applyParametersToModelProperties ( const SimTK::Vector &  parameterValues,
bool  initSystemAndDisableConstraints = false 
) const

Apply paramater values to the models created from the model passed to initialize() within the current MocoProblem.

Values must be consistent with the order of parameters returned from createParameterNames().

Note: initSystem() must be called on each model after calls to this method in order for provided parameter values to be applied to the model. You can pass true to have initSystem() called for you, and to also re-disable any constraints re-enabled by the initSystem() call (see getModelDisabledConstraints()).

◆ calcKinematicConstraintErrors()

SimTK::Vector OpenSim::MocoProblemRep::calcKinematicConstraintErrors ( const SimTK::State &  state) const
inline

Calculate the errors in all the scalar kinematic constraint equations in this phase.

This may not be the most efficient solution for solvers, but is rather intended as a convenience method for a quick implementation or for debugging model constraints causing issues in an optimal control problem.

◆ createKinematicConstraintNames()

std::vector<std::string> OpenSim::MocoProblemRep::createKinematicConstraintNames ( ) const

Get the constraint names of all the kinematic constraints.

Note: this should only be called after initialize().

◆ createStateVariableNamesInSystemOrder()

std::vector<std::string> OpenSim::MocoProblemRep::createStateVariableNamesInSystemOrder ( std::unordered_map< int, int > &  yIndexMap) const

This excludes generalized coordinate and speed states if isPrescribedKinematics() is true.

◆ getAccelerationMotion()

const AccelerationMotion& OpenSim::MocoProblemRep::getAccelerationMotion ( ) const
inline

This is a component inside ModelDisabledConstraints that you can use to set the value of generalized accelerations UDot, for use in implicit dynamics formulations.

The motion is not necessarily enabled.

◆ getConstraintForces()

const DiscreteForces& OpenSim::MocoProblemRep::getConstraintForces ( ) const
inline

This is a component inside ModelDisabledConstraints that you can use to set the value of discrete forces, intended to hold the constraint forces obtained from ModelBase.

◆ getControlInfo()

const MocoVariableInfo& OpenSim::MocoProblemRep::getControlInfo ( const std::string &  name) const

Get information for actuator controls.

If the control is associated with a non-scalar actuator (i.e. uses multiple control variables), then the control name will be the actuator path appended by the control index (e.g. "/actuator_0"); See MocoPhase::setControlInfo().

◆ getCostByIndex()

const MocoGoal& OpenSim::MocoProblemRep::getCostByIndex ( int  index) const

Get a cost by index.

The order is the same as in getCostNames(). Note: this does not perform a bounds check.

◆ getEndpointConstraint()

const MocoGoal& OpenSim::MocoProblemRep::getEndpointConstraint ( const std::string &  name) const

Get an endpoint constraint by name.

This returns a MocoGoal in endpoint constraint mode.

◆ getEndpointConstraintByIndex()

const MocoGoal& OpenSim::MocoProblemRep::getEndpointConstraintByIndex ( int  index) const

Get an endpoint constraint by index.

The order is the same as in getEndpointConstraintNames(). Note: this does not perform a bounds check.

◆ getImplicitComponentReferencePtrs()

const std::vector<std::pair<std::string, SimTK::ReferencePtr<const Component> > >& OpenSim::MocoProblemRep::getImplicitComponentReferencePtrs ( ) const
inline

Get reference pointers to components that enforce dynamics in implicit form.

This returns a vector of pairs including the name of the discrete derivative variable and the component reference pointer.

◆ getImplicitResidualReferencePtrs()

const std::vector<SimTK::ReferencePtr<const Output<double> > >& OpenSim::MocoProblemRep::getImplicitResidualReferencePtrs ( ) const
inline

Get a vector of reference pointers to model outputs that return residual values for any components with dynamics in implicit forms.

The references returned are from the model returned by getModelDisabledConstraints().

◆ getKinematicConstraint()

const MocoKinematicConstraint& OpenSim::MocoProblemRep::getKinematicConstraint ( const std::string &  name) const

Get a MocoKinematicConstraint from this MocoPhase.

Note: this does not include MocoPathConstraints, use getPathConstraint() instead. Since these are created directly from model information, this should only be called after initialization. TODO

◆ getKinematicConstraintEquationNames()

std::vector<std::string> OpenSim::MocoProblemRep::getKinematicConstraintEquationNames ( bool  includeDerivatives) const

Get a vector of names for all kinematic constraint equations.

Kinematic constraint equations are ordered as so:

  • position-level constraints
  • velocity-level constraints
  • acceleration-level constraints If includeDerivatives is true, the ordering is:
  • position-level constraints
  • first derivative of position-level constraints (denoted by suffix "d")
  • velocity-level constraints
  • second derivative of position-level constraints (suffix "dd")
  • first derivative of velocity-level constraints (suffix "d")
  • acceleration-level constraints

◆ getModelBase()

const Model& OpenSim::MocoProblemRep::getModelBase ( ) const
inline

Get a reference to the copy of the model being used by this MocoProblemRep.

This model is not the model given to MocoGoal or MocoPathConstraint, but can be used within solvers to compute constraint forces and constraint errors (see getModelDisabledConstraints() for more details). Any parameter updates via a MocoParameter added to the problem will be applied to this model.

◆ getModelDisabledConstraints()

const Model& OpenSim::MocoProblemRep::getModelDisabledConstraints ( ) const
inline

Get a reference to a copy of the model being used by this MocoProblemRep, but with all constraints disabled and an additional DiscreteForces component.

This new component can be used to apply constraint forces computed from the base model to this model, which updates the discrete variables in the state associated with these forces. You should use this model to compute accelerations via getModelDisabledConstraints().realizeAccleration(state), making sure to add any constraint forces to the model preceeding the realization. This model is the same instance as that given to MocoGoal and MocoPathConstraint, ensuring that realizing to Stage::Acceleration in these classes produces the same accelerations computed by the solver. Any parameter updates via a MocoParameter added to the problem will be applied to this model.

◆ getMultiplierInfos()

const std::vector<MocoVariableInfo>& OpenSim::MocoProblemRep::getMultiplierInfos ( const std::string &  kinematicConstraintInfoName) const

Given a kinematic constraint name, get a vector of MocoVariableInfos corresponding to the Lagrange multipliers for that kinematic constraint.

Note: Since these are created directly from model constraint information, this should only be called after initialization. TODO

◆ getNumKinematicConstraintEquations()

int OpenSim::MocoProblemRep::getNumKinematicConstraintEquations ( ) const
inline

Get the number of scalar kinematic constraints in the MocoProblem.

This does not include path constraints equations.

◆ getNumPathConstraintEquations()

int OpenSim::MocoProblemRep::getNumPathConstraintEquations ( ) const
inline

Get the number of scalar path constraints in the MocoProblem.

This does not include kinematic constraints equations.

◆ getPathConstraint()

const MocoPathConstraint& OpenSim::MocoProblemRep::getPathConstraint ( const std::string &  name) const

Get a MocoPathConstraint.

Note: this does not include MocoKinematicConstraints, use getKinematicConstraint() instead.

◆ getPathConstraintByIndex()

const MocoPathConstraint& OpenSim::MocoProblemRep::getPathConstraintByIndex ( int  index) const

Get a path constraint by index.

The order is the same as in getPathConstraintNames(). Note: this does not perform a bounds check.

◆ getTimeFinalBounds()

MocoFinalBounds OpenSim::MocoProblemRep::getTimeFinalBounds ( ) const

Note: the return value is constructed fresh on every call from the internal property. Avoid repeated calls to this function.

◆ getTimeInitialBounds()

MocoInitialBounds OpenSim::MocoProblemRep::getTimeInitialBounds ( ) const

Note: the return value is constructed fresh on every call from the internal property. Avoid repeated calls to this function.

◆ printDescription()

void OpenSim::MocoProblemRep::printDescription ( std::ostream &  stream = std::cout) const

Print a description of this problem, including costs and variable bounds.

By default, the description is printed to the console (cout), but you can provide your own stream.

◆ updStateDisabledConstraints()

SimTK::State& OpenSim::MocoProblemRep::updStateDisabledConstraints ( int  index = 0) const
inline

This is a state object that solvers can use with ModelDisabledConstraints.

Some solvers may need to use 2 state objects at once; you can supply an index of 1 to get a second state object.


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