System Class Reference

The handle class which serves as the abstract parent of all Systems. More...

#include <System.h>

Inheritance diagram for System:
MultibodySystem MolecularMechanicsSystem CompoundSystem

List of all members.

Classes

class  EventTriggerInfo
 This class is used to communicate between the System and an Integrator regarding the properties of a particular event trigger function. More...
class  Guts
 This is the declaration for the System::Guts class, the abstract object to which a System handle points. More...
class  ProjectOptions

Public Member Functions

 System ()
 System (const System &)
Systemoperator= (const System &)
 ~System ()
const StringgetName () const
const StringgetVersion () const
void resetAllCountersToZero ()
 The System keeps mutable statistics internally, initialized to zero at construction.
long getNumRealizationsOfThisStage (Stage) const
 Whenever the system was realized from Stage-1 to the indicated Stage, this counter is bumped.
long getNumRealizeCalls () const
 Return the total number of calls to realizeTopology(), realizeModel(), or realize(), regardless of whether these routines actually did anything when called.
long getNumQProjections () const
 Count the number of times we call project() with a particular option set.
long getNumUProjections () const
long getNumQErrorEstimateProjections () const
long getNumUErrorEstimateProjections () const
long getNumProjectCalls () const
 Return the total number of calls to project(), regardless of whether the call did anything.
long getNumHandlerCallsThatChangedStage (Stage) const
 handleEvents() reports the lowest Stage it modified and we bump the counter for that Stage.
long getNumHandleEventCalls () const
 This is the total number of calls to handleEvents() regardless of the outcome.
long getNumReportEventCalls () const
 This is the total number of calls to reportEvents() regardless of the outcome.
const StaterealizeTopology () const
 The following call must be made after any topological change has been made to this System, before the System can be used to perform any computations.
const StategetDefaultState () const
 This is available after realizeTopology(), and will throw an exception if realizeTopology() has not been called since the most recent topological change to this System.
StateupdDefaultState ()
void realizeModel (State &) const
 This call is required if Model-stage variables are changed from their default values.
void realize (const State &s, Stage g=Stage::HighestRuntime) const
 Realize the entire System to the indicated Stage.
void calcDecorativeGeometryAndAppend (const State &, Stage, std::vector< DecorativeGeometry > &) const
Real calcTimescale (const State &) const
 This operator can be called at Stage::Instance or higher and returns a rough estimate of a length of time we consider significant for this system.
void calcYUnitWeights (const State &, Vector &weights) const
 This operator can be called at Stage::Position to calculate a weighting vector w, with one entry for each state variable y={q,u,z}, ordered the same as Y in the State and calculated specifically for the current values of Y in the State.
void project (State &, Real consAccuracy, const Vector &yweights, const Vector &ootols, Vector &yerrest, ProjectOptions=ProjectOptions::All) const
 This optional solver projects the given State back on to the constraint manifold, by the shortest path possible in the weighted norm given by the supplied weights, satisfying the constraints by reducing the supplied tolerance norm to below consAccuracy.
void calcYErrUnitTolerances (const State &, Vector &tolerances) const
 This provides scaling information for each of the position and velocity constraints (YErr) in the State.
void setHasTimeAdvancedEvents (bool)
 This determines whether this System wants to be notified whenever time advances irreversibly.
bool hasTimeAdvancedEvents () const
void handleEvents (State &, Event::Cause, const std::vector< EventId > &eventIds, Real accuracy, const Vector &yWeights, const Vector &ooConstraintTols, Stage &lowestModified, bool &shouldTerminate) const
 This solver handles a set of events which a TimeStepper has denoted as having occurred.
void reportEvents (const State &s, Event::Cause cause, const std::vector< EventId > &eventIds) const
 This method is similar to handleEvents(), but does not allow the State to be modified.
void calcEventTriggerInfo (const State &, std::vector< EventTriggerInfo > &) const
 This routine provides the Integrator with information it needs about the individual event trigger functions, such as which sign transitions are relevant and how tightly we need to localize.
void calcTimeOfNextScheduledEvent (const State &, Real &tNextEvent, std::vector< EventId > &eventIds, bool includeCurrentTime) const
 This routine should be called to determine if and when there is an event scheduled to occur at a particular time.
void calcTimeOfNextScheduledReport (const State &, Real &tNextEvent, std::vector< EventId > &eventIds, bool includeCurrentTime) const
 This routine is similar to calcTimeOfNextScheduledEvent(), but is used for "reporting events" which do not modify the state.
SubsystemIndex adoptSubsystem (Subsystem &child)
 Take over ownership of the supplied subsystem and install it into the next free subsystem slot.
