00001 #ifndef SimTK_SimTKCOMMON_SYSTEM_GUTS_H_
00002 #define SimTK_SimTKCOMMON_SYSTEM_GUTS_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "SimTKcommon/basics.h"
00036 #include "SimTKcommon/Simmatrix.h"
00037 #include "SimTKcommon/internal/State.h"
00038 #include "SimTKcommon/internal/System.h"
00039
00040 namespace SimTK {
00041
00042 class Subsystem;
00043 class DecorativeGeometry;
00044
00079 class SimTK_SimTKCOMMON_EXPORT System::Guts {
00080 class GutsRep;
00081 friend class GutsRep;
00082
00083
00084 GutsRep* rep;
00085 public:
00086
00087 explicit Guts(const String& name="<NONAME>",
00088 const String& version="0.0.0");
00089 virtual ~Guts();
00090
00091 const String& getName() const;
00092 const String& getVersion() const;
00093
00094 void setHasTimeAdvancedEvents(bool hasEm);
00095 bool hasTimeAdvancedEvents() const;
00096
00098
00100
00101
00102
00103 const State& getDefaultState() const;
00104 State& updDefaultState();
00105
00106 void realize(const State& s, Stage g = Stage::HighestRuntime) const;
00107
00108 SubsystemIndex adoptSubsystem(Subsystem& child);
00109
00110 int getNSubsystems() const;
00111 const Subsystem& getSubsystem(SubsystemIndex) const;
00112 Subsystem& updSubsystem(SubsystemIndex);
00113
00114
00115 const System& getSystem() const;
00116 System& updSystem();
00117
00118 void setOwnerHandle(System&);
00119 bool hasOwnerHandle() const;
00120
00121 explicit Guts(class GutsRep* r) : rep(r) { }
00122 bool hasRep() const {return rep!=0;}
00123 const GutsRep& getRep() const {assert(rep); return *rep;}
00124 GutsRep& updRep() const {assert(rep); return *rep;}
00125
00126 bool systemTopologyHasBeenRealized() const;
00127 void invalidateSystemTopologyCache() const;
00128
00129
00130 System::Guts* clone() const;
00131
00132
00133
00134
00135
00136
00137 const State& realizeTopology() const;
00138 void realizeModel(State&) const;
00139 void realizeInstance (const State& s) const;
00140 void realizeTime (const State& s) const;
00141 void realizePosition (const State& s) const;
00142 void realizeVelocity (const State& s) const;
00143 void realizeDynamics (const State& s) const;
00144 void realizeAcceleration(const State& s) const;
00145 void realizeReport (const State& s) const;
00146
00147
00148 Real calcTimescale(const State&) const;
00149 void calcYUnitWeights(const State&, Vector& weights) const;
00150 void prescribe(State&, Stage) const;
00151 void project(State&, Real consAccuracy, const Vector& yweights,
00152 const Vector& ootols, Vector& yerrest, System::ProjectOptions) const;
00153 void calcYErrUnitTolerances(const State&, Vector& tolerances) const;
00154 void handleEvents
00155 (State&, Event::Cause, const Array_<EventId>& eventIds,
00156 Real accuracy, const Vector& yWeights, const Vector& ooConstraintTols,
00157 Stage& lowestModified, bool& shouldTerminate) const;
00158 void reportEvents(const State&, Event::Cause, const Array_<EventId>& eventIds) const;
00159 void calcEventTriggerInfo(const State&, Array_<EventTriggerInfo>&) const;
00160 void calcTimeOfNextScheduledEvent(const State&, Real& tNextEvent, Array_<EventId>& eventIds, bool includeCurrentTime) const;
00161 void calcTimeOfNextScheduledReport(const State&, Real& tNextEvent, Array_<EventId>& eventIds, bool includeCurrentTime) const;
00162
00163 void calcDecorativeGeometryAndAppend(const State&, Stage,
00164 Array_<DecorativeGeometry>&) const;
00165
00166
00167 protected:
00168 Guts(const Guts&);
00169
00170
00171
00172 virtual System::Guts* cloneImpl() const = 0;
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 virtual int realizeTopologyImpl(State&) const;
00184 virtual int realizeModelImpl(State&) const;
00185 virtual int realizeInstanceImpl(const State&) const;
00186 virtual int realizeTimeImpl(const State&) const;
00187 virtual int realizePositionImpl(const State&) const;
00188 virtual int realizeVelocityImpl(const State&) const;
00189 virtual int realizeDynamicsImpl(const State&) const;
00190 virtual int realizeAccelerationImpl(const State&) const;
00191 virtual int realizeReportImpl(const State&) const;
00192
00193 virtual Real calcTimescaleImpl(const State&) const;
00194
00195 virtual int calcYUnitWeightsImpl(const State&, Vector& weights) const;
00196
00197 virtual int prescribeImpl(State&, Stage) const;
00198 virtual int projectImpl(State&, Real consAccuracy, const Vector& yweights,
00199 const Vector& ootols, Vector& yerrest, System::ProjectOptions) const;
00200 virtual int calcYErrUnitTolerancesImpl(const State&, Vector& tolerances) const;
00201
00202 virtual int handleEventsImpl
00203 (State&, Event::Cause, const Array_<EventId>& eventIds,
00204 Real accuracy, const Vector& yWeights, const Vector& ooConstraintTols,
00205 Stage& lowestModified, bool& shouldTerminate) const;
00206
00207 virtual int reportEventsImpl(const State&, Event::Cause, const Array_<EventId>& eventIds) const;
00208
00209 virtual int calcEventTriggerInfoImpl(const State&, Array_<EventTriggerInfo>&) const;
00210
00211 virtual int calcTimeOfNextScheduledEventImpl(const State&, Real& tNextEvent, Array_<EventId>& eventIds, bool includeCurrentTime) const;
00212 virtual int calcTimeOfNextScheduledReportImpl(const State&, Real& tNextEvent, Array_<EventId>& eventIds, bool includeCurrentTime) const;
00213 private:
00214 Guts& operator=(const Guts&);
00215
00216 class EventTriggerInfoRep;
00217
00218 };
00219
00220
00221 }
00222
00223 #endif // SimTK_SimTKCOMMON_SYSTEM_GUTS_H_