@@ -45,13 +45,6 @@ function AdiabaticStraightPipe(; name,
45
45
46
46
eqns = Equation[]
47
47
48
- #=
49
- push!(eqns, port_a.P ~ port_b.P)
50
- push!(eqns, 0 ~ port_a.m_flow + port_b.m_flow)
51
- push!(eqns, port_b.h_outflow ~ instream(port_a.h_outflow))
52
- push!(eqns, port_a.h_outflow ~ instream(port_b.h_outflow))
53
- =#
54
-
55
48
push! (eqns, connect (port_a, port_b))
56
49
sys = ODESystem (eqns, t, vars, pars; name = name)
57
50
sys = compose (sys, subs)
101
94
@named pipe = AdiabaticStraightPipe ()
102
95
@named sink = MassFlowSource_h (m_flow_in = - 0.01 , h_in = 400e3 )
103
96
104
- streams_a = [n1m1. port_a, pipe. port_a]
105
- streams_b = [pipe. port_b, sink. port]
106
-
107
97
eqns = [connect (n1m1. port_a, pipe. port_a)
108
98
connect (pipe. port_b, sink. port)]
109
99
110
100
@named sys = ODESystem (eqns, t)
111
101
@named n1m1Test = compose (sys, n1m1, pipe, sink)
112
102
@test_nowarn structural_simplify (n1m1Test)
103
+ @unpack source, port_a = n1m1
104
+ @test sort (equations (expand_connections (n1m1)), by = string) == [0 ~ port_a. m_flow
105
+ 0 ~ source. port1. m_flow - port_a. m_flow
106
+ source. port1. P ~ port_a. P
107
+ source. port1. P ~ source. P
108
+ source. port1. h_outflow ~ port_a. h_outflow
109
+ source. port1. h_outflow ~ source. h]
110
+ @unpack port_a, port_b = pipe
111
+ @test sort (equations (expand_connections (pipe)), by = string) ==
112
+ [0 ~ - port_a. m_flow - port_b. m_flow
113
+ 0 ~ port_a. m_flow
114
+ 0 ~ port_b. m_flow
115
+ port_a. P ~ port_b. P
116
+ port_a. h_outflow ~ instream (port_b. h_outflow)
117
+ port_b. h_outflow ~ instream (port_a. h_outflow)]
118
+ @test sort (equations (expand_connections (sys)), by = string) ==
119
+ [0 ~ n1m1. port_a. m_flow + pipe. port_a. m_flow
120
+ 0 ~ pipe. port_b. m_flow + sink. port. m_flow
121
+ n1m1. port_a. P ~ pipe. port_a. P
122
+ pipe. port_b. P ~ sink. port. P]
123
+ @test sort (equations (expand_connections (n1m1Test)), by = string) ==
124
+ [0 ~ - pipe. port_a. m_flow - pipe. port_b. m_flow
125
+ 0 ~ n1m1. port_a. m_flow + pipe. port_a. m_flow
126
+ 0 ~ n1m1. source. port1. m_flow - n1m1. port_a. m_flow
127
+ 0 ~ pipe. port_b. m_flow + sink. port. m_flow
128
+ n1m1. port_a. P ~ pipe. port_a. P
129
+ n1m1. source. port1. P ~ n1m1. port_a. P
130
+ n1m1. source. port1. P ~ n1m1. source. P
131
+ n1m1. source. port1. h_outflow ~ n1m1. port_a. h_outflow
132
+ n1m1. source. port1. h_outflow ~ n1m1. source. h
133
+ pipe. port_a. P ~ pipe. port_b. P
134
+ pipe. port_a. h_outflow ~ sink. port. h_outflow
135
+ pipe. port_b. P ~ sink. port. P
136
+ pipe. port_b. h_outflow ~ n1m1. port_a. h_outflow
137
+ sink. port. P ~ sink. P
138
+ sink. port. h_outflow ~ sink. h_in
139
+ sink. port. m_flow ~ - sink. m_flow_in]
113
140
114
141
# N1M2 model and test code.
115
142
function N1M2 (; name,
@@ -165,9 +192,6 @@ function N2M2(; name,
165
192
@named port_b = TwoPhaseFluidPort ()
166
193
@named pipe = AdiabaticStraightPipe ()
167
194
168
- streams_a = [port_a, pipe. port_a]
169
- streams_b = [pipe. port_b, port_b]
170
-
171
195
subs = [port_a; port_b; pipe]
172
196
173
197
eqns = Equation[]
@@ -190,6 +214,18 @@ eqns = [connect(source.port, n2m2.port_a)
190
214
@named n2m2Test = compose (sys, n2m2, source, sink)
191
215
@test_nowarn structural_simplify (n2m2Test)
192
216
217
+ # stream var
218
+ @named sp1 = TwoPhaseFluidPort ()
219
+ @named sp2 = TwoPhaseFluidPort ()
220
+ @named sys = ODESystem ([connect (sp1, sp2)], t)
221
+ sys_exp = expand_connections (compose (sys, [sp1, sp2]))
222
+ @test sort (equations (sys_exp), by = string) == [0 ~ - sp1. m_flow - sp2. m_flow
223
+ 0 ~ sp1. m_flow
224
+ 0 ~ sp2. m_flow
225
+ sp1. P ~ sp2. P
226
+ sp1. h_outflow ~ ModelingToolkit. instream (sp2. h_outflow)
227
+ sp2. h_outflow ~ ModelingToolkit. instream (sp1. h_outflow)]
228
+
193
229
# array var
194
230
@connector function VecPin (; name)
195
231
sts = @variables v (t)[1 : 2 ]= [1.0 , 0.0 ] i (t)[1 : 2 ]= 1.0 [connect = Flow]
0 commit comments