From 01f8c7fa23ea5deac14f1cceff4ae767e81bb498 Mon Sep 17 00:00:00 2001 From: Benedikt Tissot Date: Thu, 20 Jun 2019 19:49:49 +0200 Subject: [PATCH] return success if steady state is reached for DynamicSS change retcode to success if steady state is reached for DynamicSS --- src/solve.jl | 11 +++++++++++ test/runtests.jl | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) 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