Skip to content

Commit 873f440

Browse files
Merge pull request #2493 from oscardssmith/os/fix-initdt
fix initdt calculation
2 parents de81afc + f152556 commit 873f440

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/OrdinaryDiffEqCore/src/initdt.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
oneunit_tType = oneunit(_tType)
99
dtmax_tdir = tdir * dtmax
1010

11-
dtmin = nextfloat(integrator.opts.dtmin)
12-
smalldt = convert(_tType, oneunit_tType * 1 // 10^(6))
11+
dtmin = nextfloat(max(integrator.opts.dtmin, eps(t)))
12+
smalldt = max(dtmin, convert(_tType, oneunit_tType * 1 // 10^(6)))
1313

1414
if integrator.isdae
1515
return tdir * max(smalldt, dtmin)
@@ -235,8 +235,8 @@ end
235235
oneunit_tType = oneunit(_tType)
236236
dtmax_tdir = tdir * dtmax
237237

238-
dtmin = nextfloat(integrator.opts.dtmin)
239-
smalldt = convert(_tType, oneunit_tType * 1 // 10^(6))
238+
dtmin = nextfloat(max(integrator.opts.dtmin, eps(t)))
239+
smalldt = max(dtmin, convert(_tType, oneunit_tType * 1 // 10^(6)))
240240

241241
if integrator.isdae
242242
return tdir * max(smalldt, dtmin)

test/interface/ode_initdt_tests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@ sol = solve(prob, Rodas5())
6464
# test that dtmin is set based on timespan
6565
prob = ODEProblem((u, p, t) -> 1e20 * sin(1e20 * t), 0.1, (0, 1e-19))
6666
@test solve(prob, Tsit5()).retcode == ReturnCode.Success
67+
68+
#test that we are robust to u0=0, t0!=0
69+
integ = init(ODEProblem(((u,p,t)->u), 0f0, (20f0, 0f0)), Tsit5())
70+
@test abs(integ.dt) > eps(integ.t)
71+
integ = init(ODEProblem(((du,u,p,t)->du.=u), [0f0], (20f0, 0f0)), Tsit5())
72+
@test abs(integ.dt) > eps(integ.t)

0 commit comments

Comments
 (0)