Go to the documentation of this file. 1 #ifndef SimTK_SimTKCOMMON_STATE_H_
2 #define SimTK_SimTKCOMMON_STATE_H_
159 class PerSubsystemInfo;
160 class DiscreteVarInfo;
161 class CacheEntryInfo;
162 class ListOfDependents;
707 {
return allocateCacheEntry(sx, stage, stage, value); }
730 bool q,
bool u,
bool z,
1218 const StateImpl& getImpl()
const {assert(impl);
return *impl;}
1219 StateImpl& updImpl() {assert(impl);
return *impl;}
1231 #endif // SimTK_SimTKCOMMON_STATE_H_
const Vector & getZWeights(SubsystemIndex) const
This object is intended to contain all state information for a SimTK::System, except topological info...
Definition: State.h:280
void autoUpdateDiscreteVariables()
(Advanced) This is called at the beginning of every integration step to set the values of auto-update...
Vector & updUErr(SubsystemIndex) const
int getNY() const
Get the total number ny=nq+nu+nz of shared continuous state variables.
State()
Create an empty State; this allocates an implementation object on the heap.
const Vector & getEventTriggersByStage(Stage) const
const Vector & getQDot(SubsystemIndex) const
Per-subsystem access to the shared cache entries.
CacheEntryIndex getDiscreteVarUpdateIndex(SubsystemIndex, DiscreteVariableIndex) const
For an auto-updating discrete variable, return the CacheEntryIndex for its associated update cache en...
const String & getSubsystemVersion(SubsystemIndex) const
EventTriggerByStageIndex allocateEventTrigger(SubsystemIndex, Stage stage, int nevent) const
Allocate room for nevent witness function values that will be available at the indicated stage.
void setSystemTopologyStageVersion(StageVersion topoVersion)
(Advanced) This explicitly modifies the Topology stage version; don't use this method unless you know...
Stage getDiscreteVarAllocationStage(SubsystemIndex, DiscreteVariableIndex) const
At what stage was this State when this discrete variable was allocated? The answer must be Stage::Emp...
Stage getCacheEntryAllocationStage(SubsystemIndex, CacheEntryIndex) const
At what stage was this State when this cache entry was allocated? The answer must be Stage::Empty,...
int getNU() const
Get total number of shared u's (generalized speeds; mobilities).
Vector & updUWeights()
Set u weights (and q weights indirectly).
SystemUDotErrIndex getUDotErrStart(SubsystemIndex) const
int getNUDotErr(SubsystemIndex) const
SystemYErrIndex getQErrStart() const
Returns the yErr index at which the qErr's begin. Callable at Instance stage.
int getNEventTriggers() const
Return the total number of event trigger function slots in the cache.
Vector & updZ(SubsystemIndex)
Vector & updEventTriggersByStage(Stage) const
int getNUDotErr() const
Return the total number nudotErr=mp+mv+ma of cache entries for acceleration-level constraint errors (...
Vector & updMultipliers() const
bool isCacheValueRealized(SubsystemIndex, CacheEntryIndex) const
Check whether the value in a particular cache entry has been recalculated since the last change to th...
std::mutex & getStateLock() const
Returns a mutex that should be used to lock the state whenever multiple threads are asynchronously wr...
#define SimTK_FORCE_INLINE
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:269
AbstractValue & updDiscreteVariable(SubsystemIndex, DiscreteVariableIndex)
Get a writable reference to the value stored in the indicated discrete state variable dv,...
Vector & updU(SubsystemIndex)
const Vector & getUWeights() const
Get a unit weighting (1/unit change) for each u that can be used to weight a vector du so that the di...
const String & getSubsystemName(SubsystemIndex) const
int getNZ() const
Get total number of shared z's (auxiliary state variables).
void invalidateAll(Stage)
If any subsystem or the system stage is currently at or higher than the passed-in one,...
Vector & updQ(SubsystemIndex)
Vector & updQDot(SubsystemIndex) const
SystemYIndex getUStart() const
Returns the y index at which the u's begin. Callable at Model stage.
void clear()
Restore State to default-constructed condition.
This is a System that represents the dynamics of a particle moving along a smooth surface.
Definition: Assembler.h:37
std::pair< SubsystemIndex, DiscreteVariableIndex > DiscreteVarKey
Definition: State.h:165
const Vector & getUErr(SubsystemIndex) const
CacheEntryIndex allocateCacheEntry(SubsystemIndex sx, Stage stage, AbstractValue *value) const
This is an abbreviation for allocation of a cache entry whose earliest and latest Stages are the same...
Definition: State.h:705
void setU(const Vector &u)
const Vector & getYErr() const
Return the current constraint errors for all constraints.
const Vector & getY() const
const Vector & getQErrWeights() const
Get the unit weighting (1/unit error) for each of the mp+mquat position inline constraints equations.
Real & updTime()
You can call these as long as System stage >= Model, but the stage will be backed up if necessary to ...
DiscreteVariableIndex allocateDiscreteVariable(SubsystemIndex, Stage invalidates, AbstractValue *)
The Stage supplied here in the call is the earliest subsystem stage which is invalidated by a change ...
AbstractValue & updDiscreteVarUpdateValue(SubsystemIndex, DiscreteVariableIndex) const
For an auto-updating discrete variable, return a writable reference to the value of its associated up...
const Vector & getQDotDot(SubsystemIndex) const
const Vector & getZDot(SubsystemIndex) const
ValueVersion getZValueVersion() const
(Advanced) Return a ValueVersion for z, meaning an integer that is incremented whenever any z is chan...
const AbstractValue & getCacheEntry(SubsystemIndex, CacheEntryIndex) const
Retrieve a const reference to the value contained in a particular cache entry.
SubsystemIndex addSubsystem(const String &name, const String &version)
Register a new subsystem as a client of this State.
const Vector & getMultipliers() const
SystemYIndex getZStart() const
Returns the y index at which the z's begin. Callable at Model stage.
Vector & updUErrWeights()
Set the unit weighting (1/unit error) for each of the mp+mv velocity-level inline constraints.
const Vector & getQErr(SubsystemIndex) const
const Vector & getZ() const
UDotErrIndex allocateUDotErr(SubsystemIndex, int nudoterr) const
Allocate nudoterr cache slots to hold the current error for acceleration-level (acceleration-only,...
bool hasDiscreteVar(const DiscreteVarKey &discreteVar) const
(Advanced) Check whether this State has a particular discrete state variable.
AbstractValue & updCacheEntry(SubsystemIndex, CacheEntryIndex) const
Retrieve a writable reference to the value contained in a particular cache entry.
SystemQErrIndex getQErrStart(SubsystemIndex) const
SystemUErrIndex getUErrStart(SubsystemIndex) const
Vector & updZWeights(SubsystemIndex)
String toString() const
(Debugging) Not suitable for serialization.
const Vector & getU() const
const Vector & getUErr() const
Vector & updQDotDot(SubsystemIndex) const
void setZ(const Vector &z)
const ListOfDependents & getQDependents() const
(Advanced) Return the list of cache entries for which q was specified as an explicit prerequisite.
Vector & updQErrWeights()
Set the unit weighting (1/unit error) for each of the mp+mquat position inline constraint equations.
~State()
Destruct this State object and free up the heap space it is using.
QIndex allocateQ(SubsystemIndex, const Vector &qInit)
Allocate generalized coordinates q, which are second order continuous state variables.
CacheEntryIndex allocateCacheEntry(SubsystemIndex, Stage earliest, Stage latest, AbstractValue *value) const
There are two Stages supplied explicitly as arguments to this method: earliest and latest.
#define SimTK_SimTKCOMMON_EXPORT
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:224
int getNZ(SubsystemIndex) const
Vector & updQErrWeights(SubsystemIndex)
Vector & updEventTriggersByStage(SubsystemIndex, Stage) const
const Vector & getZDot() const
const Vector & getQ(SubsystemIndex) const
Per-subsystem access to the global shared variables.
void getSystemStageVersions(Array_< StageVersion > &versions) const
(Advanced) Record the current version numbers of each valid System-level stage.
long long StageVersion
This is the type to use for Stage version numbers that get incremented whenever a state variable chan...
Definition: Stage.h:44
const Vector & getQDotDot() const
This has its own space, not a view.
const Real & getTime() const
You can call these as long as system stage >= Model.
Vector & updYErr() const
These are mutable.
long long ValueVersion
This is the type to use for state variable version numbers that get incremented whenever a state valu...
Definition: Stage.h:52
String cacheToString() const
(Debugging) Not suitable for serialization.
bool isConsistent(const SimTK::State &otherState) const
Checks if a given state has the same number of state variables, constraints, etc as this state.
void advanceSystemToStage(Stage) const
Advance the System-level current stage by one to the indicated stage.
const Vector & getQErr() const
These are just views into YErr.
Vector & updYDot() const
These are mutable.
void markDiscreteVarUpdateValueRealized(SubsystemIndex, DiscreteVariableIndex) const
Mark the update value for this auto-update discrete variable as up-to-date with respect to the state ...
const Vector & getQ() const
These are just views into Y.
const Vector & getYDot() const
Vector & updQErr(SubsystemIndex) const
QErrIndex allocateQErr(SubsystemIndex, int nqerr) const
Allocate nqerr cache slots to hold the current error for position-level (holonomic) constraint equati...
int getNumSubsystems() const
Return the number of Subsystems known to this State.
SystemQIndex getQStart(SubsystemIndex) const
UIndex allocateU(SubsystemIndex, const Vector &uInit)
Allocate generalized speeds u, which are first order continuous state variables related to the deriva...
SystemZIndex getZStart(SubsystemIndex) const
void setY(const Vector &y)
std::pair< SubsystemIndex, CacheEntryIndex > CacheEntryKey
Definition: State.h:164
Abstract base class representing an arbitrary value of unknown type.
Definition: Value.h:49
Stage getDiscreteVarInvalidatesStage(SubsystemIndex, DiscreteVariableIndex) const
What is the earliest stage that is invalidated when this discrete variable is modified?...
Vector & updQDotDot() const
This is a separate shared cache entry, not part of YDot.
int getNEventTriggersByStage(SubsystemIndex, Stage) const
const Vector & getUDotErr() const
These have their own space, they are not views.
ValueVersion getQValueVersion() const
(Advanced) Return a ValueVersion for q, meaning an integer that is incremented whenever any q is chan...
void initializeSubsystem(SubsystemIndex, const String &name, const String &version)
Set the name and version for a given subsystem, which must already have a slot allocated.
State & operator=(State &&source)
Move assignment is very fast.
Vector & updZDot(SubsystemIndex) const
This class is basically a glorified enumerated type, type-safe and range checked but permitting conve...
Definition: Stage.h:66
State(const State &)
The copy constructor has deep copy semantics; that is, this creates a new copy of the source object,...
SystemEventTriggerByStageIndex getEventTriggerStartByStage(SubsystemIndex, Stage) const
const CacheEntryInfo & getCacheEntryInfo(const CacheEntryKey &cacheEntry) const
(Advanced) Return a const reference to the cache entry information for a particular cache entry.
const ListOfDependents & getZDependents() const
(Advanced) Return the list of cache entries for which z was specified as an explicit prerequisite.
CacheEntryInfo & updCacheEntryInfo(const CacheEntryKey &cacheEntry)
(Advanced) Return a writable reference to the cache entry information for a particular cache entry.
ZIndex allocateZ(SubsystemIndex, const Vector &zInit)
Allocate auxiliary first order continuous state variables z.
const Vector & getEventTriggersByStage(SubsystemIndex, Stage) const
Stage getLowestSystemStageDifference(const Array_< StageVersion > &prevVersions) const
(Advanced) Given a list of per-stage version numbers extracted by an earlier call to getSystemStageVe...
const PerSubsystemInfo & getPerSubsystemInfo(SubsystemIndex) const
(Advanced) Return a reference to the per-subsystem information in the state.
Vector & updEventTriggers() const
const Vector & getZ(SubsystemIndex) const
SystemEventTriggerIndex getEventTriggerStartByStage(Stage) const
Return the index within the global event trigger array at which the first of the event triggers assoc...
Vector & updUDot(SubsystemIndex) const
const Vector & getEventTriggers() const
State & operator=(const State &)
Copy assignment has deep copy semantics; that is, this State will contain a copy of the source,...
int getNQErr(SubsystemIndex) const
int getNQ(SubsystemIndex) const
int getNUErr(SubsystemIndex) const
const Stage & getSystemStage() const
This returns the global stage for this State.
int getNU(SubsystemIndex) const
const Vector & getQErrWeights(SubsystemIndex) const
int getNQErr() const
Return the total number nqerr=mp+nQuaternions of cache entries for position-level constraint errors.
bool hasCacheEntry(const CacheEntryKey &cacheEntry) const
(Advanced) Check whether this State has a particular cache entry.
bool isDiscreteVarUpdateValueRealized(SubsystemIndex, DiscreteVariableIndex) const
Check whether the update value for this auto-update discrete variable has already been computed since...
const Vector & getZWeights() const
Get a unit weighting (1/unit change) for each z that can be used to weight a vector dz so that the di...
int getNMultipliers() const
Return the total number of constraint multipliers; necessarily the same as the number of acceleration...
DiscreteVariableIndex allocateAutoUpdateDiscreteVariable(SubsystemIndex, Stage invalidates, AbstractValue *, Stage updateDependsOn)
This method allocates a DiscreteVariable whose value should be updated automatically after each time ...
SystemYIndex getQStart() const
Returns the y index at which the q's begin. Callable at Model stage.
The Array_<T> container class is a plug-compatible replacement for the C++ standard template library ...
Definition: Array.h:53
CacheEntryIndex allocateLazyCacheEntry(SubsystemIndex sx, Stage earliest, AbstractValue *value) const
This is an abbreviation for allocation of a lazy cache entry.
Definition: State.h:718
SimTK_Real Real
This is the default compiled-in floating point type for SimTK, either float or double.
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:606
void advanceSubsystemToStage(SubsystemIndex, Stage) const
Advance a particular Subsystem's current stage by one to the indicated stage.
const AbstractValue & getDiscreteVarUpdateValue(SubsystemIndex, DiscreteVariableIndex) const
For an auto-updating discrete variable, return the current value of its associated update cache entry...
void setDiscreteVariable(SubsystemIndex, DiscreteVariableIndex, const AbstractValue &)
Alternate interface to updDiscreteVariable.
Vector & updUErrWeights(SubsystemIndex)
const Stage & getSubsystemStage(SubsystemIndex) const
@ Infinity
Higher than any legitimate Stage.
Definition: Stage.h:79
const AbstractValue & getDiscreteVariable(SubsystemIndex, DiscreteVariableIndex) const
Get the current value of the indicated discrete variable.
const DiscreteVarInfo & getDiscreteVarInfo(const DiscreteVarKey &discreteVar) const
(Advanced) Return a reference to the discrete variable information for a particular discrete variable...
const ListOfDependents & getUDependents() const
(Advanced) Return the list of cache entries for which u was specified as an explicit prerequisite.
UErrIndex allocateUErr(SubsystemIndex, int nuerr) const
Allocate nuerr cache slots to hold the current error for velocity-level (nonholonomic and holonomic f...
void markCacheValueNotRealized(SubsystemIndex, CacheEntryIndex) const
(Advanced) Normally cache entries are invalidated automatically, however this method allows manual in...
const Vector & getQDot() const
These are just views into YDot.
SimTK_DEFINE_UNIQUE_INDEX_TYPE(AssemblyConditionIndex)
Vector & updUWeights(SubsystemIndex)
int getNUErr() const
Return the total number nuerr=mp+mv of cache entries for velocity-level constraint errors (including ...
ValueVersion getUValueVersion() const
(Advanced) Return a ValueVersion for u, meaning an integer that is incremented whenever any u is chan...
const Vector & getUErrWeights(SubsystemIndex) const
int getNEventTriggersByStage(Stage) const
Return the size of the partition of event trigger functions which are evaluated at a given Stage.
SimTK::String is a plug-compatible std::string replacement (plus some additional functionality) inten...
Definition: String.h:62
const Vector & getMultipliers(SubsystemIndex) const
const Vector & getUDotErr(SubsystemIndex) const
Real getDiscreteVarLastUpdateTime(SubsystemIndex, DiscreteVariableIndex) const
Return the time of last update for this discrete variable.
Vector & updUDotErr(SubsystemIndex) const
StageVersion getSystemTopologyStageVersion() const
The Topology stage version number (an integer) stored in this State must match the topology cache ver...
SystemYErrIndex getUErrStart() const
Returns the yErr index at which the uErr's begin. Callable at Instance stage.
void markCacheValueRealized(SubsystemIndex, CacheEntryIndex) const
Mark the value of a particular cache entry as up to date after it has been recalculated.
void setTime(Real t)
An alternate syntax equivalent to updTime() and updY().
std::ostream & operator<<(std::ostream &o, const ContactForce &f)
Definition: CompliantContactSubsystem.h:387
void invalidateAllCacheAtOrAbove(Stage) const
If any subsystem or the system stage is currently at or higher than the passed-in one,...
SystemMultiplierIndex getMultipliersStart(SubsystemIndex) const
void setNumSubsystems(int i)
Set the number of subsystems in this state.
SystemUIndex getUStart(SubsystemIndex) const
int getNYErr() const
Get the total number nyerr=nqerr+nuerr of shared cache entries for position-level and velocity-level ...
CacheEntryIndex allocateCacheEntryWithPrerequisites(SubsystemIndex, Stage earliest, Stage latest, bool q, bool u, bool z, const Array_< DiscreteVarKey > &discreteVars, const Array_< CacheEntryKey > &cacheEntries, AbstractValue *value)
(Advanced) Allocate a cache entry with prerequisites other than just reaching a particular computatio...
Vector & updUDotErr() const
const Vector & getUErrWeights() const
Get the unit weighting (1/unit error) for each of the mp+mv velocity-level inline constraint equation...
State(State &&source)
The move constructor is very fast. The source object is left empty.
int getNMultipliers(SubsystemIndex) const
Vector & updQ()
These are just views into Y.
void setQ(const Vector &q)
Alternate interface.
const Vector & getUDot() const
Vector & updZWeights()
Set z weights.
const Vector & getU(SubsystemIndex) const
const Vector & getUWeights(SubsystemIndex) const
int getNQ() const
Get total number of shared q's (generalized coordinates; second order state variables).
Vector & updMultipliers(SubsystemIndex) const
const Vector & getUDot(SubsystemIndex) const