Simbody
3.4 (development)
|
00001 #ifndef SimTK_SIMMATH_INTEGRATOR_H_ 00002 #define SimTK_SIMMATH_INTEGRATOR_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * Simbody(tm): SimTKmath * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK 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/home/simbody. * 00011 * * 00012 * Portions copyright (c) 2006-12 Stanford University and the Authors. * 00013 * Authors: Michael Sherman * 00014 * Contributors: * 00015 * * 00016 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 00017 * not use this file except in compliance with the License. You may obtain a * 00018 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 00019 * * 00020 * Unless required by applicable law or agreed to in writing, software * 00021 * distributed under the License is distributed on an "AS IS" BASIS, * 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00023 * See the License for the specific language governing permissions and * 00024 * limitations under the License. * 00025 * -------------------------------------------------------------------------- */ 00026 00032 #include "SimTKcommon.h" 00033 #include "simmath/internal/common.h" 00034 00035 namespace SimTK { 00036 00037 00038 class IntegratorRep; 00039 00116 class SimTK_SIMMATH_EXPORT Integrator { 00117 public: 00118 Integrator() : rep(0) { } 00119 ~Integrator(); 00120 00121 // These are the exceptions that can be thrown by this class. 00122 00123 class InitializationFailed; 00124 class StepSizeTooSmall; 00125 class StepFailed; 00126 class TriedToAdvancePastFinalTime; 00127 class CantAskForEventInfoWhenNoEventTriggered; 00128 00130 const char* getMethodName() const; 00132 int getMethodMinOrder() const; 00134 int getMethodMaxOrder() const; 00138 bool methodHasErrorControl() const; 00139 00143 void initialize(const State& state); 00144 00156 void reinitialize(Stage stage, bool shouldTerminate); 00157 00160 const State& getState() const; 00162 Real getTime() const {return getState().getTime();} 00163 00166 bool isStateInterpolated() const; 00167 00171 const State& getAdvancedState() const; 00173 Real getAdvancedTime() const {return getAdvancedState().getTime();} 00174 00176 State& updAdvancedState(); 00177 00180 Real getAccuracyInUse() const; 00183 Real getConstraintToleranceInUse() const; 00184 00202 enum SuccessfulStepStatus { 00204 ReachedReportTime =1, 00206 ReachedEventTrigger =2, 00208 ReachedScheduledEvent=3, 00210 TimeHasAdvanced =4, 00212 ReachedStepLimit =5, 00214 EndOfSimulation =6, 00217 StartOfContinuousInterval=7, 00218 InvalidSuccessfulStepStatus = -1 00219 }; 00221 static String getSuccessfulStepStatusString(SuccessfulStepStatus); 00222 00226 SuccessfulStepStatus stepTo(Real reportTime, Real scheduledEventTime=Infinity); 00230 SuccessfulStepStatus stepBy(Real interval, Real scheduledEventTime=Infinity); 00231 00232 00235 Vec2 getEventWindow() const; 00238 const Array_<EventId>& getTriggeredEvents() const; 00241 const Array_<Real>& getEstimatedEventTimes() const; 00244 const Array_<Event::Trigger>& getEventTransitionsSeen() const; 00245 00246 00247 // TERMINATION // 00248 00250 enum TerminationReason { 00252 ReachedFinalTime = 1, 00254 AnUnrecoverableErrorOccurred = 2, 00256 EventHandlerRequestedTermination = 3, 00258 InvalidTerminationReason = -1 00259 }; 00260 00263 bool isSimulationOver() const; 00264 00267 TerminationReason getTerminationReason() const; 00268 00270 static String getTerminationReasonString(TerminationReason); 00271 00273 void resetAllStatistics(); 00274 00276 Real getActualInitialStepSizeTaken() const; 00277 00279 Real getPreviousStepSizeTaken() const; 00280 00282 Real getPredictedNextStepSize() const; 00283 00286 int getNumStepsAttempted() const; 00288 int getNumStepsTaken() const; 00290 int getNumRealizations() const; 00293 int getNumQProjections() const; 00296 int getNumUProjections() const; 00299 int getNumProjections() const; 00302 int getNumErrorTestFailures() const; 00307 int getNumConvergenceTestFailures() const; 00310 int getNumRealizationFailures() const; 00314 int getNumQProjectionFailures() const; 00318 int getNumUProjectionFailures() const; 00322 int getNumProjectionFailures() const; 00325 int getNumConvergentIterations() const; 00328 int getNumDivergentIterations() const; 00332 int getNumIterations() const; 00333 00336 void setFinalTime(Real tFinal); 00339 void setInitialStepSize(Real hinit); 00342 void setMinimumStepSize(Real hmin); 00345 void setMaximumStepSize(Real hmax); 00346 00352 void setFixedStepSize(Real stepSize); 00353 00357 void setAccuracy(Real accuracy); 00359 void setConstraintTolerance(Real consTol); 00364 void setUseInfinityNorm(bool useInfinityNorm); 00366 bool isInfinityNormInUse() const; 00367 00368 00373 void setInternalStepLimit(int nSteps); 00374 00378 void setReturnEveryInternalStep(bool shouldReturn); 00379 00383 void setProjectEveryStep(bool forceProject); 00394 void setAllowInterpolation(bool shouldInterpolate); 00398 void setProjectInterpolatedStates(bool shouldProject); 00402 void setForceFullNewton(bool forceFullNewton); 00403 00405 static String successfulStepStatusString(SuccessfulStepStatus stat) 00406 { return getSuccessfulStepStatusString(stat); } 00407 00408 protected: 00409 const IntegratorRep& getRep() const {assert(rep); return *rep;} 00410 IntegratorRep& updRep() {assert(rep); return *rep;} 00411 00412 // opaque implementation for binary compatibility 00413 IntegratorRep* rep; 00414 friend class IntegratorRep; 00415 }; 00416 00417 } // namespace SimTK 00418 00419 #endif // SimTK_SIMMATH_INTEGRATOR_H_