Skip to content

Commit 32cd593

Browse files
committed
Add singular system test
1 parent b12c23c commit 32cd593

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/structural_transformation/utils.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ function check_consistency(s::SystemStructure)
7575
end
7676

7777
if !isempty(unassigned_var) || !is_balanced
78-
@error "The system is structurally singular! Here are the unmatched variables:" unassigned_var
79-
throw(InvalidSystemException(""))
78+
io = IOBuffer()
79+
Base.print_array(io, unassigned_var)
80+
unassigned_var_str = String(take!(io))
81+
errmsg = "The system is structurally singular! " *
82+
"Here are the problematic variables: \n" *
83+
unassigned_var_str
84+
throw(InvalidSystemException(errmsg))
8085
end
8186

8287
return nothing

test/reduction.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,16 @@ equations = [
228228

229229
@named sys = ODESystem(equations, t, [E, C, S, P], [k₁, k₂, k₋₁, E₀])
230230
@test_throws ModelingToolkit.InvalidSystemException structural_simplify(sys)
231+
232+
# Example 5 from Pantelides' original paper
233+
@parameters t
234+
params = collect(@parameters y1(t) y2(t))
235+
sts = collect(@variables x(t) u1(t) u2(t))
236+
D = Differential(t)
237+
eqs = [
238+
0 ~ x + sin(u1 + u2)
239+
D(x) ~ x + y1
240+
cos(x) ~ sin(y2)
241+
]
242+
@named sys = ODESystem(eqs, t, sts, params)
243+
@test_throws ModelingToolkit.InvalidSystemException structural_simplify(sys)

0 commit comments

Comments
 (0)