Skip to content

Commit 1326803

Browse files
committed
I think this now works as intended
1 parent d296135 commit 1326803

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/integrator_interface.jl

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -604,14 +604,15 @@ function check_error(integrator::DEIntegrator)
604604
# The last part:
605605
# Bail out if we take a step with dt less than the minimum value (which may be time dependent)
606606
# except if we are successfully taking such a small timestep is to hit a tstop exactly
607-
# We also exit if the ODE is unstable (by default this is the same as nonfinite u)
608-
# but only consider the ODE unstable if the error is somewhat controlled
609-
# (to prevent from bailing out as unstable when we just took way too big a step)
607+
# We also exit if the ODE is unstable acording to a user chosen callbakc
608+
# but only if we accepted the step to prevent from bailing out as unstable
609+
# when we just took way too big a step)
610+
step_accepted = !hasproperty(integrator, :accept_step) || integrator.accept_step
610611
if !opts.force_dtmin && opts.adaptive
611612
if abs(integrator.dt) <= abs(opts.dtmin) &&
612-
(((hasproperty(integrator, :opts) && hasproperty(opts, :tstops)) ?
613+
(!step_accepted || ((hasproperty(integrator, :opts) && hasproperty(opts, :tstops)) ?
613614
integrator.t + integrator.dt < integrator.tdir * first(opts.tstops) :
614-
true) || (hasproperty(integrator, :accept_step) && !integrator.accept_step))
615+
true))
615616
if verbose
616617
if isdefined(integrator, :EEst)
617618
EEst = ", and step error estimate = $(integrator.EEst)"
@@ -621,8 +622,7 @@ function check_error(integrator::DEIntegrator)
621622
@warn("dt($(integrator.dt)) <= dtmin($(opts.dtmin)) at t=$(integrator.t)$EEst. Aborting. There is either an error in your model specification or the true solution is unstable.")
622623
end
623624
return ReturnCode.DtLessThanMin
624-
elseif abs(integrator.dt) <= abs(eps(integrator.t)) &&
625-
hasproperty(integrator, :accept_step) && !integrator.accept_step
625+
elseif !step_accepted && integrator.t isa AbstractFloat && abs(integrator.dt) <= abs(eps(integrator.t))
626626
if verbose
627627
if isdefined(integrator, :EEst)
628628
EEst = ", and step error estimate = $(integrator.EEst)"
@@ -634,15 +634,11 @@ function check_error(integrator::DEIntegrator)
634634
return ReturnCode.Unstable
635635
end
636636
end
637-
bigtol = max(maximum(opts.reltol), maximum(opts.abstol))
638-
if isdefined(integrator, :EEst) && integrator.EEst * bigtol < .1
639-
if opts.unstable_check(integrator.dt, integrator.u, integrator.p,
640-
integrator.t)
641-
if verbose
642-
@warn("Instability detected. Aborting")
643-
end
644-
return ReturnCode.Unstable
637+
if step_accepted && opts.unstable_check(integrator.dt, integrator.u, integrator.p, integrator.t)
638+
if verbose
639+
@warn("Instability detected. Aborting")
645640
end
641+
return ReturnCode.Unstable
646642
end
647643
if last_step_failed(integrator)
648644
if verbose

0 commit comments

Comments
 (0)