OrdinaryDiffEq.jl
OrdinaryDiffEq.jl copied to clipboard
DABDF2() crashes when callbacks are introduced
using DifferentialEquations
function f(out,du,u,p,t)
out[1] = - 0.04u[1] + 1e4*u[2]*u[3] - du[1]
out[2] = + 0.04u[1] - 3e7*u[2]^2 - 1e4*u[2]*u[3] - du[2]
out[3] = u[1] + u[2] + u[3] - 1.0
end
u₀ = [1.0, 0, 0]
du₀ = [-0.04, 0.04, 0.0]
tspan = (0.0,100000.0)
differential_vars = [true,true,false]
prob = DAEProblem(f,du₀,u₀,tspan,differential_vars=differential_vars)
#define callback that stops integration when u[1] becomes 0.5
condition(u,time,integrator) = u[1] - 0.5
affect!(integrator) = terminate!(integrator)
cb = ContinuousCallback(condition,affect!)
sol = solve(prob,DABDF2(),callback = cb)
Results in error message:
MethodError: no method matching f(::Vector{Float64}, ::Vector{Float64}, ::SciMLBase.NullParameters, ::Float64) Closest candidates are: f(::Any, ::Any, ::Any, ::Any, ::Any)
This correctly works with the out of place version, so the issue seems to be isolated to in place calls. MWE below:
using DifferentialEquations
function f(du,u,p,t)
out = similar(u)
out[1] = - 0.04u[1] + 1e4*u[2]*u[3] - du[1]
out[2] = + 0.04u[1] - 3e7*u[2]^2 - 1e4*u[2]*u[3] - du[2]
out[3] = u[1] + u[2] + u[3] - 1.0
end
u₀ = [1.0, 0, 0]
du₀ = [-0.04, 0.04, 0.0]
tspan = (0.0,100000.0)
differential_vars = [true,true,false]
prob = DAEProblem(f,du₀,u₀,tspan,differential_vars=differential_vars)
#define callback that stops integration when u[1] becomes 0.5
condition(u,time,integrator) = u[1] - 0.5
affect!(integrator) = terminate!(integrator)
cb = ContinuousCallback(condition,affect!)
sol = solve(prob,DABDF2(),callback = cb)
Yeah the fix was a part of https://github.com/SciML/OrdinaryDiffEq.jl/pull/1105 but it never got merged. We'll need to finish that up.