API  4.5
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...
 
template<class C = Component>
const C * findComponent (const ComponentPath &pathToFind) const
 Find a Component to which this Component is an ancestor—in other words, a Component that is directly owned by this Component or is owned by one of its sub-components, sub-sub-components, etc. More...
 
template<class C = Component>
const C * findComponent (const std::string &pathToFind) const
 Same as findComponent(const ComponentPath&), but accepting a string (a path or just a name) as input. More...
 
const StateVariabletraverseToStateVariable (const std::string &pathName) const
 Get a StateVariable anywhere in the Component tree, given a StateVariable path. More...
 
const StateVariabletraverseToStateVariable (const ComponentPath &path) const
 Get a StateVariable anywhere in the Component tree, given a StateVariable path. 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...
 
const ObjectgetConnectee (const std::string &name) const
 Get the connectee as an Object. More...
 
const AbstractSocketgetSocket (const std::string &name) const
 Get an AbstractSocket for the given socket name. 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...
 
Print information to the console
void printSubcomponentInfo () const
 List all subcomponents by name and recurse into these components to list their subcomponents, and so on. More...
 
void printSocketInfo () const
 List all the Sockets of this component and whether or not they are connected. More...
 
void printInputInfo () const
 List all the inputs of this component and whether or not they are connected. More...
 
template<typename C >
void printSubcomponentInfo () const
 
void printOutputInfo (const bool includeDescendants=true) const
 Print outputs of this component and optionally, those of all subcomponents. 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...
 
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

 SimTK_DEFINE_UNIQUE_INDEX_TYPE (MemberSubcomponentIndex)
 
template<class C = Component>
MemberSubcomponentIndex constructSubcomponent (const std::string &name)
 Construct a subcomponent as a data member of this Component. More...
 
template<class C = Component>
const C & getMemberSubcomponent (MemberSubcomponentIndex ix) const
 
template<class C = Component>
C & updMemberSubcomponent (MemberSubcomponentIndex ix)
 
void adoptSubcomponent (Component *subcomponent)
 Adopt a component as a subcomponent of this Component. More...
 
size_t getNumImmediateSubcomponents () const
 Get the number of Subcomponents immediately owned by this Component. More...
 
size_t getNumMemberSubcomponents () const
 Get the number of Subcomponents that are data members of this Component. More...
 
size_t getNumPropertySubcomponents () const
 Get the number of Subcomponents that are properties of this Component. More...
 
size_t getNumAdoptedSubcomponents () const
 Get the number of Subcomponents adopted by this Component. More...
 
std::vector< SimTK::ReferencePtr< const Component > > getImmediateSubcomponents () const
 Access this Component's immediate subcomponents (not those owned by subcomponents) More...
 
template<class C >
const C * traversePathToComponent (ComponentPath path) const
 
void setNextSubcomponentInSystem (const Component &sub) const
 Helper method to enable Component makers to specify the order of their subcomponents to be added to the System during addToSystem(). More...
 
void resetSubcomponentOrder ()
 resetSubcomponentOrder clears this Component's list of ordered subcomponents (but otherwise leaves subcomponents untouched). More...
 
void updateFromXMLNode (SimTK::Xml::Element &node, int versionNumber) override
 Handle a change in XML syntax for Sockets. More...
 
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...
 
Component Extension Interface

The 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 are virtual and may be implemented by subclasses of Components.

Note
Every implementation of virtual extend method xxx(args) must begin with the line "Super::extend<xxx>(args);" to ensure that the parent class is called before the child class method.

The base class implementations ensures that the corresponding calls are made to any subcomponents which are owned by this Component. Ownership is established by the subcomponent being a data member (not serialized), a property (serialized), or created and adopted based on other settings or options that arise from the properties. For example, a Model (Component) may have to split a body and add a Weld constraint to handle a closed loop specified by Joints that are properties of the Model. The new Body and Weld (components) are created and adopted as part of connecting the model to form a valid multibody tree.

So assuming that your concrete Component and all intermediate classes from which it derives properly follow the requirement of calling the Super class method first, the order of operations enforced here for a call to a single method will be

  1. Component base class computations
  2. calls to that same method for intermediate Component-derived objects' computations, in order down from Component, and
  3. call to that method for the bottom-level concrete class.
  4. finally calls to that same method for all subcomponents You should consider this ordering when designing a Component.
virtual void extendAddComponent (Component *subcomponent)
 Perform any secondary operations, e.g. More...
 
virtual void extendFinalizeFromProperties ()
 Perform any time-invariant calculations, data structure initializations, or other configuration based on the component's properties to form a functioning (but not yet connected) component. More...
 
virtual void extendFinalizeConnections (Component &root)
 Perform any necessary initializations required to connect the component (and it subcomponents) to other components and mark the connection status. More...
 
void initComponentTreeTraversal (const Component &root) const
 Build the tree of Components from this component through its descendants. More...
 
virtual void extendAddToSystem (SimTK::MultibodySystem &system) const
 Add appropriate Simbody elements (if needed) to the System corresponding to this component and specify needed state resources. More...
 
virtual void extendAddToSystemAfterSubcomponents (SimTK::MultibodySystem &system) const
 Add appropriate Simbody elements (if needed) to the System after your component's subcomponents have had a chance to add themselves to the system. More...
 
virtual void extendInitStateFromProperties (SimTK::State &state) const
 Transfer property values or other state-independent initial values into this component's state variables in the passed-in state argument. More...
 
virtual void extendSetPropertiesFromState (const SimTK::State &state)
 Update this component's property values to match the specified State, if the component has created any state variable that is intended to correspond to a property. More...
 
virtual void 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. More...
 
void setStateVariableDerivativeValue (const SimTK::State &state, const std::string &name, double deriv) const
 Set the derivative of a state variable by name when computed inside of this Component's computeStateVariableDerivatives() method. More...
 
Component Advanced Interface

You probably won't need to override methods in this section.

These provide a way for you to perform computations ("realizations") that must be scheduled in carefully-ordered stages as described in the class description above. The typical operation will be that the given SimTK::State provides you with the inputs you need for your computation, which you will then write into some element of the state cache, where later computations can pick it up.

Note
Once again it is crucial that, if you override a method here, you invoke the superclass method as the first line in your implementation, via a call like "Super::extendRealizePosition(state);". This will ensure that all necessary base class computations are performed, and that subcomponents are handled properly.
Warning
Currently the realize() methods here are invoked early in the sequence of realizations at a given stage, meaning that you will not be able to access other computations at that same stage. TODO: Should defer calls to these until at least kinematic realizations at the same stage have been performed.
See also
Simbody documentation for more information about realization.
virtual void extendRealizeTopology (SimTK::State &state) const
 Obtain state resources that are needed unconditionally, and perform computations that depend only on the system topology. More...
 
virtual void extendRealizeModel (SimTK::State &state) const
 Obtain and name state resources (like state variables allocated by an underlying Simbody component) that may be needed, depending on modeling options. More...
 
virtual void extendRealizeInstance (const SimTK::State &state) const
 Perform computations that depend only on instance variables, like lengths and masses. More...
 
virtual void extendRealizeTime (const SimTK::State &state) const
 Perform computations that depend only on time and earlier stages. More...
 
virtual void extendRealizePosition (const SimTK::State &state) const
 Perform computations that depend only on position-level state variables and computations performed in earlier stages (including time). More...
 
virtual void extendRealizeVelocity (const SimTK::State &state) const
 Perform computations that depend only on velocity-level state variables and computations performed in earlier stages (including position, and time). More...
 
virtual void extendRealizeDynamics (const SimTK::State &state) const
 Perform computations (typically forces) that may depend on dynamics-stage state variables, and on computations performed in earlier stages (including velocity, position, and time), but not on other forces, accelerations, constraint multipliers, or reaction forces. More...
 
virtual void extendRealizeAcceleration (const SimTK::State &state) const
 Perform computations that may depend on applied forces. More...
 
virtual void extendRealizeReport (const SimTK::State &state) const
 Perform computations that may depend on anything but are only used for reporting and cannot affect subsequent simulation behavior. More...
 
Component System Creation and Access Methods

These methods support implementing concrete Components.

Add methods can only be called inside of extendAddToSystem() and are useful for creating the underlying SimTK::System level variables that are used for computing values of interest.

Warning
Accessors for System indices are intended for component internal use only.
void addModelingOption (const std::string &optionName, int maxFlagValue) const
 Add a modeling option (integer flag stored in the State) for use by this Component. More...
 
void addStateVariable (const std::string &stateVariableName, const SimTK::Stage &invalidatesStage=SimTK::Stage::Dynamics, bool isHidden=false) const
 Add a continuous system state variable belonging to this Component, and assign a name by which to refer to it. More...
 
void addStateVariable (Component::StateVariable *stateVariable) const
 The above method provides a convenient interface to this method, which automatically creates an 'AddedStateVariable' and allocates resources in the SimTK::State for this variable. More...
 
void addDiscreteVariable (const std::string &discreteVariableName, SimTK::Stage invalidatesStage) const
 Add a system discrete variable belonging to this Component, 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. More...
 
SimTK::MultibodySystem & updSystem () const
 Get writable reference to the MultibodySystem that this component is connected to. More...
 
int getStateIndex (const std::string &name) const
 Get the index of a Component's continuous state variable in the Subsystem for allocations. More...
 
SimTK::SystemYIndex getStateVariableSystemIndex (const std::string &stateVariableName) const
 Get the System Index of a state variable allocated by this Component. More...
 
const SimTK::DiscreteVariableIndex getDiscreteVariableIndex (const std::string &name) const
 Get the index of a Component's discrete variable in the Subsystem for allocations. More...
 
Internal methods for constructing Sockets, Outputs, Inputs

To declare Sockets, Outputs, and Inputs for your component, use the following macros within your class declaration (ideally at the top near property declarations):

The methods below are used in those macros, and you should not use these methods yourself.

template<typename T >
PropertyIndex constructSocket (const std::string &name, const std::string &propertyComment)
 Construct a specialized Socket for this Component's dependence on another Component. More...
 
template<typename T , typename CompType = Component>
bool constructOutput (const std::string &name, T(CompType::*const memFunc)(const SimTK::State &) const, const SimTK::Stage &dependsOn=SimTK::Stage::Acceleration)
 Construct an output for a member function of the same component. More...
 
template<typename T , typename CompType = Component>
bool constructOutput (const std::string &name, const T &(CompType::*const memFunc)(const SimTK::State &) const, const SimTK::Stage &dependsOn=SimTK::Stage::Acceleration)
 This variant handles component member functions that return the output value by const reference (const T&). More...
 
template<typename T , typename CompType >
bool constructListOutput (const std::string &name, T(CompType::*const memFunc)(const SimTK::State &, const std::string &channel) const, const SimTK::Stage &dependsOn=SimTK::Stage::Acceleration)
 Construct an output that can have multiple channels. More...
 
bool constructOutputForStateVariable (const std::string &name)
 Construct an Output for a StateVariable. More...
 
template<typename T >
PropertyIndex constructInput (const std::string &name, bool isList, const std::string &propertyComment, const SimTK::Stage &requiredAtStage=SimTK::Stage::Instance)
 Construct an Input (socket) for this Component's dependence on an Output signal. 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 *doc)
 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...
 

Static Protected Member Functions

static void prependComponentPathToConnecteePath (Component &subcomponent)
 For internal use. 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...
 
template<class T >
class ComponentMeasure
 

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 AbstractOutputgetOutput (const std::string &name) const
 Get the Output provided by this Component by name. 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...
 

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 &name) const
 Get a ModelingOption flag for this Component by name. More...
 
void setModelingOption (SimTK::State &state, const std::string &name, int flag) const
 Set the value of a ModelingOption flag for this Component. More...
 
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 getDiscreteVariableValue (const SimTK::State &state, const std::string &name) const
 Get the value of a discrete variable allocated by this Component by name. More...
 
void setDiscreteVariableValue (SimTK::State &state, const std::string &name, double value) const
 Set the value of a discrete variable allocated by this Component by name. More...
 
template<class T >
SimTK::CacheEntryIndex getCacheVariableIndex (const CacheVariable< T > &cv) const
 Get the index of a Component's cache variable in the Subsystem for allocations. More...
 
SimTK::CacheEntryIndex getCacheVariableIndex (const std::string &name) const
 Get the index of a Component's cache variable in the Subsystem for allocations. More...
 
template<class T >
const T & getCacheVariableValue (const SimTK::State &state, const std::string &name) const
 Get the value of a cache variable allocated by this Component by name. More...
 
template<class T >
const T & getCacheVariableValue (const SimTK::State &state, const CacheVariable< T > &cv) const
 Get the value of a cache variable allocated by this Component. More...
 
template<typename T >
void setCacheVariableValue (const SimTK::State &state, const std::string &k, T value) const
 Set the value of a cache variable, identified by name, to a new value and mark the cache variable as valid. More...
 
template<typename T >
void setCacheVariableValue (const SimTK::State &state, const CacheVariable< T > &cv, T value) const
 Set the value of a cache variable to a new value and mark the cache variable as valid. More...
 
template<typename T >
T & updCacheVariableValue (const SimTK::State &state, const std::string &name) const
 Returns a mutable reference to the value of a cache variable identified by name. More...
 
template<typename T >
T & updCacheVariableValue (const SimTK::State &state, const CacheVariable< T > &cv) const
 Returns a mutable reference to the value of a cache variable. More...
 
bool isCacheVariableValid (const SimTK::State &state, const std::string &name) const
 Returns true if the cache variable, identified by name, is valid. More...
 
template<class T >
bool isCacheVariableValid (const SimTK::State &state, const CacheVariable< T > &cv) const
 Returns true if the cache variable is valid. More...
 
void markCacheVariableValid (const SimTK::State &state, const std::string &name) const
 Marks the value of a cache variable, identified by name, as valid. More...
 
template<typename T >
void markCacheVariableValid (const SimTK::State &state, const CacheVariable< T > &cv) const
 Marks the value of a cache variable as valid. More...
 
void markCacheVariableInvalid (const SimTK::State &state, const std::string &name) const
 Marks the value of a cache variable, identified by name, as invalid. More...
 
template<class T >
void markCacheVariableInvalid (const SimTK::State &state, const CacheVariable< T > &cv) const
 Marks the value of a cache variable as invalid. More...
 
template<class T >
CacheVariable< T > addCacheVariable (std::string name, T variablePrototype, SimTK::Stage dependsOnStage) const
 Add a state cache entry belonging to this Component to hold calculated values that must be automatically invalidated when certain state values change. More...
 

Access to the owning component (advanced).

const ComponentgetOwner () const
 Access the owner of this Component. More...
 
bool hasOwner () const
 (For advanced users) Check if this Component has an owner. More...
 
const ComponentgetRoot () const
 Obtain the root Component, which is this component if it is orphaned. More...
 
void setOwner (const Component &owner)
 Set this Component's reference to its owning Component More...
 

Nested Classes

class  CacheVariable
 A cache variable containing a value of type T. More...
 
