SPHinXsys  alpha version
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
SPH::StateEngine Class Reference

Classes

class  AddedStateVariable
 Class for handling state variable added (allocated) by this StateEngine. More...
 
class  StateVariable
 
struct  StateVariableInfo
 To hold related info about discrete variables. More...
 

Public Member Functions

void addStateVariable (std::string statevariablename, SimTK::Stage invalidatestage)
 
void addStateVariable (StateEngine::StateVariable *statevariable)
 
SimTK::DefaultSystemSubsystem & getDefaultSubsystem ()
 
SimTK::DefaultSystemSubsystem & updDefaultSubsystem ()
 
StateVariabletraverseToStateVariable (std::string &pathname)
 
bool isAllStatesVariablesListValid ()
 
 StateEngine (SimTK::MultibodySystem &system)
 
virtual ~StateEngine ()
 
void InitializeState ()
 
SimTK::MultibodySystem & getMultibodySystem ()
 
SimTK::MultibodySystem & updMultibodySystem ()
 
int getNumOfStateVariables ()
 
int getNumStateVariablesAddedByEngine ()
 
Array< std::string > getStateVariableNames ()
 
SimTK::Vector getStateVariableValues ()
 
void reporter (SimTK::State &state_)
 
void writeStateInfoToXml (int ite_rst_, const SimTK::State &state_)
 
SimTK::State readAndSetStateInfoFromXml (int ite_rst_, SimTK::MultibodySystem &system_)
 
Realize the Simbody System and State to Computational Stage.

Methods in this section enable advanced and scripting users access to realize the Simbody MultibodySystem and the provided state to a desired computational (realization) Stage.

void realizeTime ()
 
void realizePosition ()
 
void realizeVelocity ()
 
void realizeDynamics ()
 
void realizeAcceleration ()
 
void realizeReport ()
 

Public Attributes

std::map< std::string, StateVariableInfonamedstatevariableinfo_
 
SimTK::Array_< SimTK::ReferencePtr< StateVariable > > allstatevariables_
 
SimTK::ReferencePtr< SimTK::System > statesassociatedsystem_
 
SimTK::ReferencePtr< SimTK::MultibodySystem > mbsystem_
 
SimTK::State working_state_
 
std::string restart_folder_
 

Protected Member Functions

void resizeXmlDocForSimbody (size_t input_size)
 

Protected Attributes

XmlEngine simbody_xml_engine_
 
UniquePtrKeepers< AddedStateVariableadded_state_variable_ptr_keeper_
 

Constructor & Destructor Documentation

◆ StateEngine()

SPH::StateEngine::StateEngine ( SimTK::MultibodySystem &  system)

Default constructor

◆ ~StateEngine()

virtual SPH::StateEngine::~StateEngine ( )
inlinevirtual

Destructor is virtual to allow concrete StateEngine to cleanup.

Member Function Documentation

◆ addStateVariable() [1/2]

void SPH::StateEngine::addStateVariable ( std::string  statevariablename,
SimTK::Stage  invalidatestage 
)

Add a continuous system state variable belonging to this Engine, 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

Allocate space for a new state variable.

◆ addStateVariable() [2/2]

void SPH::StateEngine::addStateVariable ( StateEngine::StateVariable statevariable)

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

don't add state if there is another state variable with the same name.
assign a "slot" for a state variable by name state variable index will be invalid by default upon allocation during realizeTopology the index will be set

◆ getMultibodySystem()

SimTK::MultibodySystem & SPH::StateEngine::getMultibodySystem ( )

Get the underlying MultibodySystem that this StateEngine 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 StateEngine has not added itself to the System.

See also
hasSystem().

◆ getNumOfStateVariables()

int SPH::StateEngine::getNumOfStateVariables ( )

Get the number of "continuous" state variables maintained by the State Engine.

◆ getNumStateVariablesAddedByEngine()

int SPH::StateEngine::getNumStateVariablesAddedByEngine ( )
inline

Get the number of continuous states that the State Engine added to the underlying computational system.

