SciML / ModelingToolkit.jl

An acausal modeling framework for automatically parallelized scientific machine learning (SciML) in Julia. A computer algebra system for integrated symbolics for physics-informed machine learning and automated transformations of differential equations
https://mtk.sciml.ai/dev/
Other
1.42k stars 207 forks source link

Support for DAE's without differential terms #969

Closed tshort closed 8 months ago

tshort commented 3 years ago

Here's a basic example that fails during solving:

using ModelingToolkit, DifferentialEquations

@parameters t
D = Differential(t)
@variables x(t)

sys = structural_simplify(ODESystem([sin(t) ~ x^2], t))
prob = ODAEProblem(sys, [x => 0.0], (0, 5))
sol = solve(prob, Tsit5())

The error is:

julia> sol = solve(prob, Tsit5())
ERROR: StackOverflowError:
Stacktrace:
 [1] recursive_unitless_bottom_eltype(::Type{Any}) at C:\XXX\.julia\packages\RecursiveArrayTools\FMjdW\src\utils.jl:86 (repeats 65221 times)
tshort commented 3 years ago

This also fails:

using Sundials
sys = ODESystem([sin(t) ~ x^2], t)
sys = DAEProblem(sys, [D(x) => 0.0], [x => 0.0], (0, 5))
sol = solve(prob, IDA())
YingboMa commented 3 years ago

It's a NonlinearSystem

julia> prob = NonlinearProblem(sys, [1.0], [1.0])
NonlinearProblem with uType Vector{Float64}. In-place: true
u0: 1-element Vector{Float64}:
 1.0

julia> using NonlinearSolve

julia> solve(prob, NewtonRaphson())
u: 1-element Vector{Float64}:
 0.9173172760000521
ChrisRackauckas commented 3 years ago

I'll leave this open because technically we could handle this a bit nicer in the solvers, exiting early and all of that, but in any case the user has a workaround.

ChrisRackauckas commented 8 months ago

@oscardssmith opened enough issues that we got this working.