Skip to content

Commit a5ec10c

Browse files
feat: ensure causal connectors generate causally ordered equations
1 parent 2426464 commit a5ec10c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/systems/connectors.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -780,11 +780,11 @@ function generate_connection_equations_and_stream_connections(
780780
inner_output = cvert
781781
end
782782
end
783-
root, rest = Iterators.peel(cset)
784-
root_var = variable_from_vertex(sys, root)
785-
for cvert in rest
786-
var = variable_from_vertex(sys, cvert)
787-
push!(eqs, root_var ~ var)
783+
root_vert = something(inner_output, outer_input)
784+
root_var = variable_from_vertex(sys, root_vert)
785+
for cvert in cset
786+
isequal(cvert, root_vert) && continue
787+
push!(eqs, variable_from_vertex(sys, cvert) ~ root_var)
788788
end
789789
elseif vtype === Stream
790790
push!(stream_connections, cset)

test/components.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,12 @@ end
335335
sys = complete(outer)
336336
@test getmetadata(sys, Int, nothing) == "test"
337337
end
338+
339+
@testset "Causal connections generate causal equations" begin
340+
@named input = RealInput()
341+
@named output = RealOutput()
342+
@named sys = System([connect(output, input)], t; systems = [input, output])
343+
eq = only(equations(expand_connections(sys)))
344+
# as opposed to `output.u ~ input.u`
345+
@test isequal(eq, input.u ~ output.u)
346+
end

0 commit comments

Comments
 (0)