Hello everyone,
I want to use CashKarp RK explicit algorithm (Numerical Recipe 2nd Edition RK) from Sundials.jl for my particular ODE system and need a discrete callback to do some manipulations after each time step.
https://sundials.readthedocs.io/en/latest/arkode/Butcher_link.html#cash-karp-6-4-5
J.R. Cash and A.H. Karp. A variable order Runge-Kutta method for initial value problems with rapidly varying right-hand sides. ACM Transactions on Mathematical Software, 16(3):201–222, 1990. doi:10.1145/79505.79507.
I am facing a bug when I am using Sundials (ARKODE) with the discrete callback. Following is the minimal code to reproduce the bug (I have modified the example from the Documentation and added a discrete callback).
using DifferentialEquations
using Sundials
function lorenz(du,u,p,t)
du[1] = 10.0(u[2]-u[1])
du[2] = u[1]*(28.0-u[3]) - u[2]
du[3] = u[1]*u[2] - (8/3)*u[3]
end
u0 = [1.0;0.0;0.0]
tspan = (0.0,100.0)
prob = ODEProblem(lorenz,u0,tspan)
condition(u, t, integrator) = true
function affect!(integrator)
@info "------------------------------------------------------------------"
end
cb = DiscreteCallback(condition, affect!)
alg = ARKODE(Sundials.Explicit(),etable = Sundials.CASH_KARP_6_4_5)
sol = solve(prob,alg;callback=cb)
using Plots; plot(sol,vars=(1,2,3))
The above minimal code gives the following error:
ERROR: MethodError: no method matching ARKStepReInit(::Sundials.Handle{…}, ::Nothing, ::ODEFunction{…}, ::Float64, ::Vector{…})
Closest candidates are:
ARKStepReInit(::Any, ::Ptr{Nothing}, ::Ptr{Nothing}, ::Any, ::Any)
@ Sundials ~/.julia/packages/Sundials/jrHAF/lib/libsundials_api.jl:42
ARKStepReInit(::Any, ::Ptr{Nothing}, ::Ptr{Nothing}, ::Float64, ::Union{Ptr{Sundials._generic_N_Vector}, Sundials.NVector})
@ Sundials ~/.julia/packages/Sundials/jrHAF/lib/libsundials_api.jl:35
I didn’t find the direct implementation of this algorithm in DifferentialEquations.jl and that’s why I want to use the Sundials interface.
Also, it seems that there is no unit test for ARKODE with callback in Sundials.jl unit tests …
Could anyone help me to fix the above bug? I am not sure if the above interface to call Sundials ARKODE is correct, maybe I am missing something …
Thanks