SciML / Sundials.jl

Julia interface to Sundials, including a nonlinear solver (KINSOL), ODE's (CVODE and ARKODE), and DAE's (IDA) in a SciML scientific machine learning enabled manner
https://diffeq.sciml.ai
BSD 2-Clause "Simplified" License
208 stars 78 forks source link

Using `saveat` with IDA results in derivatives with sharp discontinuities #452

Open topolarity opened 8 months ago

topolarity commented 8 months ago

Describe the bug 🐞

If saveat is provided to solve() when using IDA, the resulting derivative values appear to have strong discontinuities.

Minimal Reproducible Example 👇

julia> using OrdinaryDiffEq, Sundials, Plots
julia> dae_f(du, u, _, t) = [du[1] - u[2], u[2] - sin(t)]
julia> prob = DAEProblem(DAEFunction(dae_f), [0.0, 0.0], [0.0, 0.0], (0., 2π), nothing,
                         differential_vars=[true,false], abstol=1e-6, reltol=1e-1)
julia> sol = solve(prob, IDA(), saveat=.01)
julia> plot(sol(sol.t, Val{1}))
image

Environment (please complete the following information):

  [459566f4] DiffEqCallbacks v2.36.1
⌃ [1dea7af3] OrdinaryDiffEq v6.70.0
  [c3572dad] Sundials v4.23.2

Additional context

Kudos to @oscardssmith for finding this one.

topolarity commented 8 months ago

Without saveat the interpolation is also quite cursed:

julia> sol = solve(prob, IDA())
julia> t′ = 0.0:1e-3:2π
julia> plot(sol(t′, Val{1}))
image
ChrisRackauckas commented 8 months ago

This seems pretty inherent to Sundials since we don't (can't?) recreate its internal polynomial.