CVODEIntegrator

class CVODEIntegrator : public rr::Integrator

A RoadRunner integrator based on CVODE; serves as RoadRunner’s main integrator for ODEs.

Provides a wrapper around CVODE from the SUNDIALS suite. CVODE has two main solvers: an Adams-Moulton solver for non-stiff problems, and a backward differentiation formula (BDF) solver for stiff problems. See: https://computation.llnl.gov/casc/sundials/documentation/toms_sundials.pdf

Author

WBC, ETS, MTK

Public Functions

explicit CVODEIntegrator(ExecutableModel *oModel)

Constructor: takes an executable model, does not own the pointer.

Author

WBC, ETS, MTK

~CVODEIntegrator() override

Destructor.

Author

WBC, ETS, MTK

virtual void syncWithModel(ExecutableModel *m) override

Called whenever a new model is loaded to allow integrator to reset internal state.

Author

JKM

virtual void loadConfigSettings() override

It looks like this method only get used inside resetSettings.

virtual void loadSBMLSettings(const std::string &filename) override

Load an SBML settings file and apply the configuration options.

Author

WBC

Note

Can assign relative and absolute tolerances

virtual std::string getName() const override

Get the name for this integrator.

Author

WBC

Note

Delegates to getName

virtual std::string getDescription() const override

Get the description for this integrator.

Author

WBC

Note

Delegates to getDescription

virtual std::string getHint() const override

Get the hint for this integrator.

Author

WBC

Note

Delegates to getHint

virtual Solver *construct(ExecutableModel *executableModel) const override

construct an instance of type CVODEIntegrator.

implements the Registrar interface. Used in factory creation of Integrators.

virtual IntegrationMethod getIntegrationMethod() const override

Always deterministic for CVODE.

Author

WBC, ETS, MTK

virtual void setValue(const std::string &setting, Setting value) override

Sets the value of an integrator setting (e.g. absolute_tolerance)

Author

WBC, ETS, MTK

void setMaxOrder(int newValue)

sets the value of maximum order, which defaults to 12 for Adams (non-stiff) and 5 for BDF (Stiff).

Once a CVODEIntegrator has been created, increasing the order value beyond the original value is not possible (because the underlying sundials objects require more memory). Attempts to do so will simply be ignored.

virtual void setIndividualTolerance(std::string sid, double value) override

Sets tolerance for individual species.

Author

FY

virtual void setConcentrationTolerance(Setting value) override

Sets tolerance based on concentration of species.

First converts the concentration tolerances to amount tolerances by multiplying the compartment volume of species. Whichever is smaller will be stored as absolute_tolerance and used in the integration process.

Author

FY

virtual std::vector<double> getConcentrationTolerance() override

Gets tolerance based on concentration of species.

Author

FY

virtual void resetSettings() override

Reset all integrator settings to their respective default values.

Author

JKM

virtual void tweakTolerances() override

Fix tolerances for SBML tests.

In order to ensure that the results of the SBML test suite remain valid, this method enforces a lower bound on tolerance values. Sets minimum absolute and relative tolerances to Config::CVODE_MIN_ABSOLUTE and Config::CVODE_MIN_RELATIVE resp.

Author

JKM, WBC, ETS, MTK

virtual double integrate(double t0, double hstep) override

Main integration routine.

Author

WBC, ETS, MTK

virtual void restart(double timeStart) override

Reset time to zero and reinitialize model.

Applies events which occur before time zero. Reinitializes CVODE and the executable model.

Author

WBC, ETS, MTK

virtual IntegratorListenerPtr getListener() override

Gets the integrator listener.

Author

WBC, ETS

virtual void setListener(IntegratorListenerPtr) override

Sets the integrator listener.

Author

WBC, ETS

void checkType() const

Does a RT type check which throws if it fails, EVEN IF RTTI IS DISABLED.

Author

JKM

void checkVectorSize(int expected, size_t real) const

Does a size check which throws if it fails.

Author

FY

void checkIndex(int index, int size) const

Does a index check which throws if it is out of bound.

Author

FY

std::string ToString(int val) const

Converts integer to std::string for error print.

Author

FY

std::string ToString(size_t val) const

Converts size_t to std::string for error print.

Author

LPS

N_Vector getStateVector() const

getter for the internal state std::vector

SUNNonlinearSolver getSolver() const

getter for the internal Sundials linear solver object

void *getCvodeMemory() const

getter for the internal CVode memory buffer

explicit Integrator(ExecutableModel *model)
Integrator()

Private Functions

void testRootsAtInitialTime()
bool haveVariables() const
void assignResultsToModel() const
void setCVODETolerances()

Propagates changes in the “absolute_tolerance” and “relative_tolerance” settings to the CVODE library.

Author

WBC, ETS, JKM

void reInit(double t0)

Reinitialize sundials objects.

void updateCVODE()

Propagates changes in the following settings to CVODE:

.

Author

WBC, ETS, JKM

  • initial_time_step

  • minimum_time_step

  • maximum_time_step

  • maximum_num_steps

  • absolute_tolerance (via setCVODETolerances)

  • relative_tolerance (via setCVODETolerances)

void applyPendingEvents(double timeEnd)
void applyEvents(double timeEnd, std::vector<unsigned char> &previousEventStatus)
double applyVariableStepPendingEvents()
void create()
void freeSundialsMemory()

Private Members

void *mCVODE_Memory = nullptr
N_Vector mStateVector = nullptr
SUNMatrix jac = nullptr
SUNNonlinearSolver nonLinSolver = nullptr
SUNLinearSolver linSolver = nullptr
IntegratorListenerPtr listener
double mLastEventTime
bool variableStepPendingEvent
bool variableStepTimeEndEvent
std::vector<double> variableStepPostEventState
std::vector<unsigned char> eventStatus
bool stateVectorVariables
unsigned long typecode_

Private Static Attributes

static const int mDefaultMaxNumSteps = 20000
static const int mDefaultMaxAdamsOrder = 12
static const int mDefaultMaxBDFOrder = 5

Friends

friend class ForwardSensitivitySolver
friend int cvodeDyDtFcn(double t, N_Vector cv_y, N_Vector cv_ydot, void *f_data)
friend int cvodeRootFcn(double t, N_Vector y, double *gout, void *g_data)