Simbody  3.7
State.h
Go to the documentation of this file.
1 #ifndef SimTK_SimTKCOMMON_STATE_H_
2 #define SimTK_SimTKCOMMON_STATE_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * Simbody(tm): SimTKcommon *
6  * -------------------------------------------------------------------------- *
7  * This is part of the SimTK biosimulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org. *
11  * *
12  * Portions copyright (c) 2005-15 Stanford University and the Authors. *
13  * Authors: Michael Sherman *
14  * Contributors: Peter Eastman *
15  * *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17  * not use this file except in compliance with the License. You may obtain a *
18  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19  * *
20  * Unless required by applicable law or agreed to in writing, software *
21  * distributed under the License is distributed on an "AS IS" BASIS, *
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23  * See the License for the specific language governing permissions and *
24  * limitations under the License. *
25  * -------------------------------------------------------------------------- */
26 
31 // Note: the StateImpl.h header is included at the end of this file to
32 // complete the inline part of the State definition.
33 #include "SimTKcommon/basics.h"
34 #include "SimTKcommon/Simmatrix.h"
36 
37 #include <ostream>
38 #include <cassert>
39 #include <algorithm>
40 #include <mutex>
41 #include <array>
42 
43 namespace SimTK {
44 
45 
49 
57 
70 
82 
94 
100 
106 
113 
124 
135 
146 
157 
158 class StateImpl;
159 class PerSubsystemInfo;
160 class DiscreteVarInfo;
161 class CacheEntryInfo;
162 class ListOfDependents;
163 
164 using CacheEntryKey = std::pair<SubsystemIndex,CacheEntryIndex>;
165 using DiscreteVarKey = std::pair<SubsystemIndex,DiscreteVariableIndex>;
166 
281 public:
284 
291 State(const State&);
292 
294 State(State&& source);
295 
303 
306 State& operator=(State&& source);
307 
310 
312 void clear();
313 
337 bool isConsistent(const SimTK::State& otherState) const;
338 
342 inline void setNumSubsystems(int i);
343 
346 inline void initializeSubsystem(SubsystemIndex, const String& name,
347  const String& version);
348 
355 inline SubsystemIndex addSubsystem(const String& name, const String& version);
356 
358 inline int getNumSubsystems() const;
359 inline const String& getSubsystemName (SubsystemIndex) const;
361 inline const Stage& getSubsystemStage (SubsystemIndex) const;
362 
364 inline const Stage& getSystemStage() const;
365 
372 inline void invalidateAll(Stage);
373 
382 
394 inline void advanceSystemToStage(Stage) const;
395 
401 
418 inline QIndex allocateQ(SubsystemIndex, const Vector& qInit);
426 inline UIndex allocateU(SubsystemIndex, const Vector& uInit);
432 inline ZIndex allocateZ(SubsystemIndex, const Vector& zInit);
449 inline QErrIndex allocateQErr (SubsystemIndex, int nqerr) const;
452 inline UErrIndex allocateUErr (SubsystemIndex, int nuerr) const;
457 inline UDotErrIndex allocateUDotErr(SubsystemIndex, int nudoterr) const;
477 allocateEventTrigger(SubsystemIndex, Stage stage, int nevent) const;
504 inline DiscreteVariableIndex
506 
559  AbstractValue*, Stage updateDependsOn);
562 inline CacheEntryIndex
566 inline Stage
572 inline Stage
574 
575 
578 inline const AbstractValue&
581 inline Real
587 inline const AbstractValue&
594 inline AbstractValue&
599 inline bool
603 inline void
605 
609 inline AbstractValue&
612 inline void
696 inline CacheEntryIndex
698  AbstractValue* value) const;
699 
704 inline CacheEntryIndex
706  AbstractValue* value) const
707 { return allocateCacheEntry(sx, stage, stage, value); }
708 
717 inline CacheEntryIndex
719  AbstractValue* value) const {
720  return allocateCacheEntry(sx, earliest, Stage::Infinity, value);
721 }
722 
727 inline CacheEntryIndex
729  (SubsystemIndex, Stage earliest, Stage latest,
730  bool q, bool u, bool z,
731  const Array_<DiscreteVarKey>& discreteVars,
732  const Array_<CacheEntryKey>& cacheEntries,
733  AbstractValue* value);
734 
737 inline Stage
739 
746 inline const AbstractValue&
748 
755 inline AbstractValue&
757 
767 
781 
790 
810 inline int getNY() const;
815 inline int getNQ() const;
817 inline SystemYIndex getQStart() const;
821 inline int getNU() const;
823 inline SystemYIndex getUStart() const;
827 inline int getNZ() const;
829 inline SystemYIndex getZStart() const;
833 inline int getNYErr() const;
836 inline int getNQErr() const;
842 inline int getNUErr() const;
849 inline int getNUDotErr() const;
854 inline int getNMultipliers() const; // =mp+mv+ma, necessarily the same as NUDotErr
857 inline int getNEventTriggers() const;
860 inline int getNEventTriggersByStage(Stage) const;
870 inline std::mutex& getStateLock() const;
871 
873 
887 
889 inline int getNQ(SubsystemIndex) const;
891 inline int getNU(SubsystemIndex) const;
893 inline int getNZ(SubsystemIndex) const;
894 
896 inline int getNQErr(SubsystemIndex) const;
898 inline int getNUErr(SubsystemIndex) const;
900 inline int getNUDotErr(SubsystemIndex) const;
902 inline int getNMultipliers(SubsystemIndex) const;
903 
907 
909 
910 inline const Vector& getEventTriggers() const;
911 inline const Vector& getEventTriggersByStage(Stage) const;
913 
914 inline Vector& updEventTriggers() const; // mutable
917 
919 inline const Vector& getQ(SubsystemIndex) const;
920 inline const Vector& getU(SubsystemIndex) const;
921 inline const Vector& getZ(SubsystemIndex) const;
922 
923 inline const Vector& getUWeights(SubsystemIndex) const;
924 inline const Vector& getZWeights(SubsystemIndex) const;
925 
929 
932 
934 inline const Vector& getQDot(SubsystemIndex) const;
935 inline const Vector& getUDot(SubsystemIndex) const;
936 inline const Vector& getZDot(SubsystemIndex) const;
937 inline const Vector& getQDotDot(SubsystemIndex) const;
938 
939 inline Vector& updQDot(SubsystemIndex) const; // these are mutable
943 
944 inline const Vector& getQErr(SubsystemIndex) const;
945 inline const Vector& getUErr(SubsystemIndex) const;
946 inline const Vector& getUDotErr(SubsystemIndex) const;
947 inline const Vector& getMultipliers(SubsystemIndex) const;
948 
949 inline const Vector& getQErrWeights(SubsystemIndex) const;
950 inline const Vector& getUErrWeights(SubsystemIndex) const;
951 
952 inline Vector& updQErr(SubsystemIndex) const; // these are mutable
956 
959 
961 inline const Real& getTime() const;
962 inline const Vector& getY() const; // {Q,U,Z} packed and in that order
963 
965 inline const Vector& getQ() const;
966 inline const Vector& getU() const;
967 inline const Vector& getZ() const;
968 
969 
1004 inline const Vector& getUWeights() const; // diag(Wu)
1005 
1012 inline const Vector& getZWeights() const;
1013 
1018 
1023 
1026 inline Real& updTime(); // Back up to Stage::Time-1
1027 inline Vector& updY(); // Back up to Stage::Dynamics-1
1028 
1030 inline void setTime(Real t);
1031 inline void setY(const Vector& y);
1032 
1034 inline Vector& updQ(); // Back up to Stage::Position-1
1035 inline Vector& updU(); // Back up to Stage::Velocity-1
1036 inline Vector& updZ(); // Back up to Stage::Dynamics-1
1037 
1039 inline void setQ(const Vector& q);
1040 inline void setU(const Vector& u);
1041 inline void setZ(const Vector& z);
1042 
1043 inline const Vector& getYDot() const; // Stage::Acceleration
1044 
1046 inline const Vector& getQDot() const; // Stage::Velocity
1047 inline const Vector& getZDot() const; // Stage::Dynamics
1048 inline const Vector& getUDot() const; // Stage::Acceleration
1049 
1051 inline const Vector& getQDotDot() const; // Stage::Acceleration
1052 
1054 inline Vector& updYDot() const; // Stage::Acceleration-1
1055 inline Vector& updQDot() const; // Stage::Velocity-1 (view into YDot)
1056 inline Vector& updZDot() const; // Stage::Dynamics-1 "
1057 inline Vector& updUDot() const; // Stage::Acceleration-1 "
1058 
1062 inline Vector& updQDotDot() const; // Stage::Acceleration-1
1063 
1066 inline const Vector& getYErr() const; // Stage::Velocity
1067 
1069 inline const Vector& getQErr() const; // Stage::Position (index 3 constraints)
1070 inline const Vector& getUErr() const; // Stage::Velocity (index 2 constraints)
1071 
1073 inline const Vector& getUDotErr() const; // Stage::Acceleration (index 1 constraints)
1074 inline const Vector& getMultipliers() const; // Stage::Acceleration
1075 
1078 inline const Vector& getQErrWeights() const;
1079 
1090 inline const Vector& getUErrWeights() const;
1091 
1097 
1103 
1105 inline Vector& updYErr() const; // Stage::Velocity-1
1106 inline Vector& updQErr() const; // Stage::Position-1 (view into YErr)
1107 inline Vector& updUErr() const; // Stage::Velocity-1 "
1108 
1109 inline Vector& updUDotErr() const; // Stage::Acceleration-1 (not a view)
1110 inline Vector& updMultipliers() const; // Stage::Acceleration-1 (not a view)
1111 
1123 inline void getSystemStageVersions(Array_<StageVersion>& versions) const;
1124 
1135  (const Array_<StageVersion>& prevVersions) const;
1136 
1144 
1160 
1164 inline const ListOfDependents& getQDependents() const;
1168 inline const ListOfDependents& getUDependents() const;
1172 inline const ListOfDependents& getZDependents() const;
1173 
1175 inline bool hasCacheEntry(const CacheEntryKey& cacheEntry) const;
1176 
1179 SimTK_FORCE_INLINE const CacheEntryInfo&
1180 getCacheEntryInfo(const CacheEntryKey& cacheEntry) const;
1181 
1184 SimTK_FORCE_INLINE CacheEntryInfo&
1186 
1189 inline bool hasDiscreteVar(const DiscreteVarKey& discreteVar) const;
1190 
1193 SimTK_FORCE_INLINE const DiscreteVarInfo&
1194 getDiscreteVarInfo(const DiscreteVarKey& discreteVar) const;
1195 
1198 SimTK_FORCE_INLINE const PerSubsystemInfo&
1200 
1205 
1207 inline String toString() const;
1209 inline String cacheToString() const;
1212 //------------------------------------------------------------------------------
1213 // The implementation class and associated inline methods are defined in a
1214 // separate header file included below.
1215  private:
1216 StateImpl* impl;
1217 
1218 const StateImpl& getImpl() const {assert(impl); return *impl;}
1219 StateImpl& updImpl() {assert(impl); return *impl;}
1220 };
1221 
1222 // Dump state and cache to a stream for debugging; this is not serialization.
1224 operator<<(std::ostream& o, const State& s);
1225 
1226 } // namespace SimTK
1227 
1228 // This completes the inline definition of State.
1230 
1231 #endif // SimTK_SimTKCOMMON_STATE_H_
SimTK::State::getZWeights
const Vector & getZWeights(SubsystemIndex) const
SimTK::State
This object is intended to contain all state information for a SimTK::System, except topological info...
Definition: State.h:280
SimTK::State::autoUpdateDiscreteVariables
void autoUpdateDiscreteVariables()
(Advanced) This is called at the beginning of every integration step to set the values of auto-update...
SimTK::State::updUErr
Vector & updUErr(SubsystemIndex) const
SimTK::State::getNY
int getNY() const
Get the total number ny=nq+nu+nz of shared continuous state variables.
SimTK::State::State
State()
Create an empty State; this allocates an implementation object on the heap.
SimTK::State::getEventTriggersByStage
const Vector & getEventTriggersByStage(Stage) const
UErrIndex
SimTK::State::getQDot
const Vector & getQDot(SubsystemIndex) const
Per-subsystem access to the shared cache entries.
SimTK::State::getDiscreteVarUpdateIndex
CacheEntryIndex getDiscreteVarUpdateIndex(SubsystemIndex, DiscreteVariableIndex) const
For an auto-updating discrete variable, return the CacheEntryIndex for its associated update cache en...
SimTK::State::getSubsystemVersion
const String & getSubsystemVersion(SubsystemIndex) const
QErrIndex
SimTK::State::allocateEventTrigger
EventTriggerByStageIndex allocateEventTrigger(SubsystemIndex, Stage stage, int nevent) const
Allocate room for nevent witness function values that will be available at the indicated stage.
SimTK::State::setSystemTopologyStageVersion
void setSystemTopologyStageVersion(StageVersion topoVersion)
(Advanced) This explicitly modifies the Topology stage version; don't use this method unless you know...
SimTK::State::getDiscreteVarAllocationStage
Stage getDiscreteVarAllocationStage(SubsystemIndex, DiscreteVariableIndex) const
At what stage was this State when this discrete variable was allocated? The answer must be Stage::Emp...
SimTK::State::getCacheEntryAllocationStage
Stage getCacheEntryAllocationStage(SubsystemIndex, CacheEntryIndex) const
At what stage was this State when this cache entry was allocated? The answer must be Stage::Empty,...
SimTK::State::getNU
int getNU() const
Get total number of shared u's (generalized speeds; mobilities).
SimTK::State::updUWeights
Vector & updUWeights()
Set u weights (and q weights indirectly).
SimTK::State::getUDotErrStart
SystemUDotErrIndex getUDotErrStart(SubsystemIndex) const
DiscreteVariableIndex
SystemQErrIndex
SimTK::State::getNUDotErr
int getNUDotErr(SubsystemIndex) const
UIndex
SystemYErrIndex
SimTK::State::getQErrStart
SystemYErrIndex getQErrStart() const
Returns the yErr index at which the qErr's begin. Callable at Instance stage.
SystemUErrIndex
SimTK::State::getNEventTriggers
int getNEventTriggers() const
Return the total number of event trigger function slots in the cache.
SimTK::State::updZ
Vector & updZ(SubsystemIndex)
SimTK::State::updEventTriggersByStage
Vector & updEventTriggersByStage(Stage) const
SimTK::State::getNUDotErr
int getNUDotErr() const
Return the total number nudotErr=mp+mv+ma of cache entries for acceleration-level constraint errors (...
SimTK::State::updZDot
Vector & updZDot() const
UDotErrIndex
SimTK::State::updMultipliers
Vector & updMultipliers() const
SimTK::State::isCacheValueRealized
bool isCacheValueRealized(SubsystemIndex, CacheEntryIndex) const
Check whether the value in a particular cache entry has been recalculated since the last change to th...
SimTK::State::getStateLock
std::mutex & getStateLock() const
Returns a mutex that should be used to lock the state whenever multiple threads are asynchronously wr...
SimTK_FORCE_INLINE
#define SimTK_FORCE_INLINE
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:269
SimTK::State::updDiscreteVariable
AbstractValue & updDiscreteVariable(SubsystemIndex, DiscreteVariableIndex)
Get a writable reference to the value stored in the indicated discrete state variable dv,...
SimTK::State::updU
Vector & updU(SubsystemIndex)
SimTK::State::updZ
Vector & updZ()
SimTK::State::getUWeights
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...
SimTK::State::getSubsystemName
const String & getSubsystemName(SubsystemIndex) const
SimTK::State::getNZ
int getNZ() const
Get total number of shared z's (auxiliary state variables).
SimTK::State::invalidateAll
void invalidateAll(Stage)
If any subsystem or the system stage is currently at or higher than the passed-in one,...
SimTK::State::updQ
Vector & updQ(SubsystemIndex)
SimTK::State::updQDot
Vector & updQDot(SubsystemIndex) const
SimTK::State::getUStart
SystemYIndex getUStart() const
Returns the y index at which the u's begin. Callable at Model stage.
SimTK::State::clear
void clear()
Restore State to default-constructed condition.
SimTK
This is a System that represents the dynamics of a particle moving along a smooth surface.
Definition: Assembler.h:37
SimTK::DiscreteVarKey
std::pair< SubsystemIndex, DiscreteVariableIndex > DiscreteVarKey
Definition: State.h:165
Simmatrix.h
SimTK::State::getUErr
const Vector & getUErr(SubsystemIndex) const
SimTK::State::allocateCacheEntry
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
SimTK::State::setU
void setU(const Vector &u)
SimTK::State::getYErr
const Vector & getYErr() const
Return the current constraint errors for all constraints.
SimTK::State::getY
const Vector & getY() const
SimTK::State::getQErrWeights
const Vector & getQErrWeights() const
Get the unit weighting (1/unit error) for each of the mp+mquat position inline constraints equations.
SimTK::State::updTime
Real & updTime()
You can call these as long as System stage >= Model, but the stage will be backed up if necessary to ...
SimTK::State::updU
Vector & updU()
SimTK::State::allocateDiscreteVariable
DiscreteVariableIndex allocateDiscreteVariable(SubsystemIndex, Stage invalidates, AbstractValue *)
The Stage supplied here in the call is the earliest subsystem stage which is invalidated by a change ...
SimTK::State::updDiscreteVarUpdateValue
AbstractValue & updDiscreteVarUpdateValue(SubsystemIndex, DiscreteVariableIndex) const
For an auto-updating discrete variable, return a writable reference to the value of its associated up...
SimTK::State::getQDotDot
const Vector & getQDotDot(SubsystemIndex) const
SimTK::State::getZDot
const Vector & getZDot(SubsystemIndex) const
SimTK::State::getZValueVersion
ValueVersion getZValueVersion() const
(Advanced) Return a ValueVersion for z, meaning an integer that is incremented whenever any z is chan...
SimTK::State::getCacheEntry
const AbstractValue & getCacheEntry(SubsystemIndex, CacheEntryIndex) const
Retrieve a const reference to the value contained in a particular cache entry.
SimTK::State::addSubsystem
SubsystemIndex addSubsystem(const String &name, const String &version)
Register a new subsystem as a client of this State.
SimTK::State::getMultipliers
const Vector & getMultipliers() const
SimTK::State::getZStart
SystemYIndex getZStart() const
Returns the y index at which the z's begin. Callable at Model stage.
SimTK::State::updUErrWeights
Vector & updUErrWeights()
Set the unit weighting (1/unit error) for each of the mp+mv velocity-level inline constraints.
SimTK::State::getQErr
const Vector & getQErr(SubsystemIndex) const
SimTK::State::getZ
const Vector & getZ() const
SimTK::State::allocateUDotErr
UDotErrIndex allocateUDotErr(SubsystemIndex, int nudoterr) const
Allocate nudoterr cache slots to hold the current error for acceleration-level (acceleration-only,...
SimTK::State::hasDiscreteVar
bool hasDiscreteVar(const DiscreteVarKey &discreteVar) const
(Advanced) Check whether this State has a particular discrete state variable.
SystemQIndex
SystemEventTriggerIndex
SimTK::State::updCacheEntry
AbstractValue & updCacheEntry(SubsystemIndex, CacheEntryIndex) const
Retrieve a writable reference to the value contained in a particular cache entry.
SimTK::State::getQErrStart
SystemQErrIndex getQErrStart(SubsystemIndex) const
SimTK::State::getUErrStart
SystemUErrIndex getUErrStart(SubsystemIndex) const
MultiplierIndex
SimTK::State::updZWeights
Vector & updZWeights(SubsystemIndex)
SimTK::State::toString
String toString() const
(Debugging) Not suitable for serialization.
SimTK::State::getU
const Vector & getU() const
SimTK::State::getUErr
const Vector & getUErr() const
SimTK::State::updQDotDot
Vector & updQDotDot(SubsystemIndex) const
SimTK::State::setZ
void setZ(const Vector &z)
SimTK::State::getQDependents
const ListOfDependents & getQDependents() const
(Advanced) Return the list of cache entries for which q was specified as an explicit prerequisite.
SimTK::State::updQErrWeights
Vector & updQErrWeights()
Set the unit weighting (1/unit error) for each of the mp+mquat position inline constraint equations.
SimTK::State::~State
~State()
Destruct this State object and free up the heap space it is using.
SimTK::State::allocateQ
QIndex allocateQ(SubsystemIndex, const Vector &qInit)
Allocate generalized coordinates q, which are second order continuous state variables.
SimTK::State::allocateCacheEntry
CacheEntryIndex allocateCacheEntry(SubsystemIndex, Stage earliest, Stage latest, AbstractValue *value) const
There are two Stages supplied explicitly as arguments to this method: earliest and latest.
SimTK_SimTKCOMMON_EXPORT
#define SimTK_SimTKCOMMON_EXPORT
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:224
SimTK::State::getNZ
int getNZ(SubsystemIndex) const
SimTK::State::updQErrWeights
Vector & updQErrWeights(SubsystemIndex)
SimTK::State::updEventTriggersByStage
Vector & updEventTriggersByStage(SubsystemIndex, Stage) const
SimTK::State::getZDot
const Vector & getZDot() const
SimTK::State::getQ
const Vector & getQ(SubsystemIndex) const
Per-subsystem access to the global shared variables.
SimTK::State::getSystemStageVersions
void getSystemStageVersions(Array_< StageVersion > &versions) const
(Advanced) Record the current version numbers of each valid System-level stage.
SimTK::StageVersion
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
SimTK::State::getQDotDot
const Vector & getQDotDot() const
This has its own space, not a view.
SimTK::State::getTime
const Real & getTime() const
You can call these as long as system stage >= Model.
SimTK::State::updYErr
Vector & updYErr() const
These are mutable.
SimTK::ValueVersion
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
SimTK::State::cacheToString
String cacheToString() const
(Debugging) Not suitable for serialization.
SimTK::State::isConsistent
bool isConsistent(const SimTK::State &otherState) const
Checks if a given state has the same number of state variables, constraints, etc as this state.
SimTK::State::advanceSystemToStage
void advanceSystemToStage(Stage) const
Advance the System-level current stage by one to the indicated stage.
SimTK::State::getQErr
const Vector & getQErr() const
These are just views into YErr.
SystemMultiplierIndex
SimTK::State::updYDot
Vector & updYDot() const
These are mutable.
ZIndex
SimTK::State::markDiscreteVarUpdateValueRealized
void markDiscreteVarUpdateValueRealized(SubsystemIndex, DiscreteVariableIndex) const
Mark the update value for this auto-update discrete variable as up-to-date with respect to the state ...
SimTK::State::getQ
const Vector & getQ() const
These are just views into Y.
SimTK::State::getYDot
const Vector & getYDot() const
SimTK::State::updQErr
Vector & updQErr(SubsystemIndex) const
SimTK::State::updUErr
Vector & updUErr() const
SimTK::State::updQErr
Vector & updQErr() const
SimTK::State::allocateQErr
QErrIndex allocateQErr(SubsystemIndex, int nqerr) const
Allocate nqerr cache slots to hold the current error for position-level (holonomic) constraint equati...
SimTK::State::getNumSubsystems
int getNumSubsystems() const
Return the number of Subsystems known to this State.
SimTK::State::getQStart
SystemQIndex getQStart(SubsystemIndex) const
SimTK::State::allocateU
UIndex allocateU(SubsystemIndex, const Vector &uInit)
Allocate generalized speeds u, which are first order continuous state variables related to the deriva...
SimTK::State::getZStart
SystemZIndex getZStart(SubsystemIndex) const
SimTK::State::setY
void setY(const Vector &y)
SimTK::CacheEntryKey
std::pair< SubsystemIndex, CacheEntryIndex > CacheEntryKey
Definition: State.h:164
SimTK::AbstractValue
Abstract base class representing an arbitrary value of unknown type.
Definition: Value.h:49
SimTK::State::getDiscreteVarInvalidatesStage
Stage getDiscreteVarInvalidatesStage(SubsystemIndex, DiscreteVariableIndex) const
What is the earliest stage that is invalidated when this discrete variable is modified?...
QIndex
SimTK::State::updQDotDot
Vector & updQDotDot() const
This is a separate shared cache entry, not part of YDot.
SimTK::State::getNEventTriggersByStage
int getNEventTriggersByStage(SubsystemIndex, Stage) const
SimTK::State::getUDotErr
const Vector & getUDotErr() const
These have their own space, they are not views.
SimTK::State::getQValueVersion
ValueVersion getQValueVersion() const
(Advanced) Return a ValueVersion for q, meaning an integer that is incremented whenever any q is chan...
SimTK::State::initializeSubsystem
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.
SimTK::State::operator=
State & operator=(State &&source)
Move assignment is very fast.
SimTK::State::updZDot
Vector & updZDot(SubsystemIndex) const
SimTK::Stage
This class is basically a glorified enumerated type, type-safe and range checked but permitting conve...
Definition: Stage.h:66
SimTK::State::State
State(const State &)
The copy constructor has deep copy semantics; that is, this creates a new copy of the source object,...
SimTK::State::updY
Vector & updY()
SimTK::State::getEventTriggerStartByStage
SystemEventTriggerByStageIndex getEventTriggerStartByStage(SubsystemIndex, Stage) const
Event.h
SimTK::State::getCacheEntryInfo
const CacheEntryInfo & getCacheEntryInfo(const CacheEntryKey &cacheEntry) const
(Advanced) Return a const reference to the cache entry information for a particular cache entry.
SimTK::State::getZDependents
const ListOfDependents & getZDependents() const
(Advanced) Return the list of cache entries for which z was specified as an explicit prerequisite.
SimTK::State::updCacheEntryInfo
CacheEntryInfo & updCacheEntryInfo(const CacheEntryKey &cacheEntry)
(Advanced) Return a writable reference to the cache entry information for a particular cache entry.
SimTK::State::allocateZ
ZIndex allocateZ(SubsystemIndex, const Vector &zInit)
Allocate auxiliary first order continuous state variables z.
SystemZIndex
SimTK::State::getEventTriggersByStage
const Vector & getEventTriggersByStage(SubsystemIndex, Stage) const
SimTK::State::getLowestSystemStageDifference
Stage getLowestSystemStageDifference(const Array_< StageVersion > &prevVersions) const
(Advanced) Given a list of per-stage version numbers extracted by an earlier call to getSystemStageVe...
SimTK::State::updUDot
Vector & updUDot() const
SimTK::State::getPerSubsystemInfo
const PerSubsystemInfo & getPerSubsystemInfo(SubsystemIndex) const
(Advanced) Return a reference to the per-subsystem information in the state.
SimTK::State::updEventTriggers
Vector & updEventTriggers() const
SimTK::State::getZ
const Vector & getZ(SubsystemIndex) const
EventTriggerByStageIndex
SimTK::State::getEventTriggerStartByStage
SystemEventTriggerIndex getEventTriggerStartByStage(Stage) const
Return the index within the global event trigger array at which the first of the event triggers assoc...
SimTK::State::updUDot
Vector & updUDot(SubsystemIndex) const
SimTK::State::getEventTriggers
const Vector & getEventTriggers() const
SimTK::State::operator=
State & operator=(const State &)
Copy assignment has deep copy semantics; that is, this State will contain a copy of the source,...
SimTK::State::getNQErr
int getNQErr(SubsystemIndex) const
SimTK::State::getNQ
int getNQ(SubsystemIndex) const
SimTK::State::getNUErr
int getNUErr(SubsystemIndex) const
SimTK::State::getSystemStage
const Stage & getSystemStage() const
This returns the global stage for this State.
SimTK::State::getNU
int getNU(SubsystemIndex) const
SimTK::State::getQErrWeights
const Vector & getQErrWeights(SubsystemIndex) const
SimTK::State::getNQErr
int getNQErr() const
Return the total number nqerr=mp+nQuaternions of cache entries for position-level constraint errors.
SystemEventTriggerByStageIndex
SimTK::State::hasCacheEntry
bool hasCacheEntry(const CacheEntryKey &cacheEntry) const
(Advanced) Check whether this State has a particular cache entry.
SimTK::State::isDiscreteVarUpdateValueRealized
bool isDiscreteVarUpdateValueRealized(SubsystemIndex, DiscreteVariableIndex) const
Check whether the update value for this auto-update discrete variable has already been computed since...
SimTK::State::getZWeights
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...
SimTK::State::getNMultipliers
int getNMultipliers() const
Return the total number of constraint multipliers; necessarily the same as the number of acceleration...
StateImpl.h
SimTK::State::allocateAutoUpdateDiscreteVariable
DiscreteVariableIndex allocateAutoUpdateDiscreteVariable(SubsystemIndex, Stage invalidates, AbstractValue *, Stage updateDependsOn)
This method allocates a DiscreteVariable whose value should be updated automatically after each time ...
SimTK::State::getQStart
SystemYIndex getQStart() const
Returns the y index at which the q's begin. Callable at Model stage.
SimTK::Array_
The Array_<T> container class is a plug-compatible replacement for the C++ standard template library ...
Definition: Array.h:53
SimTK::State::allocateLazyCacheEntry
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
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
SimTK::State::advanceSubsystemToStage
void advanceSubsystemToStage(SubsystemIndex, Stage) const
Advance a particular Subsystem's current stage by one to the indicated stage.
SimTK::State::getDiscreteVarUpdateValue
const AbstractValue & getDiscreteVarUpdateValue(SubsystemIndex, DiscreteVariableIndex) const
For an auto-updating discrete variable, return the current value of its associated update cache entry...
SubsystemIndex
SimTK::State::setDiscreteVariable
void setDiscreteVariable(SubsystemIndex, DiscreteVariableIndex, const AbstractValue &)
Alternate interface to updDiscreteVariable.
SimTK::State::updUErrWeights
Vector & updUErrWeights(SubsystemIndex)
SystemUIndex
SimTK::State::getSubsystemStage
const Stage & getSubsystemStage(SubsystemIndex) const
SimTK::Stage::Infinity
@ Infinity
Higher than any legitimate Stage.
Definition: Stage.h:79
SimTK::Vector_< Real >
SimTK::State::getDiscreteVariable
const AbstractValue & getDiscreteVariable(SubsystemIndex, DiscreteVariableIndex) const
Get the current value of the indicated discrete variable.
SimTK::State::getDiscreteVarInfo
const DiscreteVarInfo & getDiscreteVarInfo(const DiscreteVarKey &discreteVar) const
(Advanced) Return a reference to the discrete variable information for a particular discrete variable...
CacheEntryIndex
SimTK::State::getUDependents
const ListOfDependents & getUDependents() const
(Advanced) Return the list of cache entries for which u was specified as an explicit prerequisite.
basics.h
SimTK::State::allocateUErr
UErrIndex allocateUErr(SubsystemIndex, int nuerr) const
Allocate nuerr cache slots to hold the current error for velocity-level (nonholonomic and holonomic f...
SimTK::State::markCacheValueNotRealized
void markCacheValueNotRealized(SubsystemIndex, CacheEntryIndex) const
(Advanced) Normally cache entries are invalidated automatically, however this method allows manual in...
SimTK::State::getQDot
const Vector & getQDot() const
These are just views into YDot.
SimTK::SimTK_DEFINE_UNIQUE_INDEX_TYPE
SimTK_DEFINE_UNIQUE_INDEX_TYPE(AssemblyConditionIndex)
SimTK::State::updUWeights
Vector & updUWeights(SubsystemIndex)
SimTK::State::getNUErr
int getNUErr() const
Return the total number nuerr=mp+mv of cache entries for velocity-level constraint errors (including ...
SimTK::State::getUValueVersion
ValueVersion getUValueVersion() const
(Advanced) Return a ValueVersion for u, meaning an integer that is incremented whenever any u is chan...
SimTK::State::getUErrWeights
const Vector & getUErrWeights(SubsystemIndex) const
SimTK::State::getNEventTriggersByStage
int getNEventTriggersByStage(Stage) const
Return the size of the partition of event trigger functions which are evaluated at a given Stage.
SimTK::String
SimTK::String is a plug-compatible std::string replacement (plus some additional functionality) inten...
Definition: String.h:62
SimTK::State::getMultipliers
const Vector & getMultipliers(SubsystemIndex) const
SimTK::State::getUDotErr
const Vector & getUDotErr(SubsystemIndex) const
SimTK::State::getDiscreteVarLastUpdateTime
Real getDiscreteVarLastUpdateTime(SubsystemIndex, DiscreteVariableIndex) const
Return the time of last update for this discrete variable.
SimTK::State::updUDotErr
Vector & updUDotErr(SubsystemIndex) const
SimTK::State::updQDot
Vector & updQDot() const
SimTK::State::getSystemTopologyStageVersion
StageVersion getSystemTopologyStageVersion() const
The Topology stage version number (an integer) stored in this State must match the topology cache ver...
SimTK::State::getUErrStart
SystemYErrIndex getUErrStart() const
Returns the yErr index at which the uErr's begin. Callable at Instance stage.
SimTK::State::markCacheValueRealized
void markCacheValueRealized(SubsystemIndex, CacheEntryIndex) const
Mark the value of a particular cache entry as up to date after it has been recalculated.
SimTK::State::setTime
void setTime(Real t)
An alternate syntax equivalent to updTime() and updY().
SimTK::operator<<
std::ostream & operator<<(std::ostream &o, const ContactForce &f)
Definition: CompliantContactSubsystem.h:387
SystemUDotErrIndex
SimTK::State::invalidateAllCacheAtOrAbove
void invalidateAllCacheAtOrAbove(Stage) const
If any subsystem or the system stage is currently at or higher than the passed-in one,...
SimTK::State::getMultipliersStart
SystemMultiplierIndex getMultipliersStart(SubsystemIndex) const
SimTK::State::setNumSubsystems
void setNumSubsystems(int i)
Set the number of subsystems in this state.
SimTK::State::getUStart
SystemUIndex getUStart(SubsystemIndex) const
SimTK::State::getNYErr
int getNYErr() const
Get the total number nyerr=nqerr+nuerr of shared cache entries for position-level and velocity-level ...
SimTK::State::allocateCacheEntryWithPrerequisites
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...
SimTK::State::updUDotErr
Vector & updUDotErr() const
SimTK::State::getUErrWeights
const Vector & getUErrWeights() const
Get the unit weighting (1/unit error) for each of the mp+mv velocity-level inline constraint equation...
SimTK::State::State
State(State &&source)
The move constructor is very fast. The source object is left empty.
SimTK::State::getNMultipliers
int getNMultipliers(SubsystemIndex) const
SimTK::State::updQ
Vector & updQ()
These are just views into Y.
SimTK::State::setQ
void setQ(const Vector &q)
Alternate interface.
SystemYIndex
SimTK::State::getUDot
const Vector & getUDot() const
SimTK::State::updZWeights
Vector & updZWeights()
Set z weights.
SimTK::State::getU
const Vector & getU(SubsystemIndex) const
SimTK::State::getUWeights
const Vector & getUWeights(SubsystemIndex) const
SimTK::State::getNQ
int getNQ() const
Get total number of shared q's (generalized coordinates; second order state variables).
SimTK::State::updMultipliers
Vector & updMultipliers(SubsystemIndex) const
SimTK::State::getUDot
const Vector & getUDot(SubsystemIndex) const