Chaste
Release::2017.1
|
#include <CvodeAdaptor.hpp>
Public Member Functions | |
CvodeAdaptor (double relTol=1e-4, double absTol=1e-6) | |
~CvodeAdaptor () | |
void | SetTolerances (double relTol=1e-4, double absTol=1e-6) |
double | GetRelativeTolerance () |
double | GetAbsoluteTolerance () |
double | GetLastStepSize () |
void | SetForceReset (bool autoReset) |
void | SetMinimalReset (bool minimalReset) |
void | ResetSolver () |
OdeSolution | Solve (AbstractOdeSystem *pOdeSystem, std::vector< double > &rYValues, double startTime, double endTime, double maxStep, double timeSampling) |
void | Solve (AbstractOdeSystem *pOdeSystem, std::vector< double > &rYValues, double startTime, double endTime, double maxStep) |
void | CheckForStoppingEvents () |
void | SetMaxSteps (long int numSteps) |
long int | GetMaxSteps () |
Public Member Functions inherited from AbstractIvpOdeSolver | |
virtual void | SolveAndUpdateStateVariable (AbstractOdeSystem *pAbstractOdeSystem, double startTime, double endTime, double timeStep) |
bool | StoppingEventOccurred () |
double | GetStoppingTime () |
AbstractIvpOdeSolver () | |
virtual | ~AbstractIvpOdeSolver () |
Public Member Functions inherited from Identifiable | |
virtual | ~Identifiable () |
std::string | GetIdentifier () const |
Protected Member Functions | |
void | SetupCvode (AbstractOdeSystem *pOdeSystem, std::vector< double > &rInitialY, double startTime, double maxStep) |
void | FreeCvodeMemory () |
void | CvodeError (int flag, const char *msg) |
Private Member Functions | |
template<class Archive > | |
void | serialize (Archive &archive, const unsigned int version) |
void | RecordStoppingPoint (double stopTime, N_Vector yEnd) |
Private Attributes | |
void * | mpCvodeMem |
CvodeData | mData |
double | mRelTol |
double | mAbsTol |
double | mLastInternalStepSize |
long int | mMaxSteps |
bool | mCheckForRoots |
N_Vector | mLastSolutionState |
double | mLastSolutionTime |
bool | mForceReset |
bool | mForceMinimalReset |
Friends | |
class | boost::serialization::access |
Additional Inherited Members | |
Protected Attributes inherited from AbstractIvpOdeSolver | |
bool | mStoppingEventOccurred |
double | mStoppingTime |
The CVODE adaptor ODE solver class.
Assumes that it will be solving stiff systems, so uses BDF/Newton.
The timeStep parameters of the abstract class are here used to specify *maximum* steps, since the solver is adaptive.
Repeated calls to Solve will no longer set up and delete CVODE memory, unless the following method is called:
SetForceReset(true) - reset each time Solve() is called
default behaviour - reset if state variables change, or we ask to solve from a different time than the last solve call finished.
SetMinimalReset(true) - ignore changes in state vars and just reset if the time is inconsistent.
Definition at line 92 of file CvodeAdaptor.hpp.
Default constructor. Can optionally set relative and absolute tolerances.
relTol | the relative tolerance for the solver |
absTol | the absolute tolerance for the solver |
Definition at line 443 of file CvodeAdaptor.cpp.
CvodeAdaptor::~CvodeAdaptor | ( | ) |
Destructor. Frees memory.
Definition at line 462 of file CvodeAdaptor.cpp.
References DeleteVector(), FreeCvodeMemory(), and mLastSolutionState.
void CvodeAdaptor::CheckForStoppingEvents | ( | ) |
Make the solver check for stopping events using CVODE's rootfinding functionality.
By default we do not check.
Definition at line 503 of file CvodeAdaptor.cpp.
References mCheckForRoots.
|
protected |
Report an error from CVODE.
This will (probably) never be called, since we supply an error handler function which throws an exception.
flag | error flag |
msg | error message |
Definition at line 315 of file CvodeAdaptor.cpp.
References EXCEPTION.
Referenced by Solve().
|
protected |
Free CVODE memory after solving a system of ODEs.
Definition at line 280 of file CvodeAdaptor.cpp.
References mpCvodeMem.
Referenced by Solve(), and ~CvodeAdaptor().
double CvodeAdaptor::GetAbsoluteTolerance | ( | ) |
double CvodeAdaptor::GetLastStepSize | ( | ) |
Definition at line 498 of file CvodeAdaptor.cpp.
References mLastInternalStepSize.
long int CvodeAdaptor::GetMaxSteps | ( | ) |
Definition at line 513 of file CvodeAdaptor.cpp.
References CHASTE_CLASS_EXPORT, and mMaxSteps.
double CvodeAdaptor::GetRelativeTolerance | ( | ) |
Record where the last solve got to so we know whether to re-initialise.
stopTime | the finishing time |
yEnd | the state variables at this time |
Definition at line 468 of file CvodeAdaptor.cpp.
References CreateVectorIfEmpty(), GetVectorComponent(), GetVectorSize(), mForceReset, mLastSolutionState, mLastSolutionTime, and SetVectorComponent().
Referenced by Solve().
void CvodeAdaptor::ResetSolver | ( | ) |
Successive calls to Solve will attempt to intelligently determine whether to re-initialise the internal CVODE solver, or whether we are simply extending the previous solution forward in time. This mechanism compares the state vector to its previous value, and the start time to the end of the last solve, which captures most cases where re-initialisation is required. However, changes to the RHS function can also require this, and cannot be automatically detected. In such cases users must call this function to force re-initialisation.
Definition at line 309 of file CvodeAdaptor.cpp.
References DeleteVector(), and mLastSolutionState.
Referenced by SetForceReset().
|
inlineprivate |
Archive, never used directly - boost uses this.
archive | the archive |
version | the current version of this class |
Definition at line 104 of file CvodeAdaptor.hpp.
void CvodeAdaptor::SetForceReset | ( | bool | autoReset | ) |
Set whether to automatically re-initialise CVODE on every call to Solve, or whether to attempt to guess when re-initialisation is needed. See also ResetSolver.
autoReset | whether to reset on every Solve |
Definition at line 290 of file CvodeAdaptor.cpp.
References mForceReset, ResetSolver(), and SetMinimalReset().
Referenced by SetMinimalReset().
void CvodeAdaptor::SetMaxSteps | ( | long int | numSteps | ) |
Change the maximum number of steps to be taken by the solver in its attempt to reach the next output time. Default is 500.
numSteps | new maximum number of steps |
Definition at line 508 of file CvodeAdaptor.cpp.
References mMaxSteps.
void CvodeAdaptor::SetMinimalReset | ( | bool | minimalReset | ) |
Set whether to reduce the checking done when guessing when re-initialisation is needed, so it ignores changes in the state variables. If call with true argument, will call SetForceReset(false).
minimalReset | whether to avoid checking for changes in state variables |
Definition at line 300 of file CvodeAdaptor.cpp.
References mForceMinimalReset, and SetForceReset().
Referenced by SetForceReset().
Set relative and absolute tolerances; both scalars. If no parameters are given, tolerances will be reset to default values.
relTol | the relative tolerance for the solver |
absTol | the absolute tolerance for the solver |
Definition at line 482 of file CvodeAdaptor.cpp.
|
protected |
Set up the CVODE data structures needed to solve the given system.
pOdeSystem | the ODE system being solved |
rInitialY | initial conditions vector |
startTime | when to simulate from |
maxStep | maximum time step |
Initial conditions for the ODE solver.
Definition at line 179 of file CvodeAdaptor.cpp.
References DeleteVector(), EXCEPTION, AbstractUntemplatedParameterisedSystem::GetNumberOfStateVariables(), GetVectorComponent(), GetVectorSize(), mAbsTol, mCheckForRoots, mData, mForceMinimalReset, mForceReset, mLastSolutionState, mLastSolutionTime, mMaxSteps, mpCvodeMem, mRelTol, CvodeData_::pSystem, CvodeData_::pY, and CompareDoubles::WithinAnyTolerance().
Referenced by Solve().
|
virtual |
Solve the given ODE system, returning the solution at sampling intervals.
pOdeSystem | the ODE system to solve |
rYValues | the initial state variable values (note: this vector will also be used as working memory) |
startTime | the time to start solving at |
endTime | the time to solve to |
maxStep | the maximum time step to be taken by the adaptive solver |
timeSampling | the interval at which to sample the solution |
Implements AbstractIvpOdeSolver.
Definition at line 326 of file CvodeAdaptor.cpp.
References TimeStepper::AdvanceOneTimeStep(), AbstractOdeSystem::CalculateStoppingEvent(), CvodeError(), DeleteVector(), TimeStepper::EstimateTimeSteps(), EXCEPTION, FreeCvodeMemory(), TimeStepper::GetNextTime(), AbstractUntemplatedParameterisedSystem::GetSystemInformation(), TimeStepper::GetTotalTimeStepsTaken(), TimeStepper::IsTimeAtEnd(), mCheckForRoots, mLastInternalStepSize, mLastSolutionTime, mpCvodeMem, AbstractIvpOdeSolver::mStoppingEventOccurred, AbstractIvpOdeSolver::mStoppingTime, RecordStoppingPoint(), OdeSolution::rGetSolutions(), OdeSolution::rGetTimes(), OdeSolution::SetNumberOfTimeSteps(), OdeSolution::SetOdeSystemInformation(), SetupCvode(), and UNUSED_OPT.
|
virtual |
Solve the given ODE system, storing the final result in rYValues.
pOdeSystem | the ODE system to solve |
rYValues | the initial state variable values; will be filled in with the final values on return |
startTime | the time to start solving at |
endTime | the time to solve to |
maxStep | the maximum time step to be taken by the adaptive solver |
Implements AbstractIvpOdeSolver.
Definition at line 394 of file CvodeAdaptor.cpp.
References AbstractOdeSystem::CalculateStoppingEvent(), CvodeError(), DeleteVector(), EXCEPTION, FreeCvodeMemory(), mCheckForRoots, mLastInternalStepSize, mpCvodeMem, AbstractIvpOdeSolver::mStoppingEventOccurred, AbstractIvpOdeSolver::mStoppingTime, RecordStoppingPoint(), SetupCvode(), and UNUSED_OPT.
|
friend |
Needed for serialization.
Definition at line 96 of file CvodeAdaptor.hpp.
|
private |
Absolute tolerance for the ODE solver.
Definition at line 125 of file CvodeAdaptor.hpp.
Referenced by GetAbsoluteTolerance(), SetTolerances(), and SetupCvode().
|
private |
Whether to check for stopping events.
Definition at line 137 of file CvodeAdaptor.hpp.
Referenced by CheckForStoppingEvents(), SetupCvode(), and Solve().
|
private |
The CVODE data structure.
Definition at line 119 of file CvodeAdaptor.hpp.
Referenced by SetupCvode().
|
private |
Whether to ignore changes in the state variables when deciding whether to reset.
Definition at line 149 of file CvodeAdaptor.hpp.
Referenced by SetMinimalReset(), and SetupCvode().
|
private |
Whether to automatically reset CVODE on each Solve call.
Definition at line 146 of file CvodeAdaptor.hpp.
Referenced by RecordStoppingPoint(), SetForceReset(), and SetupCvode().
|
private |
The size of the previous timestep.
Definition at line 128 of file CvodeAdaptor.hpp.
Referenced by GetLastStepSize(), and Solve().
|
private |
Remember where the last solve got to so we know whether to re-initialise.
Definition at line 140 of file CvodeAdaptor.hpp.
Referenced by RecordStoppingPoint(), ResetSolver(), SetupCvode(), and ~CvodeAdaptor().
|
private |
Remember where the last solve got to so we know whether to re-initialise.
Definition at line 143 of file CvodeAdaptor.hpp.
Referenced by RecordStoppingPoint(), SetupCvode(), and Solve().
|
private |
The maximum number of steps to be taken by the solver in its attempt to reach the next output time.
Definition at line 134 of file CvodeAdaptor.hpp.
Referenced by GetMaxSteps(), SetMaxSteps(), and SetupCvode().
|
private |
Pointer to the CVODE memory block.
Definition at line 116 of file CvodeAdaptor.hpp.
Referenced by FreeCvodeMemory(), SetupCvode(), and Solve().
|
private |
Relative tolerance for the ODE solver.
Definition at line 122 of file CvodeAdaptor.hpp.
Referenced by GetRelativeTolerance(), SetTolerances(), and SetupCvode().