Skip to content

Commit

Permalink
fix out of place init dt for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Jan 16, 2017
1 parent e6a1cca commit 8769c76
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/initdt.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

function ode_determine_initdt{uType,tType,uEltypeNoUnits}(u0::uType,t::tType,tdir,dtmax,abstol,reltol::uEltypeNoUnits,internalnorm,f,order)
function ode_determine_initdt{tType,uType,F}(u0,t::tType,tdir,dtmax,abstol,reltol,internalnorm,prob::AbstractODEProblem{uType,tType,true,F},order)
f = prob.f
f₀ = similar(u0./t); f₁ = similar(u0./t); u₁ = similar(u0)
sk = abstol+abs.(u0)*reltol
d₀ = internalnorm(u0./sk)
Expand Down Expand Up @@ -28,11 +29,12 @@ function ode_determine_initdt{uType,tType,uEltypeNoUnits}(u0::uType,t::tType,tdi
dt = tdir*min(100dt₀,dt₁)
end

function ode_determine_initdt{uType<:Number,tType,uEltypeNoUnits}(u0::uType,t::tType,tdir,dtmax,abstol,reltol::uEltypeNoUnits,internalnorm,f,order)
function ode_determine_initdt{uType,tType,F}(u0::uType,t,tdir,dtmax,abstol,reltol,internalnorm,prob::AbstractODEProblem{uType,tType,false,F},order)
f = prob.f
sk = abstol+abs(u0)*reltol
d₀ = abs(u0/sk)
d₀ = internalnorm(u0/sk)
f₀ = f(t,u0)
d₁ = abs(f₀/sk)
d₁ = internalnorm(f₀/sk)
T0 = typeof(d₀)
T1 = typeof(d₁)
if d₀ < T0(1//10^(5)) || d₁ < T1(1//10^(5))
Expand All @@ -43,7 +45,7 @@ function ode_determine_initdt{uType<:Number,tType,uEltypeNoUnits}(u0::uType,t::t
dt₀ = min(dt₀,tdir*dtmax)
u₁ = u0 + tdir*dt₀*f₀
f₁ = f(t+tdir*dt₀,u₁)
d₂ = abs((f₁-f₀)./(abstol+abs(u0)*reltol))/dt₀*tType(1)
d₂ = internalnorm((f₁-f₀)./(abstol+abs(u0)*reltol))/dt₀*tType(1)
if max(d₁,d₂) <= T1(1//10^(15))
dt₁ = max(tType(1//10^(6)),dt₀*1//10^(3))
else
Expand Down
2 changes: 1 addition & 1 deletion src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function init{uType,tType,isinplace,algType<:OrdinaryDiffEqAlgorithm,F,recompile
tTypeNoUnits = typeof(recursive_one(t))

if dt == zero(dt) && adaptive
dt = tType(ode_determine_initdt(u0,t,tdir,dtmax,uEltype(abstol),uEltypeNoUnits(reltol),internalnorm,f,order))
dt = tType(ode_determine_initdt(u0,t,tdir,dtmax,uEltype(abstol),uEltypeNoUnits(reltol),internalnorm,prob,order))
end

if sign(dt)!=tdir && dt!=tType(0)
Expand Down
2 changes: 2 additions & 0 deletions test/ode/ode_inplace_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ alloc1 = @allocated sol = solve(prob_ode_large2Dlinear,Euler(),dt=1//2^(8),save_
alloc2 = @allocated sol2 = solve(prob_ode_large2Dlinear,Euler(),sol[:],sol.t,sol.k;dt=1//2^(8),save_timeseries=true)

@test alloc2 <= alloc1

sol =solve(prob,Tsit5())

0 comments on commit 8769c76

Please sign in to comment.