I tried the very most basic forced DAE I could think of and implemented an RC-circuit:
using Sundials
using OrdinaryDiffEq
using Test
u(t) = t < 0.5 ? 0.0 : 1.0
p = (R=1.0, C=1.0)
righthandside = (out, dx, x, p, t) -> begin # simple RC circuit DAE
# x: [v_C, v_R, i_C, i_R]
out[1] = 1 / p.C * x[3] - dx[1] # dv_C/dt = i_C/C
out[2] = x[2] - p.R * x[4] # v_R - R*i_R = 0 (Standard Ohm's law)
out[3] = x[1] + x[2] - u(t) # v_C + v_R - u(t) = 0
out[4] = x[3] - x[4] # i_C - i_R = 0 (Series current equality)
return out
end
prob = DAEProblem(
righthandside,
zeros(4), # initial state derivative
zeros(4), # initial state
(0.0, 10.0),
p;
differential_vars=[true, false, false, false],
)
integrator = init(prob, IDA(); reltol=1e-6, abstol=1e-6, initializealg=OrdinaryDiffEq.BrownFullBasicInit())
for t in range(0.0; stop=10.0, step=0.1)
step!(integrator, 0.1, true)
end
@test OrdinaryDiffEq.SciMLBase.successful_retcode(sol)
@test sol.t[end] ≈ 10.0
However, I get an error from the solver.
julia> include("dae.jl")
[ERROR][rank 0][/workspace/srcdir/sundials/src/idas/idas.c:5732][IDAHandleFailure] At t = 0.5 and h = 1.06658388718261e-17, the error test failed repeatedly or with |h| = hmin.
Test Passed
Is stepping the integrator manually to the discontinuity and using a callback not the same?