Skip to content

Commit c15a594

Browse files
fix callback proposed dt for direction
1 parent a4bbc55 commit c15a594

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/callbacks.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ end
766766
function apply_callback!(integrator,callback::Union{ContinuousCallback,VectorContinuousCallback},cb_time,prev_sign,event_idx)
767767

768768
if isadaptive(integrator)
769-
set_proposed_dt!(integrator, max(nextfloat(integrator.opts.dtmin), callback.dtrelax * integrator.dt))
769+
set_proposed_dt!(integrator, integrator.tdir * max(nextfloat(integrator.opts.dtmin), integrator.tdir * callback.dtrelax * integrator.dt))
770770
end
771771

772772
change_t_via_interpolation!(integrator,integrator.tprev+cb_time)

test/downstream/ode_event_tests.jl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ end
1818

1919
callback = ContinuousCallback(condition,affect!)
2020

21+
sol = solve(prob,Tsit5(),callback=callback)
22+
@test length(sol) < 20
23+
24+
condition= function (out, u,t,integrator) # Event when event_f(u,t,k) == 0
25+
out[1] = - t - 2.95
26+
end
27+
28+
affect! = function (integrator, idx)
29+
if idx == 1
30+
integrator.u = integrator.u + 2
31+
end
32+
end
33+
34+
callback = VectorContinuousCallback(condition,affect!,1)
35+
2136
sol = solve(prob,Tsit5(),callback=callback)
2237

2338
f = function (du,u,p,t)
@@ -260,7 +275,7 @@ end
260275
prob = ODEProblem(model, u0, tspan, perror)
261276
integrator = init(
262277
prob,
263-
Rosenbrock23();
278+
Rosenbrock23();
264279
callback=CallbackSet(
265280
PositiveDomain(),
266281
DiscreteCallback(condition, affect!),
@@ -272,4 +287,3 @@ integrator = init(
272287
)
273288

274289
sol = solve!(integrator)
275-

0 commit comments

Comments
 (0)