Simbody
|
00001 #ifndef SimTK_SIMMATH_INTEGRATOR_H_ 00002 #define SimTK_SIMMATH_INTEGRATOR_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * SimTK Core: SimTK Simmath(tm) * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK Core biosimulation toolkit originating from * 00008 * Simbios, the NIH National Center for Physics-Based Simulation of * 00009 * Biological Structures at Stanford, funded under the NIH Roadmap for * 00010 * Medical Research, grant U54 GM072970. See https://simtk.org. * 00011 * * 00012 * Portions copyright (c) 2006-7 Stanford University and the Authors. * 00013 * Authors: Michael Sherman * 00014 * Contributors: * 00015 * * 00016 * Permission is hereby granted, free of charge, to any person obtaining a * 00017 * copy of this software and associated documentation files (the "Software"), * 00018 * to deal in the Software without restriction, including without limitation * 00019 * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 00020 * and/or sell copies of the Software, and to permit persons to whom the * 00021 * Software is furnished to do so, subject to the following conditions: * 00022 * * 00023 * The above copyright notice and this permission notice shall be included in * 00024 * all copies or substantial portions of the Software. * 00025 * * 00026 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 00027 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 00028 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 00029 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 00030 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 00031 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 00032 * USE OR OTHER DEALINGS IN THE SOFTWARE. * 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 // These are the exceptions that can be thrown by this class. 00132 00133 class InitializationFailed; 00134 class StepSizeTooSmall; 00135 class StepFailed; 00136 class TriedToAdvancePastFinalTime; 00137 class CantAskForEventInfoWhenNoEventTriggered; 00138 00140 const char* getMethodName() const; 00142 int getMethodMinOrder() const; 00144 int getMethodMaxOrder() const; 00148 bool methodHasErrorControl() const; 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 // TERMINATION // 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 // opaque implementation for binary compatibility 00400 IntegratorRep* rep; 00401 friend class IntegratorRep; 00402 00403 private: 00404 // OBSOLETE 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 } // namespace SimTK 00415 00416 #endif // SimTK_SIMMATH_INTEGRATOR_H_