Skip to content

Commit 75e50e5

Browse files
Revert DAEProblem initdt to original 1e-6*tdist formula and fix test tolerances
The DAEProblem ode_determine_initdt was inadvertently changed from 1e-6*tdist to 0.001*tdist in the initial StiffInitDt commit. This 1000x larger initial step caused chaotic divergence between SArray and Array DFBDF DAE solutions. Also updates the NonlinearSolve newton test to use proportional nf tolerance (2%) instead of absolute (+20), since exact nf counts depend on initial step size selection which differs between DefaultInitDt and StiffInitDt. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8763701 commit 75e50e5

3 files changed

Lines changed: 8 additions & 12 deletions

File tree

lib/OrdinaryDiffEqCore/src/initdt.jl

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -835,9 +835,8 @@ end
835835
return tdir * max(dtmin, min(h0, tdir * dtmax))
836836
end
837837

838-
# Simple initial step size for DAE problems: h = 0.001 * tdist.
838+
# Simple initial step size for DAE problems: h = 1e-6 * tdist.
839839
# Kept simple to avoid type issues with ComplexF64, ForwardDiff Duals, etc.
840-
# Based on IDA from SUNDIALS (Hindmarsh et al., 2005).
841840
@inline function ode_determine_initdt(
842841
u0, t, tdir, dtmax, abstol, reltol, internalnorm,
843842
prob::SciMLBase.AbstractDAEProblem{
@@ -847,13 +846,8 @@ end
847846
integrator
848847
) where {duType, uType, tType}
849848
_tType = eltype(tType)
850-
dtmin = nextfloat(max(integrator.opts.dtmin, eps(t)))
851849
tspan = prob.tspan
852-
tdist = abs(tspan[2] - tspan[1])
853-
tdist = isfinite(tdist) ? tdist : oneunit(_tType)
854-
855-
h = convert(_tType, 1 // 1000) * tdist
856-
h = max(h, dtmin)
857-
h = min(h, tdir * dtmax)
858-
return tdir * h
850+
init_dt = abs(tspan[2] - tspan[1])
851+
init_dt = isfinite(init_dt) ? init_dt : oneunit(_tType)
852+
return convert(_tType, init_dt * 1 // 10^(6))
859853
end

lib/OrdinaryDiffEqNonlinearSolve/test/newton_tests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ for prob in (prob_ode_lorenz, prob_ode_orego)
1616
reltol = 1.0e-12, abstol = 1.0e-12
1717
)
1818
@test sol2.retcode == SciMLBase.ReturnCode.Success
19-
@test sol2.stats.nf <= sol1.stats.nf + 20
19+
# BackTracking line search should not significantly increase nf count.
20+
# Use 2% tolerance since exact counts depend on initial step size selection.
21+
@test sol2.stats.nf <= ceil(Int, sol1.stats.nf * 1.02)
2022
end

test/interface/static_array_tests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,4 @@ prob = DAEProblem(g2, Array(du0), Array(u0), (0.0, 10.0))
294294
sol2 = solve(prob, DFBDF(autodiff = AutoFiniteDiff()), reltol = 1.0e-8, abstol = 1.0e-8)
295295

296296
@test all(iszero, sol1[:, 1] - sol2[:, 1])
297-
@test all(abs.(sol1[:, end] .- sol2[:, end]) .< 1e-4)
297+
@test all(abs.(sol1[:, end] .- sol2[:, end]) .< 1e-5)

0 commit comments

Comments
 (0)