`VectorContinuousCallback` not picking up threshold

Answered in https://github.com/SciML/DifferentialEquations.jl/issues/843. This was a “user error”. When you check the callback:

function extinction_affect!(integrator, event_idx)
    # loop again through all species
    @show integrator.u,event_idx
    for i in 1:4
        if event_idx == i
            integrator.u[i] = 0
        end
    end
    biomass_sim!(get_tmp_cache(integrator)[1], integrator.u, integrator.p, integrator.t)
    @show get_tmp_cache(integrator)[1]
end

It is definitely called and does exactly as intended.

(integrator.u, event_idx) = ([5.347462662161639, 5.731062469090074, 7.64667777801325, 0.05000000000000008], 4)
(get_tmp_cache(integrator))[1] = [-2.0231159499021523, -1.3369848518263594, -1.5954424894710222, -6.798261538038756]
(integrator.u, event_idx) = ([12.968499097445866, 30.506371944743357, 0.050000000000001314, -53.521085634736835], 3)
(get_tmp_cache(integrator))[1] = [4.676904953209599, 12.256522670471728, -2.0978067243405967, -20.548116814707996]

but what this also shows is that, even if u[4] = 0, du[4] < 0 and so it’s clear why it goes negative: that’s due to how the ODE is defined. You should flip a parameter or something to make the derivative = 0 if you want to keep it at zero past the callback point.

1 Like