Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor dt handling #553

Merged
merged 1 commit into from
Nov 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src/solve.jl
Original file line number Diff line number Diff line change
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