class  StateVariable
 

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

◆ addCacheVariable()

template<class T >
CacheVariable<T> OpenSim::Component::addCacheVariable ( std::string  name,
variablePrototype,
SimTK::Stage  dependsOnStage 
) const
inlineprotected

Add a state cache entry belonging to this Component to hold calculated values that must be automatically invalidated when certain state values change.

Cache entries contain values whose computations depend on state variables and provide convenience and/or efficiency by holding on to them in memory (cache) to avoid recomputation. Once the state changes, the cache values automatically become invalid and has to be recomputed based on the current state before it can be referenced again. Any attempt to reference an invalid cache entry results in an exception being thrown.

Cache entry validity is managed by computation Stage, rather than by dependence on individual state variables. Changing a variables whose "invalidates" stage is the same or lower as the one specified as the "depends on" stage here cause the cache entry to be invalidated. For example, a body's momentum, which is dependent on position and velocity states, should have Stage::Velocity as its dependsOnStage. Then if a Velocity stage variable or lower (e.g. Position stage) changes, then the cache is invalidated. But, if a Dynamics stage variable (or above) is changed, the velocity remains valid so the cache entry does not have to be recomputed.

Parameters
[in]nameThe name you are assigning to this cache entry. Must be unique within this model component.
[in]variablePrototypeAn object defining the type of value, and a default value of that type, to be held in this cache entry. Can be a simple int or an elaborate class, as long as it has deep copy semantics.
[in]dependsOnStageThis is the highest computational stage on which this cache entry's value computation depends. State changes at this level or lower will invalidate the cache entry.

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

◆ addDiscreteVariable()

void OpenSim::Component::addDiscreteVariable ( const std::string &  discreteVariableName,
SimTK::Stage  invalidatesStage 
) const
protected

Add a system discrete variable belonging to this Component, 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.

◆ addModelingOption()

void OpenSim::Component::addModelingOption ( const std::string &  optionName,
int  maxFlagValue 
) const
protected

Add a modeling option (integer flag stored in the State) for use by this Component.

Each modeling option is identified by its own optionName, specified here. Modeling options enable the model component to be configured differently in order to represent different operating modes. For example, if two modes of operation are necessary (mode off and mode on) then specify optionName, "mode" with maxFlagValue = 1. Subsequent gets will return 0 or 1 and set will only accept 0 and 1 as acceptable values. Changing the value of a model option invalidates Stage::Instance and above in the State, meaning all calculations involving time, positions, velocity, and forces are invalidated.

◆ addStateVariable() [1/2]

void OpenSim::Component::addStateVariable ( const std::string &  stateVariableName,
const SimTK::Stage &  invalidatesStage = SimTK::Stage::Dynamics,
bool  isHidden = false 
) const
protected

Add a continuous system state variable belonging to this Component, and assign a name by which to refer to it.

Changing the value of this state variable will automatically invalidate everything at and above its invalidatesStage, which is normally Stage::Dynamics meaning that there are forces that depend on this variable. If you define one or more of these variables you must also override computeStateVariableDerivatives() to provide time derivatives for them. Note, all corresponding system indices are automatically determined using this interface. As an advanced option you may choose to hide the state variable from being accessed outside of this component, in which case it is considered to be "hidden". You may also want to create an Output for this state variable; see OpenSim_DECLARE_OUTPUT_FOR_STATE_VARIABLE for more information. Reporters should use such an Output to get the StateVariable's value (instead of using getStateVariableValue()).

Parameters
[in]stateVariableNamestring value to access variable by name
[in]invalidatesStagethe system realization stage that is invalidated when variable value is changed
[in]isHiddenflag (bool) to optionally hide this state variable from being accessed outside this component as an Output

◆ addStateVariable() [2/2]

void OpenSim::Component::addStateVariable ( Component::StateVariable stateVariable) const
protected

The above method provides a convenient interface to this method, which automatically creates an 'AddedStateVariable' and allocates resources in the SimTK::State for this variable.

This interface allows the creator to add/expose state variables that are allocated by underlying Simbody components and specify how the state variable value is accessed by implementing a concrete StateVariable and adding it to the component using this method. You may also want to create an Output for this state variable; see OpenSim_DECLARE_OUTPUT_FOR_STATE_VARIABLE for more information. Reporters should use such an Output to get the StateVariable's value (instead of using getStateVariableValue()).

◆ addToSystem()

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

Have the Component add itself to the underlying computational System.

◆ adoptSubcomponent()

void OpenSim::Component::adoptSubcomponent ( Component subcomponent)
protected

Adopt a component as a subcomponent of this Component.

Component methods (e.g. addToSystem(), initStateFromProperties(), ...) are automatically invoked on subcomponents when called on this Component. Realization is also performed automatically on subcomponents. All subcomponents are owned, therefore this Component also takes ownership.

◆ 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::ElasticFoundationForce, OpenSim::Probe, OpenSim::Thelen2003Muscle, OpenSim::FunctionBasedPath, OpenSim::Joint, OpenSim::Reporter< InputT >, OpenSim::Reporter< T >, OpenSim::DeGrooteFregly2016Muscle, OpenSim::MuscleFixedWidthPennationModel, OpenSim::ModelComponent, OpenSim::FirstOrderMuscleActivationDynamics, OpenSim::Frame, OpenSim::MuscleFirstOrderActivationDynamicModel, OpenSim::AckermannVanDenBogert2010Force, OpenSim::Muscle, OpenSim::CMC, OpenSim::SmoothSphereHalfSpaceForce, 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::Controller, 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::PrescribedController, 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::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, OpenSim::DiscreteController, and OpenSim::StationPlaneContactForce.

◆ computeStateVariableDerivatives()

virtual void OpenSim::Component::computeStateVariableDerivatives ( const SimTK::State &  s) const
protectedvirtual

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.

Override to set the derivatives of state variables added to the system by this component. (also see extendAddToSystem()). If the component adds states and computeStateVariableDerivatives is not implemented by the component, an exception is thrown when the system tries to evaluate its derivatives.

Implement like this:

void computeStateVariableDerivatives(const SimTK::State& state) const {
// Let the parent class set the derivative values for the
// the state variables that it added.
Super::computeStateVariableDerivatives(state)
// Compute derivative values for states allocated by this component
// as a function of the state.
double deriv = ...
// Then set the derivative value by state variable name
setStateVariableDerivativeValue(state, "<state_variable_name>", deriv);
}

For subclasses, it is highly recommended that you first call Super::computeStateVariableDerivatives(state) to preserve the derivative computation of the parent class and to only specify the derivatives of the state variables added by name. One does have the option to override all the derivative values for the parent by accessing the derivatives by their state variable name. This is necessary, for example, if a newly added state variable is coupled to the dynamics (derivatives) of the states variables that were added by the parent.

Reimplemented in OpenSim::Model, OpenSim::Millard2012AccelerationMuscle, OpenSim::Millard2012EquilibriumMuscle, OpenSim::DeGrooteFregly2016Muscle, OpenSim::Delp1990Muscle_Deprecated, OpenSim::ActivationFiberLengthMuscle_Deprecated, OpenSim::FirstOrderMuscleActivationDynamics, OpenSim::ClutchedPathSpring, OpenSim::ActivationFiberLengthMuscle, and OpenSim::ActivationCoordinateActuator.

◆ constructInput()

template<typename T >
PropertyIndex OpenSim::Component::constructInput ( const std::string &  name,
bool  isList,
const std::string &  propertyComment,
const SimTK::Stage &  requiredAtStage = SimTK::Stage::Instance 
)
inlineprotected

Construct an Input (socket) for this Component's dependence on an Output signal.

It is a placeholder for the Output and its type and enables the Component to automatically traverse its dependencies and provide a meaningful message if the provided Output is incompatible or non-existent. This also specifies at what stage the output must be valid for the component to consume it as an input. If the Output's dependsOnStage is above the Input's requiredAtStage, an Exception is thrown because the output cannot satisfy the Input's requirement. This function also creates a Property in this component to store the connectee paths for this input; the propertyComment argument is the comment to use for that Property.

◆ constructListOutput()

template<typename T , typename CompType >
bool OpenSim::Component::constructListOutput ( const std::string &  name,
T(CompType::*)(const SimTK::State &, const std::string &channel) const  memFunc,
const SimTK::Stage &  dependsOn = SimTK::Stage::Acceleration 
)
inlineprotected

Construct an output that can have multiple channels.

You add Channels to this Output in extendFinalizeFromProperties() using AbstractOutput::addChannel(). The member function you provide must take the name of the channel whose value is requested.

◆ constructOutput() [1/2]

template<typename T , typename CompType = Component>
bool OpenSim::Component::constructOutput ( const std::string &  name,
T(CompType::*)(const SimTK::State &) const  memFunc,
const SimTK::Stage &  dependsOn = SimTK::Stage::Acceleration 
)
inlineprotected

Construct an output for a member function of the same component.

The following must be true about componentMemberFunction, the function that returns the output:

  1. It is a member function of this component.
  2. The member function is const.
  3. It takes only one input, which is const SimTK::State&
  4. The function returns the computed quantity by value (e.g., double computeQuantity(const SimTK::State&) const).

You must also provide the stage on which the output depends.

You can ask outputs for their value only after you call finalizeFromProperties().

See also
constructOutputForStateVariable()

◆ constructOutput() [2/2]

template<typename T , typename CompType = Component>
bool OpenSim::Component::constructOutput ( const std::string &  name,
const T &(CompType::*)(const SimTK::State &) const  memFunc,
const SimTK::Stage &  dependsOn = SimTK::Stage::Acceleration 
)
inlineprotected

This variant handles component member functions that return the output value by const reference (const T&).

Warning
ONLY use this with member functions that fetch quantities that are stored within the passed-in SimTK::State. The function cannot return local variables.

◆ constructOutputForStateVariable()

bool OpenSim::Component::constructOutputForStateVariable ( const std::string &  name)
protected

Construct an Output for a StateVariable.

While this method is a convenient way to construct an Output for a StateVariable, it is inefficient because it uses a string lookup. To create a more efficient Output, create a member variable that returns the state variable directly; see the implementations of Coordinate::getValue() or Muscle::getActivation() for examples.

Parameters
nameName of the output, which must be the same as the name of the corresponding state variable.

◆ constructSocket()

template<typename T >
PropertyIndex OpenSim::Component::constructSocket ( const std::string &  name,
const std::string &  propertyComment 
)
inlineprotected

Construct a specialized Socket for this Component's dependence on another Component.

It serves as a placeholder for the Component and its type and enables the Component to automatically traverse its dependencies and provide a meaningful message if the provided Component is incompatible or non-existent. This function also creates a Property in this component to store the connectee path for this socket; the propertyComment argument is the comment to use for that Property.

◆ constructSubcomponent()

template<class C = Component>
MemberSubcomponentIndex OpenSim::Component::constructSubcomponent ( const std::string &  name)
inlineprotected

Construct a subcomponent as a data member of this Component.

All Component interface calls are automatically invoked on its subcomponents.

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

◆ extendAddComponent()

virtual void OpenSim::Component::extendAddComponent ( Component subcomponent)
inlineprotectedvirtual

Perform any secondary operations, e.g.

to investigate the component or to insert it into a particular internal list (for grouping), after adding the subcomponent to this component. This is intended primarily for composites like Model to have more control over the handling of a component being added to it.

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

void MyComponent::extendAddComponent(Component* subcomponent) {
Super::extendAddComponent(); // invoke parent class method
// ... your code goes here
// ... initialize any internal data structures
}

◆ extendAddToSystem()

virtual void OpenSim::Component::extendAddToSystem ( SimTK::MultibodySystem &  system) const
inlineprotectedvirtual

Add appropriate Simbody elements (if needed) to the System corresponding to this component and specify needed state resources.

extendAddToSystem() is called when the Simbody System is being created to represent a completed system (model) for computation. That is, connect() 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 extendAddToSystem() only.

Note that this method is const; you may not modify your model component or the containing model during this call. Any modifications you need should instead be performed in finalizeFromProperties() or at the latest connect(), which are non-const. The only exception is that you may need to record access information for resources you create in the system, such as an index number. For most Components, OpenSim base classes either provide convenience methods or handle indices automatically. Otherwise, you must declare indices as mutable data members so that you can set them here.

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

void MyComponent::extendAddToSystem(SimTK::MultibodySystem& system) const {
// Perform any additions to the system required by your Super
Super::extendAddToSystem(system);
// ... your code goes here
}

This method assumes that this Component's addToSystem will be invoked before its subcomponents. If you need your subcomponents to be added to the system, first (e.g. require of a Force to be anchored to a SimTK::MobilizedBody specified by subcomponents) then you must implement: extendAddToSystemAfterSubcomponents(). It is possible to implement both method to add system elements before and then after your subcomponents have added themselves. Caution is required that Simbody elements are not added twice especially when order is unimportant.

Parameters
[in,out]systemThe MultibodySystem being added to.
See also
addModelingOption(), addStateVariable(), addDiscreteVariables(), addCacheVariable()

Reimplemented in OpenSim::Model, OpenSim::Millard2012AccelerationMuscle, OpenSim::Millard2012EquilibriumMuscle, OpenSim::Muscle, OpenSim::Frame, OpenSim::Blankevoort1991Ligament, OpenSim::Joint, OpenSim::Coordinate, OpenSim::Probe, OpenSim::ScalarActuator, OpenSim::CMC, OpenSim::ConstantCurvatureJoint, OpenSim::CoordinateLimitForce, OpenSim::GeometryPath, OpenSim::ScapulothoracicJoint, OpenSim::Ligament, OpenSim::DeGrooteFregly2016Muscle, OpenSim::ExpressionBasedPointToPointForce, OpenSim::RollingOnSurfaceConstraint, OpenSim::SmoothSphereHalfSpaceForce, OpenSim::EllipsoidJoint, OpenSim::Delp1990Muscle_Deprecated, OpenSim::Point, OpenSim::ActivationFiberLengthMuscle_Deprecated, OpenSim::ClutchedPathSpring, OpenSim::FirstOrderMuscleActivationDynamics, OpenSim::Controller, OpenSim::TorqueActuator, OpenSim::Force, OpenSim::CoordinateCouplerConstraint, OpenSim::FreeJoint, OpenSim::ActivationFiberLengthMuscle, OpenSim::ExpressionBasedCoordinateForce, OpenSim::BallJoint, OpenSim::PointToPointActuator, OpenSim::GimbalJoint, OpenSim::PlanarJoint, OpenSim::UniversalJoint, OpenSim::HuntCrossleyForce, OpenSim::PinJoint, OpenSim::SpringGeneralizedForce, OpenSim::SliderJoint, OpenSim::ConstantDistanceConstraint, OpenSim::PointActuator, OpenSim::PointConstraint, OpenSim::Actuator, OpenSim::AbstractReporter, OpenSim::ActivationCoordinateActuator, OpenSim::PointOnLineConstraint, OpenSim::ConstantMuscleActivation, OpenSim::PhysicalOffsetFrame, OpenSim::ElasticFoundationForce, OpenSim::WeldJoint, OpenSim::Ground, OpenSim::DiscreteForces, and OpenSim::PathWrapPoint.

