-
-
Notifications
You must be signed in to change notification settings - Fork 233
Description
Describe the bug 🐞
Stream connector equations are present when used to connect connectors directly, but absent when used in a submodel.
Relatedly, I have (not shared, not MWE'ed) model code with only two components connected via stream
, that unexpectedly fails, but succeeds when the connector type is across
.
Expected behavior
Stream equations should be there.
A system of two components connected via across
should be equivalent to a connection via stream
(AFAIK!)
Minimal Reproducible Example 👇
From https://discourse.julialang.org/t/stream-connections-of-subsystems/121279, by @se-schmitt. See also SciML/ProcessSimulator.jl#17
using ModelingToolkit
using ModelingToolkit: t_nounits as t
@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 mysys = Sys()
sys_exp = expand_connections(mysys)
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)
However, when the components are directly inside a single @mtkmodel
, the equations are there:
@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)
Another demonstration of the problem is that when taking out the , [connect = Stream]
part (making it across
), the number of equations for my_sys
grows by 1 (bad; stream
should have more equations), but shrinks by 1 for sys2
(as expected).
Environment (please complete the following information):
- Output of
using Pkg; Pkg.status()
MTK 9.49.0
- Output of
versioninfo()
Julia 1.10.5