Skip to content

Commit cf33b30

Browse files
committed
make initial dt nothing
1 parent 2a43d9c commit cf33b30

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

lib/OrdinaryDiffEqCore/src/initdt.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@
103103
still works for matrix-free definitions of the mass matrix.
104104
=#
105105

106-
if prob.f.mass_matrix != I && (!(prob.f isa DynamicalODEFunction) ||
107-
any(mm != I for mm in prob.f.mass_matrix))
106+
if prob.f.mass_matrix !== I && (!(prob.f isa DynamicalODEFunction) ||
107+
any(mm !== I for mm in prob.f.mass_matrix))
108108
ftmp = zero(f₀)
109109
try
110110
integrator.alg.linsolve(ftmp, copy(prob.f.mass_matrix), f₀, true)

lib/OrdinaryDiffEqCore/src/solve.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ function SciMLBase.__init(
2929
!default_linear_interpolation(prob, alg),
3030
calck = (callback !== nothing && callback !== CallbackSet()) ||
3131
(dense) || !isempty(saveat), # and no dense output
32-
dt = isdiscretealg(alg) && isempty(tstops) ?
33-
eltype(prob.tspan)(1) : eltype(prob.tspan)(0),
32+
dt = nothing,
3433
dtmin = eltype(prob.tspan)(0),
3534
dtmax = eltype(prob.tspan)((prob.tspan[end] - prob.tspan[1])),
3635
force_dtmin = false,
@@ -127,7 +126,7 @@ function SciMLBase.__init(
127126
if (((!(alg isa OrdinaryDiffEqAdaptiveAlgorithm) &&
128127
!(alg isa OrdinaryDiffEqCompositeAlgorithm) &&
129128
!(alg isa DAEAlgorithm)) || !adaptive || !isadaptive(alg)) &&
130-
dt == tType(0) && isempty(tstops)) && dt_required(alg)
129+
isnothing(dt) && isempty(tstops)) && dt_required(alg)
131130
throw(ArgumentError("Fixed timestep methods require a choice of dt or choosing the tstops"))
132131
end
133132
if !isadaptive(alg) && adaptive
@@ -343,7 +342,7 @@ function SciMLBase.__init(
343342
alg_choice = _alg isa CompositeAlgorithm ? Int[] : nothing
344343

345344
if (!adaptive || !isadaptive(_alg)) && save_everystep && tspan[2] - tspan[1] != Inf
346-
if dt == 0
345+
if isnothing(dt)
347346
steps = length(tstops)
348347
else
349348
# For fixed dt, the only time dtmin makes sense is if it's smaller than eps().
@@ -400,14 +399,16 @@ function SciMLBase.__init(
400399
else
401400
uprev2 = uprev
402401
end
403-
402+
403+
_dt = isdiscretealg(alg) && isempty(tstops) ?
404+
eltype(prob.tspan)(1) : eltype(prob.tspan)(0)
404405
if prob isa DAEProblem
405406
cache = alg_cache(_alg, du, u, res_prototype, rate_prototype, uEltypeNoUnits,
406-
uBottomEltypeNoUnits, tTypeNoUnits, uprev, uprev2, f, t, dt,
407+
uBottomEltypeNoUnits, tTypeNoUnits, uprev, uprev2, f, t, _dt,
407408
reltol_internal, p, calck, Val(isinplace(prob)))
408409
else
409410
cache = alg_cache(_alg, u, rate_prototype, uEltypeNoUnits, uBottomEltypeNoUnits,
410-
tTypeNoUnits, uprev, uprev2, f, t, dt, reltol_internal, p, calck,
411+
tTypeNoUnits, uprev, uprev2, f, t, _dt, reltol_internal, p, calck,
411412
Val(isinplace(prob)))
412413
end
413414

@@ -494,8 +495,8 @@ function SciMLBase.__init(
494495
# we don't want to differentiate through eigenvalue estimation
495496
eigen_est = inv(one(tType))
496497
tprev = t
497-
dtcache = tType(dt)
498-
dtpropose = tType(dt)
498+
dtcache = tType(_dt)
499+
dtpropose = tType(_dt)
499500
iter = 0
500501
kshortsize = 0
501502
reeval_fsal = false
@@ -530,7 +531,7 @@ function SciMLBase.__init(
530531
typeof(opts), typeof(fsalfirst),
531532
typeof(last_event_error), typeof(callback_cache),
532533
typeof(initializealg), typeof(differential_vars)}(
533-
sol, u, du, k, t, tType(dt), f, p,
534+
sol, u, du, k, t, tType(_dt), f, p,
534535
uprev, uprev2, duprev, tprev,
535536
_alg, dtcache, dtchangeable,
536537
dtpropose, tdir, eigen_est, EEst,
@@ -596,7 +597,7 @@ function SciMLBase.__init(
596597
end
597598
end
598599

599-
handle_dt!(integrator)
600+
handle_dt!(integrator, dt)
600601
integrator
601602
end
602603

@@ -632,8 +633,8 @@ end
632633

633634
# Helpers
634635

635-
function handle_dt!(integrator)
636-
if iszero(integrator.dt) && integrator.opts.adaptive
636+
function handle_dt!(integrator, dt)
637+
if isnothing(dt) && integrator.opts.adaptive
637638
auto_dt_reset!(integrator)
638639
if sign(integrator.dt) != integrator.tdir && !iszero(integrator.dt) &&
639640
!isnan(integrator.dt)

0 commit comments

Comments
 (0)