Hi, I have a system with two subsystems (which themself have two connectors with stream variables). I want to connect the connectors of the subsystem in the main system
using ModelingToolkit
using ModelingToolkit: t_nounits as t, scalarize
@connector TwoPhaseFluidPort begin
@variables begin
(h_outflow(t) = 0.0), [connect = Stream]
(m_flow(t) = 0.0), [connect = Flow]
P(t) = 0.0
end
end
@mtkmodel SubSys begin
@components begin
sp1 = TwoPhaseFluidPort()
sp2 = TwoPhaseFluidPort()
end
end
@mtkmodel Sys begin
@components begin
subsys = SubSys()
end
@equations begin
connect(subsys.sp1, subsys.sp2)
end
end
@named sys = Sys()
sys_exp = expand_connections(sys)
eqs = equations(sys_exp)
# Output:
# 2-element Vector{Equation}:
# 0 ~ subsys₊sp1₊m_flow(t) + subsys₊sp2₊m_flow(t)
# subsys₊sp1₊P(t) ~ subsys₊sp2₊P(t)
The stream equations are missing. They appear when I don’t use subsystems:
@mtkmodel Sys2 begin
@components begin
sp1 = TwoPhaseFluidPort()
sp2 = TwoPhaseFluidPort()
end
@equations begin
connect(sp1, sp2)
end
end
@named sys2 = Sys2()
sys2_exp = expand_connections(sys2)
eqs2 = equations(sys2_exp)
# Output:
# 6-element Vector{Equation}:
# sp1₊h_outflow(t) ~ ModelingToolkit.instream(sp2₊h_outflow(t))
# sp2₊h_outflow(t) ~ ModelingToolkit.instream(sp1₊h_outflow(t))
# 0 ~ sp1₊m_flow(t)
# 0 ~ sp2₊m_flow(t)
# 0 ~ -sp1₊m_flow(t) - sp2₊m_flow(t)
# sp1₊P(t) ~ sp2₊P(t)
Is this a bug or do I have to do sth differently?
I’m using Julia 1.10.5 with following package versions:
[961ee093] ModelingToolkit v9.46.1