-
-
Notifications
You must be signed in to change notification settings - Fork 217
Stream connector equations missing when used in subsystem #3171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
MTK's connectors are designed according to https://specification.modelica.org/master/connectors-and-connections.html. This might be intentional behavior given that specification and the discussion in #3008. I'm working on figuring this out myself to provide a concrete reason for this behavior. |
This is intentional. In the "not working" example, both connectors are "inside connectors". The spec mentions:
Which justifies the missing stream equations. In the second example with 6 equations, the equations setting flow variables to zero comes from the fact that both connectors are outer connectors. Outer connectors are expected to connect to other components. If they were, those equations would not be generated. |
This confused me. In the standard
And indeed, in my own code, I had forgotten
that now succeeds, 👍 I'll close this, but if any of the above is mistaken, I'd appreciate a correction. Thank you for investigating! |
The definition of inside and outside connectors is in https://specification.modelica.org/master/connectors-and-connections.html#inside-and-outside-connectors. They are defined with respect to a component. |
Right, I understand this explanation for
suggests that we couldn't use stream connections in such a system. However it looks like this is not the correct interpretation, since
And indeed inside connectors that use |
How does one use instream? |
@cstjean Could you please share the code that makes it work? Where do you call instream? |
I'm sorry, I don't have code that I can easily share. Rapid sketch: @connector FluidPort begin
@variables begin
density(t) = 0.0, [connect = Stream]
mass_flow(t) = 0.0, [connect = Flow]
P(t) = 0.0 # you need that variable even if you don't use pressure
end
end
@mtkmodel Source begin
@components begin
outlet = FluidPort()
end
@equations begin
outlet.density ~ 0.8
outlet.m_flow ~ 10
end
end
@mtkmodel Tank begin
@components begin
inlet = FluidPort()
end
@variables begin
total_mass = 0
density = 0.3
end
@equations begin
D(total_mass) ~ inlet.mass_flow
D(density) ~ whatever + somethingsomething * instream(inlet.density) # instream is necessary for all uses of `inlet.density`
inlet.density ~ -99999 # this is often necessary for MTK :( It specifies the density during backflow. I set it to -99999 to detect problems (since I don't have backflows) but it's super wonky
end
end
@mtkmodel Sys begin
@components begin
source = Source()
tank = Tank()
end
@equations begin
connect(source.outlet, tank.inlet)
end
end I didn't run this, but hopefully it can give you a starting point. Getting to that basic system took me a lot of trial and error, it's not a polished part of MTK. |
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 isacross
.Expected behavior
Stream equations should be there.
A system of two components connected via
across
should be equivalent to a connection viastream
(AFAIK!)Minimal Reproducible Example 👇
From https://discourse.julialang.org/t/stream-connections-of-subsystems/121279, by @se-schmitt. See also SciML/ProcessSimulator.jl#17
However, when the components are directly inside a single
@mtkmodel
, the equations are there:Another demonstration of the problem is that when taking out the
, [connect = Stream]
part (making itacross
), the number of equations formy_sys
grows by 1 (bad;stream
should have more equations), but shrinks by 1 forsys2
(as expected).Environment (please complete the following information):
using Pkg; Pkg.status()
versioninfo()
The text was updated successfully, but these errors were encountered: