Skip to content

Commit b3c3016

Browse files
fix: handle edge case in trivial_tearing!
1 parent 3425e1e commit b3c3016

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/systems/systemstructure.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ function trivial_tearing!(ts::TearingState)
635635
matched_vars = BitSet()
636636
# variable to index in fullvars
637637
var_to_idx = Dict{Any, Int}(ts.fullvars .=> eachindex(ts.fullvars))
638+
sys_eqs = equations(ts)
638639

639640
complete!(ts.structure)
640641
var_to_diff = ts.structure.var_to_diff
@@ -654,6 +655,14 @@ function trivial_tearing!(ts::TearingState)
654655
push!(blacklist, i)
655656
continue
656657
end
658+
# Edge case for `var ~ var` equations. They don't show up in the incidence
659+
# graph because `TearingState` makes them `0 ~ 0`, but they do cause `var`
660+
# to show up twice in `original_eqs` which fails the assertion.
661+
sys_eq = sys_eqs[i]
662+
if isequal(sys_eq.lhs, 0) && isequal(sys_eq.rhs, 0)
663+
continue
664+
end
665+
657666
# if a variable was the LHS of two trivial observed equations, we wouldn't have
658667
# included it in the list. Error if somehow it made it through.
659668
@assert !(vari in matched_vars)

0 commit comments

Comments
 (0)