Skip to content

Commit

Permalink
use false position method
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Dec 22, 2017
1 parent f9bd71c commit 9a27d17
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/callbacks.jl
Expand Up @@ -106,15 +106,16 @@ 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
tmp = ode_interpolant(Θ,integrator,callback.idxs,Val{0})
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
Expand Down
2 changes: 1 addition & 1 deletion test/ode/ode_event_tests.jl
Expand Up @@ -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
Expand Down

0 comments on commit 9a27d17

Please sign in to comment.