SciML / DelayDiffEq.jl

Delay differential equation (DDE) solvers in Julia for the SciML scientific machine learning ecosystem. Covers neutral and retarded delay differential equations, and differential-algebraic equations.
Other
59 stars 26 forks source link

In DDEs constant_lags break PresetTimeCallback #205

Open laserschwelle opened 3 years ago

laserschwelle commented 3 years ago

I wanted to modulate a DDE system at equidistant points in time. But if the constant_lags=[τ] parameter is set some combinations of delay times and distance between modulations don't work. Not every point in tstops triggers the affect.

Here is a minimal example:

using DifferentialEquations

f(u,h,p,t) = 0
h(p, t) = 0.0

p = 0.3       # delay time
step = 0.04   # intervall for callbacks
num = 1000    # number of callbacks

end_time = step*num
tstops = step:step:end_time  # callback preset times

counter = 0
function affect!(integrator)
    integrator.u = rand()
    global counter += 1
end
cb = PresetTimeCallback(tstops,affect!)

st_length = length(tstops)
println("step_times length: $st_length")

prob_const_lag = DDEProblem(f,h,(0,end_time),p,constant_lags=[p])
solve(prob_const_lag,callback=cb);
println("#callbacks: $counter")

counter = 0
prob_without = DDEProblem(f,h,(0,end_time),p)
solve(prob_without,callback=cb);
println("#callbacks: $counter")

Note: For step = 0.123 the code runs as expected.