int getNSubsystems () const
 How may Subsystems are in here?
const SubsystemgetSubsystem (SubsystemIndex) const
 Obtain read-only access to a particular subsystem by its index.
SubsystemupdSubsystem (SubsystemIndex)
 Obtain writable access to a particular subsystem by its index.
const DefaultSystemSubsystemgetDefaultSubsystem () const
 Get read-only access to the default subsystem which is present in every system.
DefaultSystemSubsystemupdDefaultSubsystem ()
 Get writable access to the default subsystem which is present in every system.
bool isOwnerHandle () const
bool isEmptyHandle () const
bool isSameSystem (const System &otherSystem) const
bool systemTopologyHasBeenRealized () const
 You can check whether realizeTopology() has been called since the last topological change to this Syatem.
const System::GutsgetSystemGuts () const
System::GutsupdSystemGuts ()
void adoptSystemGuts (System::Guts *g)
 System (System::Guts *g)
bool hasGuts () const

Static Public Member Functions

static Real calcWeightedRMSNorm (const Vector &values, const Vector &weights)
static Real calcWeightedInfinityNorm (const Vector &values, const Vector &weights)

Friends

class Guts

Detailed Description

The handle class which serves as the abstract parent of all Systems.

A System serves as a mediator for a group of interacting Subsystems. All will share a single system State, and typically subsystems will need access to content in the state which is produced by other subsystems.

A System provides a unique SubsystemIndex (a small positive integer) for each of its subsystems, and the subsystems are constructed knowing their indices. The indices are used subsequently by the subsystems to find their own entries in the system state, and by each subsystem to refer to others within the same system. Index 0 is reserved for use by the System itself, e.g. for system-global state variables.

Concrete Systems understand the kinds of subsystems they contain. For example, a MultibodySystem might contain a mechanical subsystem, some force subsystems, and a geometry subsystem. At each computation stage, a subsystem is realized in a single operation. That operation can refer to computations from already-realized subsystems, but cannot initiate computation in other subsystems. The System must know the proper order with which to realize the subsystems at each stage, and that ordering is likely to vary with stage. For example, at Position stage the mechanical positions must be realized before the configuration-dependent force elements. However, at Acceleration stage, the force elements must be realized before the mechanical accelerations can be calculated.

There are two distinct users of this class:

Only methods intended for System Users and a few bookkeeping methods are in the main System class, which is a SimTK Handle class, meaning that it consists only of a single pointer, which points to a System::Guts class. The Guts class is abstract, and virtual methods to be implemented by System Developers in the concrete System are defined there, along with other utilities of use to the concrete System Developer but not to the end user. The Guts class is declared in a separate header file, and only people who are writing their own System classes need look there.


Constructor & Destructor Documentation

System (  )  [inline]
System ( const System  ) 
~System (  ) 
System ( System::Guts g  )  [inline, explicit]

Member Function Documentation

SubsystemIndex adoptSubsystem ( Subsystem child  ) 

Take over ownership of the supplied subsystem and install it into the next free subsystem slot.

The new slot index is returned.

void adoptSystemGuts ( System::Guts g  ) 
void calcDecorativeGeometryAndAppend ( const State ,
Stage  ,
std::vector< DecorativeGeometry > &   
) const
void calcEventTriggerInfo ( const State ,
std::vector< EventTriggerInfo > &   
) const

This routine provides the Integrator with information it needs about the individual event trigger functions, such as which sign transitions are relevant and how tightly we need to localize.

This is considered Instance stage information so cannot change during a continuous integration interval (so an Integrator can process it upon restart(Instance)), however it can be updated whenever a discrete update is made to the State. A default implementation is provided which returns default EventTriggerInfo for each event trigger in State. State must already be realized to Stage::Instance.

void calcTimeOfNextScheduledEvent ( const State ,
Real &  tNextEvent,
std::vector< EventId > &  eventIds,
bool  includeCurrentTime 
) const

This routine should be called to determine if and when there is an event scheduled to occur at a particular time.

This is a *lot* cheaper than making the Integrator hunt these down like ordinary state-dependent events. The returned time can be passed to the Integrator's stepping function as the advance time limit.

void calcTimeOfNextScheduledReport ( const State ,
Real &  tNextEvent,
std::vector< EventId > &  eventIds,
bool  includeCurrentTime 
) const

This routine is similar to calcTimeOfNextScheduledEvent(), but is used for "reporting events" which do not modify the state.

Events returned by this method should be handled by invoking reportEvents() instead of handleEvents().

Real calcTimescale ( const State  )  const

This operator can be called at Stage::Instance or higher and returns a rough estimate of a length of time we consider significant for this system.

For example, this could be the period of the highest-frequency oscillation that we care about. This can be used as a hint by numerical integrators in choosing their initial step size, and suggests how velocity variables should be scaled relative to their corresponding position variables.

static Real calcWeightedInfinityNorm ( const Vector values,
const Vector weights 
) [inline, static]
static Real calcWeightedRMSNorm ( const Vector values,
const Vector weights 
) [inline, static]
void calcYErrUnitTolerances ( const State ,
Vector tolerances 
) const

This provides scaling information for each of the position and velocity constraints (YErr) in the State.

The tolerance is the absolute error in the constraint which is considered a "unit violation" of that state. Then if T=diag(tol) and c the vector of constraint errors, we can use a weighted RMS norm condition like RMS(T*c) <= accuracy to define when constraints have been adequately met. This is expected to be a cheap operation but not to change during a study. State must be realized to Stage::Model.

void calcYUnitWeights ( const State ,
Vector weights 
) const

This operator can be called at Stage::Position to calculate a weighting vector w, with one entry for each state variable y={q,u,z}, ordered the same as Y in the State and calculated specifically for the current values of Y in the State.

Weight wi is proportional to the "importance" of state variable yi with respect to some criteria determined by the System, such that wi*dyi=1 indicates that a change dyi in state yi produces approximately a unit change in the weighting criteria. This is intended for use by numerical integration methods for step size control. The idea is to allow creation of a weighted RMS norm which returns 1 just when all the state variable changes have a unit effect. The norm is RMS(W*dy) where W=diag(w). A value of 1 for this norm would typically be a huge error. For example, if your accuracy requirement is 0.1%, you would test that the weighted RMS norm is <= .001. We expect this operation to be fairly expensive and thus the integrator is expected to invoke it only occasionally.

const State& getDefaultState (  )  const

This is available after realizeTopology(), and will throw an exception if realizeTopology() has not been called since the most recent topological change to this System.

This method returns the same reference returned by realizeTopology(). The State to which a reference is returned was created by the most recent realizeTopology() call. It has already been realized through the Model Stage, using default values for all the Model-stage variables. All later-stage variables have been allocated and set to their default values. You can use this state directly to obtain information about the System in its default state or you can use this state to initialize other States to which you have write access. Those States are then suitable for further computation with this System.

const DefaultSystemSubsystem& getDefaultSubsystem (  )  const

Get read-only access to the default subsystem which is present in every system.

const String& getName (  )  const
int getNSubsystems (  )  const

How may Subsystems are in here?

long getNumHandleEventCalls (  )  const

This is the total number of calls to handleEvents() regardless of the outcome.

long getNumHandlerCallsThatChangedStage ( Stage   )  const

handleEvents() reports the lowest Stage it modified and we bump the counter for that Stage.

We also count reportEvents() calls here as having "changed" Stage::Report.

long getNumProjectCalls (  )  const

Return the total number of calls to project(), regardless of whether the call did anything.

long getNumQErrorEstimateProjections (  )  const
long getNumQProjections (  )  const

Count the number of times we call project() with a particular option set.

long getNumRealizationsOfThisStage ( Stage   )  const

Whenever the system was realized from Stage-1 to the indicated Stage, this counter is bumped.

Note that a single call to realize() can cause several counters to get bumped.

long getNumRealizeCalls (  )  const

Return the total number of calls to realizeTopology(), realizeModel(), or realize(), regardless of whether these routines actually did anything when called.

long getNumReportEventCalls (  )  const

This is the total number of calls to reportEvents() regardless of the outcome.

long getNumUErrorEstimateProjections (  )  const
long getNumUProjections (  )  const
const Subsystem& getSubsystem ( SubsystemIndex   )  const

Obtain read-only access to a particular subsystem by its index.

const System::Guts& getSystemGuts (  )  const [inline]
const String& getVersion (  )  const
void handleEvents ( State ,
Event::Cause  ,
const std::vector< EventId > &  eventIds,
Real  accuracy,
const Vector yWeights,
const Vector ooConstraintTols,
Stage lowestModified,
bool &  shouldTerminate 
) const

This solver handles a set of events which a TimeStepper has denoted as having occurred.

The event handler may make discontinuous changes in the State, in general both to discrete and continuous variables, but NOT to time. It cannot change topological information. If changes are made to continuous variables, the handler is required to make sure the returned state satisfies the constraints to the indicated accuracy level. On return, the handleEvents routine should set the output variable lowestModified to the Stage level of the lowest-stage variable it modified. This information tells the time stepper how much of a restart it must perform on the underlying numerical integrator. When in doubt, set lowestModified to Stage::Model, which will cause a complete restart. Finally, if the handler determines that the occurrence of some event requires that the simulation be terminated it should set 'shouldTerminate' to true before returning.

bool hasGuts (  )  const [inline]
bool hasTimeAdvancedEvents (  )  const
bool isEmptyHandle (  )  const
bool isOwnerHandle (  )  const
bool isSameSystem ( const System otherSystem  )  const
System& operator= ( const System  ) 
void project ( State ,
Real  consAccuracy,
const Vector yweights,
const Vector ootols,
Vector yerrest,
ProjectOptions  = ProjectOptions::All 
) const

This optional solver projects the given State back on to the constraint manifold, by the shortest path possible in the weighted norm given by the supplied weights, satisfying the constraints by reducing the supplied tolerance norm to below consAccuracy.

May also project out the constraint-normal component of the passed-in error estimate vector yerrest. This is part of the integration of the continuous DAE system and thus should never require an integrator restart. The System author must ensure that only position and velocity stage, continuous variables are updated by this call. On return the state will be realized to at least Stage::Velocity.

If ProjectOptions::VelocityOnly is selected, only the velocity will be projected. In that case is assumed that the positions already satisfy the constraints (to within tolerance), and the State has already been realized to at least Stage::Position.

void realize ( const State s,
Stage  g = Stage::HighestRuntime 
) const

Realize the entire System to the indicated Stage.

The passed-in State must have been initialized to work with this System, and it must already have been realized through Stage::Model, since the realize() method doesn't have write access to the State. If the state has already been realized to the requested stage or higher, nothing happens here. Otherwise, the state is realized one stage at a time until it reaches the requested stage.

Referenced by PeriodicPdbWriter::handleEvent().

void realizeModel ( State  )  const

This call is required if Model-stage variables are changed from their default values.

The System topology must already have been realized (that is, realizeTopology() must have been called since the last topological change made to the System). Also, the supplied State must already have been initialized to work with this System either by copying the default state or some other State of this System. If it has already been realized to Stage::Model or higher, nothing happens here. Otherwise, all the state variables at Stage::Instance or higher are allocated or reallocated (if necessary), and reinitialized to their default values. NOTE: any State information at Stage::Instance or higher in the passed-in State is *destroyed* here. The number, types and memory locations of those state variables will change, so any existing references or pointers to them are invalid after this call. Note that this routine modifies its State argument, but makes no changes at all to the System itself and is hence const.

const State& realizeTopology (  )  const

The following call must be made after any topological change has been made to this System, before the System can be used to perform any computations.

Perhaps surprisingly, the method is const. That's because the topology cannot be changed by this method. Various mutable "cache" entries will get calculated, including the default State, a reference to which is returned. The returned State has already been realized through the Model Stage, using the defaults for the Model-stage variables, meaning that all later stage variables have been allocated and set to their default values as well. You can access this same default State again using getDefaultState(). If the current topology has already been realized, this call does nothing but return a reference to the already-built default State.

void reportEvents ( const State s,
Event::Cause  cause,
const std::vector< EventId > &  eventIds 
) const

This method is similar to handleEvents(), but does not allow the State to be modified.

It is used for scheduled events that were marked as being reports.

void resetAllCountersToZero (  ) 

The System keeps mutable statistics internally, initialized to zero at construction.

These *must not* affect results in any way. Although the stats are mutable, we only allow them to be reset by a caller who has write access since setting the stats to zero is associated with construction.

void setHasTimeAdvancedEvents ( bool   ) 

This determines whether this System wants to be notified whenever time advances irreversibly.

If set true, time advancement is treated as an event. Otherwise, time advancement proceeds silently. TODO: currently not using State so this is a Topology stage variable, but should probably be Model stage.

bool systemTopologyHasBeenRealized (  )  const

You can check whether realizeTopology() has been called since the last topological change to this Syatem.

If you don't check and just plunge ahead you are likely to encounter an exception since very few things will work without topology having been realized.

State& updDefaultState (  ) 
DefaultSystemSubsystem& updDefaultSubsystem (  ) 

Get writable access to the default subsystem which is present in every system.

Subsystem& updSubsystem ( SubsystemIndex   ) 

Obtain writable access to a particular subsystem by its index.

System::Guts& updSystemGuts (  )  [inline]

Friends And Related Function Documentation

friend class Guts [friend]

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

Generated on Wed Dec 30 11:05:29 2009 for SimTKcore by  doxygen 1.6.1