Skip to content
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
13 changes: 13 additions & 0 deletions lib/ModelingToolkitTearing/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,19 @@ end
@test length(ts.fullvars) == 2
end

@testset "`rm_eqs_vars!` allows removing variables with an anti-derivative" begin
@variables x(t)
@named sys = System([D(x) ~ 2x], t)
ts = TearingState(sys)
xidx = findfirst(isequal(x), ts.fullvars)::Int
dxidx = ts.structure.var_to_diff[xidx]::Int
eqidx = only(𝑑neighbors(ts.structure.graph, dxidx))::Int
StateSelection.rm_eqs_vars!(ts, [eqidx], [dxidx])
@test length(equations(ts)) == 0
@test length(ts.fullvars) == 1
@test ts.structure.var_to_diff[1] === nothing
end

@testset "Unknowns in underdetermined systems aren't counted twice" begin
@variables x[1:3]
@mtkcompile sys = System([x[1] ~ 2x[2]+3x[3], x[2]^3 + x[3]^3 - 9 ~ 0], [x[1], x[2], x[3]], []) fully_determined=false
Expand Down
1 change: 1 addition & 0 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ function default_rm_eqs_vars!(
vdiff = var_to_diff[v]
if vdiff isa Int
vdiff = old_to_new_var[vdiff]
vdiff > 0 || continue
end
new_var_to_diff[newv] = vdiff
end
Expand Down
Loading