OpenSim
OpenSim 3.0
|
A concrete class that specifies the interface to a musculoskeletal model. More...
#include <Model.h>
Public Member Functions | |
Model () | |
Default constructor creates a %Model containing only the ground Body | |
Model (const std::string &filename) SWIG_DECLARE_EXCEPTION | |
Constructor from an OpenSim XML model file. | |
Model (const Model &source) | |
Copy constructor copies model components but does not copy any run-time | |
Model & | operator= (const Model &source) |
Copy assignment copies model components but does not copy any run-time | |
void | setup () SWIG_DECLARE_EXCEPTION |
Perform some set up functions that happen after the object has been deserialized. | |
void | cleanup () |
Perform some clean up functions that are normally done from the destructor however this gives the GUI a way to proactively do the cleaning without waiting for garbage collection to do the actual cleanup. | |
void | buildSystem () |
After the %Model and its components have been constructed, call this to interconnect the components and then create the Simbody MultibodySystem needed to represent the Model computationally. | |
SimTK::State & | initializeState () |
After buildSystem() has been called, and any additional modifications to the Simbody MultibodySystem have been made, call this method to finalize the MultibodySystem (by calling its realizeTopology() method), obtain a default state, and assemble it so that position constraints are satisified. | |
SimTK::State & | initSystem () SWIG_DECLARE_EXCEPTION |
Convenience method that invokes buildSystem() and then | |
void | initStateWithoutRecreatingSystem (SimTK::State &state) const |
This is called after the Model is fully created but before starting a simulation. | |
void | invalidateSystem () |
Mark the computational system as invalid. | |
bool | isValidSystem () |
Check that the underlying computational system representing the model is valid. | |
void | formStateStorage (const Storage &originalStorage, Storage &statesStorage) |
create a storage (statesStorage) that has same label order as model's states with values populated from originalStorage, 0.0 for those states unspecified in the originalStorage. | |
void | formQStorage (const Storage &originalStorage, Storage &qStorage) |
void | updateAssemblyConditions (SimTK::State &s) |
Update the AssemblySolver to the latest coordinate locking/constraints. | |
void | assemble (SimTK::State &state, const Coordinate *coord=NULL, double weight=10) |
Find the kinematic state of the model that satisfies constraints and coordinate goals If assemble is being called due to a coordinate set value, provide the option to weight that coordinate value more heavily if specified. | |
void | equilibrateMuscles (SimTK::State &state) |
Update the state of all Muscles so they are in equilibrium. | |
virtual int | getNumStateVariables () const |
Get the number of "Continuous" state variables maintained by the ModelComponent and its specified subcomponents. | |
void | addComponent (ModelComponent *aComponent) |
Add ModelComponents to the Model. | |
void | addBody (Body *aBody) |
void | addConstraint (Constraint *aConstraint) |
void | addForce (Force *aForce) |
void | addProbe (Probe *aProbe) |
void | addContactGeometry (ContactGeometry *aContactGeometry) |
const std::string & | getInputFileName () const |
Get the XML file name used to construct the model. | |
void | setInputFileName (const std::string &fileName) |
Set the XML file name used to construct the model. | |
const std::string & | getCredits () const |
Get the credits (e.g., model author names) associated with the model. | |
void | setAuthors (const std::string &aCredits) |
Set the credits (e.g., model author names) associated with the model. | |
const std::string & | getPublications () const |
Get the publications associated with the model. | |
void | setPublications (const std::string &aPublications) |
Set the publications associated with the model. | |
const Units & | getLengthUnits () const |
Get the length units associated with the model. | |
const Units & | getForceUnits () const |
Get the force units associated with the model. | |
SimTK::Vec3 | getGravity () const |
Get the gravity vector in the global frame. | |
bool | setGravity (const SimTK::Vec3 &aGrav) |
Set the gravity vector in the gloabl frame. | |
int | getNumMarkers () const |
Get the number of markers in the model. | |
int | getNumContactGeometries () const |
Get the number of ContactGeometries in the model. | |
int | getNumBodies () const |
Get the total number of bodies in the model. | |
int | getNumJoints () const |
Get the total number of joints in the model. | |
int | getNumCoordinates () const |
Get the total number of coordinates in the model. | |
int | getNumSpeeds () const |
Get the total number of speeds in the model. | |
int | getNumProbes () const |
Get the total number of probes in the model. | |
const Set< Actuator > & | getActuators () const |
Get the subset of Forces in the model which are actuators. | |
Set< Actuator > & | updActuators () |
const Set< Muscle > & | getMuscles () const |
Get the subset of Forces in the model which are muscles. | |
Set< Muscle > & | updMuscles () |
const ForceSet & | getForceSet () const |
ForceSet & | updForceSet () |
const ProbeSet & | getProbeSet () const |
Get the subset of Probes in the model. | |
ProbeSet & | updProbeSet () |
const ComponentSet & | getMiscModelComponentSet () const |
Get the subset of misc ModelComponents in the model. | |
ComponentSet & | updMiscModelComponentSet () |
int | getNumAnalyses () const |
Get the number of analyses in the model. | |
int | getNumControls () const |
Get the number of controls for this the model. | |
SimTK::Vector & | updDefaultControls () const |
Writable access to the default values for controls. | |
const SimTK::Vector & | getDefaultControls () const |
SimTK::Vector & | updControls (const SimTK::State &s) const |
Update the controls for this the model at a given state. | |
const SimTK::Vector & | getControls (const SimTK::State &s) const |
Const access to controls does not invalidate dynamics. | |
void | computeControls (const SimTK::State &state, SimTK::Vector &controls) const |
Compute the controls for the model. | |
bool | isControlled () const |
Get a flag indicating if the model needs controls to operate its actuators. | |
void | storeControls (const SimTK::State &s, int step) |
void | printControlStorage (const std::string &fileName) const |
const ControllerSet & | getControllerSet () const |
ControllerSet & | updControllerSet () |
bool | getAllControllersEnabled () const |
void | setAllControllersEnabled (bool enabled) |
void | applyDefaultConfiguration (SimTK::State &s) |
const SimbodyEngine & | getSimbodyEngine () const |
Get the model's dynamics engine. | |
SimbodyEngine & | updSimbodyEngine () |
void | getStateValues (const SimTK::State &state, Array< double > &stateValues) const |
Get the values of state variables in the same ordering as returned by getStateVariableNames(). | |
void | setStateValues (SimTK::State &state, const double *stateValues) const |
Set the values of state variables which are passed in the same ordering as returned by getStateVariableNames(). | |
int | getNumMuscleStates () const |
void | setInitialTime (double ti) |
CoordinateSet & | updCoordinateSet () |
const CoordinateSet & | getCoordinateSet () const |
BodySet & | updBodySet () |
const BodySet & | getBodySet () const |
JointSet & | updJointSet () |
const JointSet & | getJointSet () const |
AnalysisSet & | updAnalysisSet () |
const AnalysisSet & | getAnalysisSet () const |
ContactGeometrySet & | updContactGeometrySet () |
const ContactGeometrySet & | getContactGeometrySet () const |
Body & | getGroundBody () const |
ConstraintSet & | updConstraintSet () |
const ConstraintSet & | getConstraintSet () const |
MarkerSet & | updMarkerSet () |
const MarkerSet & | getMarkerSet () const |
int | replaceMarkerSet (const SimTK::State &s, MarkerSet &aMarkerSet) |
void | writeMarkerFile (const std::string &aFileName) const |
void | updateMarkerSet (MarkerSet &aMarkerSet) |
int | deleteUnusedMarkers (const Array< std::string > &aMarkerNames) |
void | addAnalysis (Analysis *aAnalysis) |
Add an analysis to the model. | |
void | addController (Controller *aController) |
void | removeAnalysis (Analysis *analysis, bool deleteIt=true) |
Remove an analysis from the model. | |
void | removeController (Controller *aController) |
bool | scale (SimTK::State &state, const ScaleSet &scaleSet, double finalMass=-1.0, bool preserveMassDist=false) |
Scale the model. | |
void | printBasicInfo (std::ostream &aOStream) const |
Print some basic information about the model. | |
void | printDetailedInfo (const SimTK::State &s, std::ostream &aOStream) const |
Print detailed information about the model. | |
void | disownAllComponents () |
Model relinquishes ownership of all components such as: Bodies, Constraints, Forces, ConactGeometry and so on. | |
void | overrideAllActuators (SimTK::State &s, bool flag) |
Convenice function to turn on/off overriding the force for all actuators. | |
const std::string & | getValidationLog () |
Get a log of errors/warnings ecountered when loading/constructing the model. | |
void | clearValidationLog () |
const Object & | getObjectByTypeAndName (const std::string &typeString, const std::string &nameString) SWIG_DECLARE_EXCEPTION |
Utility to get a reference to an Object based on its name and type throws an exception if the object was not found. | |
Visualization | |
Methods in this group affect visualization of this Model, which may be through the OpenSim GUI or through the use of a ModelVisualizer which can provide limited run-time display and user interaction capability for an OpenSim API-based program. If you enable visualization at the API level, the Model will create a ModelVisualizer that you can use to control display and user interaction. In turn, the ModelVisualizer makes use of a Simbody SimTK::Visualizer; for advanced features you can ask the ModelVisualizer to give you direct access to the SimTK::Visualizer; consult Simbody documentation for more details. | |
const ModelDisplayHints & | getDisplayHints () const |
Get read only access to the ModelDisplayHints object stored with this | |
ModelDisplayHints & | updDisplayHints () |
Get writable access to the ModelDisplayHints object stored with this | |
void | setUseVisualizer (bool visualize) |
Request or suppress visualization of this Model. | |
bool | getUseVisualizer () const |
Return the current setting of the "use visualizer" flag, which will take effect at the next call to initSystem() on this Model. | |
bool | hasVisualizer () const |
Test whether a ModelVisualizer has been created for this Model. | |
const ModelVisualizer & | getVisualizer () const |
Obtain read-only access to the ModelVisualizer. | |
ModelVisualizer & | updVisualizer () |
Obtain writable access to the ModelVisualizer. | |
Access to the Simbody System and components | |
Methods in this section provide advanced users access to the underlying Simbody System and associated subcomponents that are constructed and maintained by this Model. Note that these are not available until after initSystem() has been invoked on this Model. Be very careful if you call any of the upd() methods since modifying a System after the Model creates it can require reinitialization. | |
const SimTK::MultibodySystem & | getMultibodySystem () const |
Get read-only access to the internal Simbody MultibodySystem that was created by this Model at the last initSystem() call. | |
SimTK::MultibodySystem & | updMultibodySystem () const |
(Advanced) Get writable access to the internal Simbody MultibodySystem that was created by this Model at the last initSystem() call. | |
const SimTK::DefaultSystemSubsystem & | getDefaultSubsystem () const |
Get read-only access to the internal DefaultSystemSubsystem allocated | |
SimTK::DefaultSystemSubsystem & | updDefaultSubsystem () |
(Advanced) Get writable access to the internal DefaultSystemSubsystem | |
const SimTK::SimbodyMatterSubsystem & | getMatterSubsystem () const |
Get read-only access to the internal SimbodyMatterSubsystem allocated | |
SimTK::SimbodyMatterSubsystem & | updMatterSubsystem () |
(Advanced) Get writable access to the internal SimbodyMatterSubsystem | |
const SimTK::Force::Gravity & | getGravityForce () const |
Get read-only access to the Simbody Force::Gravity element that was | |
SimTK::Force::Gravity & | updGravityForce () |
(Advanced) Get writable access to the Simbody Force::Gravity element | |
const SimTK::GeneralForceSubsystem & | getForceSubsystem () const |
Get read-only access to the internal Simbody GeneralForceSubsystem | |
SimTK::GeneralForceSubsystem & | updForceSubsystem () |
(Advanced) Get writable access to the internal Simbody | |
Implementation of Object interface | |
These methods are Model's implementation of virtual methods defined in the Object class from which Model derives (indirectly through ModelComponent). | |
~Model () | |
Destructor. | |
void | updateFromXMLNode (SimTK::Xml::Element &aNode, int versionNumber=-1) |
Override of the default implementation to account for versioning. | |
Implementation of ModelComponent interface | |
These methods are Model's implementation of virtual methods defined in the ModelComponent class from which Model derives. The implementations here serve as dispatchers that treat all contained ModelComponents (and model elements that are not ModelComponents) as subcomponents whose corresponding methods need to be called. | |
void | connectToModel (Model &model) override |
Perform any necessary initializations required to connect the component into the Model, and check for error conditions. | |
void | addToSystem (SimTK::MultibodySystem &system) const override |
Add appropriate Simbody elements (if needed) to the System corresponding to this component and specify needed state resources. | |
void | initStateFromProperties (SimTK::State &state) const override |
Transfer property values or other state-independent initial values into this component's state variables in the passed-in state argument. | |
void | setPropertiesFromState (const SimTK::State &state) override |
Given a State, set all default values for this Model to match those found in the State. | |
void | generateDecorations (bool fixed, const ModelDisplayHints &hints, const SimTK::State &state, SimTK::Array_< SimTK::DecorativeGeometry > &appendToThis) const override |
Optional method for generating arbitrary display geometry that reflects | |
Array< std::string > | getStateVariableNames () const |
Get the names of the states. | |
double | getStateVariable (const SimTK::State &state, const std::string &name) const |
Get the value of a state variable of this Model. | |
SimTK::SystemYIndex | getStateVariableSystemIndex (const std::string &stateVariableName) const |
Get the System Index of a state variable allocated by this ModelComponent. | |
![]() | |
ModelComponent () | |
Default constructor. | |
ModelComponent (const std::string &aFileName, bool aUpdateFromXMLNode=true) SWIG_DECLARE_EXCEPTION | |
Construct ModelComponent from an XML file. | |
ModelComponent (SimTK::Xml::Element &aNode) | |
Construct ModelComponent from a specific node in an XML document. | |
ModelComponent (const ModelComponent &source) | |
Construct ModelComponent with its contents copied from another ModelComponent; this is a deep copy so nothing is shared with the source after the copy. | |
virtual | ~ModelComponent () |
Destructor is virtual to allow concrete model component cleanup. | |
ModelComponent & | operator= (const ModelComponent &aModelComponent) |
Assignment operator to copy contents of an existing component. | |
const Model & | getModel () const |
Get a const reference to the Model this component is part of. | |
Model & | updModel () |
Get a modifiable reference to the Model this component is part of. | |
virtual void | updateDisplayer (const SimTK::State &s) |
In case the ModelComponent has a visual representation (VisualObject), override this method to update it. | |
int | getModelingOption (const SimTK::State &state, const std::string &name) const |
Get a ModelingOption flag for this ModelComponent by name. | |
void | setModelingOption (SimTK::State &state, const std::string &name, int flag) const |
Set the value of a ModelingOption flag for this ModelComponent. | |
void | setStateVariable (SimTK::State &state, const std::string &name, double value) const |
Set the value of a state variable allocated by this ModelComponent by name. | |
double | getDiscreteVariable (const SimTK::State &state, const std::string &name) const |
Get the value of a discrete variable allocated by this ModelComponent by name. | |
void | setDiscreteVariable (SimTK::State &state, const std::string &name, double value) const |
Set the value of a discrete variable allocated by this ModelComponent by name. | |
template<typename T > | |
const T & | getCacheVariable (const SimTK::State &state, const std::string &name) const |
Get the value of a cache variable allocated by this ModelComponent by name. | |
template<typename T > | |
T & | updCacheVariable (const SimTK::State &state, const std::string &name) const |
Obtain a writable cache variable value allocated by this ModelComponent by name. | |
void | markCacheVariableValid (const SimTK::State &state, const std::string &name) const |
After updating a cache variable value allocated by this ModelComponent, you can mark its value as valid, which will not change until the realization stage falls below the minimum set at the time the cache variable was created. | |
void | markCacheVariableInvalid (const SimTK::State &state, const std::string &name) const |
Mark a cache variable value allocated by this ModelComponent as invalid. | |
bool | isCacheVariableValid (const SimTK::State &state, const std::string &name) const |
Enables the to monitor the validity of the cache variable value using the returned flag. | |
template<typename T > | |
void | setCacheVariable (const SimTK::State &state, const std::string &name, T &value) const |
Set cache variable value allocated by this ModelComponent by name. | |
![]() | |
virtual | ~Object () |
Virtual destructor for cleanup. | |
virtual Object * | clone () const =0 |
Create a new heap-allocated copy of the concrete object to which this | |
virtual const std::string & | getConcreteClassName () const =0 |
Returns the class name of the concrete %Object-derived class of the | |
virtual const VisibleObject * | getDisplayer () const |
Methods to support making the object displayable in the GUI or Visualizer Implemented only in few objects. | |
virtual VisibleObject * | updDisplayer () |
get Non const pointer to VisibleObject | |
bool | isEqualTo (const Object &aObject) const |
Equality operator wrapper for use from languages not supporting operator overloading. | |
Object & | operator= (const Object &aObject) |
Copy assignment copies he base class fields, including the | |
virtual bool | operator== (const Object &aObject) const |
Determine if two objects are equal. | |
virtual bool | operator< (const Object &aObject) const |
Provide an ordering for objects so they can be put in sorted | |
void | setName (const std::string &name) |
Set the name of the Object. | |
const std::string & | getName () const |
Get the name of this Object. | |
void | setDescription (const std::string &description) |
Set description, a one-liner summary. | |
const std::string & | getDescription () const |
Get description, a one-liner summary. | |
const std::string & | getAuthors () const |
Get Authors of this Object. | |
const std::string & | getReferences () const |
Get references or publications to cite if using this object. | |
void | setReferences (const std::string &references) |
Set references or publications to cite if using this object. | |
int | getNumProperties () const |
Determine how many properties are stored with this Object. | |
const AbstractProperty & | getPropertyByIndex (int propertyIndex) const |
Get a const reference to a property by its index number, returned as an AbstractProperty. | |
AbstractProperty & | updPropertyByIndex (int propertyIndex) |
Get a writable reference to a property by its index number, returned as an AbstractProperty. | |
bool | hasProperty (const std::string &name) const |
Return true if this %Object has a property of any type with the | |
const AbstractProperty & | getPropertyByName (const std::string &name) const |
Get a const reference to a property by its name, returned as an AbstractProperty. | |
AbstractProperty & | updPropertyByName (const std::string &name) |
Get a writable reference to a property by its name, returned as an AbstractProperty. | |
template<class T > | |
bool | hasProperty () const |
Return true if this %Object contains an unnamed, one-object property | |
template<class T > | |
const Property< T > & | getProperty (const PropertyIndex &index) const |
Get property of known type Property\<T> as a const reference; | |
template<class T > | |
Property< T > & | updProperty (const PropertyIndex &index) |
Get property of known type Property\<T> as a writable reference; | |
void | setObjectIsUpToDateWithProperties () |
When an object is initialized using the current values of its properties, it can set a flag indicating that it is up to date. | |
bool | isObjectUpToDateWithProperties () const |
Returns \c true if any property's value has changed since the last time setObjectIsUpToDateWithProperties() was called. | |
void | readObjectFromXMLNodeOrFile (SimTK::Xml::Element &objectElement, int versionNumber) |
We're given an XML element from which we are to populate this Object. | |
virtual void | updateXMLNode (SimTK::Xml::Element &parent) |
Serialize this object into the XML node that represents it. | |
bool | getInlined () const |
Inlined means an in-memory Object that is not associated with an XMLDocument. | |
void | setInlined (bool aInlined, const std::string &aFileName="") |
Mark this as inlined or not and optionally provide a file name to associate with the new XMLDocument for the non-inline case. | |
std::string | getDocumentFileName () const |
If there is a document associated with this object then return the | |
void | setAllPropertiesUseDefault (bool aUseDefault) |
bool | print (const std::string &fileName) |
Write this %Object into an XML file of the given name; conventionally | |
std::string | dump (bool dumpName=false) |
dump the XML representation of this Object into an std::string and return it. | |
void | clearObjectIsUpToDateWithProperties () |
For testing or debugging purposes, manually clear the "object is up to | |
virtual bool | isA (const char *type) const |
The default implementation returns true only if the supplied string is "Object"; each Object-derived class overrides this to match its own class name. | |
const std::string & | toString () const |
Wrapper to be used on Java side to display objects in tree; this returns | |
PropertySet & | getPropertySet () |
OBSOLETE: Get a reference to the PropertySet maintained by the | |
const PropertySet & | getPropertySet () const |
Friends | |
class | ModelComponent |
Additional Inherited Members | |
![]() | |
static void | registerType (const Object &defaultObject) |
Register an instance of a class; if the class is already registered it | |
static void | renameType (const std::string &oldTypeName, const std::string &newTypeName) |
Support versioning by associating the current %Object type with an | |
static const Object * | getDefaultInstanceOfType (const std::string &concreteClassName) |
Return a pointer to the default instance of the registered (concrete) Object whose class name is given, or NULL if the type is not registered. | |
template<class T > | |
static bool | isObjectTypeDerivedFrom (const std::string &concreteClassName) |
Return true if the given concrete object type represents a subclass of the template object type T, and thus could be referenced with a T*. | |
static Object * | newInstanceOfType (const std::string &concreteClassName) |
Create a new instance of the concrete %Object type whose class name is | |
static void | getRegisteredTypenames (Array< std::string > &typeNames) |
Retrieve all the typenames registered so far. | |
template<class T > | |
static void | getRegisteredObjectsOfGivenType (ArrayPtrs< T > &rArray) |
Return an array of pointers to the default instances of all registered (concrete) Object types that derive from a given Object-derived type that does not have to be concrete. | |
static void | PrintPropertyInfo (std::ostream &os, const std::string &classNameDotPropertyName) |
Dump formatted property information to a given output stream, useful | |
static void | PrintPropertyInfo (std::ostream &os, const std::string &className, const std::string &propertyName) |
Same as the other signature but the class name and property name are | |
static Object * | makeObjectFromFile (const std::string &fileName) |
Create an %OpenSim object whose type is based on the tag at the root | |
static const std::string & | getClassName () |
Return the name of this class as a string; i.e., "Object". | |
static void | setSerializeAllDefaults (bool shouldSerializeDefaults) |
Static function to control whether all registered objects and their properties are written to the defaults section of output files rather than only those values for which the default was explicitly overwritten when read in from an input file or set programmatically. | |
static bool | getSerializeAllDefaults () |
Report the value of the "serialize all defaults" flag. | |
static bool | isKindOf (const char *type) |
Returns true if the passed-in string is "Object"; each %Object-derived | |
static void | setDebugLevel (int newLevel) |
Set the debug level to get verbose output. | |
static int | getDebugLevel () |
Get current setting of debug level. | |
static Object * | SafeCopy (const Object *aObject) |
Use the clone() method to duplicate the given object unless the pointer | |
static void | RegisterType (const Object &defaultObject) |
OBSOLETE alternate name for registerType(). | |
static void | RenameType (const std::string &oldName, const std::string &newName) |
OBSOLETE alternate name for renameType(). | |
![]() | |
static const std::string | DEFAULT_NAME |
Name used for default objects when they are serialized. | |
![]() | |
virtual SimTK::Vector | computeStateVariableDerivatives (const SimTK::State &s) const |
If a model component has allocated any continuous state variables using the addStateVariable() method, then computeStateVariableDerivatives() must be implemented to provide time derivatives for those states. | |
void | includeAsSubComponent (ModelComponent *aComponent) |
Include another ModelComponent as a Subcomponent of this ModelComponent. | |
void | addModelingOption (const std::string &optionName, int maxFlagValue) const |
Add a modeling option (integer flag stored in the State) for use by this ModelComponent. | |
void | addStateVariable (const std::string &stateVariableName, SimTK::Stage invalidatesStage=SimTK::Stage::Dynamics) const |
Add a continuous system state variable belonging to this ModelComponent, | |
void | addDiscreteVariable (const std::string &discreteVariableName, SimTK::Stage invalidatesStage) const |
Add a system discrete variable belonging to this ModelComponent, give it a name by which it can be referenced, and declare the lowest Stage that should be invalidated if this variable's value is changed. | |
template<class T > | |
void | addCacheVariable (const std::string &cacheVariableName, const T &variablePrototype, SimTK::Stage dependsOnStage) const |
Add a state cache entry belonging to this ModelComponent to hold calculated values that must be automatically invalidated when certain state values change. | |
const int | getStateIndex (const std::string &name) const |
Get the index of a ModelComponent's continuous state variable in the Subsystem for allocations. | |
const SimTK::DiscreteVariableIndex | getDiscreteVariableIndex (const std::string &name) const |
Get the index of a ModelComponent's discrete variable in the Subsystem for allocations. | |
const SimTK::CacheEntryIndex | getCacheVariableIndex (const std::string &name) const |
Get the index of a ModelComponent's cache variable in the Subsystem for allocations. | |
![]() | |
Model * | _model |
The model this component belongs to. | |
![]() | |
#define | OpenSim_DECLARE_CONCRETE_OBJECT(ConcreteClass, SuperClass) |
Macro to be included as the first line of the class declaration for any non-templatized, concrete class that derives from OpenSim::Object. | |
#define | OpenSim_DECLARE_ABSTRACT_OBJECT(ConcreteClass, SuperClass) |
Macro to be included as the first line of the class declaration for any still-abstract class that derives from OpenSim::Object. | |
#define | OpenSim_DECLARE_CONCRETE_OBJECT_T(ConcreteClass, TArg, SuperClass) |
Macro to be included as the first line of the class declaration for any templatized, concrete class that derives from OpenSim::Object, like Set<T>. | |
#define | OpenSim_DECLARE_ABSTRACT_OBJECT_T(ConcreteClass, TArg, SuperClass) |
Macro to be included as the first line of the class declaration for any templatized, still-abstract class that derives from OpenSim::Object. |
A concrete class that specifies the interface to a musculoskeletal model.
You can read this in from an XML file or create it programmatically, and modify it via the API.
A Model contains ModelComponents, and is itself a ModelComponent so must satisfy the ModelComponent interface, as well as the Object interface from which ModelComponent derives. This allows a Model to allocate "global" resources using ModelComponent resource-allocation facilities.
Computation using a Model is done by creating a computational representation of the Model, called a System (SimTK::System), using Simbody. Creation of the System is initiated by a call to the Model's initSystem() method. The System and related objects are maintained in a runtime section of the Model object. You can also ask a Model to provide visualization using the setUseVisualizer() method, in which case it will allocate an maintain a ModelVisualizer.
OpenSim::Model::Model | ( | ) |
Default constructor creates a %Model containing only the ground Body
and a set of default properties.
|
explicit |
OpenSim::Model::Model | ( | const Model & | source | ) |
Copy constructor copies model components but does not copy any run-time
objects.
source | The Model to be copied. |
OpenSim::Model::~Model | ( | ) |
Destructor.
void OpenSim::Model::addAnalysis | ( | Analysis * | aAnalysis | ) |
Add an analysis to the model.
aAnalysis | pointer to the analysis to add |
void OpenSim::Model::addBody | ( | Body * | aBody | ) |
void OpenSim::Model::addComponent | ( | ModelComponent * | aComponent | ) |
void OpenSim::Model::addConstraint | ( | Constraint * | aConstraint | ) |
void OpenSim::Model::addContactGeometry | ( | ContactGeometry * | aContactGeometry | ) |
void OpenSim::Model::addController | ( | Controller * | aController | ) |
void OpenSim::Model::addForce | ( | Force * | aForce | ) |
void OpenSim::Model::addProbe | ( | Probe * | aProbe | ) |
|
overridevirtual |
Add appropriate Simbody elements (if needed) to the System
corresponding to this component and specify needed state resources.
addToSystem() is called when the Simbody System is being created to represent a completed Model for computation. That is, connectToModel() will already have been invoked on all components before any addToSystem() call is made. Helper methods for adding modeling options, state variables and their derivatives, discrete variables, and cache entries are available and can be called within addToSystem() only.
Note that this method is const; you must not modify your model component or the containing model during this call. Any modifications you need should instead be performed in connectToModel(), which is non-const. One exception is that you may need to record access information for resources you create in the system, such as an index number. You should declare those data members mutable so that you can set them here.
If you override this method, be sure to invoke the base class method first, using code like this:
[in,out] | system | The System being created. |
Reimplemented from OpenSim::ModelComponent.
void OpenSim::Model::applyDefaultConfiguration | ( | SimTK::State & | s | ) |
void OpenSim::Model::assemble | ( | SimTK::State & | state, |
const Coordinate * | coord = NULL , |
||
double | weight = 10 |
||
) |
Find the kinematic state of the model that satisfies constraints and coordinate goals If assemble is being called due to a coordinate set value, provide the option to weight that coordinate value more heavily if specified.
void OpenSim::Model::buildSystem | ( | ) |
After the %Model and its components have been constructed, call this to
interconnect the components and then create the Simbody MultibodySystem needed to represent the Model computationally.
The connectToModel() method of each contained ModelComponent will be invoked, and then their addToSystem() methods are invoked. The resulting MultibodySystem is maintained internally by the Model. After this call, you may obtain a writable reference to the System using updMultibodySystem() which you can use to make any additions you want. Then when the System is complete, call initializeState() to finalize it and obtain an initial State.
void OpenSim::Model::cleanup | ( | ) |
Perform some clean up functions that are normally done from the destructor however this gives the GUI a way to proactively do the cleaning without waiting for garbage collection to do the actual cleanup.
|
inline |
void OpenSim::Model::computeControls | ( | const SimTK::State & | state, |
SimTK::Vector & | controls | ||
) | const |
Compute the controls for the model.
Calls down to the Controllers to make their contributions to the controls.
[in] | state | System state from which Controllers should draw when computing their control outputs. |
[out] | controls | The complete vector of controls into which individual controller contributions should be added. |
|
inlineoverridevirtual |
Perform any necessary initializations required to connect the
component into the Model, and check for error conditions.
connectToModel() is invoked on all components to complete construction of a Model, prior to creating a Simbody System to represent it computationally. It may also be invoked at times just for its error-checking side effects.
If you override this method, be sure to invoke the base class method first, using code like this:
Note that this method is expected to check for modeling errors and should throw an OpenSim::Exception if there is something wrong. For example, if your model component references another object by name, you should verify that it exists in the supplied Model, which is not guaranteed since components may be independently instantiated or constructed from XML files.
[in,out] | model | The Model currently being constructed to which this ModelComponent should be connected. |
Reimplemented from OpenSim::ModelComponent.
int OpenSim::Model::deleteUnusedMarkers | ( | const Array< std::string > & | aMarkerNames | ) |
void OpenSim::Model::disownAllComponents | ( | ) |
Model relinquishes ownership of all components such as: Bodies, Constraints, Forces, ConactGeometry and so on.
That means the freeing of the memory of these objects is up to the caller.
void OpenSim::Model::equilibrateMuscles | ( | SimTK::State & | state | ) |
Update the state of all Muscles so they are in equilibrium.
create a storage (statesStorage) that has same label order as model's states with values populated from originalStorage, 0.0 for those states unspecified in the originalStorage.
|
overridevirtual |
Optional method for generating arbitrary display geometry that reflects
this ModelComponent at the specified state.
This will be called once to obtain ground- and body-fixed geometry (with fixed=true
), and then once per frame (with fixed=false
) to generate on-the-fly geometry such as rubber band lines, force arrows, labels, or debugging aids.
If you override this method, be sure to invoke the base class method first, using code like this:
[in] | fixed | If true , generate only geometry that is independent of time, configuration, and velocity. Otherwise generate only such dependent geometry. |
[in] | hints | See documentation for ModelDisplayHints; you may want to alter the geometry you generate depending on what you find there. For example, you can determine whether the user wants to see debug geometry. |
[in] | state | The State for which geometry should be produced. See below for more information. |
[in,out] | appendToThis | Array to which generated geometry should be appended via the push_back() method. |
When called with fixed=true
only modeling options and parameters (Instance variables) should affect geometry; time, position, and velocity should not. In that case OpenSim will already have realized the state through Instance stage. When called with fixed=false
, you may consult any relevant value in state. However, to avoid unnecessary computation, OpenSim guarantees only that state will have been realized through Position stage; if you need anything higher than that (reaction forces, for example) you should make sure the state is realized through Acceleration stage.
Reimplemented from OpenSim::ModelComponent.
Get the subset of Forces in the model which are actuators.
bool OpenSim::Model::getAllControllersEnabled | ( | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
const ControllerSet& OpenSim::Model::getControllerSet | ( | ) | const |
const SimTK::Vector& OpenSim::Model::getControls | ( | const SimTK::State & | s | ) | const |
Const access to controls does not invalidate dynamics.
|
inline |
|
inline |
Get the credits (e.g., model author names) associated with the model.
|
inline |
|
inline |
Get read-only access to the internal DefaultSystemSubsystem allocated
by this Model's Simbody MultibodySystem.
Reimplemented from OpenSim::ModelComponent.
|
inline |
Get read only access to the ModelDisplayHints object stored with this
Model.
These should be checked whenever display geometry is being generated.
|
inline |
|
inline |
Get read-only access to the internal Simbody GeneralForceSubsystem
allocated by this Model.
|
inline |
Get the force units associated with the model.
SimTK::Vec3 OpenSim::Model::getGravity | ( | ) | const |
Get the gravity vector in the global frame.
|
inline |
Get read-only access to the Simbody Force::Gravity element that was
allocated by this Model.
Body& OpenSim::Model::getGroundBody | ( | ) | const |
|
inline |
Get the XML file name used to construct the model.
const JointSet& OpenSim::Model::getJointSet | ( | ) | const |
|
inline |
Get the length units associated with the model.
|
inline |
|
inline |
Get read-only access to the internal SimbodyMatterSubsystem allocated
by this Model.
|
inline |
Get the subset of misc ModelComponents in the model.
|
inline |
Get read-only access to the internal Simbody MultibodySystem that was
created by this Model at the last initSystem() call.
Get the subset of Forces in the model which are muscles.
int OpenSim::Model::getNumAnalyses | ( | ) | const |
Get the number of analyses in the model.
int OpenSim::Model::getNumBodies | ( | ) | const |
Get the total number of bodies in the model.
int OpenSim::Model::getNumContactGeometries | ( | ) | const |
Get the number of ContactGeometries in the model.
int OpenSim::Model::getNumControls | ( | ) | const |
Get the number of controls for this the model.
Only valid once underlying system for the model has been created. Throws an exception if called before Model::initSystem()
int OpenSim::Model::getNumCoordinates | ( | ) | const |
Get the total number of coordinates in the model.
int OpenSim::Model::getNumJoints | ( | ) | const |
Get the total number of joints in the model.
int OpenSim::Model::getNumMarkers | ( | ) | const |
Get the number of markers in the model.
int OpenSim::Model::getNumMuscleStates | ( | ) | const |
int OpenSim::Model::getNumProbes | ( | ) | const |
Get the total number of probes in the model.
int OpenSim::Model::getNumSpeeds | ( | ) | const |
Get the total number of speeds in the model.
|
virtual |
Get the number of "Continuous" state variables maintained by the ModelComponent and its specified subcomponents.
Reimplemented from OpenSim::ModelComponent.
const Object& OpenSim::Model::getObjectByTypeAndName | ( | const std::string & | typeString, |
const std::string & | nameString | ||
) |
Utility to get a reference to an Object based on its name and type throws an exception if the object was not found.
names are case sensitive
typeString | the type of object being looked up (Body, Force, Constraint, Coordinate, Joint, Marker, Controller) |
nameString | the name of the object being looked up |
|
inline |
Get the subset of Probes in the model.
|
inline |
Get the publications associated with the model.
|
inline |
Get the model's dynamics engine.
void OpenSim::Model::getStateValues | ( | const SimTK::State & | state, |
Array< double > & | stateValues | ||
) | const |
Get the values of state variables in the same ordering as returned by getStateVariableNames().
Values are dug out from the passed-in state based on Y-indices that are associated with the named state variables.
[in] | state | State from which values are to be obtained. |
[out] | stateValues | Array used to collect the reordered state values. |
double OpenSim::Model::getStateVariable | ( | const SimTK::State & | state, |
const std::string & | name | ||
) | const |
Get the value of a state variable of this Model.
state | the State for which to get the value |
name | the name (string) of the state variable of interest |
Reimplemented from OpenSim::ModelComponent.
|
virtual |
Get the names of the states.
These are the continuous states introduced by OpenSim ModelComponents and exposed thru the ModelComponent API.
Reimplemented from OpenSim::ModelComponent.
|
virtual |
Get the System Index of a state variable allocated by this ModelComponent.
Returns an InvalidIndex if no state variable with the name provided is found.
stateVariableName | the name of the state variable |
Reimplemented from OpenSim::ModelComponent.
|
inline |
Return the current setting of the "use visualizer" flag, which will
take effect at the next call to initSystem() on this Model.
|
inline |
Get a log of errors/warnings ecountered when loading/constructing the model.
|
inline |
Obtain read-only access to the ModelVisualizer.
This will throw an exception if visualization was not requested or initSystem() not yet called.
|
inline |
Test whether a ModelVisualizer has been created for this Model.
Even if visualization has been requested there will be no visualizer present until initSystem() has been successfully invoked. Use this method prior to calling getVisualizer() or updVisualizer() to avoid an unpleasant exception.
SimTK::State& OpenSim::Model::initializeState | ( | ) |
After buildSystem() has been called, and any additional modifications
to the Simbody MultibodySystem have been made, call this method to finalize the MultibodySystem (by calling its realizeTopology() method), obtain a default state, and assemble it so that position constraints are satisified.
The initStateFromProperties() method of each contained ModelComponent will be invoked. A reference to the internally-maintained default State is returned; your first action should usually be to copy it into your own State object, for example:
|
overridevirtual |
Transfer property values or other state-independent initial values
into this component's state variables in the passed-in state argument.
This is called after a SimTK::System and State have been created for the Model (that is, after addToSystem() has been called on all components). You should override this method if your component has properties (serializable values) that can affect initial values for your state variables. You can also perform any other state-independent calculations here that result in state initial conditions.
If you override this method, be sure to invoke the base class method first, using code like this:
state | The state that will receive the new initial conditions. |
Reimplemented from OpenSim::ModelComponent.
|
inline |
This is called after the Model is fully created but before starting a simulation.
It ONLY initializes the computational system used to simulate the model and addToSystem() has been called already. This method should only be used if if additional SimTK::System components are being added using the SimTK API and the programmer is certain that the model's system has been created.
|
inline |
Convenience method that invokes buildSystem() and then
A reference to the internally-maintained default State is returned; your first action should usually be to copy it into your own State object, for example:
void OpenSim::Model::invalidateSystem | ( | ) |
Mark the computational system as invalid.
This should be called whenever a property of the model is modified. Once this has been called, no calculations can be done until initSystem() is called again.
bool OpenSim::Model::isControlled | ( | ) | const |
Get a flag indicating if the model needs controls to operate its actuators.
bool OpenSim::Model::isValidSystem | ( | ) |
Check that the underlying computational system representing the model is valid.
That is, is the system ready for performing calculations.
Copy assignment copies model components but does not copy any run-time
objects.
source | The Model to be copied. |
void OpenSim::Model::overrideAllActuators | ( | SimTK::State & | s, |
bool | flag | ||
) |
Convenice function to turn on/off overriding the force for all actuators.
void OpenSim::Model::printBasicInfo | ( | std::ostream & | aOStream | ) | const |
Print some basic information about the model.
aOStream | Output stream. |
void OpenSim::Model::printControlStorage | ( | const std::string & | fileName | ) | const |
void OpenSim::Model::printDetailedInfo | ( | const SimTK::State & | s, |
std::ostream & | aOStream | ||
) | const |
Print detailed information about the model.
aOStream | Output stream. |
void OpenSim::Model::removeAnalysis | ( | Analysis * | analysis, |
bool | deleteIt = true |
||
) |
Remove an analysis from the model.
analysis | Pointer to the analysis to remove. |
deleteIt | Whether the removed object should be deleted. |
void OpenSim::Model::removeController | ( | Controller * | aController | ) |
int OpenSim::Model::replaceMarkerSet | ( | const SimTK::State & | s, |
MarkerSet & | aMarkerSet | ||
) |
bool OpenSim::Model::scale | ( | SimTK::State & | state, |
const ScaleSet & | scaleSet, | ||
double | finalMass = -1.0 , |
||
bool | preserveMassDist = false |
||
) |
Scale the model.
state | State containing parameter values that might be modified here. |
scaleSet | The set of XYZ scale factors for the bodies. |
finalMass | The mass that the scaled model should have. |
preserveMassDist | Whether or not the masses of the individual bodies should be scaled with the body scale factors. |
void OpenSim::Model::setAllControllersEnabled | ( | bool | enabled | ) |
|
inline |
Set the credits (e.g., model author names) associated with the model.
aCredits | The string of credits. |
Reimplemented from OpenSim::Object.
bool OpenSim::Model::setGravity | ( | const SimTK::Vec3 & | aGrav | ) |
Set the gravity vector in the gloabl frame.
aGrav | The XYZ gravity vector |
void OpenSim::Model::setInitialTime | ( | double | ti | ) |
|
inline |
Set the XML file name used to construct the model.
fileName | The XML file name. |
|
overridevirtual |
Given a State, set all default values for this Model to match those found in the State.
Reimplemented from OpenSim::ModelComponent.
|
inline |
Set the publications associated with the model.
aPublications | The string of publications. |
void OpenSim::Model::setStateValues | ( | SimTK::State & | state, |
const double * | stateValues | ||
) | const |
Set the values of state variables which are passed in the same ordering as returned by getStateVariableNames().
Values are set in the passed in state object based on Y-indices that are associated with the named state variables.
[out] | state | State to be modified. |
[in] | stateValues | Pointer to an array of values corresponding to each of the named state variables. |
void OpenSim::Model::setup | ( | ) |
Perform some set up functions that happen after the object has been deserialized.
TODO: this method is not yet designed to be called after a model has been copied.
|
inline |
Request or suppress visualization of this Model.
This flag is checked during initSystem() and if set causes the Model to allocate a ModelVisualizer that provides visualization and interaction with the Model as it is executing. The default is no visualization.
void OpenSim::Model::storeControls | ( | const SimTK::State & | s, |
int | step | ||
) |
|
inline |
void OpenSim::Model::updateAssemblyConditions | ( | SimTK::State & | s | ) |
Update the AssemblySolver to the latest coordinate locking/constraints.
|
virtual |
Override of the default implementation to account for versioning.
Reimplemented from OpenSim::Object.
void OpenSim::Model::updateMarkerSet | ( | MarkerSet & | aMarkerSet | ) |
|
inline |
|
inline |
|
inline |
ControllerSet& OpenSim::Model::updControllerSet | ( | ) |
SimTK::Vector& OpenSim::Model::updControls | ( | const SimTK::State & | s | ) | const |
Update the controls for this the model at a given state.
Only valid once underlying system for the model has been created. Throws an exception if called before Model::initSystem() This call invalidates the dynamics of the model.
|
inline |
|
inline |
Writable access to the default values for controls.
These values are used for control value during a simulation unless updated, for example, by a Controller
|
inline |
(Advanced) Get writable access to the internal DefaultSystemSubsystem
allocated by this Model's Simbody MultibodySystem.
Reimplemented from OpenSim::ModelComponent.
|
inline |
Get writable access to the ModelDisplayHints object stored with this
Model.
The GUI or ModelVisualizer can update these as a result of user requests, or an OpenSim API program can set them programmatically.
|
inline |
|
inline |
(Advanced) Get writable access to the internal Simbody
GeneralForceSubsystem allocated by this Model.
|
inline |
(Advanced) Get writable access to the Simbody Force::Gravity element
that was allocated by this Model.
JointSet& OpenSim::Model::updJointSet | ( | ) |
|
inline |
|
inline |
(Advanced) Get writable access to the internal SimbodyMatterSubsystem
allocated by this Model.
|
inline |
|
inline |
(Advanced) Get writable access to the internal Simbody MultibodySystem
that was created by this Model at the last initSystem() call.
Be careful if you make modifications to the System because that will invalidate initialization already performed by the Model.
|
inline |
|
inline |
|
inline |
Obtain writable access to the ModelVisualizer.
This will throw an exception if visualization was not requested or initSystem() not yet called. Writable access to the ModelVisualizer requires that you have writable access to this containing Model.
void OpenSim::Model::writeMarkerFile | ( | const std::string & | aFileName | ) | const |
|
friend |