-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Currently the solvers can handle DAEs, as long as they are given as ODEProblems with a mass-matrix. But in principle DAEProblems should also work, so we should have this.
The main problem is that, as we rely on OrdinaryDiffEq.solve, algorithms can't actually solve both ODEs and DAEs:
https://github.com/SciML/OrdinaryDiffEq.jl/blob/f52a126fa713f1d2d9d5744af63775c2156701ff/src/solve.jl#L74-L80
if prob isa DiffEqBase.AbstractDAEProblem && alg isa OrdinaryDiffEqAlgorithm
error("You cannot use an ODE Algorithm with a DAEProblem")
end
if prob isa DiffEqBase.AbstractODEProblem && alg isa DAEAlgorithm
error("You cannot use an DAE Algorithm with a ODEProblem")
endI'm not sure what the best way out here would be. A hacky solution would be to transform each ODE problem into a DAE problem like this:
function ode2dae(prob::ODEProblem)
@assert isinplace(prob)
function dae!(resid, du, u, p, t)
prob.f(resid, u, p, t)
resid .-= du
end
du0 = similar(prob.u0)
prob.f(du0, prob.u0, prob.p, prob.tspan[1])
return DAEProblem(dae!, prob.du0, prob.u0, prob.tspan, prob.p)
endand then just make all the methods DAE solvers, but that would also be confusing to users.
The cleanest solution might be to change the OrdinaryDiffEq.jl check from alg isa OrdinaryDiffEqAlgorithm to can_solve(prob, alg) or something similar.