◆ extendAddToSystemAfterSubcomponents()

virtual void OpenSim::Component::extendAddToSystemAfterSubcomponents ( SimTK::MultibodySystem &  system) const
inlineprotectedvirtual

Add appropriate Simbody elements (if needed) to the System after your component's subcomponents have had a chance to add themselves to the system.

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

void MyComponent::
extendAddToSystemAfterSubcomponents(SimTK::MultibodySystem& system) const {
// Perform any additions to the system required by your Super
Super::extendAddToSystemAfterSubcomponents(system);
// ... your code goes here
}
Parameters
[in,out]systemThe MultibodySystem being added to.
See also
extendAddToSystem()

Reimplemented in OpenSim::PointToPointSpring, and OpenSim::WeldConstraint.

◆ extendFinalizeConnections()

virtual void OpenSim::Component::extendFinalizeConnections ( Component root)
inlineprotectedvirtual

Perform any necessary initializations required to connect the component (and it subcomponents) to other components and mark the connection status.

Provides a check for error conditions. connect() is invoked on all components to form a directed acyclic graph of the multibody system, prior to creating the Simbody MultibodySystem to represent it computationally. It may also be invoked at times just for its error-checking side effects.

The "root" Component argument is the root node of the directed graph composed of all the subcomponents (and their subcomponents and so on ...) and their interconnections. This should yield a fully connected root component. For ModelComponents this is the Model component. But a Model can be connected to an environment or world component with several other models, by choosing the environment/world as the root.

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

void MyComponent::extendFinalizeConnections(Component& root) {
Super::extendFinalizeConnections(root); // invoke parent class method
// ... your code goes here
}

Reimplemented in OpenSim::TableReporter_< InputT, ValueT >, and OpenSim::Geometry.

Referenced by OpenSim::TableReporter_< InputT, ValueT >::extendFinalizeConnections().

◆ extendFinalizeFromProperties()

virtual void OpenSim::Component::extendFinalizeFromProperties ( )
inlineprotectedvirtual

Perform any time-invariant calculations, data structure initializations, or other configuration based on the component's properties to form a functioning (but not yet connected) component.

For example, each property should be checked to ensure that its value is within an acceptable range. When this method returns, the component will be marked as being up-to-date with its properties. Do not perform any configuration that depends on the SimTK::MultibodySystem; it is not available at this point.

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

void MyComponent::extendFinalizeFromProperties() {
Super::extendFinalizeFromProperties(); // invoke parent class method
// ... your code goes here
// ... catch invalid property values
// ... initialize any internal data structures
}

Reimplemented in OpenSim::Model, OpenSim::Mesh, OpenSim::Blankevoort1991Ligament, OpenSim::Joint, OpenSim::MuscleFixedWidthPennationModel, OpenSim::Thelen2003Muscle, OpenSim::EspositoMiller2018Force, OpenSim::ExternalForce, OpenSim::ModelComponent, OpenSim::GeometryPath, OpenSim::PathSpring, OpenSim::PhysicalFrame, OpenSim::Ligament, OpenSim::DeGrooteFregly2016Muscle, OpenSim::OffsetFrame< PhysicalFrame >, OpenSim::FunctionBasedBushingForce, OpenSim::WrapObject, OpenSim::ClutchedPathSpring, OpenSim::MuscleFirstOrderActivationDynamicModel, OpenSim::ControlSetController, OpenSim::Body, OpenSim::PathPoint, OpenSim::WrapTorus, OpenSim::WrapSphere, OpenSim::WrapCylinder, OpenSim::WrapEllipsoid, OpenSim::ModelComponentSet< T >, 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 >, and OpenSim::Ground.

◆ extendInitStateFromProperties()

virtual void OpenSim::Component::extendInitStateFromProperties ( SimTK::State &  state) const
inlineprotectedvirtual

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 extendAddToSystem() 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:

void MyComponent::extendInitStateFromProperties(SimTK::State& state) const {
Super::extendInitStateFromProperties(state); // invoke parent class method
// ... your code goes here
}
Parameters
stateThe state that will receive the new initial conditions.
See also
extendSetPropertiesFromState()

Reimplemented in OpenSim::Model, OpenSim::Millard2012AccelerationMuscle, OpenSim::Millard2012EquilibriumMuscle, OpenSim::Muscle, OpenSim::Joint, OpenSim::Thelen2003Muscle, OpenSim::Coordinate, OpenSim::ConstantCurvatureJoint, OpenSim::GeometryPath, OpenSim::DeGrooteFregly2016Muscle, OpenSim::RollingOnSurfaceConstraint, OpenSim::EllipsoidJoint, OpenSim::ActivationFiberLengthMuscle_Deprecated, OpenSim::ClutchedPathSpring, OpenSim::FirstOrderMuscleActivationDynamics, OpenSim::CorrectionController, OpenSim::FreeJoint, OpenSim::ActivationFiberLengthMuscle, OpenSim::Force, OpenSim::BallJoint, OpenSim::GimbalJoint, OpenSim::Constraint, OpenSim::ActivationCoordinateActuator, and OpenSim::ConstantMuscleActivation.

◆ extendRealizeAcceleration()

virtual void OpenSim::Component::extendRealizeAcceleration ( const SimTK::State &  state) const
protectedvirtual

Perform computations that may depend on applied forces.

◆ extendRealizeDynamics()

virtual void OpenSim::Component::extendRealizeDynamics ( const SimTK::State &  state) const
protectedvirtual

Perform computations (typically forces) that may depend on dynamics-stage state variables, and on computations performed in earlier stages (including velocity, position, and time), but not on other forces, accelerations, constraint multipliers, or reaction forces.

Reimplemented in OpenSim::Ligament, and OpenSim::PathActuator.

◆ extendRealizeInstance()

virtual void OpenSim::Component::extendRealizeInstance ( const SimTK::State &  state) const
protectedvirtual

Perform computations that depend only on instance variables, like lengths and masses.

Reimplemented in OpenSim::Coordinate, and OpenSim::SmoothSphereHalfSpaceForce.

◆ extendRealizeModel()

virtual void OpenSim::Component::extendRealizeModel ( SimTK::State &  state) const
protectedvirtual

Obtain and name state resources (like state variables allocated by an underlying Simbody component) that may be needed, depending on modeling options.

Also, perform any computations that depend only on topology and selected modeling options.

◆ extendRealizePosition()

virtual void OpenSim::Component::extendRealizePosition ( const SimTK::State &  state) const
protectedvirtual

Perform computations that depend only on position-level state variables and computations performed in earlier stages (including time).

◆ extendRealizeReport()

virtual void OpenSim::Component::extendRealizeReport ( const SimTK::State &  state) const
protectedvirtual

Perform computations that may depend on anything but are only used for reporting and cannot affect subsequent simulation behavior.

Reimplemented in OpenSim::AbstractReporter.

◆ extendRealizeTime()

virtual void OpenSim::Component::extendRealizeTime ( const SimTK::State &  state) const
protectedvirtual

Perform computations that depend only on time and earlier stages.

◆ extendRealizeTopology()

virtual void OpenSim::Component::extendRealizeTopology ( SimTK::State &  state) const
protectedvirtual

Obtain state resources that are needed unconditionally, and perform computations that depend only on the system topology.

Reimplemented in OpenSim::DiscreteController.

◆ extendRealizeVelocity()

virtual void OpenSim::Component::extendRealizeVelocity ( const SimTK::State &  state) const
protectedvirtual

Perform computations that depend only on velocity-level state variables and computations performed in earlier stages (including position, and time).

◆ extendSetPropertiesFromState()

virtual void OpenSim::Component::extendSetPropertiesFromState ( const SimTK::State &  state)
inlineprotectedvirtual

Update this component's property values to match the specified State, if the component has created any state variable that is intended to correspond to a property.

Thus, state variable values can persist as part of the model component and be serialized as a property.

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

void MyComponent::extendSetPropertiesFromState(const SimTK::State& state) {
Super::extendSetPropertiesFromState(state); // invoke parent class method
// ... your code goes here
}
Parameters
stateThe State from which values may be extracted to set persistent property values.
See also
extendInitStateFromProperties()

Reimplemented in OpenSim::Model, OpenSim::Millard2012AccelerationMuscle, OpenSim::Millard2012EquilibriumMuscle, OpenSim::Muscle, OpenSim::Joint, OpenSim::Thelen2003Muscle, OpenSim::Coordinate, OpenSim::ConstantCurvatureJoint, OpenSim::RollingOnSurfaceConstraint, OpenSim::DeGrooteFregly2016Muscle, OpenSim::EllipsoidJoint, OpenSim::ActivationFiberLengthMuscle_Deprecated, OpenSim::ClutchedPathSpring, OpenSim::FirstOrderMuscleActivationDynamics, OpenSim::Force, OpenSim::FreeJoint, OpenSim::ActivationFiberLengthMuscle, OpenSim::BallJoint, OpenSim::GimbalJoint, OpenSim::Constraint, OpenSim::ActivationCoordinateActuator, and OpenSim::ConstantMuscleActivation.

◆ 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::ModOpIgnoreActivationDynamics::operate(), OpenSim::ModOpIgnoreTendonCompliance::operate(), OpenSim::ModOpTendonComplianceDynamicsModeDGF::operate(), OpenSim::ModOpScaleMaxIsometricForce::operate(), OpenSim::ModOpUseImplicitTendonComplianceDynamicsDGF::operate(), OpenSim::ModOpIgnorePassiveFiberForcesDGF::operate(), OpenSim::ModOpPassiveFiberStrainAtOneNormForceDGF::operate(), OpenSim::ModOpScaleActiveFiberForceCurveWidthDGF::operate(), OpenSim::ModOpFiberDampingDGF::operate(), and OpenSim::ModOpReplacePathsWithFunctionBasedPaths::operate().

◆ findComponent() [1/2]

template<class C = Component>
const C* OpenSim::Component::findComponent ( const ComponentPath pathToFind) const
inline

Find a Component to which this Component is an ancestor—in other words, a Component that is directly owned by this Component or is owned by one of its sub-components, sub-sub-components, etc.

The Component can be found by type (by specifying a template argument) and either path or name.

Here is an example of searching for a component of any type with the name 'elbow_flexion':

if (const Component* found =
model.findComponent(ComponentPath("elbow_flexion"))) {
std::cout << found.getName() << std::endl;
}

Here, we require that 'elbow_flexion' is of type Coordinate.

if (const Coordinate* found =
model.findComponent<Coordinate>(ComponentPath("elbow_flexion"))) {
std::cout << "Coordinate " << found.getName() << std::endl;
}

The search can be sped up considerably if the path or even partial path name is known. For example, "forearm/elbow/elbow_flexion" will find the Coordinate component of the elbow joint that connects the forearm body in linear time (linear search for name at each component level). Whereas supplying "elbow_flexion" requires a tree search. Returns nullptr (None in Python, empty array in Matlab) if Component of that specified name cannot be found.

NOTE: If the component name is ambiguous, an exception is thrown. To disambiguate, more information must be provided, such as the template argument to specify the type and/or a path rather than just the name.

References OpenSim::ComponentPath::getComponentName(), OpenSim::ComponentPath::pushBack(), and OpenSim::ComponentPath::toString().

◆ findComponent() [2/2]

template<class C = Component>
const C* OpenSim::Component::findComponent ( const std::string &  pathToFind) const
inline

Same as findComponent(const ComponentPath&), but accepting a string (a path or just a name) as input.

◆ 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().

◆ getCacheVariableIndex() [1/2]

template<class T >
SimTK::CacheEntryIndex OpenSim::Component::getCacheVariableIndex ( const CacheVariable< T > &  cv) const
inline

Get the index of a Component's cache variable in the Subsystem for allocations.

Template Parameters
TType of value held in the cache variable
Parameters
cvA CacheVariable<T>, as allocated by Component::addCacheVariable
Returns
A valid SimTK::CacheEntryIndex, which callers can use with Simbody methods (e.g. markCacheValueRealized)

◆ getCacheVariableIndex() [2/2]

SimTK::CacheEntryIndex OpenSim::Component::getCacheVariableIndex ( const std::string &  name) const

Get the index of a Component's cache variable in the Subsystem for allocations.

Template Parameters
TType of value held in the cache variable
Parameters
nameName of the cache variable, as provided to Component::addCacheVariable
Returns
A valid SimTK::CacheEntryIndex, which callers can use with simbody methods (e.g. markCacheValueRealized)

◆ getCacheVariableValue() [1/2]

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

Get the value of a cache variable allocated by this Component by name.

Parameters
statethe State from which to get the value
namethe name of the cache variable
Returns
T A const reference to the cache variable's value
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ getCacheVariableValue() [2/2]

template<class T >
const T& OpenSim::Component::getCacheVariableValue ( const SimTK::State &  state,
const CacheVariable< T > &  cv 
) const
inline

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

Parameters
statethe State from which to get the value
cvthe cache variable
Returns
T A const reference to the cache variable's value
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

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

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:
exampleMocoTrack.cpp.

◆ 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::ElasticFoundationForce, OpenSim::Probe, OpenSim::Thelen2003Muscle, OpenSim::FunctionBasedPath, OpenSim::Joint, OpenSim::Reporter< InputT >, OpenSim::Reporter< T >, OpenSim::DeGrooteFregly2016Muscle, OpenSim::MuscleFixedWidthPennationModel, OpenSim::ModelComponent, OpenSim::FirstOrderMuscleActivationDynamics, OpenSim::Frame, OpenSim::MuscleFirstOrderActivationDynamicModel, OpenSim::AckermannVanDenBogert2010Force, OpenSim::Muscle, OpenSim::CMC, OpenSim::SmoothSphereHalfSpaceForce, 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::Controller, 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::PrescribedController, 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::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, OpenSim::DiscreteController, and OpenSim::StationPlaneContactForce.

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

◆ getConnectee() [1/2]

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/2]

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

◆ getDiscreteVariableIndex()

const SimTK::DiscreteVariableIndex OpenSim::Component::getDiscreteVariableIndex ( const std::string &  name) const
protected

Get the index of a Component's discrete variable in the Subsystem for allocations.

This method is intended for derived Components that may need direct access to its underlying Subsystem.

◆ getDiscreteVariableValue()

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

Get the value of a discrete variable allocated by this Component by name.

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

◆ getImmediateSubcomponents()

std::vector<SimTK::ReferencePtr<const Component> > OpenSim::Component::getImmediateSubcomponents ( ) const
protected

Access this Component's immediate subcomponents (not those owned by subcomponents)

Referenced by traversePathToComponent().

◆ 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().

◆ getMemberSubcomponent()

template<class C = Component>
const C& OpenSim::Component::getMemberSubcomponent ( MemberSubcomponentIndex  ix) const
inlineprotected

