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 project(State&, Real consAccuracy, const Vector& yweights,
00151 const Vector& ootols, Vector& yerrest, System::ProjectOptions) const;
00152 void calcYErrUnitTolerances(const State&, Vector& tolerances) const;
00153 void handleEvents
00154 (State&, Event::Cause, const std::vector<EventId>& eventIds,
00155 Real accuracy, const Vector& yWeights, const Vector& ooConstraintTols,
00156 Stage& lowestModified, bool& shouldTerminate) const;
00157 void reportEvents(const State&, Event::Cause, const std::vector<EventId>& eventIds) const;
00158 void calcEventTriggerInfo(const State&, std::vector<EventTriggerInfo>&) const;
00159 void calcTimeOfNextScheduledEvent(const State&, Real& tNextEvent, std::vector<EventId>& eventIds, bool includeCurrentTime) const;
00160 void calcTimeOfNextScheduledReport(const State&, Real& tNextEvent, std::vector<EventId>& eventIds, bool includeCurrentTime) const;
00161
00162 void calcDecorativeGeometryAndAppend(const State&, Stage,
00163 std::vector<DecorativeGeometry>&) const;
00164
00165
00166 protected:
00167 Guts(const Guts&);
00168
00169
00170
00171 virtual System::Guts* cloneImpl() const = 0;
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 virtual int realizeTopologyImpl(State&) const;
00183 virtual int realizeModelImpl(State&) const;
00184 virtual int realizeInstanceImpl(const State&) const;
00185 virtual int realizeTimeImpl(const State&) const;
00186 virtual int realizePositionImpl(const State&) const;
00187 virtual int realizeVelocityImpl(const State&) const;
00188 virtual int realizeDynamicsImpl(const State&) const;
00189 virtual int realizeAccelerationImpl(const State&) const;
00190 virtual int realizeReportImpl(const State&) const;
00191
00192 virtual Real calcTimescaleImpl(const State&) const;
00193
00194 virtual int calcYUnitWeightsImpl(const State&, Vector& weights) const;
00195
00196 virtual int projectImpl(State&, Real consAccuracy, const Vector& yweights,
00197 const Vector& ootols, Vector& yerrest, System::ProjectOptions) const;
00198 virtual int calcYErrUnitTolerancesImpl(const State&, Vector& tolerances) const;
00199
00200 virtual int handleEventsImpl
00201 (State&, Event::Cause, const std::vector<EventId>& eventIds,
00202 Real accuracy, const Vector& yWeights, const Vector& ooConstraintTols,
00203 Stage& lowestModified, bool& shouldTerminate) const;
00204
00205 virtual int reportEventsImpl(const State&, Event::Cause, const std::vector<EventId>& eventIds) const;
00206
00207 virtual int calcEventTriggerInfoImpl(const State&, std::vector<EventTriggerInfo>&) const;
00208
00209 virtual int calcTimeOfNextScheduledEventImpl(const State&, Real& tNextEvent, std::vector<EventId>& eventIds, bool includeCurrentTime) const;
00210 virtual int calcTimeOfNextScheduledReportImpl(const State&, Real& tNextEvent, std::vector<EventId>& eventIds, bool includeCurrentTime) const;
00211 private:
00212 Guts& operator=(const Guts&);
00213
00214 class EventTriggerInfoRep;
00215
00216 };
00217
00218
00219 }
00220
00221 #endif // SimTK_SimTKCOMMON_SYSTEM_GUTS_H_