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 std::vector<EventId>& getTriggeredEvents() const;
00259 const std::vector<Real>& getEstimatedEventTimes() const;
00262 const std::vector<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 long getNumStepsAttempted() const;
00303 long getNumStepsTaken() const;
00305 long getNumRealizations() const;
00307 long getNumProjections() const;
00310 long getNumErrorTestFailures() const;
00313 long getNumConvergenceTestFailures() const;
00316 long getNumRealizationFailures() const;
00319 long getNumProjectionFailures() const;
00322 long getNumConvergentIterations() const;
00325 long getNumDivergentIterations() const;
00329 long getNumIterations() const;
00330
00333 void setFinalTime(Real tFinal);
00336 void setInitialStepSize(Real hinit);
00339 void setMinimumStepSize(Real hmin);
00342 void setMaximumStepSize(Real hmax);
00343
00348 void setFixedStepSize(Real stepSize);
00349
00352 void setAccuracy(Real accuracy);
00357 void setRelativeTolerance(Real relTol);
00362 void setAbsoluteTolerance(Real absTol);
00364 void setConstraintTolerance(Real consTol);
00365
00369 void setInternalStepLimit(int nSteps);
00370
00373 void setReturnEveryInternalStep(bool shouldReturn);
00374
00378 void setProjectEveryStep(bool forceProject);
00387 void setAllowInterpolation(bool shouldInterpolate);
00390 void setProjectInterpolatedStates(bool shouldProject);
00391
00392
00393 long getNStepsAttempted() const {return getNumStepsAttempted();}
00394 long getNStepsTaken() const {return getNumStepsTaken();}
00395 long getNRealizations() const {return getNumRealizations();}
00396 long getNProjections() const {return getNumProjections();}
00397 long getNErrorTestFailures() const {return getNumErrorTestFailures();}
00398 long getNRealizationFailures() const {return getNumRealizationFailures();}
00399 long getNProjectionFailures() const {return getNumProjectionFailures();}
00400
00401 protected:
00402 const IntegratorRep& getRep() const {assert(rep); return *rep;}
00403 IntegratorRep& updRep() {assert(rep); return *rep;}
00404
00405
00406 IntegratorRep* rep;
00407 friend class IntegratorRep;
00408 };
00409
00410 }
00411
00412 #endif // SimTK_SIMMATH_INTEGRATOR_H_