◆ getModelingOption()

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

Get a ModelingOption flag for this Component by name.

The flag is an integer corresponding to the index of modelingOptionNames used add the modeling option to the component.

See also
addModelingOption
Parameters
statethe State in which to set the modeling option
namethe name (string) of the modeling option of interest
Returns
flag integer value for modeling option

◆ getNumAdoptedSubcomponents()

size_t OpenSim::Component::getNumAdoptedSubcomponents ( ) const
protected

Get the number of Subcomponents adopted by this Component.

◆ getNumImmediateSubcomponents()

size_t OpenSim::Component::getNumImmediateSubcomponents ( ) const
inlineprotected

Get the number of Subcomponents immediately owned by this Component.

◆ getNumInputs()

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

Access the number of Inputs that this component has.

◆ getNumMemberSubcomponents()

size_t OpenSim::Component::getNumMemberSubcomponents ( ) const
protected

Get the number of Subcomponents that are data members of this Component.

◆ getNumOutputs()

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

Access the number of Outputs that this component has.

◆ getNumPropertySubcomponents()

size_t OpenSim::Component::getNumPropertySubcomponents ( ) const
protected

Get the number of Subcomponents that are properties of this Component.

◆ 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

◆ getOwner()

const Component& OpenSim::Component::getOwner ( ) const

Access the owner of this Component.

An exception is thrown if the Component has no owner; in this case, the component is the root component, or is orphaned.

See also
hasOwner()

Referenced by traversePathToComponent().

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

◆ getRoot()

const Component& OpenSim::Component::getRoot ( ) const

Obtain the root Component, which is this component if it is orphaned.

Referenced by traversePathToComponent().

◆ 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);
}

◆ getStateIndex()

int OpenSim::Component::getStateIndex ( const std::string &  name) const
protected

Get the index of a Component's continuous state variable in the Subsystem for allocations.

This method is intended for derived Components that may need direct access to its underlying Subsystem.

◆ getStateVariableDerivativeValue()

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)

◆ getStateVariableNames()

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

Get the names 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)

◆ getStateVariableSystemIndex()

SimTK::SystemYIndex OpenSim::Component::getStateVariableSystemIndex ( const std::string &  stateVariableName) const
protected

Get the System Index of a state variable allocated by this Component.

Returns an InvalidIndex if no state variable with the name provided is found.

Parameters
stateVariableNamethe name of the state variable

◆ 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
namepath 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().

◆ hasOwner()

bool OpenSim::Component::hasOwner ( ) const

(For advanced users) Check if this Component has an owner.

A component may not have an owner if it: (1) is the root component, or (2) has not been added to another component

Referenced by traversePathToComponent().

◆ 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().

◆ initComponentTreeTraversal()

void OpenSim::Component::initComponentTreeTraversal ( const Component root) const
protected

Build the tree of Components from this component through its descendants.

This method is invoked whenever a ComponentList<C> is requested. Note that all components must have been added to the model (or its subcomponents), otherwise it will not be included in the tree and will not be found for iteration or for connection. The implementation populates the _nextComponent ReferencePtr with a pointer to the next Component in tree pre-order traversal.

Exceptions
ComponentIsRootWithNoSubcomponentsif the Component is the root and yet has no subcomponents.

◆ initStateFromProperties()

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

Initialize Component's state variable values from its properties.

◆ isCacheVariableValid() [1/2]

bool OpenSim::Component::isCacheVariableValid ( const SimTK::State &  state,
const std::string &  name 
) const

Returns true if the cache variable, identified by name, is valid.

This method enables callers to monitor the validity of the cache variable, which enables the caller to decide whether to update the cache variable's value (or not). When computing an update is costly, use this method to check whether computing the value is necessary.

Parameters
statethe State in which the cache variable's value resides
namethe name of the cache variable
Returns
bool whether the cache variable's value is valid or not
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ isCacheVariableValid() [2/2]

template<class T >
bool OpenSim::Component::isCacheVariableValid ( const SimTK::State &  state,
const CacheVariable< T > &  cv 
) const
inline

Returns true if the cache variable is valid.

This method enables callers to monitor the validity of the cache variable, which enables the caller to decide whether to update the cache variable's value (or not). When computing an update is costly, use this method to check whether computing the value is necessary.

Parameters
statethe State in which the cache variable's value resides
cvthe cache variable
Returns
bool whether the cache variable's value is valid or not
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ 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)?

◆ markCacheVariableInvalid() [1/2]

void OpenSim::Component::markCacheVariableInvalid ( const SimTK::State &  state,
const std::string &  name 
) const

Marks the value of a cache variable, identified by name, as invalid.

Upon marking a cache variable's value as invalid, it will remain invalid until Component::markCacheVariableValid is called (or a method which uses that, such as Component::setCacheVariableValue, is called).

  • Cache variables are automatically marked as invalid when the realization stage falls below the minimum realization stage set when the cache variable was initialized with Component::addCacheVariable.
  • Cache variables may be indirectly marked as invalid by other methods. For example, a component-added state variable may invalidate a cache variable at a lower stage. Concretely:
    • A (hypothetical) component has a length state variable
    • There are cache variables that are computed from length (e.g. strain)
    • So changing the length may invalidate the strain indirectly (depending on how the state variable is handled)
Parameters
statethe State in which the cache variable's value resides
namethe name of the cache variable
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ markCacheVariableInvalid() [2/2]

template<class T >
void OpenSim::Component::markCacheVariableInvalid ( const SimTK::State &  state,
const CacheVariable< T > &  cv 
) const
inline

Marks the value of a cache variable as invalid.

Upon marking a cache variable's value as invalid, it will remain invalid until Component::markCacheVariableValid is called (or a method which uses that, such as Component::setCacheVariableValue, is called).

  • Cache variables are automatically marked as invalid when the realization stage falls below the minimum realization stage set when the cache variable was initialized with Component::addCacheVariable.
  • Cache variables may be indirectly marked as invalid by other methods. For example, a component-added state variable may invalidate a cache variable at a lower stage. Concretely:
    • A (hypothetical) component has a length state variable
    • There are cache variables that are computed from length (e.g. strain)
    • So changing the length may invalidate the strain indirectly (depending on how the state variable is handled)
Parameters
statethe State in which the cache variable's value resides
cvthe cache variable
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ markCacheVariableValid() [1/2]

void OpenSim::Component::markCacheVariableValid ( const SimTK::State &  state,
const std::string &  name 
) const

Marks the value of a cache variable, identified by name, as valid.

Upon marking a cache variable's value as valid, the cache variable will remain valid until either:

This method causes Component::isCacheVariableValid to return true. Component::isCacheVariableValid is commonly used by value-getting methods to decide on whether to return the value as-is or recompute the value. Therefore, if a cache variable is not marked as valid then the cache variable's value may be recomputed more than necessary, which may be costly.

Parameters
statethe State in which the cache variable's value resides
namethe name of the cache variable
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ markCacheVariableValid() [2/2]

template<typename T >
void OpenSim::Component::markCacheVariableValid ( const SimTK::State &  state,
const CacheVariable< T > &  cv 
) const
inline

Marks the value of a cache variable as valid.

Upon marking a cache variable's value as valid, the cache variable will remain valid until either:

This method causes Component::isCacheVariableValid to return true. Component::isCacheVariableValid is commonly used by value-getting methods to decide on whether to return the value as-is or recompute the value. Therefore, if a cache variable is not marked as valid then the cache variable's value may be recomputed more than necessary, which may be costly.

Parameters
statethe State in which the cache variable's value resides
cvthe cache variable
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ operator=()

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

