Skip to content

Commit

Permalink
Merge pull request #670 from visr/retcode
Browse files Browse the repository at this point in the history
Remove check in `check_error!`
  • Loading branch information
ChrisRackauckas authored Apr 29, 2024
2 parents 9d87ca0 + 14f6bce commit 9e92fc6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/integrator_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ Same as `check_error` but also set solution's return code
"""
function check_error!(integrator::DEIntegrator)
code = check_error(integrator)
integrator.sol = solution_new_retcode(integrator.sol, code)
if code != ReturnCode.Success
integrator.sol = solution_new_retcode(integrator.sol, code)
postamble!(integrator)
end
return code
Expand Down
21 changes: 19 additions & 2 deletions test/integrator_tests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using SciMLBase
mutable struct DummySolution
retcode::Any

struct DummySolution
retcode::SciMLBase.ReturnCode.T
end

SciMLBase.solution_new_retcode(::DummySolution, code) = DummySolution(code)

mutable struct DummyIntegrator{Alg, IIP, U, T} <: SciMLBase.DEIntegrator{Alg, IIP, U, T}
uprev::U
tprev::T
Expand Down Expand Up @@ -46,6 +49,9 @@ function SciMLBase.done(integrator::DummyIntegrator)
integrator.t > 10
end

SciMLBase.check_error(::DummyIntegrator) = ReturnCode.Success
SciMLBase.postamble!(::DummyIntegrator) = nothing

integrator = DummyIntegrator()
@test step_dt!(integrator, 1.5) == 2
@test step_dt!(integrator, 1.5, true) == 1.5
Expand All @@ -62,3 +68,14 @@ for (uprev, tprev, u, t) in intervals(DummyIntegrator())
end
@test eltype(collect(intervals(DummyIntegrator()))) ==
Tuple{Vector{Float64}, Float64, Vector{Float64}, Float64}

@test integrator.sol.retcode == ReturnCode.Default
@test check_error(integrator) == ReturnCode.Success
@test integrator.sol.retcode == ReturnCode.Default
@test SciMLBase.check_error!(integrator) == ReturnCode.Success
@test integrator.sol.retcode == ReturnCode.Success

let
integrator = DummyIntegrator()
@test 0 == @allocated SciMLBase.check_error!(integrator)
end

0 comments on commit 9e92fc6

Please sign in to comment.