Hi All,
What is the magic that happens inside of the “ModelingToolkit.ODESystem”?
When I have the DAE system in the next form:
using DifferentialEquations, OrdinaryDiffEq, Sundials
u0 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
du0 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
t1 = [0.0:0.1:10.0;]
tspan = (t1[1], last(t1))
function dfdt(out, du, u, p, t)
out[1] = u[8] / 1.072
out[2] = u[9] / 0.2638
out[3] = u[10] / 1.682
out[4] = u[11] / 0.8365
out[5] = u[12] / 0.7265
out[6] = u[2] / 1.304
out[7] = u[4] / 0.8586
out[8] = u[10] + u[11] + u[7] - u[9] - u[6]
out[9] = u[1] - u[3] - u[2]
out[10] = u[3] - u[5] - u[4]
out[11] = u[8] + u[9] + u[6] - 1.0 + u[1]
out[12] = u[11] + u[7] - u[12] - u[5]
end
differential_vars = [true, true, true, true, true, true, true,
false, false, false, false, false]
prob = DAEProblem(dfdt, du0, u0, tspan, differential_vars=differential_vars)
sol = solve(prob, IDA())
I can’t get a reasonable solution.
The result:
[IDAS ERROR] IDACalcIC
Newton/Linesearch algorithm failed to converge.
retcode: InitialFailure
But when I use the ModelingToolkit:
using ModelingToolkit, DifferentialEquations,Sundials
@variables t x[1:12](t)
D = Differential(t)
eqs = [
D(x[1]) ~ x[8] / 1.072,
D(x[2]) ~ x[9] / 0.2638,
D(x[3]) ~ x[10] / 1.682,
D(x[4]) ~ x[11] / 0.8365,
D(x[5]) ~ x[12] / 0.7265,
D(x[6]) ~ x[2] / 1.304,
D(x[7]) ~ x[4] / 0.8586,
0 ~ x[10] + x[11] + x[7] - x[9] - x[6],
0 ~ x[1] - x[3] - x[2],
0 ~ x[3] - x[5] - x[4],
0 ~ x[8] + x[9] + x[6] - 1.0 + x[1],
0 ~ x[11] + x[7] - x[12] - x[5]
]
@named sys = ODESystem(eqs)
u0 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
du0 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
t1 = [0.0:0.1:10.0;]
tspan = (t1[1], last(t1))
prob = DAEProblem(sys, du0, u0, tspan)
sol = solve(prob, IDA())
I can get a reasonable result.
The solver (IDA()) and DAEs are absolutely the same.