diff --git a/include/amici/solver.h b/include/amici/solver.h index ab4f8ef427..8ddff86763 100644 --- a/include/amici/solver.h +++ b/include/amici/solver.h @@ -964,6 +964,12 @@ class Solver { */ int getMaxConvFails() const; + /** + * @brief Get the current time of the solver. + * @return internal time of the solver + */ + virtual realtype get_current_time() const = 0; + /** * @brief Serialize Solver (see boost::serialization::serialize) * @param ar Archive to serialize to diff --git a/include/amici/solver_cvodes.h b/include/amici/solver_cvodes.h index 592298b7ec..28b7b61014 100644 --- a/include/amici/solver_cvodes.h +++ b/include/amici/solver_cvodes.h @@ -91,6 +91,8 @@ class CVodeSolver : public Solver { void setNonLinearSolverB(int which) const override; + realtype get_current_time() const override; + protected: void calcIC(realtype tout1) const override; diff --git a/include/amici/solver_idas.h b/include/amici/solver_idas.h index 079cee6399..ffcc5368b5 100644 --- a/include/amici/solver_idas.h +++ b/include/amici/solver_idas.h @@ -106,6 +106,8 @@ class IDASolver : public Solver { void setNonLinearSolverB(int which) const override; + realtype get_current_time() const override; + protected: /** * @brief Postprocessing of the solver memory after a discontinuity diff --git a/src/solver_cvodes.cpp b/src/solver_cvodes.cpp index 4fe97720d8..42671e3d96 100644 --- a/src/solver_cvodes.cpp +++ b/src/solver_cvodes.cpp @@ -386,6 +386,17 @@ void CVodeSolver::setNonLinearSolverB(int const which) const { throw CvodeException(status, "CVodeSetNonlinearSolverB"); } +realtype CVodeSolver::get_current_time() const { + if (!solver_memory_) + return std::numeric_limits::quiet_NaN(); + + realtype time; + int status = CVodeGetCurrentTime(solver_memory_.get(), &time); + if (status != CV_SUCCESS) + throw CvodeException(status, "CVodeGetCurrentTime"); + return time; +} + void CVodeSolver::setErrHandlerFn() const { int status = CVodeSetErrHandlerFn( solver_memory_.get(), wrapErrHandlerFn, diff --git a/src/solver_idas.cpp b/src/solver_idas.cpp index 1c69a041db..e65e435e05 100644 --- a/src/solver_idas.cpp +++ b/src/solver_idas.cpp @@ -17,7 +17,7 @@ namespace amici { /* - * The following static members are callback function to CVODES. + * The following static members are callback function to IDAS. * Their signatures must not be changes. */ @@ -419,7 +419,7 @@ void IDASolver::reInitPostProcess( auto status = IDASetStopTime(ida_mem, tout); if (status != IDA_SUCCESS) - throw IDAException(status, "CVodeSetStopTime"); + throw IDAException(status, "IDASetStopTime"); status = IDASolve( ami_mem, tout, t, yout->getNVector(), ypout->getNVector(), IDA_ONE_STEP @@ -835,7 +835,7 @@ void IDASolver::setNonLinearSolver() const { solver_memory_.get(), non_linear_solver_->get() ); if (status != IDA_SUCCESS) - throw CvodeException(status, "CVodeSetNonlinearSolver"); + throw IDAException(status, "IDASetNonlinearSolver"); } void IDASolver::setNonLinearSolverSens() const { @@ -865,7 +865,7 @@ void IDASolver::setNonLinearSolverSens() const { } if (status != IDA_SUCCESS) - throw CvodeException(status, "CVodeSolver::setNonLinearSolverSens"); + throw IDAException(status, "IDASolver::setNonLinearSolverSens"); } void IDASolver::setNonLinearSolverB(int which) const { @@ -873,7 +873,18 @@ void IDASolver::setNonLinearSolverB(int which) const { solver_memory_.get(), which, non_linear_solver_B_->get() ); if (status != IDA_SUCCESS) - throw CvodeException(status, "CVodeSetNonlinearSolverB"); + throw IDAException(status, "IDASetNonlinearSolverB"); +} + +realtype IDASolver::get_current_time() const { + if (!solver_memory_) + return std::numeric_limits::quiet_NaN(); + + realtype time; + int status = IDAGetCurrentTime(solver_memory_.get(), &time); + if (status != IDA_SUCCESS) + throw IDAException(status, "IDAGetCurrentTime"); + return time; } /**