-
-
Notifications
You must be signed in to change notification settings - Fork 236
Closed
Description
In some cases when solving a model we have a differential-algebraic system of equations where two variables and have an initial condition of the form .
We created a thread in the Julia forum to ask how to input such initial condition in ModelingToolkit, and it was suggested to open an issue here.
Here's a MWE which returns an error:
using ModelingToolkit, DifferentialEquations
@variables t
D = Differential(t)
function system_f(; name)
@variables f(t) g(t)
eqs = [D(f) ~ g - f]
ODESystem(eqs; name)
end
function system_g(; name)
@variables g(t)
eqs = [g ~ t]
ODESystem(eqs; name)
end
@named f = system_f()
@named g = system_g()
connected_eqs = [
f.g ~ g.g,
]
@named _model = ODESystem(connected_eqs, t)
@named model = compose(_model, [f, g])
model = structural_simplify(model)
prob = ODEProblem(model, [f.f => g.g], (0.0, 10.0))
sol = solve(prob)If we replace the last two lines in the above block with the following ones, the code works, but the solution is clearly a workaround that could be improved:
pre_prob = ODEProblem(model, [f.f=>42,g.g=>42], (0.0, 10.0))
pre_sol = solve(pre_prob)
prob = ODEProblem(model, [f.f=>pre_sol[g.g, 1],g.g=>pre_sol[g.g, 1]], (0.0, 10.0))
sol = solve(prob)universmile
Metadata
Metadata
Assignees
Labels
No labels