From 9a27d173a4840a52ec47521cea5d53090ac7df27 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 22 Dec 2017 11:32:35 -0800 Subject: [PATCH] use false position method --- src/callbacks.jl | 5 +++-- test/ode/ode_event_tests.jl | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/callbacks.jl b/src/callbacks.jl index cfa1a02589..5a7d4417df 100644 --- a/src/callbacks.jl +++ b/src/callbacks.jl @@ -106,7 +106,7 @@ function find_callback_time(integrator,callback) tmp = @view integrator.cache.tmp[callback.idxs] end end - find_zero = (Θ) -> begin + zero_func = (Θ) -> begin if typeof(integrator.cache) <: OrdinaryDiffEqMutableCache && !(typeof(callback.idxs) <: Number) ode_interpolant!(tmp,Θ,integrator,callback.idxs,Val{0}) else @@ -114,7 +114,8 @@ function find_callback_time(integrator,callback) end callback.condition(integrator.tprev+Θ*integrator.dt,tmp,integrator) end - Θ = prevfloat(prevfloat(fzero(find_zero,bottom_θ,top_Θ))) + Θ = prevfloat(prevfloat(find_zero(zero_func,(bottom_θ,top_Θ),FalsePosition(),abstol = callback.abstol/10))) + #Θ = prevfloat(prevfloat(fzero(zero_func,bottom_θ,top_Θ))) # 2 prevfloat guerentees that the new time is either 1 or 2 floating point # numbers just before the event, but not after. If there's a barrier # which is never supposed to be crossed, then this will ensure that diff --git a/test/ode/ode_event_tests.jl b/test/ode/ode_event_tests.jl index 0ff82781a2..58ffd1a975 100644 --- a/test/ode/ode_event_tests.jl +++ b/test/ode/ode_event_tests.jl @@ -163,7 +163,7 @@ terminate_callback2 = ContinuousCallback(condtion,nothing,affect2!,interp_points sol5 = solve(prob2,Vern7(),callback=terminate_callback2) -@test sol5[end][1] < 1.3e-12 +@test sol5[end][1] < 1.3e-10 @test sol5.t[end] ≈ 3*sqrt(50*2/9.81) condtion= function (t,u,integrator) # Event when event_f(t,u,k) == 0