Skip to content

Commit

Permalink
Merge pull request #2493 from oscardssmith/os/fix-initdt
Browse files Browse the repository at this point in the history
fix initdt calculation
  • Loading branch information
ChrisRackauckas authored Oct 12, 2024
2 parents de81afc + f152556 commit 873f440
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/OrdinaryDiffEqCore/src/initdt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
oneunit_tType = oneunit(_tType)
dtmax_tdir = tdir * dtmax

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

if integrator.isdae
return tdir * max(smalldt, dtmin)
Expand Down Expand Up @@ -235,8 +235,8 @@ end
oneunit_tType = oneunit(_tType)
dtmax_tdir = tdir * dtmax

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

if integrator.isdae
return tdir * max(smalldt, dtmin)
Expand Down
6 changes: 6 additions & 0 deletions test/interface/ode_initdt_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ sol = solve(prob, Rodas5())
# test that dtmin is set based on timespan
prob = ODEProblem((u, p, t) -> 1e20 * sin(1e20 * t), 0.1, (0, 1e-19))
@test solve(prob, Tsit5()).retcode == ReturnCode.Success

#test that we are robust to u0=0, t0!=0
integ = init(ODEProblem(((u,p,t)->u), 0f0, (20f0, 0f0)), Tsit5())
@test abs(integ.dt) > eps(integ.t)
integ = init(ODEProblem(((du,u,p,t)->du.=u), [0f0], (20f0, 0f0)), Tsit5())
@test abs(integ.dt) > eps(integ.t)

0 comments on commit 873f440

Please sign in to comment.