#include <CvodeAdaptor.hpp>
Inherits AbstractIvpOdeSolver.
Public Member Functions | |
CvodeAdaptor (double relTol=1e-4, double absTol=1e-6) | |
void | SetTolerances (double relTol=1e-4, double absTol=1e-6) |
double | GetRelativeTolerance () |
double | GetAbsoluteTolerance () |
double | GetLastStepSize () |
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 () |
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) |
Private Attributes | |
void * | mpCvodeMem |
N_Vector | mInitialValues |
CvodeData | mData |
double | mRelTol |
double | mAbsTol |
double | mLastInternalStepSize |
long int | mMaxSteps |
bool | mCheckForRoots |
Friends | |
class | boost::serialization::access |
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.
Note that a call to Solve will initialise the CVODE solver, and free its working memory when done. There is thus a non-trivial overhead involved.
Definition at line 82 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 352 of file CvodeAdaptor.cpp.
void CvodeAdaptor::CheckForStoppingEvents | ( | ) |
Make the solver check for stopping events using CVODE's rootfinding functionality.
By default we do not check.
Definition at line 383 of file CvodeAdaptor.cpp.
References mCheckForRoots.
void CvodeAdaptor::CvodeError | ( | int | flag, | |
const char * | msg | |||
) | [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 238 of file CvodeAdaptor.cpp.
References EXCEPTION.
Referenced by Solve().
void CvodeAdaptor::FreeCvodeMemory | ( | ) | [protected] |
Free CVODE memory after solving a system of ODEs.
Definition at line 226 of file CvodeAdaptor.cpp.
References mInitialValues, and mpCvodeMem.
Referenced by Solve().
double CvodeAdaptor::GetAbsoluteTolerance | ( | ) |
double CvodeAdaptor::GetLastStepSize | ( | ) |
Get the last step size used internally by CVODE in the last Solve call
Definition at line 378 of file CvodeAdaptor.cpp.
References mLastInternalStepSize.
long int CvodeAdaptor::GetMaxSteps | ( | ) |
Get the maximum number of steps to be taken by the solver in its attempt to reach the next output time.
Definition at line 393 of file CvodeAdaptor.cpp.
References mMaxSteps.
double CvodeAdaptor::GetRelativeTolerance | ( | ) |
void CvodeAdaptor::serialize | ( | Archive & | archive, | |
const unsigned int | version | |||
) | [inline, private] |
Archive, never used directly - boost uses this.
archive | the archive | |
version | the current version of this class |
Reimplemented from AbstractIvpOdeSolver.
Definition at line 94 of file CvodeAdaptor.hpp.
References mAbsTol, mCheckForRoots, mLastInternalStepSize, mMaxSteps, and mRelTol.
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 388 of file CvodeAdaptor.cpp.
References mMaxSteps.
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 362 of file CvodeAdaptor.cpp.
void CvodeAdaptor::SetupCvode | ( | AbstractOdeSystem * | pOdeSystem, | |
std::vector< double > & | rInitialY, | |||
double | startTime, | |||
double | maxStep | |||
) | [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 |
Definition at line 173 of file CvodeAdaptor.cpp.
References EXCEPTION, AbstractUntemplatedParameterisedSystem::GetNumberOfStateVariables(), mAbsTol, mCheckForRoots, mData, mInitialValues, mMaxSteps, mpCvodeMem, mRelTol, CvodeData_::pSystem, and CvodeData_::pY.
Referenced by Solve().
void CvodeAdaptor::Solve | ( | AbstractOdeSystem * | pOdeSystem, | |
std::vector< double > & | rYValues, | |||
double | startTime, | |||
double | endTime, | |||
double | maxStep | |||
) | [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 310 of file CvodeAdaptor.cpp.
References AbstractOdeSystem::CalculateStoppingEvent(), CvodeError(), EXCEPTION, FreeCvodeMemory(), mCheckForRoots, mInitialValues, mLastInternalStepSize, mpCvodeMem, AbstractIvpOdeSolver::mStoppingEventOccurred, AbstractIvpOdeSolver::mStoppingTime, and SetupCvode().
OdeSolution CvodeAdaptor::Solve | ( | AbstractOdeSystem * | pOdeSystem, | |
std::vector< double > & | rYValues, | |||
double | startTime, | |||
double | endTime, | |||
double | maxStep, | |||
double | timeSampling | |||
) | [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 249 of file CvodeAdaptor.cpp.
References TimeStepper::AdvanceOneTimeStep(), AbstractOdeSystem::CalculateStoppingEvent(), CvodeError(), TimeStepper::EstimateTimeSteps(), EXCEPTION, FreeCvodeMemory(), TimeStepper::GetNextTime(), AbstractUntemplatedParameterisedSystem::GetSystemInformation(), TimeStepper::GetTotalTimeStepsTaken(), TimeStepper::IsTimeAtEnd(), mCheckForRoots, mInitialValues, mLastInternalStepSize, mpCvodeMem, AbstractIvpOdeSolver::mStoppingEventOccurred, AbstractIvpOdeSolver::mStoppingTime, OdeSolution::rGetSolutions(), OdeSolution::rGetTimes(), OdeSolution::SetNumberOfTimeSteps(), OdeSolution::SetOdeSystemInformation(), and SetupCvode().
friend class boost::serialization::access [friend] |
Needed for serialization.
Reimplemented from AbstractIvpOdeSolver.
Definition at line 86 of file CvodeAdaptor.hpp.
double CvodeAdaptor::mAbsTol [private] |
Absolute tolerance for the ODE solver.
Definition at line 118 of file CvodeAdaptor.hpp.
Referenced by GetAbsoluteTolerance(), serialize(), SetTolerances(), and SetupCvode().
bool CvodeAdaptor::mCheckForRoots [private] |
Whether to check for stopping events.
Definition at line 130 of file CvodeAdaptor.hpp.
Referenced by CheckForStoppingEvents(), serialize(), SetupCvode(), and Solve().
CvodeData CvodeAdaptor::mData [private] |
The CVODE data structure.
Definition at line 112 of file CvodeAdaptor.hpp.
Referenced by SetupCvode().
N_Vector CvodeAdaptor::mInitialValues [private] |
Initial conditions for the ODE solver.
Definition at line 109 of file CvodeAdaptor.hpp.
Referenced by FreeCvodeMemory(), SetupCvode(), and Solve().
double CvodeAdaptor::mLastInternalStepSize [private] |
The size of the previous timestep.
Definition at line 121 of file CvodeAdaptor.hpp.
Referenced by GetLastStepSize(), serialize(), and Solve().
long int CvodeAdaptor::mMaxSteps [private] |
The maximum number of steps to be taken by the solver in its attempt to reach the next output time.
Definition at line 127 of file CvodeAdaptor.hpp.
Referenced by GetMaxSteps(), serialize(), SetMaxSteps(), and SetupCvode().
void* CvodeAdaptor::mpCvodeMem [private] |
Pointer to the CVODE memory block.
Definition at line 106 of file CvodeAdaptor.hpp.
Referenced by FreeCvodeMemory(), SetupCvode(), and Solve().
double CvodeAdaptor::mRelTol [private] |
Relative tolerance for the ODE solver.
Definition at line 115 of file CvodeAdaptor.hpp.
Referenced by GetRelativeTolerance(), serialize(), SetTolerances(), and SetupCvode().