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

Use DiffEqBase.check_error! #72

Merged
merged 1 commit into from
Apr 14, 2018
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/StochasticDiffEq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module StochasticDiffEq

import Base: linspace

import Base: start, next, done, eltype

import RandomNumbers: Xorshifts

using Reexport
Expand All @@ -31,7 +29,9 @@ module StochasticDiffEq
resize_non_user_cache!,deleteat_non_user_cache!,addat_non_user_cache!,
terminate!,get_du, get_dt,get_proposed_dt,set_proposed_dt!,
u_modified!,savevalues!,add_tstop!,add_saveat!,set_reltol!,
set_abstol!
set_abstol!, postamble!, last_step_failed

using DiffEqBase: check_error!

const CompiledFloats = Union{Float32,Float64}

Expand Down
34 changes: 4 additions & 30 deletions src/integrators/integrator_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,11 @@ end
end
end

last_step_failed(integrator::SDEIntegrator) =
integrator.last_stepfail && !integrator.opts.adaptive

@def sde_exit_condtions begin
if integrator.iter > integrator.opts.maxiters
if integrator.opts.verbose
warn("Max Iters Reached. Aborting")
end
postamble!(integrator)
integrator.sol = solution_new_retcode(integrator.sol,:MaxIters)
return integrator.sol
end
if !integrator.opts.force_dtmin && integrator.opts.adaptive && abs(integrator.dt) <= abs(integrator.opts.dtmin)
if integrator.opts.verbose
warn("dt <= dtmin. Aborting. If you would like to force continuation with dt=dtmin, set force_dtmin=true")
end
postamble!(integrator)
integrator.sol = solution_new_retcode(integrator.sol,:DtLessThanMin)
return integrator.sol
end
if integrator.opts.unstable_check(integrator.dt,integrator.u,integrator.p,integrator.t)
if integrator.opts.verbose
warn("Instability detected. Aborting")
end
postamble!(integrator)
integrator.sol = solution_new_retcode(integrator.sol,:Unstable)
return integrator.sol
end
if integrator.last_stepfail && !integrator.opts.adaptive # Only false if doubled
if integrator.opts.verbose
warn("Newton steps could not converge and algorithm is not adaptive. Use a lower dt.")
end
postamble!(integrator)
integrator.sol = solution_new_retcode(integrator.sol,:ConvergenceFailure)
if check_error!(integrator) != :Success
return integrator.sol
end
end
Expand Down
50 changes: 0 additions & 50 deletions src/iterator_interface.jl
Original file line number Diff line number Diff line change
@@ -1,51 +1,3 @@
function start(integrator::SDEIntegrator)
0
end

@inline function next(integrator::SDEIntegrator,state)
state += 1
step!(integrator) # Iter updated in the step! header
# Next is callbacks -> iterator -> top
integrator,state
end

done(integrator::SDEIntegrator) = done(integrator,integrator.iter)

@inline function done(integrator::SDEIntegrator,state)
if integrator.iter > integrator.opts.maxiters
if integrator.opts.verbose
warn("Interrupted. Larger maxiters is needed.")
end
postamble!(integrator)
return true
end
if integrator.opts.unstable_check(integrator.dt,integrator.u,integrator.p,integrator.t)
if integrator.opts.verbose
warn("Instability detected. Aborting")
end
postamble!(integrator)
return true
end
if !integrator.opts.force_dtmin && integrator.opts.adaptive && abs(integrator.dt) <= abs(integrator.opts.dtmin)
if integrator.opts.verbose
warn("dt <= dtmin. Aborting. If you would like to force continuation with dt=dtmin, set force_dtmin=true")
end
postamble!(integrator)
return true
end
if isempty(integrator.opts.tstops)
postamble!(integrator)
return true
elseif integrator.just_hit_tstop
integrator.just_hit_tstop = false
if integrator.opts.stop_at_next_tstop
postamble!(integrator)
return true
end
end
false
end

@inline function step!(integrator::SDEIntegrator)
if integrator.opts.advance_to_tstop
@inbounds while integrator.tdir*integrator.t < integrator.tdir*top(integrator.opts.tstops)
Expand All @@ -65,5 +17,3 @@ end
end
@inbounds handle_tstop!(integrator)
end

eltype(integrator::SDEIntegrator) = typeof(integrator)