Skip to content

Commit

Permalink
Merge pull request #553 from JuliaDiffEq/handle_dt
Browse files Browse the repository at this point in the history
Refactor dt handling
  • Loading branch information
devmotion committed Nov 4, 2018
2 parents c20a103 + 5299cb8 commit bd47c47
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/solve.jl
Expand Up @@ -325,19 +325,7 @@ function DiffEqBase.__init(
save_start && typeof(alg) <: CompositeAlgorithm && copyat_or_push!(alg_choice,1,integrator.cache.current)
end

if integrator.dt == zero(integrator.dt) && integrator.opts.adaptive
auto_dt_reset!(integrator)
if sign(integrator.dt)!=integrator.tdir && integrator.dt!=tType(0) && !isnan(integrator.dt)
error("Automatic dt setting has the wrong sign. Exiting. Please report this error.")
end
if isnan(integrator.dt)
if verbose
@warn("Automatic dt set the starting dt as NaN, causing instability.")
end
end
elseif integrator.opts.adaptive && integrator.dt > zero(integrator.dt) && integrator.tdir < 0
integrator.dt *= integrator.tdir # Allow positive dt, but auto-convert
end
handle_dt!(integrator)

integrator
end
Expand Down Expand Up @@ -367,6 +355,22 @@ end

# Helpers

function handle_dt!(integrator)
if iszero(integrator.dt) && integrator.opts.adaptive
auto_dt_reset!(integrator)
if sign(integrator.dt)!=integrator.tdir && !iszero(integrator.dt) && !isnan(integrator.dt)
error("Automatic dt setting has the wrong sign. Exiting. Please report this error.")
end
if isnan(integrator.dt)
if verbose
@warn("Automatic dt set the starting dt as NaN, causing instability.")
end
end
elseif integrator.opts.adaptive && integrator.dt > zero(integrator.dt) && integrator.tdir < 0
integrator.dt *= integrator.tdir # Allow positive dt, but auto-convert
end
end

function tstop_saveat_disc_handling(tstops,saveat,d_discontinuities,tdir,tspan,tType)

if isempty(d_discontinuities) && isempty(tstops) # TODO: Specialize more
Expand Down

0 comments on commit bd47c47

Please sign in to comment.