Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the solvers work for actual DAEProblems #284

Open
nathanaelbosch opened this issue Jan 4, 2024 · 0 comments
Open

Make the solvers work for actual DAEProblems #284

nathanaelbosch opened this issue Jan 4, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@nathanaelbosch
Copy link
Owner

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")
    end

I'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)
end

and 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.

@nathanaelbosch nathanaelbosch added the enhancement New feature or request label Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant