Integrator.h
Go to the documentation of this file.00001 #ifndef SimTK_SIMMATH_INTEGRATOR_H_
00002 #define SimTK_SIMMATH_INTEGRATOR_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
00040 #include "SimTKcommon.h"
00041 #include "simmath/internal/common.h"
00042
00043 namespace SimTK {
00044
00045
00046 class IntegratorRep;
00047
00127 class SimTK_SIMMATH_EXPORT Integrator {
00128 public:
00129 Integrator() : rep(0) { }
00130
00131
00132
00133 class InitializationFailed;
00134 class StepSizeTooSmall;
00135 class StepFailed;
00136 class TriedToAdvancePastFinalTime;
00137 class CantAskForEventInfoWhenNoEventTriggered;
00138
00140 const char* getMethodName();
00142 int getMethodMinOrder();
00144 int getMethodMaxOrder();
00148 bool methodHasErrorControl();
00149
00153 void initialize(const State& state);
00154
00166 void reinitialize(Stage stage, bool shouldTerminate);
00167
00170 const State& getState() const;
00172 Real getTime() const {return getState().getTime();}
00173
00176 bool isStateInterpolated() const;
00177
00181 const State& getAdvancedState() const;
00183 Real getAdvancedTime() const {return getAdvancedState().getTime();}
00184
00186 State& updAdvancedState();
00187
00190 Real getAccuracyInUse() const;
00193 Real getConstraintToleranceInUse() const;
00196 Real getTimeScaleInUse() const;
00199 const Vector& getStateWeightsInUse() const;
00202 const Vector& getConstraintWeightsInUse() const;
00203
00221 enum SuccessfulStepStatus {
00223 ReachedReportTime =1,
00225 ReachedEventTrigger =2,
00227 ReachedScheduledEvent=3,
00229 TimeHasAdvanced =4,
00231 ReachedStepLimit =5,
00233 EndOfSimulation =6,
00235 StartOfContinuousInterval=7,
00236 InvalidSuccessfulStepStatus = -1
00237 };
00239 static String successfulStepStatusString(SuccessfulStepStatus);
00240
00244 SuccessfulStepStatus stepTo(Real reportTime, Real scheduledEventTime=Infinity);
00248 SuccessfulStepStatus stepBy(Real interval, Real scheduledEventTime=Infinity);
00249
00250
00253 Vec2 getEventWindow() const;
00256 const Array_<EventId>& getTriggeredEvents() const;
00259 const Array_<Real>& getEstimatedEventTimes() const;
00262 const Array_<Event::Trigger>& getEventTransitionsSeen() const;
00263
00264
00265
00266
00268 enum TerminationReason {
00270 ReachedFinalTime = 1,
00272 AnUnrecoverableErrorOccurred = 2,
00274 EventHandlerRequestedTermination = 3,
00276 InvalidTerminationReason = -1
00277 };
00278
00281 bool isSimulationOver() const;
00282
00285 TerminationReason getTerminationReason() const;
00286
00288 void resetAllStatistics();
00289
00291 Real getActualInitialStepSizeTaken() const;
00292
00294 Real getPreviousStepSizeTaken() const;
00295
00297 Real getPredictedNextStepSize() const;
00298
00301 int getNumStepsAttempted() const;
00303 int getNumStepsTaken() const;
00305 int getNumRealizations() const;
00307 int getNumProjections() const;
00310 int getNumErrorTestFailures() const;
00315 int getNumConvergenceTestFailures() const;
00318 int getNumRealizationFailures() const;
00321 int getNumProjectionFailures() const;
00324 int getNumConvergentIterations() const;
00327 int getNumDivergentIterations() const;
00331 int getNumIterations() const;
00332
00335 void setFinalTime(Real tFinal);
00338 void setInitialStepSize(Real hinit);
00341 void setMinimumStepSize(Real hmin);
00344 void setMaximumStepSize(Real hmax);
00345
00350 void setFixedStepSize(Real stepSize);
00351
00354 void setAccuracy(Real accuracy);
00359 void setRelativeTolerance(Real relTol);
00364 void setAbsoluteTolerance(Real absTol);
00366 void setConstraintTolerance(Real consTol);
00367
00371 void setInternalStepLimit(int nSteps);
00372
00375 void setReturnEveryInternalStep(bool shouldReturn);
00376
00380 void setProjectEveryStep(bool forceProject);
00389 void setAllowInterpolation(bool shouldInterpolate);
00392 void setProjectInterpolatedStates(bool shouldProject);
00393
00394
00395 protected:
00396 const IntegratorRep& getRep() const {assert(rep); return *rep;}
00397 IntegratorRep& updRep() {assert(rep); return *rep;}
00398
00399
00400 IntegratorRep* rep;
00401 friend class IntegratorRep;
00402
00403 private:
00404
00405 int getNStepsAttempted() const {return getNumStepsAttempted();}
00406 int getNStepsTaken() const {return getNumStepsTaken();}
00407 int getNRealizations() const {return getNumRealizations();}
00408 int getNProjections() const {return getNumProjections();}
00409 int getNErrorTestFailures() const {return getNumErrorTestFailures();}
00410 int getNRealizationFailures() const {return getNumRealizationFailures();}
00411 int getNProjectionFailures() const {return getNumProjectionFailures();}
00412 };
00413
00414 }
00415
00416 #endif // SimTK_SIMMATH_INTEGRATOR_H_