Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Solver::get_current_time #2346

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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
21 changes: 16 additions & 5 deletions src/solver_idas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

Expand Down Expand Up @@ -419,7 +419,7 @@

auto status = IDASetStopTime(ida_mem, tout);
if (status != IDA_SUCCESS)
throw IDAException(status, "CVodeSetStopTime");
throw IDAException(status, "IDASetStopTime");

Check warning on line 422 in src/solver_idas.cpp

View check run for this annotation

Codecov / codecov/patch

src/solver_idas.cpp#L422

Added line #L422 was not covered by tests

status = IDASolve(
ami_mem, tout, t, yout->getNVector(), ypout->getNVector(), IDA_ONE_STEP
Expand Down Expand Up @@ -835,7 +835,7 @@
solver_memory_.get(), non_linear_solver_->get()
);
if (status != IDA_SUCCESS)
throw CvodeException(status, "CVodeSetNonlinearSolver");
throw IDAException(status, "IDASetNonlinearSolver");

Check warning on line 838 in src/solver_idas.cpp

View check run for this annotation

Codecov / codecov/patch

src/solver_idas.cpp#L838

Added line #L838 was not covered by tests
}

void IDASolver::setNonLinearSolverSens() const {
Expand Down Expand Up @@ -865,15 +865,26 @@
}

if (status != IDA_SUCCESS)
throw CvodeException(status, "CVodeSolver::setNonLinearSolverSens");
throw IDAException(status, "IDASolver::setNonLinearSolverSens");

Check warning on line 868 in src/solver_idas.cpp

View check run for this annotation

Codecov / codecov/patch

src/solver_idas.cpp#L868

Added line #L868 was not covered by tests
}

void IDASolver::setNonLinearSolverB(int which) const {
int status = IDASetNonlinearSolverB(
solver_memory_.get(), which, non_linear_solver_B_->get()
);
if (status != IDA_SUCCESS)
throw CvodeException(status, "CVodeSetNonlinearSolverB");
throw IDAException(status, "IDASetNonlinearSolverB");

Check warning on line 876 in src/solver_idas.cpp

View check run for this annotation

Codecov / codecov/patch

src/solver_idas.cpp#L876

Added line #L876 was not covered by tests
}

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 IDAException(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
}

/**
Expand Down
Loading