Skip to content

Commit 2fa86b9

Browse files
Merge pull request #488 from SciML/has_tstops
add missing has_tstop interface function
2 parents 445c860 + 159a501 commit 2fa86b9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/integrators/integrator_interface.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ jac_iter(integrator::StochasticCompositeCache) = Iterators.flatten(jac_iter(c) f
7474
push!(integrator.opts.tstops, integrator.tdir * t)
7575
end
7676

77+
DiffEqBase.has_tstop(integrator::SDEIntegrator) = !isempty(integrator.opts.tstops)
78+
DiffEqBase.first_tstop(integrator::SDEIntegrator) = first(integrator.opts.tstops)
79+
DiffEqBase.pop_tstop!(integrator::SDEIntegrator) = pop!(integrator.opts.tstops)
7780

7881
function DiffEqBase.add_saveat!(integrator::SDEIntegrator,t)
7982
integrator.tdir * (t - integrator.t) < 0 && error("Tried to add a saveat that is behind the current time. This is strictly forbidden")

test/events_test.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,16 @@ cb = ContinuousCallback(condition2,affect2!,nothing);
104104
prob = SDEProblem(HM_neuron!,HM_noise!,x0,(0.0,1999.9),params);
105105
sol = solve(prob,ImplicitEM(),reltol = 1e-4, abstol = 1e-6,dense = true,callback=cb);
106106
sol = solve(prob,SKenCarp(),reltol = 1e-4, abstol = 1e-6,dense = true,callback=cb);
107+
108+
using DiffEqCallbacks
109+
110+
function f(du,u,p,t)
111+
du[1] = p[1] -u[1]
112+
end
113+
114+
function g(du,u,p,t)
115+
du[1] = p[2]
116+
end
117+
118+
sprob = SDEProblem(f,g,[1.0],(0.0,10.0),[1.0,0.1])
119+
sol = solve(sprob,ImplicitEM(),callback=PositiveDomain())

0 commit comments

Comments
 (0)