Simbody  3.7
SubsystemGuts.h
Go to the documentation of this file.
1 #ifndef SimTK_SimTKCOMMON_SUBSYSTEM_GUTS_H_
2 #define SimTK_SimTKCOMMON_SUBSYSTEM_GUTS_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/home/simbody. *
11  * *
12  * Portions copyright (c) 2006-14 Stanford University and the Authors. *
13  * Authors: Michael Sherman *
14  * Contributors: *
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 
27 #include "SimTKcommon/basics.h"
28 #include "SimTKcommon/Simmatrix.h"
30 
31 #include <cassert>
32 
33 namespace SimTK {
34 
35 class System;
36 class DecorativeGeometry;
37 
38 //==============================================================================
39 // SUBSYSTEM :: GUTS
40 //==============================================================================
48 public:
49 
54 explicit Guts(const String& name="<NONAME>", const String& version="0.0.0");
55 
57 virtual ~Guts();
58 
61 Guts(const Guts&);
62 
65 const String& getName() const {return m_subsystemName;}
68 const String& getVersion() const {return m_subsystemVersion;}
69 
83 QIndex allocateQ(State& s, const Vector& qInit) const
84 { return s.allocateQ(getMySubsystemIndex(), qInit); }
85 UIndex allocateU(State& s, const Vector& uInit) const
86 { return s.allocateU(getMySubsystemIndex(), uInit); }
87 ZIndex allocateZ(State& s, const Vector& zInit) const
88 { return s.allocateZ(getMySubsystemIndex(), zInit); }
89 
92 { return s.allocateDiscreteVariable(getMySubsystemIndex(), g, v); }
93 DiscreteVariableIndex allocateAutoUpdateDiscreteVariable
94  (State& s, Stage invalidates, AbstractValue* v, Stage updateDependsOn) const
96  (getMySubsystemIndex(),invalidates,v,updateDependsOn); }
97 
98 CacheEntryIndex allocateCacheEntry
99  (const State& s, Stage dependsOn, Stage computedBy, AbstractValue* v) const
100 { return s.allocateCacheEntry
101  (getMySubsystemIndex(), dependsOn, computedBy, v); }
102 CacheEntryIndex allocateCacheEntry
103  (const State& state, Stage g, AbstractValue* v) const
104 { return allocateCacheEntry(state, g, g, v); }
105 CacheEntryIndex allocateLazyCacheEntry
106  (const State& state, Stage earliest, AbstractValue* v) const
107 { return allocateCacheEntry(state, earliest, Stage::Infinity, v); }
108 
109 QErrIndex allocateQErr(const State& s, int nqerr) const
110 { return s.allocateQErr(getMySubsystemIndex(), nqerr); }
111 UErrIndex allocateUErr(const State& s, int nuerr) const
112 { return s.allocateUErr(getMySubsystemIndex(), nuerr); }
113 UDotErrIndex allocateUDotErr(const State& s, int nudoterr) const
114 { return s.allocateUDotErr(getMySubsystemIndex(), nudoterr); }
116 allocateEventTriggersByStage(const State& s, Stage g, int ntriggers) const
117 { return s.allocateEventTrigger(getMySubsystemIndex(),g,ntriggers); }
118 
119 const Vector& getQ(const State& s) const
120 { return s.getQ(getMySubsystemIndex()); }
121 const Vector& getU(const State& s) const
122 { return s.getU(getMySubsystemIndex()); }
123 const Vector& getZ(const State& s) const
124 { return s.getZ(getMySubsystemIndex()); }
125 const Vector& getUWeights(const State& s) const
126 { return s.getUWeights(getMySubsystemIndex()); }
127 const Vector& getZWeights(const State& s) const
128 { return s.getZWeights(getMySubsystemIndex()); }
129 
130 Vector& updQ(State& s) const {return s.updQ(getMySubsystemIndex());}
131 Vector& updU(State& s) const {return s.updU(getMySubsystemIndex());}
132 Vector& updZ(State& s) const {return s.updZ(getMySubsystemIndex());}
133 
134 const Vector& getQDot (const State& s) const
135 { return s.getQDot(getMySubsystemIndex()); }
136 const Vector& getUDot (const State& s) const
137 { return s.getUDot(getMySubsystemIndex()); }
138 const Vector& getZDot (const State& s) const
139 { return s.getZDot(getMySubsystemIndex()); }
140 const Vector& getQDotDot(const State& s) const
141 { return s.getQDotDot(getMySubsystemIndex()); }
142 
143 Vector& updQDot (const State& s) const
144 { return s.updQDot(getMySubsystemIndex()); }
145 Vector& updUDot (const State& s) const
146 { return s.updUDot(getMySubsystemIndex()); }
147 Vector& updZDot (const State& s) const
148 { return s.updZDot(getMySubsystemIndex()); }
149 Vector& updQDotDot(const State& s) const
150 { return s.updQDotDot(getMySubsystemIndex()); }
151 
152 const Vector& getQErr(const State& s) const
153 { return s.getQErr(getMySubsystemIndex()); }
154 const Vector& getUErr(const State& s) const
155 { return s.getUErr(getMySubsystemIndex()); }
156 const Vector& getQErrWeights(const State& s) const
157 { return s.getQErrWeights(getMySubsystemIndex()); }
158 const Vector& getUErrWeights(const State& s) const
159 { return s.getUErrWeights(getMySubsystemIndex()); }
160 
161 const Vector& getUDotErr(const State& s) const
162 { return s.getUDotErr(getMySubsystemIndex()); }
163 const Vector& getMultipliers(const State& s) const
164 { return s.getMultipliers(getMySubsystemIndex()); }
165 const Vector& getEventTriggersByStage(const State& s, Stage g) const
166 { return s.getEventTriggersByStage(getMySubsystemIndex(),g); }
167 
168 Vector& updQErr(const State& s) const
169 { return s.updQErr(getMySubsystemIndex()); }
170 Vector& updUErr(const State& s) const
171 { return s.updUErr(getMySubsystemIndex()); }
172 Vector& updUDotErr(const State& s) const
173 { return s.updUDotErr(getMySubsystemIndex()); }
174 Vector& updMultipliers(const State& s) const
175 { return s.updMultipliers(getMySubsystemIndex()); }
177 { return s.updEventTriggersByStage(getMySubsystemIndex(),g); }
178 
179 SystemQIndex getQStart(const State& s) const
180 { return s.getQStart(getMySubsystemIndex()); }
181 int getNQ(const State& s) const
182 { return s.getNQ(getMySubsystemIndex()); }
183 
184 SystemUIndex getUStart(const State& s) const
185 { return s.getUStart(getMySubsystemIndex()); }
186 int getNU(const State& s) const
187 { return s.getNU(getMySubsystemIndex()); }
188 
189 SystemZIndex getZStart(const State& s) const
190 { return s.getZStart(getMySubsystemIndex()); }
191 int getNZ(const State& s) const
192 { return s.getNZ(getMySubsystemIndex()); }
193 
195 { return s.getQErrStart(getMySubsystemIndex()); }
196 int getNQErr(const State& s) const
197 { return s.getNQErr(getMySubsystemIndex()); }
198 
200 { return s.getUErrStart(getMySubsystemIndex()); }
201 int getNUErr(const State& s) const
202 { return s.getNUErr(getMySubsystemIndex()); }
203 
205 { return s.getUDotErrStart(getMySubsystemIndex()); }
206 int getNUDotErr(const State& s) const
207 { return s.getNUDotErr(getMySubsystemIndex()); }
208 
210 { return s.getMultipliersStart(getMySubsystemIndex()); }
211 int getNMultipliers(const State& s) const
212 { return s.getNMultipliers(getMySubsystemIndex()); }
213 
215 { return s.getEventTriggerStartByStage(getMySubsystemIndex(),g); }
216 int getNEventTriggersByStage (const State& s, Stage g) const
217 { return s.getNEventTriggersByStage(getMySubsystemIndex(),g); }
218 
219 
220 // For convenience.
221 void setQ(State& s, const Vector& q) const {
222  SimTK_ASSERT(q.size() == getNQ(s), "Subsystem::Guts::setQ()");
223  updQ(s) = q;
224 }
225 void setU(State& s, const Vector& u) const {
226  SimTK_ASSERT(u.size() == getNU(s), "Subsystem::Guts::setU()");
227  updU(s) = u;
228 }
229 void setZ(State& s, const Vector& z) const {
230  SimTK_ASSERT(z.size() == getNZ(s), "Subsystem::Guts::setZ()");
231  updZ(s) = z;
232 }
233 
234 Stage getStage(const State& s) const
235 { return s.getSubsystemStage(getMySubsystemIndex()); }
236 void advanceToStage(const State& s, Stage g) const
237 { s.advanceSubsystemToStage(getMySubsystemIndex(), g); }
238 
239 const AbstractValue&
241 { return s.getDiscreteVariable(getMySubsystemIndex(), index); }
243 { return s.updDiscreteVariable(getMySubsystemIndex(), index); }
244 const AbstractValue& getCacheEntry(const State& s, CacheEntryIndex index) const
245 { return s.getCacheEntry(getMySubsystemIndex(), index); }
247 { return s.updCacheEntry(getMySubsystemIndex(), index); }
249 { return s.getDiscreteVarLastUpdateTime(getMySubsystemIndex(),dx); }
252 { return s.getDiscreteVarUpdateIndex(getMySubsystemIndex(),dx); }
253 const AbstractValue&
255 { return s.getDiscreteVarUpdateValue(getMySubsystemIndex(),dx); }
258 { return s.updDiscreteVarUpdateValue(getMySubsystemIndex(),dx); }
259 bool isDiscreteVarUpdateValueRealized
260  (const State& s, DiscreteVariableIndex dx) const
261 { return s.isDiscreteVarUpdateValueRealized(getMySubsystemIndex(),dx); }
262 void markDiscreteVarUpdateValueRealized
263  (const State& s, DiscreteVariableIndex dx) const
264 { return s.markDiscreteVarUpdateValueRealized(getMySubsystemIndex(),dx); }
265 
266 bool isCacheValueRealized(const State& s, CacheEntryIndex cx) const
267 { return s.isCacheValueRealized(getMySubsystemIndex(), cx); }
268 
270 { s.markCacheValueRealized(getMySubsystemIndex(), cx); }
271 
273 { s.markCacheValueNotRealized(getMySubsystemIndex(), cx); }
278 MeasureIndex adoptMeasure(AbstractMeasure& m);
279 
286 template <class T> Measure_<T> getMeasure_(MeasureIndex mx) const
287 { return Measure_<T>::getAs(getMeasure(mx)); }
288 
293 AbstractMeasure getMeasure(MeasureIndex mx) const {
294  SimTK_ASSERT(0 <= mx && mx < m_measures.size(),
295  "Subsystem::Guts::getMeasure()");
296  return AbstractMeasure(m_measures[mx]);
297 }
298 
299 bool isInSystem() const {return m_mySystem != 0;}
300 bool isInSameSystem(const Subsystem& otherSubsystem) const;
301 
302 const System& getSystem() const {
303  SimTK_ASSERT(isInSystem(), "Subsystem::getSystem()");
304  return *m_mySystem;
305 }
307  SimTK_ASSERT(isInSystem(), "Subsystem::updSystem()");
308  return *m_mySystem;
309 }
311  SimTK_ASSERT(!isInSystem(), "Subsystem::setSystem()");
312  SimTK_ASSERT(id.isValid(), "Subsystem::setSystem()");
313  m_mySystem = &sys;
314  m_mySubsystemIndex = id;
315 }
317  SimTK_ASSERT(isInSystem(), "Subsystem::getMySubsystemIndex()");
318  return m_mySubsystemIndex;
319 }
320 
321 
326 { return m_subsystemTopologyRealized; }
327 
336 void invalidateSubsystemTopologyCache() const;
337 
338 // These are wrappers for the virtual methods defined below. They
339 // are used to ensure good behavior. Most of them deal automatically with
340 // the Subsystem's Measures, as well as invoking the corresponding virtual
341 // for the Subsystem's own processing.
342 
343 Subsystem::Guts* clone() const;
344 
345 // Realize this subsystem's part of the State from Stage-1 to Stage
346 // for the indicated stage. After doing some checking, these routines
347 // call the concrete subsystem's corresponding virtual method, and
348 // on return they make sure the stage has been properly updated.
349 // Note that these will do nothing if the Subsystem stage is already
350 // at or greater than the indicated stage.
351 void realizeSubsystemTopology (State&) const;
352 void realizeSubsystemModel (State&) const;
353 void realizeSubsystemInstance (const State&) const;
354 void realizeSubsystemTime (const State&) const;
355 void realizeSubsystemPosition (const State&) const;
356 void realizeSubsystemVelocity (const State&) const;
357 void realizeSubsystemDynamics (const State&) const;
358 void realizeSubsystemAcceleration(const State&) const;
359 void realizeSubsystemReport (const State&) const;
360 
361 // Generate decorative geometry computable at a specific stage. This will
362 // throw an exception if this subsystem's state hasn't already been realized
363 // to that stage. Note that the list is not inclusive -- you have to
364 // request geometry from each stage to get all of it.
365 // The generated geometry will be *appended* to the supplied output vector.
366 void calcDecorativeGeometryAndAppend
367  (const State&, Stage, Array_<DecorativeGeometry>&) const;
368 
369 void createScheduledEvent(const State& state, EventId& eventId) const;
370 void createTriggeredEvent(const State& state, EventId& eventId,
371  EventTriggerByStageIndex& triggerFunctionIndex,
372  Stage stage) const;
373 
374 // These methods are called by the corresponding methods of System.
375 // Each subsystem is responsible for defining its own events, and
376 // System then combines the information from them, and dispatches events
377 // to the appropriate subsystems for handling when they occur.
378 void calcEventTriggerInfo
379  (const State&, Array_<EventTriggerInfo>&) const;
380 void calcTimeOfNextScheduledEvent
381  (const State&, Real& tNextEvent, Array_<EventId>& eventIds,
382  bool includeCurrentTime) const;
383 void calcTimeOfNextScheduledReport
384  (const State&, Real& tNextEvent, Array_<EventId>& eventIds,
385  bool includeCurrentTime) const;
386 void handleEvents
387  (State&, Event::Cause, const Array_<EventId>& eventIds,
388  const HandleEventsOptions& options, HandleEventsResults& results) const;
389 void reportEvents
390  (const State&, Event::Cause, const Array_<EventId>& eventIds) const;
391 
392 protected:
393 // These virtual methods should be overridden in concrete Subsystems as
394 // necessary. They should never be called directly; instead call the
395 // wrapper routines above, which have the same name but without the "Impl"
396 // (implementation) at the end.
397 
398 // The "realize..." wrappers will call the "realize...Impl" methods below
399 // only when the current stage for the Subsystem is the one just prior
400 // to the stage being realized. For example, realizeSubsystemVelocityImpl()
401 // is called by realizeSubsystemVelocity() only when the passed-in State
402 // shows this subsystem's stage to be exactly Stage::Position.
403 //
404 // The default implementations provided here do nothing. That means the
405 // wrappers will simply check that the current stage is correct and
406 // advance it if necessary.
407 
408 // The destructor is already virtual; see above.
409 
410 virtual Subsystem::Guts* cloneImpl() const = 0;
411 
412 virtual int realizeSubsystemTopologyImpl(State& s) const {return 0;}
413 virtual int realizeSubsystemModelImpl (State& s) const {return 0;}
414 virtual int realizeSubsystemInstanceImpl(const State& s) const {return 0;}
415 virtual int realizeSubsystemTimeImpl (const State& s) const {return 0;}
416 virtual int realizeSubsystemPositionImpl(const State& s) const {return 0;}
417 virtual int realizeSubsystemVelocityImpl(const State& s) const {return 0;}
418 virtual int realizeSubsystemDynamicsImpl(const State& s) const {return 0;}
419 virtual int realizeSubsystemAccelerationImpl(const State& s)const{return 0;}
420 virtual int realizeSubsystemReportImpl (const State& s) const {return 0;}
421 
422 virtual int calcDecorativeGeometryAndAppendImpl
423  (const State&, Stage, Array_<DecorativeGeometry>&) const {return 0;}
424 
425 virtual void calcEventTriggerInfoImpl
426  (const State&, Array_<EventTriggerInfo>&) const {}
427 virtual void calcTimeOfNextScheduledEventImpl
428  (const State&, Real& tNextEvent, Array_<EventId>& eventIds,
429  bool includeCurrentTime) const {}
430 virtual void calcTimeOfNextScheduledReportImpl
431  (const State&, Real& tNextEvent, Array_<EventId>& eventIds,
432  bool includeCurrentTime) const {}
433 virtual void handleEventsImpl
434  (State&, Event::Cause, const Array_<EventId>& eventIds,
435  const HandleEventsOptions& options,
436  HandleEventsResults& results) const {}
437 virtual void reportEventsImpl
438  (const State&, Event::Cause, const Array_<EventId>& eventIds) const {}
439 
440 
441 public:
445  SimTK_ASSERT(m_myHandle, "Subsystem::getOwnerSubsystemHandle()");
446  return *m_myHandle;
447 }
451  SimTK_ASSERT(m_myHandle, "Subsystem::getOwnerSubsystemHandle()");
452  return *m_myHandle;
453 }
454 
459 void setOwnerSubsystemHandle(Subsystem& subsys) {m_myHandle=&subsys;}
460 
463 bool hasOwnerSubsystemHandle() const {return m_myHandle != 0;}
464 
465 private:
466 // Suppressed.
467 Guts& operator=(const Guts&);
468 
469 //------------------------------------------------------------------------------
470  private:
471 
472  // TOPOLOGY STATE INFORMATION
473 String m_subsystemName;
474 String m_subsystemVersion;
475 System* m_mySystem; // the System to which this Subsystem belongs
476 SubsystemIndex m_mySubsystemIndex; // Subsystem # within System
477 
478 friend class Subsystem;
479 Subsystem* m_myHandle; // the owner handle of this Guts object
480 
481 // This is the list of Measures belonging to this Subsystem.
483  m_measures;
484 
485  // TOPOLOGY CACHE INFORMATION
486 mutable bool m_subsystemTopologyRealized;
487 };
488 
489 
490 //==============================================================================
491 // SUBSYSTEM INLINES
492 //==============================================================================
493 // These had to wait for Subsystem::Guts to be defined.
494 
497 
498 inline const String& Subsystem::getName() const {return getSubsystemGuts().getName();}
499 inline const String& Subsystem::getVersion() const {return getSubsystemGuts().getVersion();}
500 
503 }
504 
507 }
508 
510 { return updSubsystemGuts().adoptMeasure(m); }
511 inline AbstractMeasure Subsystem::getMeasure(MeasureIndex mx) const
512 { return getSubsystemGuts().getMeasure(mx); }
513 
514 
515 inline bool Subsystem::isInSystem() const
516 { return getSubsystemGuts().isInSystem(); }
517 inline bool Subsystem::isInSameSystem(const Subsystem& otherSubsystem) const
518 { return getSubsystemGuts().isInSameSystem(otherSubsystem); }
519 
520 inline const System& Subsystem::getSystem() const
521 { return getSubsystemGuts().getSystem(); }
523 { return updSubsystemGuts().updSystem(); }
525 { updSubsystemGuts().setSystem(sys,id); }
526 
527 inline bool Subsystem::isOwnerHandle() const
528 { return guts==0 || &guts->getOwnerSubsystemHandle()==this; }
529 
530 } // namespace SimTK
531 
532 #endif // SimTK_SimTKCOMMON_SUBSYSTEM_GUTS_H_
const Vector & getQErrWeights(const State &s) const
Definition: SubsystemGuts.h:156
const Vector & getMultipliers(SubsystemIndex) const
SystemYIndex getZStart() const
Returns the y index at which the z&#39;s begin. Callable at Model stage.
Vector & updQDotDot(const State &s) const
Definition: SubsystemGuts.h:149
const Vector & getQ(SubsystemIndex) const
Per-subsystem access to the global shared variables.
A Subsystem is expected to be part of a larger System and to have interdependencies with other subsys...
Definition: Subsystem.h:55
Vector & updQ(SubsystemIndex)
MeasureIndex adoptMeasure(AbstractMeasure &m)
Add a new Measure to this Subsystem.
virtual int realizeSubsystemTimeImpl(const State &s) const
Definition: SubsystemGuts.h:415
#define SimTK_SimTKCOMMON_EXPORT
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:224
const AbstractValue & getDiscreteVariable(const State &s, DiscreteVariableIndex index) const
Definition: SubsystemGuts.h:240
SubsystemIndex getMySubsystemIndex() const
Return the SubsystemIndex within the containing System.
Definition: SubsystemGuts.h:495
SystemMultiplierIndex getMultipliersStart(SubsystemIndex) const
AbstractMeasure getMeasure(MeasureIndex mx) const
Return the Measure whose index within this Subsystem is given, as an AbstractMeasure (that is...
Definition: SubsystemGuts.h:293
SystemUDotErrIndex getUDotErrStart(const State &s) const
Definition: SubsystemGuts.h:204
const AbstractValue & getDiscreteVarUpdateValue(const State &s, DiscreteVariableIndex dx) const
Definition: SubsystemGuts.h:254
const AbstractValue & getDiscreteVariable(SubsystemIndex, DiscreteVariableIndex) const
Get the current value of the indicated discrete variable.
DiscreteVariableIndex allocateDiscreteVariable(State &s, Stage g, AbstractValue *v) const
Definition: SubsystemGuts.h:91
Unique integer type for Subsystem-local uDotErr indexing.
Vector & updUDot(const State &s) const
Definition: SubsystemGuts.h:145
AbstractValue & updDiscreteVariable(State &s, DiscreteVariableIndex index) const
Definition: SubsystemGuts.h:242
const Vector & getQDotDot(SubsystemIndex) const
const Vector & getUWeights(SubsystemIndex) const
int getNU(const State &s) const
Definition: SubsystemGuts.h:186
void advanceSubsystemToStage(SubsystemIndex, Stage) const
Advance a particular Subsystem&#39;s current stage by one to the indicated stage.
MeasureIndex adoptMeasure(AbstractMeasure &)
Obtain the Subsystem name if one was given on construction of the concrete Subsystem.
Definition: SubsystemGuts.h:509
int getNQErr(const State &s) const
Definition: SubsystemGuts.h:196
Unique integer type for Subsystem-local u indexing.
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
virtual int realizeSubsystemVelocityImpl(const State &s) const
Definition: SubsystemGuts.h:417
virtual int realizeSubsystemModelImpl(State &s) const
Definition: SubsystemGuts.h:413
virtual int realizeSubsystemTopologyImpl(State &s) const
Definition: SubsystemGuts.h:412
int getNUDotErr(const State &s) const
Definition: SubsystemGuts.h:206
Vector & updEventTriggersByStage(const State &s, Stage g) const
Definition: SubsystemGuts.h:176
Unique integer type for Subsystem-local uErr indexing.
SubsystemIndex getMySubsystemIndex() const
Definition: SubsystemGuts.h:316
bool subsystemTopologyHasBeenRealized() const
Returns true if this Subsystem&#39;s realizeTopology() method has been called since the last topological ...
Definition: SubsystemGuts.h:501
Unique integer type for Subsystem-local qErr indexing.
This class is basically a glorified enumerated type, type-safe and range checked but permitting conve...
Definition: Stage.h:66
EventTriggerByStageIndex allocateEventTriggersByStage(const State &s, Stage g, int ntriggers) const
Definition: SubsystemGuts.h:116
const String & getName() const
Obtain the Subsystem name if one was given on construction of the concrete Subsystem.
Definition: SubsystemGuts.h:498
SystemZIndex getZStart(const State &s) const
Definition: SubsystemGuts.h:189
const Vector & getUDotErr(SubsystemIndex) const
void setQ(State &s, const Vector &q) const
Definition: SubsystemGuts.h:221
const Vector & getUDot(SubsystemIndex) const
int getNMultipliers(const State &s) const
Definition: SubsystemGuts.h:211
#define SimTK_ASSERT(cond, msg)
Definition: ExceptionMacros.h:373
const Vector & getZDot(const State &s) const
Definition: SubsystemGuts.h:138
int getNUDotErr() const
Return the total number nudotErr=mp+mv+ma of cache entries for acceleration-level constraint errors (...
void setZ(State &s, const Vector &z) const
Definition: SubsystemGuts.h:229
CacheEntryIndex getDiscreteVarUpdateIndex(SubsystemIndex, DiscreteVariableIndex) const
For an auto-updating discrete variable, return the CacheEntryIndex for its associated update cache en...
Vector & updZDot(SubsystemIndex) const
This is the base class for all Measure handle classes.
Definition: Measure.h:151
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
virtual int realizeSubsystemDynamicsImpl(const State &s) const
Definition: SubsystemGuts.h:418
int getNZ() const
Get total number of shared z&#39;s (auxiliary state variables).
This unique integer type is for indexing global "multiplier-like" arrays, that is, arrays that inherently have the same dimension as the total number of Lagrange multipliers in the full System-level view of the State.
const Vector & getQDot(SubsystemIndex) const
Per-subsystem access to the shared cache entries.
Vector & updQ(State &s) const
Definition: SubsystemGuts.h:130
bool isInSameSystem(const Subsystem &otherSubsystem) const
Return true if this Subsystem is contained in the same System as contains the given otherSubsystem...
Definition: SubsystemGuts.h:517
virtual int realizeSubsystemPositionImpl(const State &s) const
Definition: SubsystemGuts.h:416
This object is intended to contain all state information for a SimTK::System, except topological info...
Definition: State.h:280
const Vector & getU(SubsystemIndex) const
SystemYErrIndex getQErrStart() const
Returns the yErr index at which the qErr&#39;s begin. Callable at Instance stage.
const AbstractValue & getDiscreteVarUpdateValue(SubsystemIndex, DiscreteVariableIndex) const
For an auto-updating discrete variable, return the current value of its associated update cache entry...
const Vector & getZ(const State &s) const
Definition: SubsystemGuts.h:123
SystemYIndex getUStart() const
Returns the y index at which the u&#39;s begin. Callable at Model stage.
void setSystem(System &sys, SubsystemIndex id)
Definition: SubsystemGuts.h:310
const Vector & getZWeights(SubsystemIndex) const
bool isCacheValueRealized(SubsystemIndex, CacheEntryIndex) const
Check whether the value in a particular cache entry has been recalculated since the last change to th...
AbstractValue & updDiscreteVariable(SubsystemIndex, DiscreteVariableIndex)
Get a writable reference to the value stored in the indicated discrete state variable dv...
Vector & updU(SubsystemIndex)
Vector & updUErr(SubsystemIndex) const
These are all the possible causes for events.
Definition: Event.h:126
bool isDiscreteVarUpdateValueRealized(SubsystemIndex, DiscreteVariableIndex) const
Check whether the update value for this auto-update discrete variable has already been computed since...
SystemMultiplierIndex getMultipliersStart(const State &s) const
Definition: SubsystemGuts.h:209
Vector & updQErr(const State &s) const
Definition: SubsystemGuts.h:168
Vector & updUErr(const State &s) const
Definition: SubsystemGuts.h:170
int getNQ(const State &s) const
Definition: SubsystemGuts.h:181
DiscreteVariableIndex allocateAutoUpdateDiscreteVariable(SubsystemIndex, Stage invalidates, AbstractValue *, Stage updateDependsOn)
This method allocates a DiscreteVariable whose value should be updated automatically after each time ...
const Vector & getQErr(const State &s) const
Definition: SubsystemGuts.h:152
Subsystem::Guts & updSubsystemGuts()
Obtain the Subsystem name if one was given on construction of the concrete Subsystem.
Definition: Subsystem.h:354
UDotErrIndex allocateUDotErr(const State &s, int nudoterr) const
Definition: SubsystemGuts.h:113
int getNQErr() const
Return the total number nqerr=mp+nQuaternions of cache entries for position-level constraint errors...
const Vector & getQErrWeights(SubsystemIndex) const
const Vector & getUErrWeights(const State &s) const
Definition: SubsystemGuts.h:158
int getNMultipliers() const
Return the total number of constraint multipliers; necessarily the same as the number of acceleration...
const Vector & getMultipliers(const State &s) const
Definition: SubsystemGuts.h:163
Vector & updZDot(const State &s) const
Definition: SubsystemGuts.h:147
const Vector & getUDot(const State &s) const
Definition: SubsystemGuts.h:136
void markCacheValueRealized(SubsystemIndex, CacheEntryIndex) const
Mark the value of a particular cache entry as up to date after it has been recalculated.
SystemYIndex getQStart() const
Returns the y index at which the q&#39;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
virtual int realizeSubsystemInstanceImpl(const State &s) const
Definition: SubsystemGuts.h:414
SystemEventTriggerIndex getEventTriggerStartByStage(Stage) const
Return the index within the global event trigger array at which the first of the event triggers assoc...
void invalidateSubsystemTopologyCache() const
Always call this method when a topological change is made to this Subsystem to indicate that any Stag...
This unique integer type is for indexing global "q-like" arrays, that is, arrays that inherently have...
const String & getVersion() const
Report back the version string supplied on construction; this i not interpreted in any way by Simbody...
Definition: SubsystemGuts.h:68
const Vector & getUErr(SubsystemIndex) const
This unique integer type is for indexing global "qErr-like" arrays, that is, arrays that inherently h...
Measure_< T > getMeasure_(MeasureIndex mx) const
Return the Measure whose index within this Subsystem is given.
Definition: SubsystemGuts.h:286
Unique integer type for Subsystem-local z indexing.
bool isInSameSystem(const Subsystem &otherSubsystem) const
Subsystem & updOwnerSubsystemHandle()
Return a writable reference to the Subsystem handle object that is the unique owner of this Subsystem...
Definition: SubsystemGuts.h:450
QIndex allocateQ(State &s, const Vector &qInit) const
Definition: SubsystemGuts.h:83
Vector & updQDotDot(SubsystemIndex) const
virtual int realizeSubsystemReportImpl(const State &s) const
Definition: SubsystemGuts.h:420
This unique integer type is for indexing global "uErr-like" arrays, that is, arrays that inherently h...
const Vector & getUErrWeights(SubsystemIndex) const
System & updSystem()
Return a writable reference to the System that contains this Subsystem.
Definition: SubsystemGuts.h:522
AbstractValue & updDiscreteVarUpdateValue(const State &s, DiscreteVariableIndex dx) const
Definition: SubsystemGuts.h:257
const AbstractValue & getCacheEntry(SubsystemIndex, CacheEntryIndex) const
Retrieve a const reference to the value contained in a particular cache entry.
const Vector & getQDot(const State &s) const
Definition: SubsystemGuts.h:134
QErrIndex allocateQErr(const State &s, int nqerr) const
Definition: SubsystemGuts.h:109
DiscreteVariableIndex allocateDiscreteVariable(SubsystemIndex, Stage invalidates, AbstractValue *)
The Stage supplied here in the call is the earliest subsystem stage which is invalidated by a change ...
Unique integer type for Subsystem-local q indexing.
const AbstractValue & getCacheEntry(const State &s, CacheEntryIndex index) const
Definition: SubsystemGuts.h:244
void advanceToStage(const State &s, Stage g) const
Definition: SubsystemGuts.h:236
The abstract parent of all Subsystem implementation classes.
Definition: SubsystemGuts.h:47
Vector & updQDot(SubsystemIndex) const
Vector & updMultipliers(SubsystemIndex) const
void setOwnerSubsystemHandle(Subsystem &subsys)
Provide a reference to the Subsystem handle object that is the unique owner of this Subsystem::Guts o...
Definition: SubsystemGuts.h:459
Stage getStage(const State &s) const
Definition: SubsystemGuts.h:234
const Vector & getQErr(SubsystemIndex) const
UErrIndex allocateUErr(const State &s, int nuerr) const
Definition: SubsystemGuts.h:111
Higher than any legitimate Stage.
Definition: Stage.h:79
Vector & updQErr(SubsystemIndex) const
Vector & updQDot(const State &s) const
Definition: SubsystemGuts.h:143
const Vector & getQDotDot(const State &s) const
Definition: SubsystemGuts.h:140
SystemEventTriggerByStageIndex getEventTriggerStartByStage(const State &s, Stage g) const
Definition: SubsystemGuts.h:214
const Vector & getZWeights(const State &s) const
Definition: SubsystemGuts.h:127
void setU(State &s, const Vector &u) const
Definition: SubsystemGuts.h:225
AbstractValue & updCacheEntry(SubsystemIndex, CacheEntryIndex) const
Retrieve a writable reference to the value contained in a particular cache entry. ...
Vector & updZ(State &s) const
Definition: SubsystemGuts.h:132
This unique integer type is for identifying a triggered event within a particular Stage of the full S...
CacheEntryIndex getDiscreteVarUpdateIndex(const State &s, DiscreteVariableIndex dx) const
Definition: SubsystemGuts.h:251
Real getDiscreteVarLastUpdateTime(const State &s, DiscreteVariableIndex dx) const
Definition: SubsystemGuts.h:248
void markCacheValueNotRealized(SubsystemIndex, CacheEntryIndex) const
(Advanced) Normally cache entries are invalidated automatically, however this method allows manual in...
AbstractValue & updDiscreteVarUpdateValue(SubsystemIndex, DiscreteVariableIndex) const
For an auto-updating discrete variable, return a writable reference to the value of its associated up...
ZIndex allocateZ(State &s, const Vector &zInit) const
Definition: SubsystemGuts.h:87
SystemQErrIndex getQErrStart(const State &s) const
Definition: SubsystemGuts.h:194
int getNEventTriggersByStage(const State &s, Stage g) const
Definition: SubsystemGuts.h:216
const System & getSystem() const
Return a const reference to the System that contains this Subsystem.
Definition: SubsystemGuts.h:520
SimTK::String is a plug-compatible std::string replacement (plus some additional functionality) inten...
Definition: String.h:62
const Subsystem::Guts & getSubsystemGuts() const
Obtain the Subsystem name if one was given on construction of the concrete Subsystem.
Definition: Subsystem.h:353
UIndex allocateU(State &s, const Vector &uInit) const
Definition: SubsystemGuts.h:85
Real getDiscreteVarLastUpdateTime(SubsystemIndex, DiscreteVariableIndex) const
Return the time of last update for this discrete variable.
Vector & updUDotErr(SubsystemIndex) const
Declares the user-visible part of a SimTK::State, the implementation is done in a separate internal c...
const Vector & getUErr(const State &s) const
Definition: SubsystemGuts.h:154
Abstract base class representing an arbitrary value of unknown type.
Definition: Value.h:49
SystemYErrIndex getUErrStart() const
Returns the yErr index at which the uErr&#39;s begin. Callable at Instance stage.
This unique integer type is for indexing global "uDotErr-like" arrays, that is, arrays that inherentl...
int getNQ() const
Get total number of shared q&#39;s (generalized coordinates; second order state variables).
QErrIndex allocateQErr(SubsystemIndex, int nqerr) const
Allocate nqerr cache slots to hold the current error for position-level (holonomic) constraint equati...
void setSystem(System &system, SubsystemIndex subx)
Inform this Subsystem of the System that contains it, as well as the SubsystemIndex which the System ...
Definition: SubsystemGuts.h:524
This unique integer type is for selecting discrete variables.
bool isInSystem() const
Definition: SubsystemGuts.h:299
const Vector & getEventTriggersByStage(Stage) const
This unique integer type is for indexing global "z-like" arrays, that is, arrays that inherently have...
const String & getVersion() const
Obtain the Subsystem version string if one was given on construction.
Definition: SubsystemGuts.h:499
const Vector & getUDotErr(const State &s) const
Definition: SubsystemGuts.h:161
Vector & updUDotErr(const State &s) const
Definition: SubsystemGuts.h:172
bool subsystemTopologyHasBeenRealized() const
Returns true if this subsystem&#39;s realizeTopology() method has been called since the last topological ...
Definition: SubsystemGuts.h:325
const Subsystem & getOwnerSubsystemHandle() const
Return a const reference to the Subsystem handle object that is the unique owner of this Subsystem::G...
Definition: SubsystemGuts.h:444
void markCacheValueNotRealized(const State &s, CacheEntryIndex cx) const
Definition: SubsystemGuts.h:272
QIndex allocateQ(SubsystemIndex, const Vector &qInit)
Allocate generalized coordinates q, which are second order continuous state variables.
SystemUErrIndex getUErrStart(const State &s) const
Definition: SubsystemGuts.h:199
int size() const
Definition: VectorBase.h:396
const Vector & getEventTriggersByStage(const State &s, Stage g) const
Definition: SubsystemGuts.h:165
This is the base class that serves as the parent of all SimTK System objects; most commonly Simbody&#39;s...
Definition: System.h:97
const Vector & getU(const State &s) const
Definition: SubsystemGuts.h:121
int getNZ(const State &s) const
Definition: SubsystemGuts.h:191
UIndex allocateU(SubsystemIndex, const Vector &uInit)
Allocate generalized speeds u, which are first order continuous state variables related to the deriva...
const String & getName() const
Report back the name supplied on construction; this is not interpreted in any way by Simbody...
Definition: SubsystemGuts.h:65
SystemUDotErrIndex getUDotErrStart(SubsystemIndex) const
bool isCacheValueRealized(const State &s, CacheEntryIndex cx) const
Definition: SubsystemGuts.h:266
int getNUErr(const State &s) const
Definition: SubsystemGuts.h:201
virtual int realizeSubsystemAccelerationImpl(const State &s) const
Definition: SubsystemGuts.h:419
Provide a unique integer type for identifying Subsystems.
int getNU() const
Get total number of shared u&#39;s (generalized speeds; mobilities).
Vector & updEventTriggersByStage(Stage) const
const Vector & getQ(const State &s) const
Definition: SubsystemGuts.h:119
void markDiscreteVarUpdateValueRealized(SubsystemIndex, DiscreteVariableIndex) const
Mark the update value for this auto-update discrete variable as up-to-date with respect to the state ...
ZIndex allocateZ(SubsystemIndex, const Vector &zInit)
Allocate auxiliary first order continuous state variables z.
AbstractMeasure getMeasure(MeasureIndex) const
Obtain the Subsystem name if one was given on construction of the concrete Subsystem.
Definition: SubsystemGuts.h:511
This unique integer type is for selecting non-shared cache entries.
bool isOwnerHandle() const
Is this Subsystem handle the owner of the Subsystem::Guts object it points to? This is true if the ha...
Definition: SubsystemGuts.h:527
Vector & updZ(SubsystemIndex)
Results returned by the handleEvent() method.
Definition: Event.h:345
const Vector & getZDot(SubsystemIndex) const
This is the header which should be included in user programs that would like to make use of all the S...
Unique integer type for Subsystem-local, per-stage event indexing.
Vector & updUDot(SubsystemIndex) const
Vector & updMultipliers(const State &s) const
Definition: SubsystemGuts.h:174
void invalidateSubsystemTopologyCache() const
Always call this method when a topological change is made to this Subsystem to indicate that any Stag...
Definition: SubsystemGuts.h:505
EventTriggerByStageIndex allocateEventTrigger(SubsystemIndex, Stage stage, int nevent) const
Allocate room for nevent witness function values that will be available at the indicated stage...
SystemQIndex getQStart(const State &s) const
Definition: SubsystemGuts.h:179
This unique integer type is for indexing global "u-like" arrays, that is, arrays that inherently have...
Includes internal headers providing declarations for the basic SimTK Core classes.
Vector & updU(State &s) const
Definition: SubsystemGuts.h:131
const Vector & getUWeights(const State &s) const
Definition: SubsystemGuts.h:125
const Stage & getSubsystemStage(SubsystemIndex) const
void markCacheValueRealized(const State &s, CacheEntryIndex cx) const
Definition: SubsystemGuts.h:269
const Vector & getZ(SubsystemIndex) const
const System & getSystem() const
Definition: SubsystemGuts.h:302
UDotErrIndex allocateUDotErr(SubsystemIndex, int nudoterr) const
Allocate nudoterr cache slots to hold the current error for acceleration-level (acceleration-only, nonholonomic first derivative, and holonomic second derivative) constraint equations.
bool isInSystem() const
Return true if this Subsystem is contained in a System.
Definition: SubsystemGuts.h:515
bool hasOwnerSubsystemHandle() const
Check whether this Subsystem::Guts object is currently owned by some Subsystem handle object...
Definition: SubsystemGuts.h:463
UErrIndex allocateUErr(SubsystemIndex, int nuerr) const
Allocate nuerr cache slots to hold the current error for velocity-level (nonholonomic and holonomic f...
AbstractValue & updCacheEntry(const State &s, CacheEntryIndex index) const
Definition: SubsystemGuts.h:246
Options for the handleEvent() method.
Definition: Event.h:269
This is the base handle class for all Measures whose value type is known, including all the Simbody b...
Definition: Measure.h:263
System & updSystem()
Definition: SubsystemGuts.h:306
int getNUErr() const
Return the total number nuerr=mp+mv of cache entries for velocity-level constraint errors (including ...
CacheEntryIndex allocateCacheEntry(SubsystemIndex, Stage earliest, Stage latest, AbstractValue *value) const
There are two Stages supplied explicitly as arguments to this method: earliest and latest...
int getNEventTriggersByStage(Stage) const
Return the size of the partition of event trigger functions which are evaluated at a given Stage...
SystemUIndex getUStart(const State &s) const
Definition: SubsystemGuts.h:184
This is a class to represent unique IDs for events in a type-safe way.