@@ -604,14 +604,15 @@ function check_error(integrator::DEIntegrator)
604
604
# The last part:
605
605
# Bail out if we take a step with dt less than the minimum value (which may be time dependent)
606
606
# 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
610
611
if ! opts. force_dtmin && opts. adaptive
611
612
if abs (integrator. dt) <= abs (opts. dtmin) &&
612
- (((hasproperty (integrator, :opts ) && hasproperty (opts, :tstops )) ?
613
+ (! step_accepted || ((hasproperty (integrator, :opts ) && hasproperty (opts, :tstops )) ?
613
614
integrator. t + integrator. dt < integrator. tdir * first (opts. tstops) :
614
- true ) || ( hasproperty (integrator, :accept_step ) && ! integrator . accept_step) )
615
+ true ))
615
616
if verbose
616
617
if isdefined (integrator, :EEst )
617
618
EEst = " , and step error estimate = $(integrator. EEst) "
@@ -621,8 +622,7 @@ function check_error(integrator::DEIntegrator)
621
622
@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." )
622
623
end
623
624
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))
626
626
if verbose
627
627
if isdefined (integrator, :EEst )
628
628
EEst = " , and step error estimate = $(integrator. EEst) "
@@ -634,15 +634,11 @@ function check_error(integrator::DEIntegrator)
634
634
return ReturnCode. Unstable
635
635
end
636
636
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" )
645
640
end
641
+ return ReturnCode. Unstable
646
642
end
647
643
if last_step_failed (integrator)
648
644
if verbose
0 commit comments