Skip to content
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

Handle vector valued variables correctly in get_connection_type #1895

Merged
merged 5 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/systems/connectors.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
get_connection_type(s) = getmetadata(unwrap(s), VariableConnectType, Equality)
function get_connection_type(s)
s = unwrap(s)
if istree(s) && operation(s) === getindex
s = arguments(s)[1]
end
getmetadata(s, VariableConnectType, Equality)
end

function with_connector_type(expr)
@assert expr isa Expr && (expr.head == :function || (expr.head == :(=) &&
Expand Down
12 changes: 11 additions & 1 deletion test/stream_connectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,19 @@ end

@named simple = ODESystem([connect(vp1, vp2, vp3)], t)
sys = expand_connections(compose(simple, [vp1, vp2, vp3]))
@test sort(equations(sys), by = string) == sort([vp1.v[1] ~ vp2.v[1]
@test sort(equations(sys), by = string) == sort([0 .~ collect(vp1.i)
0 .~ collect(vp2.i)
0 .~ collect(vp3.i)
vp1.v[1] ~ vp2.v[1]
vp1.v[2] ~ vp2.v[2]
vp1.v[1] ~ vp3.v[1]
vp1.v[2] ~ vp3.v[2]
0 ~ -vp1.i[1] - vp2.i[1] - vp3.i[1]
0 ~ -vp1.i[2] - vp2.i[2] - vp3.i[2]], by = string)

@connector function VectorHeatPort(; name, N = 100, T0 = 0.0, Q0 = 0.0)
@variables (T(t))[1:N]=T0 (Q(t))[1:N]=Q0 [connect = Flow]
ODESystem(Equation[], t, [T; Q], []; name = name)
end

@test_nowarn @named a = VectorHeatPort()