Skip to content

Commit 7a80a24

Browse files
authored
Merge pull request #1895 from SciML/myb/connector_type
Handle vector valued variables correctly in get_connection_type
2 parents 9952972 + cea9d83 commit 7a80a24

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/systems/connectors.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
get_connection_type(s) = getmetadata(unwrap(s), VariableConnectType, Equality)
1+
function get_connection_type(s)
2+
s = unwrap(s)
3+
if istree(s) && operation(s) === getindex
4+
s = arguments(s)[1]
5+
end
6+
getmetadata(s, VariableConnectType, Equality)
7+
end
28

39
function with_connector_type(expr)
410
@assert expr isa Expr && (expr.head == :function || (expr.head == :(=) &&

test/stream_connectors.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,19 @@ end
202202

203203
@named simple = ODESystem([connect(vp1, vp2, vp3)], t)
204204
sys = expand_connections(compose(simple, [vp1, vp2, vp3]))
205-
@test sort(equations(sys), by = string) == sort([vp1.v[1] ~ vp2.v[1]
205+
@test sort(equations(sys), by = string) == sort([0 .~ collect(vp1.i)
206+
0 .~ collect(vp2.i)
207+
0 .~ collect(vp3.i)
208+
vp1.v[1] ~ vp2.v[1]
206209
vp1.v[2] ~ vp2.v[2]
207210
vp1.v[1] ~ vp3.v[1]
208211
vp1.v[2] ~ vp3.v[2]
209212
0 ~ -vp1.i[1] - vp2.i[1] - vp3.i[1]
210213
0 ~ -vp1.i[2] - vp2.i[2] - vp3.i[2]], by = string)
214+
215+
@connector function VectorHeatPort(; name, N = 100, T0 = 0.0, Q0 = 0.0)
216+
@variables (T(t))[1:N]=T0 (Q(t))[1:N]=Q0 [connect = Flow]
217+
ODESystem(Equation[], t, [T; Q], []; name = name)
218+
end
219+
220+
@test_nowarn @named a = VectorHeatPort()

0 commit comments

Comments
 (0)