diff --git a/src/solve.jl b/src/solve.jl index 258148f..13a80cf 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -51,6 +51,17 @@ function DiffEqBase.__solve(prob::DiffEqBase.AbstractSteadyStateProblem, save_everystep=save_everystep,save_start=save_start) if sol.t[end] == _prob.tspan[end] sol = DiffEqBase.solution_new_retcode(sol, :Failure) + elseif sol.retcode == :Terminated + if isinplace(prob) + du = similar(sol.u[end]) + prob.f(du, sol.u[end], prob.p, sol.t[end]) + else + du = prob.f(sol.u[end], prob.p, sol.t[end]) + end + if all(abs(d) <= abstol || abs(d) <= reltol*abs(u) for (d,abstol, reltol, u) = + zip(du, Iterators.cycle(alg.abstol), Iterators.cycle(alg.reltol), sol.u[end])) + sol = DiffEqBase.solution_new_retcode(sol, :Success) + end end sol end diff --git a/test/runtests.jl b/test/runtests.jl index 9c6535c..d53339b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -32,16 +32,16 @@ f(du,sol.u,nothing,0) using OrdinaryDiffEq sol = solve(prob,DynamicSS(Rodas5())) -@test sol.retcode == :Terminated +@test sol.retcode == :Success f(du,sol.u[end],p,0) @test du ≈ [0,0] atol = 1e-7 sol = solve(prob,DynamicSS(Rodas5(),tspan=1e-3)) -@test sol.retcode != :Terminated +@test sol.retcode != :Success sol = solve(prob,DynamicSS(CVODE_BDF()),dt=1.0) -@test sol.retcode == :Terminated +@test sol.retcode == :Success f(du,sol.u[end],p,0) @test du ≈ [0,0] atol = 1e-6