Skip to content

Commit 668e22f

Browse files
Fix handle_dt! for discrete solvers and backward compat
The two-arg handle_dt!(integrator, dt) must also check iszero(integrator.dt) before auto-resetting, since discrete solvers set _dt=1 even when dt=nothing. Also preserve the original one-arg handle_dt! with the old iszero(integrator.dt) check for backward compatibility with DelayDiffEq and other packages. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
1 parent 67bc8a6 commit 668e22f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/OrdinaryDiffEqCore/src/solve.jl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,26 @@ end
711711

712712
# Helpers
713713

714-
handle_dt!(integrator) = handle_dt!(integrator, nothing)
714+
function handle_dt!(integrator)
715+
return if iszero(integrator.dt) && integrator.opts.adaptive
716+
auto_dt_reset!(integrator)
717+
if sign(integrator.dt) != integrator.tdir && !iszero(integrator.dt) &&
718+
!isnan(integrator.dt)
719+
error("Automatic dt setting has the wrong sign. Exiting. Please report this error.")
720+
end
721+
if isnan(integrator.dt)
722+
@SciMLMessage(
723+
"Automatic dt set the starting dt as NaN, causing instability. Exiting.",
724+
integrator.opts.verbose, :dt_NaN
725+
)
726+
end
727+
elseif integrator.opts.adaptive && integrator.dt > zero(integrator.dt) &&
728+
integrator.tdir < 0
729+
integrator.dt *= integrator.tdir # Allow positive dt, but auto-convert
730+
end
731+
end
715732
function handle_dt!(integrator, dt)
716-
return if isnothing(dt) && integrator.opts.adaptive
733+
return if isnothing(dt) && iszero(integrator.dt) && integrator.opts.adaptive
717734
auto_dt_reset!(integrator)
718735
if sign(integrator.dt) != integrator.tdir && !iszero(integrator.dt) &&
719736
!isnan(integrator.dt)

0 commit comments

Comments
 (0)