API  4.5.1
For C++ developers
OpenSim::Component Class Referenceabstract

The abstract Component class defines the interface used to add computational elements to the underlying SimTK::System (MultibodySystem). More...

+ Inheritance diagram for OpenSim::Component:

OpenSim Properties, Sockets, Outputs, Inputs

Properties (list)
Component components
 "List of components that this component owns and serializes." More...
 

Public Member Functions

 Component ()
 Default constructor. More...
 
 Component (const std::string &aFileName, bool aUpdateFromXMLNode=true)
 Construct Component from an XML file. More...
 
 Component (SimTK::Xml::Element &aNode)
 Construct Component from a specific node in an XML document. More...
 
 Component (const Component &)=default
 Use default copy constructor and assignment operator. More...
 
Componentoperator= (const Component &)=default
 
virtual ~Component ()=default
 Destructor is virtual to allow concrete Component to cleanup. More...
 
virtual void generateDecorations (bool fixed, const ModelDisplayHints &hints, const SimTK::State &state, SimTK::Array_< SimTK::DecorativeGeometry > &appendToThis) const
 Optional method for generating arbitrary display geometry that reflects this Component at the specified state. More...
 
const SimTK::MultibodySystem & getSystem () const
 Get the underlying MultibodySystem that this component is connected to. More...
 
bool hasSystem () const
 Check if this component has an underlying MultibodySystem. More...
 
bool isComponentInOwnershipTree (const Component *component) const
 Does the provided component already exist anywhere in the ownership tree (not just subcomponents of this component)? More...
 
void addComponent (Component *subcomponent)
 
Add a Component (as a subcomponent) of this component. More...
 
template<typename T = Component>
ComponentList< const T > getComponentList () const
 Get an iterator through the underlying subcomponents that this component is composed of. More...
 
template<typename T = Component>
ComponentList< T > updComponentList ()
 Similar to getComponentList(), except the resulting list allows one to modify the components. More...
 
template<typename T = Component>
unsigned countNumComponents () const
 Uses getComponentList<T>() to count the number of underlying subcomponents of the specified type. More...
 
std::string getAbsolutePathString () const
 Get the complete (absolute) pathname for this Component to its ancestral Component, which is the root of the tree to which this Component belongs. More...
 
ComponentPath getAbsolutePath () const
 Return a ComponentPath of the absolute path of this Component. More...
 
std::string getRelativePathString (const Component &wrt) const
 Get the relative path of this Component with respect to another Component, as a string. More...
 
ComponentPath getRelativePath (const Component &wrt) const
 Get the relative path of this Component with respect to another Component. More...
 
bool hasComponent (const std::string &pathname) const
 Query if there is a component (of any type) at the specified path name. More...
 
template<class C = Component>
bool hasComponent (const std::string &pathname) const
 Query if there is a component of a given type at the specified path name. More...
 
template<class C = Component>
const C & getComponent (const std::string &pathname) const
 Get a unique subcomponent of this Component by its path name and type 'C'. More...
 
template<class C = Component>
const C & getComponent (const ComponentPath &pathname) const
 
const ComponentgetComponent (const std::string &pathname) const
 Similar to the templatized getComponent(), except this returns the component as the generic Component type. More...
 
template<class C = Component>
C & updComponent (const std::string &name)
 Get a writable reference to a subcomponent. More...
 
template<class C = Component>
C & updComponent (const ComponentPath &name)
 
ComponentupdComponent (const std::string &pathname)
 Similar to the templatized updComponent(), except this returns the component as the generic Component type. More...
 
unsigned printComponentsMatching (const std::string &substring) const
 Print a list to the console of all components whose absolute path name contains the given string. More...
 
int getNumStateVariables () const
 Get the number of "continuous" state variables maintained by the Component and its subcomponents. More...
 
Array< std::string > getStateVariableNames () const
 Get the names of continuous state variables maintained by the Component and its subcomponents. More...
 
Array< std::string > getDiscreteVariableNames () const
 Get the names of discrete state variables maintained by the Component and its subcomponents. More...
 
Array< std::string > getModelingOptionNames () const
 Get the names of the modeling options maintained by the Component and its subcomponents. More...
 
Component Structural Interface

The structural interface ensures that deserialization, resolution of inter-connections, and handling of dependencies are performed systematically and prior to system creation, followed by allocation of necessary System resources.

These methods can be extended by virtual methods that form the Component Extension Interface (e.g. #extendFinalizeFromProperties) that can be implemented by subclasses of Components.

Component ensures that the corresponding calls are propagated to all of its subcomponents.

void finalizeFromProperties ()
 Define a Component's internal data members and structure according to its properties. More...
 
void finalizeConnections (Component &root)
 Satisfy the Component's connections specified by its Sockets and Inputs. More...
 
void clearConnections ()
 Disconnect/clear this Component from its aggregate component. More...
 
void addToSystem (SimTK::MultibodySystem &system) const
 Have the Component add itself to the underlying computational System. More...
 
void initStateFromProperties (SimTK::State &state) const
 Initialize Component's state variable values from its properties. More...
 
void setPropertiesFromState (const SimTK::State &state)
 Set Component's properties given a state. More...
 
Component Socket Access methods

Access Sockets of this component by name.

int getNumSockets () const
 Get the number of Sockets in this Component. More...
 
std::vector< std::string > getSocketNames () const
 Collect and return the names of the sockets in this component. More...
 
template<typename T >
const T & getConnectee (const std::string &name) const
 Get the "connectee" object that the Component's Socket is bound to. More...
 
template<typename T >
const T & getConnectee (const std::string &name, int index) const
 Get the "connectee" object at the provided index that the Component's Socket is bound to. More...
 
const ObjectgetConnectee (const std::string &name) const
 Get the connectee as an Object. More...
 
const ObjectgetConnectee (const std::string &name, int index) const
 Get the connectee at the provided index as an Object. More...
 
const AbstractSockettryGetSocket (const std::string &name) const
 Returns a pointer to the AbstractSocket with a given socket name, or nullptr if the socket with the given name does not exist on the component. More...
 
const AbstractSocketgetSocket (const std::string &name) const
 Get an AbstractSocket for the given socket name. More...
 
const AbstractSockettryUpdSocket (const std::string &name)
 Returns a writable pointer to the AbstractSocket with a given socket name, or nullptr if the socket with the given name does not exist on the component. More...
 
AbstractSocketupdSocket (const std::string &name)
 Get a writable reference to the AbstractSocket for the given socket name. More...
 
template<typename T >
const Socket< T > & getSocket (const std::string &name) const
 Get a const reference to the concrete Socket provided by this Component by name. More...
 
template<typename T >
Socket< T > & updSocket (const std::string &name)
 Get a writable reference to the concrete Socket provided by this Component by name. More...
 
Component State Access methods

Get and set modeling option, input and output values, state variable, discrete and/or cache variables in the State.

int getModelingOption (const SimTK::State &state, const std::string &path) const
 Based on a specified path, get the value of a modeling option. More...
 
int getModelingOption (const SimTK::State &state, const ComponentPath &path) const
 
void setModelingOption (SimTK::State &state, const std::string &path, int flag) const
 Based on a specified path, set the value of a modeling option. More...
 
void setModelingOption (SimTK::State &state, const ComponentPath &path, int flag) const
 
template<typename T >
const T & getInputValue (const SimTK::State &state, const std::string &name) const
 Get the Input value that this component is dependent on. More...
 
template<typename T >
const T & getOutputValue (const SimTK::State &state, const std::string &name) const
 Get the Output value provided by this Component by name. More...
 
double getStateVariableValue (const SimTK::State &state, const std::string &name) const
 Get the value of a state variable allocated by this Component. More...
 
double getStateVariableValue (const SimTK::State &state, const ComponentPath &path) const
 Get the value of a state variable allocated by this Component. More...
 
void setStateVariableValue (SimTK::State &state, const std::string &name, double value) const
 Set the value of a state variable allocated by this Component by name. More...
 
SimTK::Vector getStateVariableValues (const SimTK::State &state) const
 Get all values of the state variables allocated by this Component. More...
 
void setStateVariableValues (SimTK::State &state, const SimTK::Vector &values) const
 Set all values of the state variables allocated by this Component. More...
 
double getStateVariableDerivativeValue (const SimTK::State &state, const std::string &name) const
 Get the value of a state variable derivative computed by this Component. More...
 
double getStateVariableDerivativeValue (const SimTK::State &state, const ComponentPath &path) const
 Get the value of a state variable derivative computed by this Component. More...
 
- Public Member Functions inherited from OpenSim::Object
virtual ~Object ()
 Virtual destructor for cleanup. More...
 
bool isEqualTo (const Object &aObject) const
 Equality operator wrapper for use from languages not supporting operator overloading. More...
 
Objectoperator= (const Object &aObject)
 Copy assignment copies he base class fields, including the properties. More...
 
virtual bool operator== (const Object &aObject) const
 Determine if two objects are equal. More...
 
virtual bool operator< (const Object &aObject) const
 Provide an ordering for objects so they can be put in sorted containers. More...
 
void setName (const std::string &name)
 Set the name of the Object. More...
 
const std::string & getName () const
 Get the name of this Object. More...
 
void setDescription (const std::string &description)
 Set description, a one-liner summary. More...
 
const std::string & getDescription () const
 Get description, a one-liner summary. More...
 
const std::string & getAuthors () const
 Get Authors of this Object. More...
 
void setAuthors (const std::string &authors)
 Set Authors of this object. More...
 
const std::string & getReferences () const
 Get references or publications to cite if using this object. More...
 
void setReferences (const std::string &references)
 Set references or publications to cite if using this object. More...
 
int getNumProperties () const
 Determine how many properties are stored with this Object. More...
 
const AbstractPropertygetPropertyByIndex (int propertyIndex) const
 Get a const reference to a property by its index number, returned as an AbstractProperty. More...
 
AbstractPropertyupdPropertyByIndex (int propertyIndex)
 Get a writable reference to a property by its index number, returned as an AbstractProperty. More...
 
bool hasProperty (const std::string &name) const
 Return true if this Object has a property of any type with the given name, which must not be empty. More...
 
const AbstractPropertygetPropertyByName (const std::string &name) const
 Get a const reference to a property by its name, returned as an AbstractProperty. More...
 
AbstractPropertyupdPropertyByName (const std::string &name)
 Get a writable reference to a property by its name, returned as an AbstractProperty. More...
 
template<class T >
bool hasProperty () const
 Return true if this Object contains an unnamed, one-object property that contains objects of the given template type T. More...
 
template<class T >
const Property< T > & getProperty (const PropertyIndex &index) const
 Get property of known type Property<T> as a const reference; the property must be present and have the right type. More...
 
template<class T >
const Property< T > & getPropertyByName (const std::string &name) const
 Get property of known type Property<T> as a const reference; the property must be present and have the right type. More...
 
template<class T >
Property< T > & updProperty (const PropertyIndex &index)
 Get property of known type Property<T> as a writable reference; the property must be present and have the right type. More...
 
template<class T >
Property< T > & updPropertyByName (const std::string &name)
 Get property of known type Property<T> as a writable reference; the property must be present and have the right type.
More...
 
bool isObjectUpToDateWithProperties () const
 Returns true if no property's value has changed since the last time setObjectIsUpToDateWithProperties() was called. More...
 
void readObjectFromXMLNodeOrFile (SimTK::Xml::Element &objectElement, int versionNumber)
 We're given an XML element from which we are to populate this Object. More...
 
virtual void updateFromXMLNode (SimTK::Xml::Element &objectElement, int versionNumber)
 Use this method to deserialize an object from a SimTK::Xml::Element. More...
 
void updateXMLNode (SimTK::Xml::Element &parent, const AbstractProperty *prop=nullptr) const
 Serialize this object into the XML node that represents it. More...
 
bool getInlined () const
 Inlined means an in-memory Object that is not associated with an XMLDocument. More...
 
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. More...
 
std::string getDocumentFileName () const
 If there is a document associated with this object then return the file name maintained by the document. More...
 
int getDocumentFileVersion () const
 If there is a document associated with this object then return its version number. More...
 
void setAllPropertiesUseDefault (bool aUseDefault)
 
bool print (const std::string &fileName) const
 Write this Object into an XML file of the given name; conventionally the suffix to use is ".osim". More...
 
std::string dump () const
 dump the XML representation of this Object into an std::string and return it. More...
 
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. More...
 
const std::string & toString () const
 Wrapper to be used on Java side to display objects in tree; this returns just the object's name. More...
 
PropertySetgetPropertySet ()
 OBSOLETE: Get a reference to the PropertySet maintained by the Object. More...
 
const PropertySetgetPropertySet () const
 

Public Types

typedef Component Self
 This typedef might be useful within the member functions of this class. More...
 
typedef Object Super
 Use this typedef to refer to the superclass of this class. More...
 

Protected Member Functions

Property-related functions
const Componentget_components (int i) const
 Get the value of the i-th element of the components property. More...
 
Componentupd_components (int i)
 Get a writable reference to the i-th element of the components property. More...
 
void set_components (int i, const Component &value)
 Set the value of the i-th element of components property. More...
 
int append_components (const Component &value)
 Append an element to the components property. More...
 
- Protected Member Functions inherited from OpenSim::Object
 Object ()
 The default constructor is only for use by constructors of derived types. More...
 
 Object (const std::string &fileName, bool aUpdateFromXMLNode=true)
 Constructor from a file, to be called from other constructors that take a file as input. More...
 
 Object (const Object &source)
 Copy constructor is invoked automatically by derived classes with default copy constructors; otherwise it must be invoked explicitly. More...
 
 Object (SimTK::Xml::Element &aElement)
 Construct the base class portion of an Object from a given Xml element that describes this Object. More...
 
template<class T >
PropertyIndex addProperty (const std::string &name, const std::string &comment, const T &value)
 Define a new single-value property of known type T, with the given name, associated comment, and initial value. More...
 
template<class T >
PropertyIndex addOptionalProperty (const std::string &name, const std::string &comment)
 Add an optional property, meaning it can contain either no value or a single value. More...
 
template<class T >
PropertyIndex addOptionalProperty (const std::string &name, const std::string &comment, const T &value)
 Add an optional property, meaning it can contain either no value or a single value. More...
 
template<class T >
PropertyIndex addListProperty (const std::string &name, const std::string &comment, int minSize, int maxSize)
 Define a new list-valued property of known type T, with the given name, associated comment, minimum (==0) and maximum (>0) allowable list lengths, and a zero-length initial value. More...
 
template<class T , template< class > class Container>
PropertyIndex addListProperty (const std::string &name, const std::string &comment, int minSize, int maxSize, const Container< T > &valueList)
 Define a new list-valued property as above, but assigning an initial value via some templatized container class that supports size() and indexing. More...
 
PropertyIndex getPropertyIndex (const std::string &name) const
 Look up a property by name and return its PropertyIndex if it is found. More...
 
template<class T >
PropertyIndex getPropertyIndex () const
 Look up an unnamed property by the type of object it contains, and return its PropertyIndex if it is found. More...
 
template<class T >
void checkPropertyValueIsPositive (const Property< T > &p) const
 Throw an exception if any of the property's values are not positive. More...
 
template<class T >
void checkPropertyValueIsInSet (const Property< T > &p, const std::set< T > &set) const
 Throw an exception if any of the property's values are not in the provided set. More...
 
template<class T >
void checkPropertyValueIsInRangeOrSet (const Property< T > &p, const T &lower, const T &upper, const std::set< T > &set) const
 Throw an exception if any of the property's values are neither in the provided range nor in the provided set. More...
 
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. More...
 
void clearObjectIsUpToDateWithProperties ()
 For testing or debugging purposes, manually clear the "object is up to date with respect to properties" flag. More...
 
void makeObjectNamesConsistentWithProperties ()
 Make sure the name of an object is consistent with its property type. More...
 
void updateFromXMLDocument ()
 Use this method only if you're deserializing from a file and the object is at the top level; that is, primarily in constructors that take a file name as input. More...
 
void setDocument (XMLDocument *)
 Unconditionally set the XMLDocument associated with this object. More...
 
const XMLDocumentgetDocument () const
 Get a const pointer to the document (if any) associated with this object. More...
 
XMLDocumentupdDocument ()
 Get a writable pointer to the document (if any) associated with this object. More...
 

Friends

template<typename T >
class ComponentList
 Class that permits iterating over components/subcomponents (but does not actually contain the components themselves). More...
 
template<typename T >
class ComponentListIterator
 Class to iterate over ComponentList returned by getComponentList(). More...
 

Auto-generated functions

static ComponentsafeDownCast (OpenSim::Object *obj)
 For use in MATLAB and Python to access the concrete class. More...
 
static const std::string & getClassName ()
 This returns "Component". More...
 
void assign (Object &aObject) override
 This allows copy assignment in the Java GUI. More...
 
Componentclone () const override=0
 Create a new heap-allocated copy of the concrete object to which this Object refers. More...
 
const std::string & getConcreteClassName () const override=0
 Returns the class name of the concrete Object-derived class of the actual object referenced by this Object, as a string. More...
 

Component Inputs and Outputs Access methods

Access inputs and outputs by name and iterate over all outputs.

typedef std::map< std::string, SimTK::ClonePtr< AbstractOutput > >::const_iterator OutputConstIterator
 Define OutputConstIterator for convenience. More...
 
int getNumInputs () const
 Access the number of Inputs that this component has. More...
 
int getNumOutputs () const
 Access the number of Outputs that this component has. More...
 
std::vector< std::string > getInputNames () const
 Collect and return the names of Inputs in this component as an std::vector. More...
 
std::vector< std::string > getOutputNames () const
 Collect and return the names of Outputs in this component as an std::vector. More...
 
const AbstractInputgetInput (const std::string &name) const
 Get an Input provided by this Component by name. More...
 
AbstractInputupdInput (const std::string &name)
 Get a writable reference to an Input provided by this Component by name. More...
 
template<typename T >
const Input< T > & getInput (const std::string &name) const
 Get a concrete Input that you can directly ask for its values. More...
 
const AbstractOutputtryGetOutput (const std::string &name) const
 If it exists on the component, returns a pointer to the named Output; otherwise, returns a nullptr. More...
 
const AbstractOutputgetOutput (const std::string &name) const
 Get the Output provided by this Component by name. More...
 
AbstractOutputtryUpdOutput (const std::string &name)
 If it exists on the component returns a writable pointer to the named Output; otherwise, returns a nullptr More...
 
AbstractOutputupdOutput (const std::string &name)
 Get a writable reference to an Output provided by this Component by name. More...
 
SimTK::IteratorRange< OutputConstIteratorgetOutputs () const
 Iterate through all Outputs of this component. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from OpenSim::Object
static void registerType (const Object &defaultObject)
 Register an instance of a class; if the class is already registered it will be replaced. More...
 
static void renameType (const std::string &oldTypeName, const std::string &newTypeName)
 Support versioning by associating the current Object type with an old name. More...
 
static const ObjectgetDefaultInstanceOfType (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. More...
 
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*. More...
 
static ObjectnewInstanceOfType (const std::string &concreteClassName)
 Create a new instance of the concrete Object type whose class name is given as concreteClassName. More...
 
static void getRegisteredTypenames (Array< std::string > &typeNames)
 Retrieve all the typenames registered so far. More...
 
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. More...
 
static bool PrintPropertyInfo (std::ostream &os, const std::string &classNameDotPropertyName, bool printFlagInfo=true)
 Dump formatted property information to a given output stream, useful for creating a "help" facility for registered objects. More...
 
static bool PrintPropertyInfo (std::ostream &os, const std::string &className, const std::string &propertyName, bool printFlagInfo=true)
 Same as the other signature but the class name and property name are provided as two separate strings. More...
 
static ObjectmakeObjectFromFile (const std::string &fileName)
 Create an OpenSim object whose type is based on the tag at the root node of the XML file passed in. More...
 
static const std::string & getClassName ()
 Return the name of this class as a string; i.e., "Object". More...
 
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. More...
 
static bool getSerializeAllDefaults ()
 Report the value of the "serialize all defaults" flag. More...
 
static bool isKindOf (const char *type)
 Returns true if the passed-in string is "Object"; each Object-derived class defines a method of this name for its own class name. More...
 
static void setDebugLevel (int newLevel)
 Set the amount of logging output. More...
 
static int getDebugLevel ()
 Get the current setting of debug level. More...
 
static ObjectSafeCopy (const Object *aObject)
 Use the clone() method to duplicate the given object unless the pointer is null in which case null is returned. More...
 
static void RegisterType (const Object &defaultObject)
 OBSOLETE alternate name for registerType(). More...
 
static void RenameType (const std::string &oldName, const std::string &newName)
 OBSOLETE alternate name for renameType(). More...
 
- Static Public Attributes inherited from OpenSim::Object
static const std::string DEFAULT_NAME
 Name used for default objects when they are serialized. More...
 
- Protected Attributes inherited from OpenSim::Object
PropertySet _propertySet
 OBSOLETE: Property_Deprecated set for serializable member variables of this and derived classes. More...
 

Detailed Description

The abstract Component class defines the interface used to add computational elements to the underlying SimTK::System (MultibodySystem).

It specifies the interface that components must satisfy in order to be part of the system and provides a series of helper methods for adding variables (state, discrete, cache, ...) to the underlying system. As such, Component handles all of the bookkeeping of system indices and provides convenience access to variable values (incl. derivatives) via their names as strings.

Component's Interfaces

System and State

The MultibodySystem and its State are defined by Simbody (ref ...). Briefly, a System represents the mathematical equations that specify the behavior of a computational model. The State is a collection of all the variables that uniquely define the unknowns in the system equations. Consider a single differential equation as a system, while a single set of variable values that satisfy the equation is a state of that system. These could be values for joint coordinates, their speeds, as well other variables that govern the system dynamics (e.g. muscle activation and fiber-length variables that dictate muscle force). These variables are called continuous state variables in Simbody, but are more simply referred to as StateVariables in OpenSim. Component provides services to define and access its StateVariables and specify their dynamics (derivatives with respect to time) that are automatically and simultaneously integrated with the MultibodySystem dynamics. Common operations to integrate, take the max or min, or to delay a signal, etc. require internal variables to perform their calculations and these are also held in the State. Simbody provides the infrastructure to ensure that calculations are kept up-to-date with the state variable values.

There are other types of "State" variables such as a flag (or options) that enables a component to be disabled or for a muscle force to be overridden and and these are identified as ModelingOptions since they may change the modeled dynamics of the component. Component provides services that enable developers of components to define additional ModelingOptions.

Discrete variables

Often a component requires input from an outside source (precomputed data from a file, another program, or interaction from a user) in which case these variables do not have dynamics (differential eqns.) known to the component, but are necessary to describe the dynamical "state" of the system. An example, is a throttle component (a "controller" that provides an actuator, e.g. a motor, with a control signal like a voltage or current) which it gets as direct input from the user (via a joystick, key press, etc..). The throttle controls the motor torque output and therefore the behavior of the model. The input by the user to the throttle the motor (the controls) is necessary to specify the model dynamics at any instant and therefore are considered part of the State. In OpenSim they are simply referred to as DiscreteVariables. The Component provides services to enable developers of components to define and access its DiscreteVariables.

Cache variables

Fast and efficient simulations also require computationally expensive calculations to be performed only when necessary. Often the result of an expensive calculation can be reused many times over, while the variables it is dependent on remain fixed. The concept of holding onto these values is called caching and the variables that hold these values are call CacheVariables. It is important to note, that cache variables are not state variables. Cache variables can always be recomputed exactly from the State. OpenSim uses the Simbody infrastructure to manage cache variables and their validity. Component provides a simplified interface to define and access CacheVariables.

Stages

Many modeling and simulation codes put the onus on users and component creators to manage the validity of cache variables, which is likely to lead to undetectable errors where cache values are stale (calculated based on past state variable values). Simbody, on the other hand, provides a more strict infrastructure to make it easy to exploit the efficiencies of caching while reducing the risks of validity errors. To do this, Simbody employs the concept of computational stages to "realize" (or compute) a model's system to a particular stage requires cached quantities up to and including the stage to to computed/specified. Simbody utilizes nine realization stages (SimTK::Stage::)

  1. Topology finalize System with "slots" for most variables (above)
  2. Model specify modeling choices
  3. Instance specify modifiable model parameters
  4. Time compute time dependent quantities
  5. Position compute position dependent quantities
  6. Velocity compute velocity dependent quantities
  7. Dynamics compute system applied forces and dependent quantities
  8. Acceleration compute system accelerations and all other derivatives
  9. Report compute quantities for reporting/output

The Component interface is automatically invoked by the System and its realizations. Component users and most developers need not concern themselves with Topology, Model or Instance stages. That interaction is managed by Component when component creators implement extendAddToSystem() and use the services provided by Component. Component creators do need to determine and specify stage dependencies for Discrete and CacheVariables that they add to their components. For example, the throttle controller reads its value from user input and it is valid for all calculations as long as time does not change. If the simulation (via numerical integration) steps forward (or backward for a trial step) and updates the state, the control from a previous state (time) should be invalid and an error generated for trying to access the DiscreteVariable for the control value. To do this one specifies the "invalidates" stage (e.g. SimTK::Stage::Time) for a DiscreteVariable when the variable is added to the Component. A subsequent change to that variable will invalidate all state cache entries at that stage or higher. For example, if a DiscreteVariable is declared to invalidate Stage::Position then changing it will invalidate cache entries that depend on positions, velocities, forces, and accelerations.

Similar principles apply to CacheVariables, which requires a "dependsOn" stage to be specified when a CacheVariable is added to the component. In this case, the cache variable "shadows" the State (unlike a DiscreteVariable, which is a part of the State) holding already-computed state-dependent values so that they do not need to be recomputed until the state changes. Accessing the CacheVariable in a State whose current stage is lower than that CacheVariable's specified dependsOn stage will trigger an exception. It is up to the component to update the value of the cache variable. Component provides methods to check if the cache is valid, update its value and then to mark it as valid.

The interface of this class

The primary responsibility of a Component is to add its computational representation(s) to the underlying SimTK::System by implementing extendAddToSystem().

Additional methods provide support for adding modeling options, state and cache variables.

Public methods enable access to component variables via their names.

Subcomponents

A Component can have any number of Components within it; we call these subcomponents. Subcomponents can also contain their own subcomponents as well. There are three categories of subcomponents, which vary in whether they are configurable and fixed in number:

  • property subcomponents Any Property in a Component that is of type Component is a subcomponent. This includes list properties and Sets. This is the most common category of subcomponent, and its distinguishing feature is that these subcomponents are configurable by the user of this component. These subcomponents appear in the XML for this component, and can be modified in XML or through the API. They are also not fixed in number; users can add more property subcomponents to an existing component (though it is possible to enforce a fixed number by using one-value properties or limiting the size of a list property). The bodies, joints, forces, etc. in a Model's BodySet, JointSet, ForceSet, etc. are all examples of property subcomponents. This category of subcomponent is the most similar to what was available pre-v4.0.
  • member subcomponents These are not configurable by the user of this Component, and can only be modified by this Component. You can still access member subcomponents through the API, but only the component containing the subcomponents can modify them. Any Component class can have any number of member subcomponents, but this number is fixed for every instance of the component.
  • adopted subcomponents These are not configurable (does not appear in XML) and not fixed in number. For example, a component can decide, based on other aspects of the model, that it needs to create a new subcomponent. This can be done using adopted subcomponents.

Also, any specific Component can end up in any of these three categories. That is, if you have a MySpecialForce Component, any other Component can have it as a property subcomponent, a member subcomponent, or as an adopted subcomponent.

Author
Ajay Seth, Michael Sherman, Chris Dembia
Examples:
exampleCustomImplicitAuxiliaryDynamics.cpp.

Member Typedef Documentation

◆ OutputConstIterator

typedef std::map<std::string, SimTK::ClonePtr<AbstractOutput> >:: const_iterator OpenSim::Component::OutputConstIterator

Define OutputConstIterator for convenience.

◆ Self

This typedef might be useful within the member functions of this class.

This is generated by the OpenSim_DECLARE_*_OBJECT macros.

◆ Super

Use this typedef to refer to the superclass of this class.

Avoid using the explicit type name of the superclass; this would introduce bugs if the superclass is changed.

This is generated by the OpenSim_DECLARE_*_OBJECT macros.

Constructor & Destructor Documentation

◆ Component() [1/4]

OpenSim::Component::Component ( )

Default constructor.

◆ Component() [2/4]

OpenSim::Component::Component ( const std::string &  aFileName,
bool  aUpdateFromXMLNode = true 
)

Construct Component from an XML file.

◆ Component() [3/4]

OpenSim::Component::Component ( SimTK::Xml::Element &  aNode)
explicit

Construct Component from a specific node in an XML document.

◆ Component() [4/4]

OpenSim::Component::Component ( const Component )
default

Use default copy constructor and assignment operator.

◆ ~Component()

virtual OpenSim::Component::~Component ( )
virtualdefault

Destructor is virtual to allow concrete Component to cleanup.

Member Function Documentation

◆ addComponent()

void OpenSim::Component::addComponent ( Component subcomponent)


Add a Component (as a subcomponent) of this component.

This component takes ownership of the subcomponent and it will be serialized (appear in XML) as part of this component. Specifically, it will appear in the <components> list for this Component. If the subcomponent is already owned by this component or exists in the same hierarchy (tree) as this component, an Exception is thrown.

Note
addComponent is intended to replace existing addBody(), addJoint, ... on Model or the requirement for specific add###() methods to subcomponents to a Component.

Typical usage is:

// Start with an empty Model (which is a Component)
Model myModel;
// Create any Component type on the heap
Body* newBody = new Body();
// Customize the Component by setting its properties
newBody->setName("newBody");
newBody->setMass(10.0);
newBody->setMassCenter(SimTK::Vec3(0));
// ...
// Now add it to your model, which will take ownership of it
myModel.addComponent(newBody);
//
// Keep creating and adding new components, like Joints, Forces, etc..
Exceptions
ComponentAlreadyPartOfOwnershipTree
Parameters
subcomponentis the Component to be added.
Examples:
example2DWalkingMetabolics.cpp, exampleCustomImplicitAuxiliaryDynamics.cpp, and exampleHangingMuscle.cpp.

◆ addToSystem()

void OpenSim::Component::addToSystem ( SimTK::MultibodySystem &  system) const

Have the Component add itself to the underlying computational System.

◆ append_components()

int OpenSim::Component::append_components ( const Component value)
inlineprotected

Append an element to the components property.

◆ assign()

void OpenSim::Component::assign ( Object aObject)
inlineoverride

This allows copy assignment in the Java GUI.

Exceptions
Exceptionif the argument is not of type Component.

◆ clearConnections()

void OpenSim::Component::clearConnections ( )

Disconnect/clear this Component from its aggregate component.

Empties all component's sockets and sets them as disconnected.

◆ clone()

Component* OpenSim::Component::clone ( ) const
overridepure virtual

Create a new heap-allocated copy of the concrete object to which this Object refers.

It is up to the caller to delete the returned object when no longer needed. Every concrete object deriving from Object implements this pure virtual method automatically, via the declaration macro it invokes (e.g., OpenSim_DECLARE_CONCRETE_OBJECT()). Note that the concrete class overrides modify the return type to be a pointer to the concrete object; that still overrides the base class method because the return type is covariant with (that is, derives from) Object.

Implements OpenSim::Object.

Implemented in OpenSim::FrameGeometry, OpenSim::Mesh, OpenSim::Brick, OpenSim::Torus, OpenSim::Cone, OpenSim::Cylinder, OpenSim::Ellipsoid, OpenSim::Sphere, OpenSim::AnalyticGeometry, OpenSim::Model, OpenSim::Millard2012AccelerationMuscle, OpenSim::ConsoleReporter_< T >, OpenSim::Arrow, OpenSim::EspositoMiller2018Force, OpenSim::Bhargava2004SmoothedMuscleMetabolics, OpenSim::Umberger2010MuscleMetabolicsProbe, OpenSim::Millard2012EquilibriumMuscle, OpenSim::LineGeometry, OpenSim::Bhargava2004MuscleMetabolicsProbe, OpenSim::TableReporter_< InputT, ValueT >, OpenSim::HuntCrossleyForce, OpenSim::ElasticFoundationForce, OpenSim::Blankevoort1991Ligament, OpenSim::MeyerFregly2016Force, OpenSim::ScalarActuator, OpenSim::HuntCrossleyForce, OpenSim::DeGrooteFregly2016Muscle, OpenSim::ElasticFoundationForce, OpenSim::Probe, OpenSim::Thelen2003Muscle, OpenSim::FunctionBasedPath, OpenSim::Joint, OpenSim::Reporter< InputT >, OpenSim::StationDefinedFrame, OpenSim::Reporter< T >, OpenSim::MuscleFixedWidthPennationModel, OpenSim::ModelComponent, OpenSim::FirstOrderMuscleActivationDynamics, OpenSim::Frame, OpenSim::MuscleFirstOrderActivationDynamicModel, OpenSim::AckermannVanDenBogert2010Force, OpenSim::Muscle, OpenSim::CMC, OpenSim::Controller, OpenSim::PrescribedController, OpenSim::ControlDistributor, OpenSim::SmoothSphereHalfSpaceForce, OpenSim::SynergyController, OpenSim::InputController, OpenSim::ExternalLoads, OpenSim::OffsetFrame< PhysicalFrame >, OpenSim::ClutchedPathSpring, OpenSim::AbstractGeometryPath, OpenSim::CoordinateLimitForce, OpenSim::PhysicalFrame, OpenSim::Delp1990Muscle_Deprecated, OpenSim::RigidTendonMuscle, OpenSim::GeometryPath, OpenSim::ModelComponentSet< T >, OpenSim::RollingOnSurfaceConstraint, OpenSim::ModelComponentSet< ExternalForce >, OpenSim::ModelComponentSet< ContactGeometry >, OpenSim::ModelComponentSet< WrapObject >, OpenSim::ModelComponentSet< Force >, OpenSim::ModelComponentSet< Joint >, OpenSim::ModelComponentSet< Probe >, OpenSim::ModelComponentSet< Controller >, OpenSim::ModelComponentSet< ModelComponent >, OpenSim::ModelComponentSet< Marker >, OpenSim::ModelComponentSet< Body >, OpenSim::ModelComponentSet< Constraint >, OpenSim::ScapulothoracicJoint, OpenSim::MuscleActivationDynamics, OpenSim::ExpressionBasedPointToPointForce, OpenSim::ExternalForce, OpenSim::ActivationFiberLengthMuscle, OpenSim::Geometry, OpenSim::PathSpring, OpenSim::ExpressionBasedBushingForce, OpenSim::FunctionBasedBushingForce, OpenSim::PrescribedForce, OpenSim::TwoFrameLinker< Force, PhysicalFrame >, OpenSim::TwoFrameLinker< Constraint, PhysicalFrame >, OpenSim::ActivationFiberLengthMuscle_Deprecated, OpenSim::BushingForce, OpenSim::Ligament, OpenSim::Coordinate, OpenSim::CustomJoint, OpenSim::Schutte1993Muscle_Deprecated, OpenSim::TorqueActuator, OpenSim::BallJoint, OpenSim::CoordinateCouplerConstraint, OpenSim::BodyActuator, OpenSim::PointActuator, OpenSim::Thelen2003Muscle_Deprecated, OpenSim::PointToPointActuator, OpenSim::Actuator, OpenSim::Point, OpenSim::FreeJoint, OpenSim::UnilateralConstraint, OpenSim::ActivationCoordinateActuator, OpenSim::CoordinateActuator, OpenSim::McKibbenActuator, OpenSim::ForceSet, OpenSim::JointInternalPowerProbe, OpenSim::PhysicalOffsetFrame, OpenSim::WeldConstraint, OpenSim::ControlSetController, OpenSim::ConstantCurvatureJoint, OpenSim::EllipsoidJoint, OpenSim::CorrectionController, OpenSim::AbstractReporter, OpenSim::TableSource_< ET >, OpenSim::PathActuator, OpenSim::ExperimentalMarker, OpenSim::IMU, OpenSim::WrapObject, OpenSim::Set< Joint, ModelComponent >, OpenSim::Set< Marker, ModelComponent >, OpenSim::Set< T, ModelComponent >, OpenSim::Set< ContactGeometry, ModelComponent >, OpenSim::Set< Controller, ModelComponent >, OpenSim::Set< WrapObject, ModelComponent >, OpenSim::Set< Probe, ModelComponent >, OpenSim::Set< ModelComponent, ModelComponent >, OpenSim::Set< Body, ModelComponent >, OpenSim::Set< Constraint, ModelComponent >, OpenSim::Set< ExternalForce, ModelComponent >, OpenSim::Set< Force, ModelComponent >, OpenSim::SpringGeneralizedForce, OpenSim::ControllerSet, OpenSim::ExperimentalFrame, OpenSim::PinJoint, OpenSim::UniversalJoint, OpenSim::AccelerationMotion, OpenSim::ActuatorPowerProbe, OpenSim::ContactGeometry, OpenSim::Force, OpenSim::Marker, OpenSim::MovingPathPoint, OpenSim::MuscleActiveFiberPowerProbe, OpenSim::SystemEnergyProbe, OpenSim::PointConstraint, OpenSim::Constraint, OpenSim::GimbalJoint, OpenSim::PlanarJoint, OpenSim::WrapCylinder, OpenSim::WrapEllipsoid, OpenSim::WrapSphere, OpenSim::WrapTorus, OpenSim::SignalGenerator, OpenSim::ActuatorForceProbe, OpenSim::ConditionalPathPoint, OpenSim::JointSet, OpenSim::Station, OpenSim::PositionMotion, OpenSim::Body, OpenSim::SliderJoint, OpenSim::WeldJoint, OpenSim::PathWrapPoint, OpenSim::ConstantMuscleActivation, OpenSim::ActuatorInputController, OpenSim::ComponentSet, OpenSim::Ground, OpenSim::PointToPointSpring, OpenSim::ConstantDistanceConstraint, OpenSim::ZerothOrderMuscleActivationDynamics, OpenSim::ElasticFoundationForce, OpenSim::PathPoint, OpenSim::ProbeSet, OpenSim::PointOnLineConstraint, OpenSim::StatesTrajectoryReporter, OpenSim::WrapObjectSet, OpenSim::DiscreteForces, OpenSim::AbstractPathPoint, OpenSim::ContactGeometrySet, OpenSim::ContactHalfSpace, OpenSim::HuntCrossleyForce, OpenSim::BodySet, OpenSim::ConstraintSet, OpenSim::ContactMesh, OpenSim::MarkerSet, OpenSim::MocoScaleFactor, OpenSim::Bhargava2004SmoothedMuscleMetabolics_MuscleParameters, OpenSim::ContactSphere, OpenSim::ExpressionBasedCoordinateForce, and OpenSim::StationPlaneContactForce.

◆ countNumComponents()

template<typename T = Component>
unsigned OpenSim::Component::countNumComponents ( ) const
inline

Uses getComponentList<T>() to count the number of underlying subcomponents of the specified type.

Template Parameters
TA subclass of Component (e.g., Body, Muscle).

◆ finalizeConnections()

void OpenSim::Component::finalizeConnections ( Component root)

Satisfy the Component's connections specified by its Sockets and Inputs.

Locate Components and their Outputs to satisfy the connections in an aggregate Component (e.g. Model), which is the root of a tree of Components.

◆ finalizeFromProperties()

void OpenSim::Component::finalizeFromProperties ( )

Define a Component's internal data members and structure according to its properties.

This includes its subcomponents as part of the component ownership tree and identifies its owner (if present) in the tree. finalizeFromProperties propagates to all of the component's subcomponents prior to invoking the virtual extendFinalizeFromProperties() on itself. Note that if the Component has already been added to a System (result of addToSystem(); e.g., Model::initSystem()) when finalizeFromProperties() is called, then finalizeFromProperties() disassociates the component from that System.

Referenced by OpenSim::ModOpTendonComplianceDynamicsModeDGF::operate(), OpenSim::ModOpUseImplicitTendonComplianceDynamicsDGF::operate(), OpenSim::ModOpIgnorePassiveFiberForcesDGF::operate(), OpenSim::ModOpPassiveFiberStrainAtOneNormForceDGF::operate(), OpenSim::ModOpScaleActiveFiberForceCurveWidthDGF::operate(), and OpenSim::ModOpFiberDampingDGF::operate().

◆ generateDecorations()

virtual void OpenSim::Component::generateDecorations ( bool  fixed,
const ModelDisplayHints hints,
const SimTK::State &  state,
SimTK::Array_< SimTK::DecorativeGeometry > &  appendToThis 
) const
inlinevirtual

Optional method for generating arbitrary display geometry that reflects this Component 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.

Please note that there is a precondition that the state passed in to generateDecorations be realized to Stage::Position. If your component can visualize quantities realized at Velocity, Dynamics or Acceleration stages, then you must check that the stage has been realized before using/requesting stage dependent values. It is forbidden to realize the model to a higher stage within generateDecorations, because this can trigger costly side- effects such as evaluating all model forces even when performing a purely kinematic study.

If you override this method, be sure to invoke the base class method first, using code like this:

void MyComponent::generateDecorations
(bool fixed,
const ModelDisplayHints& hints,
const SimTK::State& state,
SimTK::Array_<SimTK::DecorativeGeometry>& appendToThis) const
{
// invoke parent class method
Super::generateDecorations(fixed,hints,state,appendToThis);
// ... your code goes here
// can render velocity dependent quanities if stage is Velocity or higher
if(state.getSystemStage() >= Stage::Velocity) {
// draw velocity vector for model COM
}
// can render computed forces if stage is Dynamics or higher
if(state.getSystemStage() >= Stage::Dynamics) {
// change the length of a force arrow based on the force in N
}
}
Parameters
[in]fixedIf true, generate only geometry that is fixed to a PhysicalFrame, configuration, and velocity. Otherwise generate only such dependent geometry.
[in]hintsSee 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]stateThe State for which geometry should be produced. See below for more information.
[in,out]appendToThisArray 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 in OpenSim::Model, OpenSim::FrameGeometry, OpenSim::ExpressionBasedBushingForce, OpenSim::ConstantCurvatureJoint, OpenSim::GeometryPath, OpenSim::FunctionBasedBushingForce, OpenSim::SmoothSphereHalfSpaceForce, OpenSim::EllipsoidJoint, OpenSim::Geometry, OpenSim::ConstantDistanceConstraint, OpenSim::IMU, OpenSim::ContactMesh, OpenSim::ContactSphere, OpenSim::Marker, OpenSim::ContactHalfSpace, OpenSim::WrapTorus, OpenSim::WrapSphere, OpenSim::WrapCylinder, OpenSim::WrapEllipsoid, and OpenSim::StationPlaneContactForce.

◆ get_components()

const Component& OpenSim::Component::get_components ( int  i) const
inlineprotected

Get the value of the i-th element of the components property.

◆ getAbsolutePath()

ComponentPath OpenSim::Component::getAbsolutePath ( ) const

Return a ComponentPath of the absolute path of this Component.

Note that this has more overhead than calling getName() because it traverses up the tree to generate the absolute pathname (and its computational cost is thus a function of depth). Consider other options if this is repeatedly called and efficiency is important. For instance, getAbsolutePathString() is faster if you only need the path as a string.

◆ getAbsolutePathString()

std::string OpenSim::Component::getAbsolutePathString ( ) const

Get the complete (absolute) pathname for this Component to its ancestral Component, which is the root of the tree to which this Component belongs.

For example: a Coordinate Component would have an absolute path name like: /arm26/elbow_r/flexion. Accessing a Component by its absolutePathName from root is guaranteed to be unique. The absolutePathName is generated on-the-fly by traversing the ownership tree and, therefore, calling this method is not "free".

Examples:
exampleMocoTrack.cpp.

Referenced by OpenSim::ConnecteeNotSpecified::ConnecteeNotSpecified().

◆ getClassName()

static const std::string& OpenSim::Component::getClassName ( )
inlinestatic

This returns "Component".

See getConcreteClassName() if you want the class name of the underlying concrete object instead.

This is generated by the OpenSim_DECLARE_*_OBJECT macros.

◆ getComponent() [1/3]

template<class C = Component>
const C& OpenSim::Component::getComponent ( const std::string &  pathname) const
inline

Get a unique subcomponent of this Component by its path name and type 'C'.

Throws ComponentNotFoundOnSpecifiedPath exception if the component at that path name location does not exist OR it is not of the correct type. For example,

auto& coord = model.getComponent<Coordinate>("right_elbow/elbow_flexion");

returns coord which is a Coordinate named "elbow_flexion" from a Joint named "right_elbow" given it is a child of the Component (Model) model. If unsure of a Component's path or whether or not it exists in the model, use printComponentsMatching() or hasComponent().

This template function cannot be used in Python/Java/MATLAB; see the non-templatized getComponent().

Parameters
pathnamea pathname of a Component of interest
Returns
const reference to component of type C at
Exceptions
ComponentNotFoundOnSpecifiedPathif no component exists
Examples:
example2DWalkingMetabolics.cpp, and exampleMocoInverse.cpp.

Referenced by OpenSim::Input< T >::finalizeConnection().

◆ getComponent() [2/3]

template<class C = Component>
const C& OpenSim::Component::getComponent ( const ComponentPath pathname) const
inline

◆ getComponent() [3/3]

const Component& OpenSim::Component::getComponent ( const std::string &  pathname) const
inline

Similar to the templatized getComponent(), except this returns the component as the generic Component type.

This can be used in Python/Java/MATLAB. Here is an example of using this in MATLAB:

coord = model.getComponent('right_elbow/elbow_flexion')
coord.getNumConnectees() % okay; this is a Component method.
coord.getDefaultClamped() % inaccessible; method on Coordinate.
Coordinate.safeDownCast(coord).getDefaultClamped() % now accessible.

Exception: in Python, you will get the concrete type (in most cases):

coord = model.getComponent('right_elbow/elbow_flexion')
coord.getDefaultClamped() # works; no downcasting necessary.

◆ getComponentList()

template<typename T = Component>
ComponentList<const T> OpenSim::Component::getComponentList ( ) const
inline

Get an iterator through the underlying subcomponents that this component is composed of.

The hierarchy of Components/subComponents forms a tree. The order of the Components is that of tree preorder traversal so that a component is traversed before its subcomponents.

for (const auto& muscle : model.getComponentList<Muscle>()) {
muscle.get_max_isometric_force();
}

The returned ComponentList does not permit modifying any components; if you want to modify the components, see updComponentList().

Template Parameters
TA subclass of Component (e.g., Body, Muscle).
Examples:
exampleMocoInverse.cpp, and exampleMocoTrack.cpp.

Referenced by OpenSim::createControlNamesForControllerType().

◆ getConcreteClassName()

const std::string& OpenSim::Component::getConcreteClassName ( ) const
overridepure virtual

Returns the class name of the concrete Object-derived class of the actual object referenced by this Object, as a string.

This is the string that is used as the tag for this concrete object in an XML file. Every concrete class derived from Object automatically overrides this method via the declaration macro it uses. See getClassName() to get the class name of the referencing (possibly abstract) class rather than the concrete object.

See also
getClassName()

Implements OpenSim::Object.

Implemented in OpenSim::FrameGeometry, OpenSim::Mesh, OpenSim::Brick, OpenSim::Torus, OpenSim::Cone, OpenSim::Cylinder, OpenSim::Ellipsoid, OpenSim::Sphere, OpenSim::Model, OpenSim::AnalyticGeometry, OpenSim::Millard2012AccelerationMuscle, OpenSim::ConsoleReporter_< T >, OpenSim::Arrow, OpenSim::EspositoMiller2018Force, OpenSim::Bhargava2004SmoothedMuscleMetabolics, OpenSim::Umberger2010MuscleMetabolicsProbe, OpenSim::Millard2012EquilibriumMuscle, OpenSim::LineGeometry, OpenSim::Bhargava2004MuscleMetabolicsProbe, OpenSim::TableReporter_< InputT, ValueT >, OpenSim::HuntCrossleyForce, OpenSim::ElasticFoundationForce, OpenSim::Blankevoort1991Ligament, OpenSim::MeyerFregly2016Force, OpenSim::ScalarActuator, OpenSim::HuntCrossleyForce, OpenSim::DeGrooteFregly2016Muscle, OpenSim::ElasticFoundationForce, OpenSim::Probe, OpenSim::Thelen2003Muscle, OpenSim::FunctionBasedPath, OpenSim::Joint, OpenSim::Reporter< InputT >, OpenSim::StationDefinedFrame, OpenSim::Reporter< T >, OpenSim::MuscleFixedWidthPennationModel, OpenSim::ModelComponent, OpenSim::FirstOrderMuscleActivationDynamics, OpenSim::Frame, OpenSim::MuscleFirstOrderActivationDynamicModel, OpenSim::AckermannVanDenBogert2010Force, OpenSim::Muscle, OpenSim::CMC, OpenSim::Controller, OpenSim::PrescribedController, OpenSim::ControlDistributor, OpenSim::SmoothSphereHalfSpaceForce, OpenSim::SynergyController, OpenSim::InputController, OpenSim::ExternalLoads, OpenSim::OffsetFrame< PhysicalFrame >, OpenSim::ClutchedPathSpring, OpenSim::AbstractGeometryPath, OpenSim::CoordinateLimitForce, OpenSim::PhysicalFrame, OpenSim::Delp1990Muscle_Deprecated, OpenSim::RigidTendonMuscle, OpenSim::GeometryPath, OpenSim::ModelComponentSet< T >, OpenSim::RollingOnSurfaceConstraint, OpenSim::ModelComponentSet< ExternalForce >, OpenSim::ModelComponentSet< ContactGeometry >, OpenSim::ModelComponentSet< WrapObject >, OpenSim::ModelComponentSet< Force >, OpenSim::ModelComponentSet< Joint >, OpenSim::ModelComponentSet< Probe >, OpenSim::ModelComponentSet< Controller >, OpenSim::ModelComponentSet< ModelComponent >, OpenSim::ModelComponentSet< Marker >, OpenSim::ModelComponentSet< Body >, OpenSim::ModelComponentSet< Constraint >, OpenSim::ScapulothoracicJoint, OpenSim::MuscleActivationDynamics, OpenSim::ExpressionBasedPointToPointForce, OpenSim::ExternalForce, OpenSim::ActivationFiberLengthMuscle, OpenSim::Geometry, OpenSim::PathSpring, OpenSim::ExpressionBasedBushingForce, OpenSim::FunctionBasedBushingForce, OpenSim::PrescribedForce, OpenSim::TwoFrameLinker< Force, PhysicalFrame >, OpenSim::TwoFrameLinker< Constraint, PhysicalFrame >, OpenSim::ActivationFiberLengthMuscle_Deprecated, OpenSim::BushingForce, OpenSim::Ligament, OpenSim::Coordinate, OpenSim::CustomJoint, OpenSim::Schutte1993Muscle_Deprecated, OpenSim::TorqueActuator, OpenSim::BallJoint, OpenSim::CoordinateCouplerConstraint, OpenSim::BodyActuator, OpenSim::PointActuator, OpenSim::Thelen2003Muscle_Deprecated, OpenSim::PointToPointActuator, OpenSim::Actuator, OpenSim::Point, OpenSim::FreeJoint, OpenSim::UnilateralConstraint, OpenSim::ActivationCoordinateActuator, OpenSim::CoordinateActuator, OpenSim::McKibbenActuator, OpenSim::ForceSet, OpenSim::JointInternalPowerProbe, OpenSim::PhysicalOffsetFrame, OpenSim::WeldConstraint, OpenSim::ControlSetController, OpenSim::ConstantCurvatureJoint, OpenSim::EllipsoidJoint, OpenSim::CorrectionController, OpenSim::AbstractReporter, OpenSim::TableSource_< ET >, OpenSim::PathActuator, OpenSim::ExperimentalMarker, OpenSim::IMU, OpenSim::WrapObject, OpenSim::Set< Joint, ModelComponent >, OpenSim::Set< Marker, ModelComponent >, OpenSim::Set< T, ModelComponent >, OpenSim::Set< ContactGeometry, ModelComponent >, OpenSim::Set< Controller, ModelComponent >, OpenSim::Set< WrapObject, ModelComponent >, OpenSim::Set< Probe, ModelComponent >, OpenSim::Set< ModelComponent, ModelComponent >, OpenSim::Set< Body, ModelComponent >, OpenSim::Set< Constraint, ModelComponent >, OpenSim::Set< ExternalForce, ModelComponent >, OpenSim::Set< Force, ModelComponent >, OpenSim::SpringGeneralizedForce, OpenSim::ControllerSet, OpenSim::ExperimentalFrame, OpenSim::PinJoint, OpenSim::UniversalJoint, OpenSim::AccelerationMotion, OpenSim::ActuatorPowerProbe, OpenSim::ContactGeometry, OpenSim::Force, OpenSim::Marker, OpenSim::MovingPathPoint, OpenSim::MuscleActiveFiberPowerProbe, OpenSim::SystemEnergyProbe, OpenSim::PointConstraint, OpenSim::Constraint, OpenSim::GimbalJoint, OpenSim::PlanarJoint, OpenSim::WrapCylinder, OpenSim::WrapEllipsoid, OpenSim::WrapSphere, OpenSim::WrapTorus, OpenSim::SignalGenerator, OpenSim::ActuatorForceProbe, OpenSim::ConditionalPathPoint, OpenSim::JointSet, OpenSim::Station, OpenSim::PositionMotion, OpenSim::Body, OpenSim::SliderJoint, OpenSim::WeldJoint, OpenSim::PathWrapPoint, OpenSim::ConstantMuscleActivation, OpenSim::ActuatorInputController, OpenSim::ComponentSet, OpenSim::Ground, OpenSim::PointToPointSpring, OpenSim::ConstantDistanceConstraint, OpenSim::ZerothOrderMuscleActivationDynamics, OpenSim::ElasticFoundationForce, OpenSim::PathPoint, OpenSim::ProbeSet, OpenSim::PointOnLineConstraint, OpenSim::StatesTrajectoryReporter, OpenSim::WrapObjectSet, OpenSim::DiscreteForces, OpenSim::AbstractPathPoint, OpenSim::ContactGeometrySet, OpenSim::ContactHalfSpace, OpenSim::HuntCrossleyForce, OpenSim::BodySet, OpenSim::ConstraintSet, OpenSim::ContactMesh, OpenSim::MarkerSet, OpenSim::MocoScaleFactor, OpenSim::Bhargava2004SmoothedMuscleMetabolics_MuscleParameters, OpenSim::ContactSphere, OpenSim::ExpressionBasedCoordinateForce, and OpenSim::StationPlaneContactForce.

Referenced by OpenSim::ConnecteeNotSpecified::ConnecteeNotSpecified().

◆ getConnectee() [1/4]

template<typename T >
const T& OpenSim::Component::getConnectee ( const std::string &  name) const
inline

Get the "connectee" object that the Component's Socket is bound to.

Guaranteed to be valid only after the Component has been connected (that is connect() has been invoked). If the Socket has not been connected, an exception is thrown.

This method is for getting the concrete connectee object, and is not available in scripting. If you want generic access to the connectee as an Object, use the non-templated version.

Template Parameters
Tthe type of the Connectee (e.g., PhysicalFrame).
Parameters
namethe name of the socket
Returns
T const reference to object that satisfies the Socket

Example:

const PhysicalFrame& frame = joint.getConnectee<PhysicalFrame>("parent_frame");
frame.getMobilizedBody();

References OpenSim::Socket< T >::getConnectee(), and OpenSim::Socket< T >::isConnected().

◆ getConnectee() [2/4]

template<typename T >
const T& OpenSim::Component::getConnectee ( const std::string &  name,
int  index 
) const
inline

Get the "connectee" object at the provided index that the Component's Socket is bound to.

Guaranteed to be valid only after the Component has been connected (that is, connect() has been invoked). If the Socket has not been connected, an exception is thrown.

This method is for getting the concrete connectee object, and is not available in scripting. If you want generic access to the connectee as an Object, use the non-templated version.

Template Parameters
Tthe type of the Connectee (e.g., Actuator).
Parameters
namethe name of the socket
indexthe index of the connectee
Returns
T const reference to object that satisfies the Socket

Example:

const Actuator& actu = controller.getConnectee<Actuator>("actuators", 1);
actu.getDefaultControls();

References OpenSim::Socket< T >::getConnectee(), and OpenSim::Socket< T >::isConnected().

◆ getConnectee() [3/4]

const Object& OpenSim::Component::getConnectee ( const std::string &  name) const
inline

Get the connectee as an Object.

This means you will not have access to the methods on the concrete connectee. This is the method you must use in MATLAB to access the connectee.

Example:

const Object& obj = joint.getConnectee("parent_frame");
obj.getName(); // method on Object works.
obj.getMobilizedBody(); // error: not available.

In MATLAB, if you want the concrete type, you need to downcast the Object. Here is an example where you know the "parent_frame" is a Body:

f = joint.getConnectee('parent_frame');
m = Body.safeDownCast(f).getMass();

Exception: in Python, you will get the concrete type (in most cases):

f = joint.getConnectee("parent_frame");
m = f.getMass() # works (if the parent frame is a body)

References OpenSim::AbstractSocket::getConnecteeAsObject(), and OpenSim::AbstractSocket::isConnected().

◆ getConnectee() [4/4]

const Object& OpenSim::Component::getConnectee ( const std::string &  name,
int  index 
) const
inline

Get the connectee at the provided index as an Object.

This means you will not have access to the methods on the concrete connectee. This is the method you must use in scripts to access the connectee.

Example:

const Object& obj = controller.getConnectee("actuators", 1);
obj.getName(); // method on Object works.
obj.getDefaultControls(); // error: not available.

In MATLAB, if you want the concrete type, you need to downcast the Object. Here is an example where you know the "actuators" are Actuators:

actu = controller.getConnectee('actuators', 1);
controls = Actuator.safeDownCast(f).getDefaultControls();

Exception: in Python, you will get the concrete type (in most cases):

actu = controller.getConnectee("actuators", 1);
controls = actu.getDefaultControls() # works (if 'actu' is an Actuator)

References OpenSim::AbstractSocket::getConnecteeAsObject(), and OpenSim::AbstractSocket::isConnected().

◆ getDiscreteVariableNames()

Array<std::string> OpenSim::Component::getDiscreteVariableNames ( ) const

Get the names of discrete state variables maintained by the Component and its subcomponents.

Each variable's name is prepended by its path in the component hierarchy.

Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ getInput() [1/2]

const AbstractInput& OpenSim::Component::getInput ( const std::string &  name) const
inline

Get an Input provided by this Component by name.

C++ example: get an Input from a Component in the model

model.getComponent("/path/to/component").getInput("inputName");

If you have not yet called finalizeFromProperties() on this component, this function will update the Input (to tell it which component it's in) before providing it to you.

Parameters
namethe name of the Input
Returns
const reference to the AbstractInput

◆ getInput() [2/2]

template<typename T >
const Input<T>& OpenSim::Component::getInput ( const std::string &  name) const
inline

Get a concrete Input that you can directly ask for its values.

If you have not yet called finalizeFromProperties() on this component, this function will update the Input (to tell it which component it's in) before providing it to you.

Parameters
namethe name of the Input
Exceptions
Exceptionif an Input with the given name does not exist.
std::bad_castif the provided type T is incorrect for the given name.

◆ getInputNames()

std::vector<std::string> OpenSim::Component::getInputNames ( ) const
inline

Collect and return the names of Inputs in this component as an std::vector.

◆ getInputValue()

template<typename T >
const T& OpenSim::Component::getInputValue ( const SimTK::State &  state,
const std::string &  name 
) const
inline

Get the Input value that this component is dependent on.

Checks if Input is connected, otherwise it will throw an exception. You can only call this method for non-list inputs. For list inputs, you must get the input using getInput(), from which you can ask for its values.

Parameters
statethe State for which to set the value
namethe name of the input
Returns
T const Input value

References OpenSim::AbstractSocket::isConnected().

◆ getModelingOption() [1/2]

int OpenSim::Component::getModelingOption ( const SimTK::State &  state,
const std::string &  path 
) const

Based on a specified path, get the value of a modeling option.

The specified path consists of the name of the modeling option prepended by its absolute or relative path in the component hierarchy.

If this component is the owner of the modeling option, the specified path should simply be the name of the modeling option.

Parameters
stateState in which to set the modeling option.
pathPath of the modeling option in the component hierarchy.
Returns
flag Value of the modeling option.
Exceptions
EmptyComponentPathif the specified path is an empty string (i.e., path == "").
VariableOwnerNotFoundOnSpecifiedPathif the candidate owner of the modeling option cannot be found at the specified path.
VariableNotFoundif the specified modeling option cannot be found in the candidate owner.
See also
Component::resolveVariableNameAndOwner()

◆ getModelingOption() [2/2]

int OpenSim::Component::getModelingOption ( const SimTK::State &  state,
const ComponentPath path 
) const

◆ getModelingOptionNames()

Array<std::string> OpenSim::Component::getModelingOptionNames ( ) const

Get the names of the modeling options maintained by the Component and its subcomponents.

Each options's name is prepended by its path in the component hierarchy.

Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ getNumInputs()

int OpenSim::Component::getNumInputs ( ) const
inline

Access the number of Inputs that this component has.

◆ getNumOutputs()

int OpenSim::Component::getNumOutputs ( ) const
inline

Access the number of Outputs that this component has.

◆ getNumSockets()

int OpenSim::Component::getNumSockets ( ) const
inline

Get the number of Sockets in this Component.

◆ getNumStateVariables()

int OpenSim::Component::getNumStateVariables ( ) const

Get the number of "continuous" state variables maintained by the Component and its subcomponents.

Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ getOutput()

const AbstractOutput& OpenSim::Component::getOutput ( const std::string &  name) const
inline

Get the Output provided by this Component by name.

C++ example: get an Output from a Component in a model

model.getComponent("/path/to/component").getOutput("outputName");
Parameters
namethe name of the Output
Returns
const reference to the AbstractOutput

Referenced by OpenSim::Input< T >::finalizeConnection().

◆ getOutputNames()

std::vector<std::string> OpenSim::Component::getOutputNames ( ) const
inline

Collect and return the names of Outputs in this component as an std::vector.

◆ getOutputs()

SimTK::IteratorRange<OutputConstIterator> OpenSim::Component::getOutputs ( ) const
inline

Iterate through all Outputs of this component.

The intent is to use this in a loop as such:

for (const auto& entry : comp.getOutputs()) {
const std::string& name = entry.first;
const AbstractOutput* output = entry.second.get();
std::cout << output->getTypeName() << std::endl;
}

This provides access to the outputs as AbstractOutputs, not as the concrete type. This also does not permit modifying the outputs.

Not available in Python/Java/MATLAB; use getOutputNames() and getOutput() instead.

◆ getOutputValue()

template<typename T >
const T& OpenSim::Component::getOutputValue ( const SimTK::State &  state,
const std::string &  name 
) const
inline

Get the Output value provided by this Component by name.

Parameters
statethe State for which to set the value
namethe name of the cache variable
Returns
T const Output value

◆ getRelativePath()

ComponentPath OpenSim::Component::getRelativePath ( const Component wrt) const

Get the relative path of this Component with respect to another Component.

◆ getRelativePathString()

std::string OpenSim::Component::getRelativePathString ( const Component wrt) const

Get the relative path of this Component with respect to another Component, as a string.

◆ getSocket() [1/2]

const AbstractSocket& OpenSim::Component::getSocket ( const std::string &  name) const
inline

Get an AbstractSocket for the given socket name.

This lets you get information about the connection (like if the socket is connected), but does not give you access to the socket's connectee. For that, use getConnectee().

If you have not yet called finalizeFromProperties() on this component, this function will update the Socket (to tell it which component it's in) before providing it to you.

C++ example

model.getComponent("/path/to/component").getSocket("socketName");

◆ getSocket() [2/2]

template<typename T >
const Socket<T>& OpenSim::Component::getSocket ( const std::string &  name) const
inline

Get a const reference to the concrete Socket provided by this Component by name.

If you have not yet called finalizeFromProperties() on this component, this function will update the Socket (to tell it which component it's in) before providing it to you.

Parameters
namethe name of the Socket
Returns
const reference to the (Abstract)Socket

◆ getSocketNames()

std::vector<std::string> OpenSim::Component::getSocketNames ( ) const
inline

Collect and return the names of the sockets in this component.

You can use this to iterate through the sockets:

for (std::string name : comp.getSocketNames()) {
const AbstractSocket& socket = getSocket(name);
}

◆ getStateVariableDerivativeValue() [1/2]

double OpenSim::Component::getStateVariableDerivativeValue ( const SimTK::State &  state,
const std::string &  name 
) const

Get the value of a state variable derivative computed by this Component.

Parameters
statethe State for which to get the derivative value
namethe name (string) of the state variable of interest
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ getStateVariableDerivativeValue() [2/2]

double OpenSim::Component::getStateVariableDerivativeValue ( const SimTK::State &  state,
const ComponentPath path 
) const

Get the value of a state variable derivative computed by this Component.

Parameters
statethe State for which to get the derivative value
pathpath to the state variable of interest
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ getStateVariableNames()

Array<std::string> OpenSim::Component::getStateVariableNames ( ) const

Get the names of continuous state variables maintained by the Component and its subcomponents.

Each variable's name is prepended by its path in the component hierarchy.

Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ getStateVariableValue() [1/2]

double OpenSim::Component::getStateVariableValue ( const SimTK::State &  state,
const std::string &  name 
) const

Get the value of a state variable allocated by this Component.

To connect this StateVariable as an input to another component (such as a Reporter), use getOutput(name); each state variable has a corresponding Output:

foo.getInput("input1").connect(bar.getOutput(name));
Parameters
statethe State for which to get the value
namethe name (string) of the state variable of interest
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)
Examples:
exampleCustomImplicitAuxiliaryDynamics.cpp.

◆ getStateVariableValue() [2/2]

double OpenSim::Component::getStateVariableValue ( const SimTK::State &  state,
const ComponentPath path 
) const

Get the value of a state variable allocated by this Component.

To connect this StateVariable as an input to another component (such as a Reporter), use getOutput(name); each state variable has a corresponding Output:

foo.getInput("input1").connect(bar.getOutput(name));
Parameters
statethe State for which to get the value
pathpath to the state variable of interest
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ getStateVariableValues()

SimTK::Vector OpenSim::Component::getStateVariableValues ( const SimTK::State &  state) const

Get all values of the state variables allocated by this Component.

Includes state variables allocated by its subcomponents.

Parameters
statethe State for which to get the value
Returns
Vector of state variable values of length getNumStateVariables() in the order returned by getStateVariableNames()
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ getSystem()

const SimTK::MultibodySystem& OpenSim::Component::getSystem ( ) const
inline

Get the underlying MultibodySystem that this component is connected to.

Make sure you have called Model::initSystem() prior to accessing the System. Throws an Exception if the System has not been created or the Component has not added itself to the System.

See also
hasSystem().

◆ hasComponent() [1/2]

bool OpenSim::Component::hasComponent ( const std::string &  pathname) const
inline

Query if there is a component (of any type) at the specified path name.

For example,

bool exists = model.hasComponent("right_elbow/elbow_flexion");

checks if model has a subcomponent "right_elbow," which has a subcomponent "elbow_flexion."

◆ hasComponent() [2/2]

template<class C = Component>
bool OpenSim::Component::hasComponent ( const std::string &  pathname) const
inline

Query if there is a component of a given type at the specified path name.

For example,

bool exists = model.hasComponent<Coordinate>("right_elbow/elbow_flexion");

checks if model has a subcomponent "right_elbow," which has a subcomponent "elbow_flexion," and that "elbow_flexion" is of type Coordinate. This method cannot be used from scripting; see the non-templatized hasComponent().

◆ hasSystem()

bool OpenSim::Component::hasSystem ( ) const
inline

Check if this component has an underlying MultibodySystem.

Returns false if the System has not been created OR if this Component has not added itself to the System.

Referenced by OpenSim::TableProcessor::processAndConvertToRadians().

◆ initStateFromProperties()

void OpenSim::Component::initStateFromProperties ( SimTK::State &  state) const

Initialize Component's state variable values from its properties.

◆ isComponentInOwnershipTree()

bool OpenSim::Component::isComponentInOwnershipTree ( const Component component) const

Does the provided component already exist anywhere in the ownership tree (not just subcomponents of this component)?

◆ operator=()

Component& OpenSim::Component::operator= ( const Component )
default

◆ printComponentsMatching()

unsigned OpenSim::Component::printComponentsMatching ( const std::string &  substring) const

Print a list to the console of all components whose absolute path name contains the given string.

You might use this if (a) you know the name of a component in your model but don't know its absolute path, (b) if you want to find all components with a given name, or (c) to get a list of all components on the right leg of a model (if all components on the right side have "_r" in their name).

A function call like:

unsigned num = comp.printComponentsMatching("rotation");

may produce output like:

* /leg_model/right_hip/rotation
* /leg_model/left_hip/rotation
* 
Returns
The number of matches.

◆ safeDownCast()

static Component* OpenSim::Component::safeDownCast ( OpenSim::Object obj)
inlinestatic

For use in MATLAB and Python to access the concrete class.

Example: cObj = Component.safeDownCast(obj). This is equivalent to dynamic_cast<Component*>(obj) in C++.

◆ set_components()

void OpenSim::Component::set_components ( int  i,
const Component value 
)
inlineprotected

Set the value of the i-th element of components property.

◆ setModelingOption() [1/2]

void OpenSim::Component::setModelingOption ( SimTK::State &  state,
const std::string &  path,
int  flag 
) const

Based on a specified path, set the value of a modeling option.

The specified path consists of the name of the modeling option prepended by its absolute or relative path in the component hierarchy.

If this component is the owner of the modeling option, the specified path should simply be the name of the modeling option.

Note
Successfully setting the value of the modeling option will revert the realization stage back to SimTK::Stage::Instance.
Parameters
stateState in which to set the modeling option.
pathPath of the modeling option in the component hierarchy.
flagValue to which to set the modeling option.
Exceptions
ModelingOptionMaxExceededif the flag is greater that the maximum allowed for the specified modeling option.
EmptyComponentPathif the specified path is an empty string (i.e., path == "").
VariableOwnerNotFoundOnSpecifiedPathif the candidate owner of the modeling option cannot be found at the specified path.
VariableNotFoundif the specified modeling option cannot be found in the candidate owner.
See also
Component::resolveVariableNameAndOwner()

◆ setModelingOption() [2/2]

void OpenSim::Component::setModelingOption ( SimTK::State &  state,
const ComponentPath path,
int  flag 
) const

◆ setPropertiesFromState()

void OpenSim::Component::setPropertiesFromState ( const SimTK::State &  state)

Set Component's properties given a state.

◆ setStateVariableValue()

void OpenSim::Component::setStateVariableValue ( SimTK::State &  state,
const std::string &  name,
double  value 
) const

Set the value of a state variable allocated by this Component by name.

Parameters
statethe State for which to set the value
namethe name of the state variable
valuethe value to set
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)
Examples:
exampleCustomImplicitAuxiliaryDynamics.cpp.

◆ setStateVariableValues()

void OpenSim::Component::setStateVariableValues ( SimTK::State &  state,
const SimTK::Vector &  values 
) const

Set all values of the state variables allocated by this Component.

Includes state variables allocated by its subcomponents. Note, this method simply sets the values on the input State. If other conditions must be met (such as satisfying kinematic constraints for Coordinates, or fiber and tendon equilibrium for muscles) you must invoke the appropriate methods on Model (e.g. assemble() to satisfy constraints or equilibrateMuscles()) to satisfy these conditions starting from the State values provided by setStateVariableValues.

Parameters
statethe State whose values are set
valuesVector of state variable values of length getNumStateVariables() in the order returned by getStateVariableNames()
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ tryGetOutput()

const AbstractOutput* OpenSim::Component::tryGetOutput ( const std::string &  name) const
inline

If it exists on the component, returns a pointer to the named Output; otherwise, returns a nullptr.

Related: getOutput

Parameters
namethe name the Output to find
Returns
if it exists, a pointer to the Output; otherwise, nullptr

◆ tryGetSocket()

const AbstractSocket* OpenSim::Component::tryGetSocket ( const std::string &  name) const
inline

Returns a pointer to the AbstractSocket with a given socket name, or nullptr if the socket with the given name does not exist on the component.

See getSocket() for more details about how the socket is looked up.

C++ example

if (const AbstractSocket* s = component.tryGetSocket("frame")) {
// do something with *s
}
else {
// handle the no-socket-by-that-name case
}

◆ tryUpdOutput()

AbstractOutput* OpenSim::Component::tryUpdOutput ( const std::string &  name)
inline

If it exists on the component returns a writable pointer to the named Output; otherwise, returns a nullptr

Related: updOutput

Parameters
namethe name of the Output to find
Returns
if it exists, a writable pointer to the Output; otherwise, nullptr

◆ tryUpdSocket()

const AbstractSocket* OpenSim::Component::tryUpdSocket ( const std::string &  name)
inline

Returns a writable pointer to the AbstractSocket with a given socket name, or nullptr if the socket with the given name does not exist on the component.

See tryGetSocket for usage example See getSocket/updSocket for other internal details

◆ upd_components()

Component& OpenSim::Component::upd_components ( int  i)
inlineprotected

Get a writable reference to the i-th element of the components property.

◆ updComponent() [1/3]

template<class C = Component>
C& OpenSim::Component::updComponent ( const std::string &  name)
inline

Get a writable reference to a subcomponent.

Use this method to edit the properties and connections of the subcomponent. Note: the method will mark this Component as out-of-date with its properties and will require finalizeFromProperties() to be invoked directly or indirectly (by finalizeConnections() or Model::initSystem())

Parameters
namethe pathname of the Component of interest
Returns
Component the component of interest
Exceptions
ComponentNotFoundOnSpecifiedPathif no component exists
See also
getComponent()

◆ updComponent() [2/3]

template<class C = Component>
C& OpenSim::Component::updComponent ( const ComponentPath name)
inline

◆ updComponent() [3/3]

Component& OpenSim::Component::updComponent ( const std::string &  pathname)
inline

Similar to the templatized updComponent(), except this returns the component as the generic Component type.

As with the non-templatized getComponent(), though, this will give the concrete type in Python in most cases.

See also
getComponent()

◆ updComponentList()

template<typename T = Component>
ComponentList<T> OpenSim::Component::updComponentList ( )
inline

Similar to getComponentList(), except the resulting list allows one to modify the components.

For example, you could use this method to change the max isometric force of all muscles:

for (auto& muscle : model.updComponentList<Muscle>()) {
muscle.set_max_isometric_force(...);
}
Note
Do NOT use this method to add (or remove) (sub)components from any component. The tree structure of the components should not be altered through this ComponentList.
Template Parameters
TA subclass of Component (e.g., Body, Muscle).

Referenced by OpenSim::ModOpTendonComplianceDynamicsModeDGF::operate(), OpenSim::ModOpUseImplicitTendonComplianceDynamicsDGF::operate(), OpenSim::ModOpIgnorePassiveFiberForcesDGF::operate(), OpenSim::ModOpPassiveFiberStrainAtOneNormForceDGF::operate(), OpenSim::ModOpScaleActiveFiberForceCurveWidthDGF::operate(), and OpenSim::ModOpFiberDampingDGF::operate().

◆ updInput()

AbstractInput& OpenSim::Component::updInput ( const std::string &  name)
inline

Get a writable reference to an Input provided by this Component by name.

C++ example: get a writable reference to an Input of a Component in a model

model.updComponent("/path/to/component").updInput("inputName");

If you have not yet called finalizeFromProperties() on this component, this function will update the Input (to tell it which component it's in) before providing it to you.

Parameters
namethe name of the Input
Returns
reference to the AbstractInput

◆ updOutput()

AbstractOutput& OpenSim::Component::updOutput ( const std::string &  name)
inline

Get a writable reference to an Output provided by this Component by name.

C++ example: get a writable reference to an Output of a Component in a model

model.updComponent("/path/to/component").updOutput("outputName");
Parameters
namethe name of the Output
Returns
reference to the AbstractOutput

Referenced by OpenSim::TableSource_< ET >::setTable_impl().

◆ updSocket() [1/2]

AbstractSocket& OpenSim::Component::updSocket ( const std::string &  name)
inline

Get a writable reference to the AbstractSocket for the given socket name.

Use this method to connect the Socket to something.

C++ example

joint.updSocket("parent_frame").connect(model.getGround());

If you have not yet called finalizeFromProperties() on this component, this function will update the Socket (to tell it which component it's in) before providing it to you.

◆ updSocket() [2/2]

template<typename T >
Socket<T>& OpenSim::Component::updSocket ( const std::string &  name)
inline

Get a writable reference to the concrete Socket provided by this Component by name.

If you have not yet called finalizeFromProperties() on this component, this function will update the Socket (to tell it which component it's in) before providing it to you.

Parameters
namethe name of the Socket
Returns
const reference to the (Abstract)Socket

Friends And Related Function Documentation

◆ ComponentList

template<typename T >
friend class ComponentList
friend

Class that permits iterating over components/subcomponents (but does not actually contain the components themselves).

◆ ComponentListIterator

template<typename T >
friend class ComponentListIterator
friend

Class to iterate over ComponentList returned by getComponentList().

OpenSim Property, Socket, Output, Input Documentation

◆ components

Component OpenSim::Component::components

"List of components that this component owns and serializes."

This property appears in XML files under the tag <components>. This property holds a list of objects, and was generated with the OpenSim_DECLARE_LIST_PROPERTY macro; see Property to learn about the property system.

See also
get_components(), upd_components(), set_components(), append_components()

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