Skip to content

Commit 09ed407

Browse files
Throw an error if structural simplification is applied twice
Fixes #3012
1 parent 2937584 commit 09ed407

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/systems/systems.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ function System(eqs::AbstractVector{<:Equation}, iv, args...; name = nothing,
33
ODESystem(eqs, iv, args...; name, kw..., checks = false)
44
end
55

6+
const REPEATED_SIMPLIFICATION_MESSAGE = "Structural simplification cannot be applied to a completed system. Double simplification is not allowed."
7+
8+
struct RepeatedStructuralSimplificationError <: Exception end
9+
10+
function Base.showerror(io::IO, e::RepeatedStructuralSimplificationError)
11+
print(io, REPEATED_SIMPLIFICATION_MESSAGE)
12+
end
13+
614
"""
715
$(SIGNATURES)
816
@@ -21,6 +29,7 @@ function structural_simplify(
2129
sys::AbstractSystem, io = nothing; simplify = false, split = true,
2230
allow_symbolic = false, allow_parameter = true, conservative = false, fully_determined = true,
2331
kwargs...)
32+
iscomplete(sys) && throw(RepeatedStructuralSimplificationError())
2433
newsys′ = __structural_simplify(sys, io; simplify,
2534
allow_symbolic, allow_parameter, conservative, fully_determined,
2635
kwargs...)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using ModelingToolkit
2+
using ModelingToolkit: t_nounits as t, D_nounits as D
3+
using Test
4+
5+
@mtkmodel FOL begin
6+
@parameters begin
7+
τ = 3.0 # parameters
8+
end
9+
@variables begin
10+
x(t) = 0.0 # dependent variables
11+
end
12+
@equations begin
13+
D(x) ~ (1 - x) / τ
14+
end
15+
end
16+
17+
@named rc_model = ODESystem(rc_eqs, t; systems)
18+
sys = structural_simplify(rc_model)
19+
@test_throws ModelingToolkit.RepeatedStructuralSimplificationError structural_simplify(sys)

test/structural_transformation/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ end
1212
@safetestset "Bareiss" begin
1313
include("bareiss.jl")
1414
end
15+
@safetestset "Errors" begin
16+
include("errors.jl")
17+
end

0 commit comments

Comments
 (0)