Skip to content

Commit

Permalink
Add Solver::get_current_time
Browse files Browse the repository at this point in the history
Prerequisite for #2246.
  • Loading branch information
dweindl committed Mar 4, 2024
1 parent e8852be commit a59e403
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/amici/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions include/amici/solver_cvodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions include/amici/solver_idas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/solver_cvodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,17 @@ void CVodeSolver::setNonLinearSolverB(int const which) const {
throw CvodeException(status, "CVodeSetNonlinearSolverB");
}

realtype CVodeSolver::get_current_time() const {

Check warning on line 389 in src/solver_cvodes.cpp

View check run for this annotation

Codecov / codecov/patch

src/solver_cvodes.cpp#L389

Added line #L389 was not covered by tests
if (!solver_memory_)
return std::numeric_limits<realtype>::quiet_NaN();

Check warning on line 391 in src/solver_cvodes.cpp

View check run for this annotation

Codecov / codecov/patch

src/solver_cvodes.cpp#L391

Added line #L391 was not covered by tests

realtype time;
int status = CVodeGetCurrentTime(solver_memory_.get(), &time);

Check warning on line 394 in src/solver_cvodes.cpp

View check run for this annotation

Codecov / codecov/patch

src/solver_cvodes.cpp#L394

Added line #L394 was not covered by tests
if (status != CV_SUCCESS)
throw CvodeException(status, "CVodeGetCurrentTime");
return time;

Check warning on line 397 in src/solver_cvodes.cpp

View check run for this annotation

Codecov / codecov/patch

src/solver_cvodes.cpp#L396-L397

Added lines #L396 - L397 were not covered by tests
}

void CVodeSolver::setErrHandlerFn() const {
int status = CVodeSetErrHandlerFn(
solver_memory_.get(), wrapErrHandlerFn,
Expand Down
11 changes: 11 additions & 0 deletions src/solver_idas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,17 @@ void IDASolver::setNonLinearSolverB(int which) const {
throw CvodeException(status, "CVodeSetNonlinearSolverB");
}

realtype IDASolver::get_current_time() const {

Check warning on line 879 in src/solver_idas.cpp

View check run for this annotation

Codecov / codecov/patch

src/solver_idas.cpp#L879

Added line #L879 was not covered by tests
if (!solver_memory_)
return std::numeric_limits<realtype>::quiet_NaN();

Check warning on line 881 in src/solver_idas.cpp

View check run for this annotation

Codecov / codecov/patch

src/solver_idas.cpp#L881

Added line #L881 was not covered by tests

realtype time;
int status = IDAGetCurrentTime(solver_memory_.get(), &time);

Check warning on line 884 in src/solver_idas.cpp

View check run for this annotation

Codecov / codecov/patch

src/solver_idas.cpp#L884

Added line #L884 was not covered by tests
if (status != IDA_SUCCESS)
throw CvodeException(status, "IDAGetCurrentTime");
return time;

Check warning on line 887 in src/solver_idas.cpp

View check run for this annotation

Codecov / codecov/patch

src/solver_idas.cpp#L886-L887

Added lines #L886 - L887 were not covered by tests
}

/**
* @brief Jacobian of xdot with respect to states x
* @param N number of state variables
Expand Down

0 comments on commit a59e403

Please sign in to comment.