diff --git a/MathLib/ODE/CVodeSolver.cpp b/MathLib/ODE/CVodeSolver.cpp index 0261d3b1f22cfdef4122d0fbd24d5907753529bf..617f27cf3f203b3c7450fdc5bf1cd66e81c77f12 100644 --- a/MathLib/ODE/CVodeSolver.cpp +++ b/MathLib/ODE/CVodeSolver.cpp @@ -93,7 +93,7 @@ private: void setFunction(std::unique_ptr<detail::FunctionHandles>&& f); void preSolve(); - void solve(const double t_end); + bool solve(const double t_end); double const* getSolution() const { return NV_DATA_S(_y); } double getTime() const { return _t; } @@ -263,12 +263,17 @@ void CVodeSolverImpl::preSolve() } } -void CVodeSolverImpl::solve(const double t_end) +bool CVodeSolverImpl::solve(const double t_end) { realtype t_reached; check_error("CVode solve", CVode(_cvode_mem, t_end, _y, &t_reached, CV_NORMAL)); _t = t_reached; + + // check_error asserts that t_end == t_reached and that solving the ODE + // went fine. Otherwise the program will be aborted. Therefore, we don't + // have to check manually for errors here and can always savely return true. + return true; } void CVodeSolverImpl::getYDot(const double t, double const* const y, @@ -325,9 +330,9 @@ void CVodeSolver::preSolve() _impl->preSolve(); } -void CVodeSolver::solve(const double t_end) +bool CVodeSolver::solve(const double t_end) { - _impl->solve(t_end); + return _impl->solve(t_end); } double const* CVodeSolver::getSolution() const diff --git a/MathLib/ODE/CVodeSolver.h b/MathLib/ODE/CVodeSolver.h index 40fc1e6456beb3d73b75ca470b48f1386244b305..c36e55e0a2ff14db79b2bbc42fb6a1bb07ce1050 100644 --- a/MathLib/ODE/CVodeSolver.h +++ b/MathLib/ODE/CVodeSolver.h @@ -39,7 +39,7 @@ protected: void setIC(const double t0, double const* const y0); void preSolve(); - void solve(const double t_end); + bool solve(const double t_end); double const* getSolution() const; double getTime() const; diff --git a/MathLib/ODE/ConcreteOdeSolver.h b/MathLib/ODE/ConcreteOdeSolver.h index c6ccce9c3c5c673319a9a47fd7612abe9aafd18b..06dad3d19c85900c77e31b729fef1157e0c35c4f 100644 --- a/MathLib/ODE/ConcreteOdeSolver.h +++ b/MathLib/ODE/ConcreteOdeSolver.h @@ -83,7 +83,7 @@ public: } void preSolve() override { Implementation::preSolve(); } - void solve(const double t) override { Implementation::solve(t); } + bool solve(const double t) override { return Implementation::solve(t); } MappedConstVector<NumEquations> getSolution() const override { return MappedConstVector<NumEquations>{Implementation::getSolution()}; diff --git a/MathLib/ODE/OdeSolver.h b/MathLib/ODE/OdeSolver.h index 7a17de76bc7e9f3f1554a37f9e0c9713669340f1..800caa377cb632952e048a7c18e77544b176d627 100644 --- a/MathLib/ODE/OdeSolver.h +++ b/MathLib/ODE/OdeSolver.h @@ -43,7 +43,7 @@ public: Eigen::Matrix<double, NumEquations, 1, Eigen::ColMajor> const& y0) = 0; virtual void preSolve() = 0; - virtual void solve(const double t) = 0; + virtual bool solve(const double t) = 0; virtual unsigned getNumEquations() const { return NumEquations; } virtual MappedConstVector<NumEquations> getSolution() const = 0;