◆ getStateVariableNames()

Array< std::string > SPH::StateEngine::getStateVariableNames ( )

Get the names of "continuous" state variables maintained by the Engine

◆ getStateVariableValues()

SimTK::Vector SPH::StateEngine::getStateVariableValues ( )

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

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
StateEngineHasNoSystemif this object has not been added to a System (i.e., if initSystem has not been called)

if the StateVariables are invalid, rebuild the list.

◆ InitializeState()

void SPH::StateEngine::InitializeState ( )

Set up the working state in presetn engine

Clear cached list of all related StateVariables if any from a previousSystem.

Set the model's operating state (internal member variable) to the default state that is stored inside the System.

Process the modified modeling option.

Realize instance variables that may have been set above. This means floating point parameters such as mass properties and geometry placements are frozen.

Realize the initial configuration in preparation. This initial configuration does not necessarily satisfy constraints.

◆ isAllStatesVariablesListValid()

bool SPH::StateEngine::isAllStatesVariablesListValid ( )

Check that the list of _allStateVariables is valid.

Consider the list of all StateVariables to be valid if all of the following conditions are true:

  1. a System has been associated with the list of StateVariables
  2. The list of all StateVariables is correctly sized (initialized)
  3. The System associated with the StateVariables is the current System

◆ readAndSetStateInfoFromXml()

SimTK::State SPH::StateEngine::readAndSetStateInfoFromXml ( int  ite_rst_,
SimTK::MultibodySystem &  system_ 
)

read state infor from xml and set it to sate. For all bodies in the matter system, their generalized coordinates, generalized velocities and transformations of the origin points are read from the restart file

◆ realizeAcceleration()

void SPH::StateEngine::realizeAcceleration ( )

Perform computations that may depend on applied forces.

◆ realizeDynamics()

void SPH::StateEngine::realizeDynamics ( )

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.

◆ realizePosition()

void SPH::StateEngine::realizePosition ( )

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

◆ realizeReport()

void SPH::StateEngine::realizeReport ( )

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

◆ realizeTime()

void SPH::StateEngine::realizeTime ( )

Perform computations that depend only on time and earlier stages.

◆ realizeVelocity()

void SPH::StateEngine::realizeVelocity ( )

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

◆ reporter()

void SPH::StateEngine::reporter ( SimTK::State &  state_)

report the state info by requested.

◆ traverseToStateVariable()

StateEngine::StateVariable * SPH::StateEngine::traverseToStateVariable ( std::string &  pathname)

Get a StateVariable anywhere in the state engine, given a StateVariable path. This returns nullptr if a StateVariable does not exist at the specified path or if the path is invalid.

◆ updMultibodySystem()

SimTK::MultibodySystem& SPH::StateEngine::updMultibodySystem ( )

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

Member Data Documentation

◆ allstatevariables_

SimTK::Array_<SimTK::ReferencePtr<StateVariable> > SPH::StateEngine::allstatevariables_
mutable

Array of all state variables for fast access during simulation.

◆ mbsystem_

SimTK::ReferencePtr<SimTK::MultibodySystem> SPH::StateEngine::mbsystem_

Reference pointer to the system that this engine manage.

◆ namedstatevariableinfo_

std::map<std::string, StateVariableInfo> SPH::StateEngine::namedstatevariableinfo_
mutable

Map names of continuous state variables of the Engine to their underlying SimTK indices.

◆ restart_folder_

std::string SPH::StateEngine::restart_folder_

Write the state data to xml file. For all bodies in the matter system, their generalized coordinates, generalized velocities and transformations of the origin points are written in the output file

◆ statesassociatedsystem_

SimTK::ReferencePtr<SimTK::System> SPH::StateEngine::statesassociatedsystem_
mutable

A handle the System associated with the above state variables.

◆ working_state_

SimTK::State SPH::StateEngine::working_state_

This is the internal 'writable' state of the engine. working_state_ will be set to the system default state when initializeState() is called.


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