◆ prependComponentPathToConnecteePath()

static void OpenSim::Component::prependComponentPathToConnecteePath ( Component subcomponent)
staticprotected

For internal use.

Update absolute connectee paths in all sockets and inputs in the subcomponent by prepending the absolute path of the subcomponent. To be used when adding subcomponent to another component.

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

◆ printInputInfo()

void OpenSim::Component::printInputInfo ( ) const

List all the inputs of this component and whether or not they are connected.

Also list the (desired) connectee paths for the inputs.

◆ printOutputInfo()

void OpenSim::Component::printOutputInfo ( const bool  includeDescendants = true) const

Print outputs of this component and optionally, those of all subcomponents.

◆ printSocketInfo()

void OpenSim::Component::printSocketInfo ( ) const

List all the Sockets of this component and whether or not they are connected.

Also list the connectee paths for sockets that are connected.

◆ printSubcomponentInfo() [1/2]

void OpenSim::Component::printSubcomponentInfo ( ) const

List all subcomponents by name and recurse into these components to list their subcomponents, and so on.

◆ printSubcomponentInfo() [2/2]

template<typename C >
void OpenSim::Component::printSubcomponentInfo ( ) const
inline

◆ resetSubcomponentOrder()

void OpenSim::Component::resetSubcomponentOrder ( )
inlineprotected

resetSubcomponentOrder clears this Component's list of ordered subcomponents (but otherwise leaves subcomponents untouched).

You can form the ordered list using setNextSubcomponentInSystem() above.

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

◆ setCacheVariableValue() [1/2]

template<typename T >
void OpenSim::Component::setCacheVariableValue ( const SimTK::State &  state,
const std::string &  k,
value 
) const
inline

Set the value of a cache variable, identified by name, to a new value and mark the cache variable as valid.

Parameters
statethe State in which to store the new value
kthe name of the cache variable
valuethe new value for this cache variable
Returns
T A const reference to the cache variable's new value
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ setCacheVariableValue() [2/2]

template<typename T >
void OpenSim::Component::setCacheVariableValue ( const SimTK::State &  state,
const CacheVariable< T > &  cv,
value 
) const
inline

Set the value of a cache variable to a new value and mark the cache variable as valid.

Parameters
statethe State in which to store the new value
cvthe cache variable to update
valuethe new value for the cache variable
Returns
T a const reference to the cache variable's new value
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ setDiscreteVariableValue()

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

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

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

◆ setModelingOption()

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

Set the value of a ModelingOption flag for this Component.

if the integer value exceeds the number of option names used to define the options, an exception is thrown. The SimTK::State Stage will be reverted back to Stage::Instance.

Parameters
statethe State in which to set the flag
namethe name (string) of the modeling option of interest
flagthe desired flag (int) value specifying the modeling option

◆ setNextSubcomponentInSystem()

void OpenSim::Component::setNextSubcomponentInSystem ( const Component sub) const
protected

Helper method to enable Component makers to specify the order of their subcomponents to be added to the System during addToSystem().

It is highly unlikely that you will need to reorder the subcomponents of your custom component. This ability is primarily intended for Model (and other top-level) components that have the responsibility of creating a valid SimTK::MultibodySystem. MultibodySystem (Simbody) elements such as MobilizedBodies must be added sequentially to form a Multibody tree. SimTK::Constraints and SimTK::Forces must be applied to MobilizedBodies that are already present in the MultibodySystem. The Model component handles this order for you and should handle user-defined Components without any issues. You should rarely need to use this method yourself. If needed, use this method in extendFinalizeConnections() of your Component (or within your extendConnectToModel() for ModelComponents) to set the order of your subcomponents. For example, Model orders subcomponents according to the Multibody tree and adds bodies and joints in order starting from Ground and growing outward. If the subcomponent already appears in the ordered list setting it later in the list has no effect. The list remains unique. NOTE: If you do need to set the order of your subcomponents, you must do so for all your immediate subcomponents, otherwise those components not in the ordered list will not be added to the System.

◆ setOwner()

void OpenSim::Component::setOwner ( const Component owner)
protected

Set this Component's reference to its owning Component

◆ setPropertiesFromState()

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

Set Component's properties given a state.

◆ setStateVariableDerivativeValue()

void OpenSim::Component::setStateVariableDerivativeValue ( const SimTK::State &  state,
const std::string &  name,
double  deriv 
) const
protected

Set the derivative of a state variable by name when computed inside of this Component's computeStateVariableDerivatives() method.

Parameters
statethe State for which to set the value
namethe name of the state variable
derivthe derivative value to set

◆ 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)

◆ SimTK_DEFINE_UNIQUE_INDEX_TYPE()

OpenSim::Component::SimTK_DEFINE_UNIQUE_INDEX_TYPE ( MemberSubcomponentIndex  )
protected

◆ traversePathToComponent()

◆ traverseToStateVariable() [1/2]

const StateVariable* OpenSim::Component::traverseToStateVariable ( const std::string &  pathName) const

Get a StateVariable anywhere in the Component tree, given a StateVariable path.

The StateVariable doesn't need to be in a subcomponent of this component; it could be located in a different branch of the Component tree (in such a case, the specified path might begin with "../").

This returns nullptr if a StateVariable does not exist at the specified path or if the path is invalid.

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

◆ traverseToStateVariable() [2/2]

const StateVariable* OpenSim::Component::traverseToStateVariable ( const ComponentPath path) const

Get a StateVariable anywhere in the Component tree, given a StateVariable path.

The StateVariable doesn't need to be in a subcomponent of this component; it could be located in a different branch of the Component tree (in such a case, the specified path might begin with "../").

This returns nullptr if a StateVariable does not exist at the specified path or if the path is invalid.

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

◆ upd_components()

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

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

◆ updateFromXMLNode()

◆ updCacheVariableValue() [1/2]

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

Returns a mutable reference to the value of a cache variable identified by name.

Note: do not forget to mark the cache variable as valid after updating. Otherwise, it will force a re-computation of the value if the computation method is monitoring the validity of the cache value.

Parameters
statethe State in which to set the value
namethe name of the cache variable
Returns
value modifiable reference to the cache variable's value
Exceptions
ComponentHasNoSystemif this Component has not been added to a System (i.e., if initSystem has not been called)

◆ updCacheVariableValue() [2/2]

template<typename T >
T& OpenSim::Component::updCacheVariableValue ( const SimTK::State &  state,
const CacheVariable< T > &  cv 
) const
inline

Returns a mutable reference to the value of a cache variable.

Note: do not forget to mark the cache variable as valid after updating. Otherwise, it will force a re-computation of the value if the computation method is monitoring the validity of the cache value.

Parameters
statethe State in which to set the value
cvthe cache variable
Returns
value modifiable reference to the cache variable's value
Exceptions
ComponentHasNoSystemif this Component has not been added to the System (i.e., if initSystem has not been called)

◆ 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::ModOpIgnoreActivationDynamics::operate(), OpenSim::ModOpIgnoreTendonCompliance::operate(), OpenSim::ModOpTendonComplianceDynamicsModeDGF::operate(), OpenSim::ModOpScaleMaxIsometricForce::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

◆ updMemberSubcomponent()

template<class C = Component>
C& OpenSim::Component::updMemberSubcomponent ( MemberSubcomponentIndex  ix)
inlineprotected

◆ 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

◆ updSystem()

SimTK::MultibodySystem& OpenSim::Component::updSystem ( ) const
protected

Get writable reference to the MultibodySystem that this component is connected to.

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

◆ ComponentMeasure

template<class T >
friend class ComponentMeasure
friend

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: