Open
Description
In the below example, I'm getting an error that appears to be about initialization. However, I can see that initialization works just fine. However, when I attempt to solve the problem I get an error, even when specifying the initial states.
MWE
using ModelingToolkit
using OrdinaryDiffEq
using Plots
using ModelingToolkit: D_nounits as D, t_nounits as t
L = 0.001
@mtkmodel System begin
@parameters begin
g = 9.807
rho = 1000
area = π*1^2
# pump
c_1 = 1*g*rho
c_2 = -10
power(t) = 0
end
@variables begin
p_1(t)
p_2(t)
h(t) = 10
flow_in(t), [guess=0]
flow_out(t)
end
@equations begin
# pump
# p_2 - p_1 ~ c_1*power + c_2*flow_in
(p_2 - p_1)*flow_in ~ power
# tank
p_2 ~ rho*g*h
D(h)*area ~ flow_in - flow_out
# inputs
p_1 ~ 0
flow_out ~ 100 * L
end
@continuous_events begin
[h ~ 5] => [power ~ 10]
[h ~ 10] => [power ~ 0]
end
end
@mtkbuild sys = System()
initsys = ModelingToolkit.generate_initializesystem(sys)
initsys = structural_simplify(initsys)
initprob = NonlinearProblem(initsys, [t=>0])
initsol = solve(initprob)
sts = unknowns(sys)
u0 = sts .=> initsol[sts]
prob = ODEProblem(sys, u0, (0, 3600))
sol = solve(prob) #ERROR: CheckInit specified but initialization not satisfied. normresid = 0.004765618901311116 > abstol = 1.0e-6