Skip to content

Commit df13e04

Browse files
committed
Fix diffeq handling in tearing_reassemble
1 parent a2111de commit df13e04

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/structural_transformation/symbolics_tearing.jl

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,6 @@ function tearing_reassemble(state::TearingState, var_eq_matching; simplify=false
145145
# if var is like D(x)
146146
isdiffvar(var) = invview(var_to_diff)[var] !== nothing && var_eq_matching[invview(var_to_diff)[var]] === SelectedState()
147147

148-
diffeqs = Equation[]
149-
# Solve solvable equations
150-
for (iv, ieq) in enumerate(var_eq_matching)
151-
is_solvable(ieq, iv) || continue
152-
# We don't solve differential equations, but we will need to try to
153-
# convert it into the mass matrix form.
154-
# We cannot solve the differential variable like D(x)
155-
if isdiffvar(iv)
156-
push!(diffeqs, solve_equation(neweqs[ieq], fullvars[iv], simplify))
157-
continue
158-
end
159-
push!(solved_equations, ieq); push!(solved_variables, iv)
160-
end
161-
162148
# Rewrite remaining equations in terms of solved variables
163149
function to_mass_matrix_form(ieq)
164150
eq = neweqs[ieq]
@@ -195,6 +181,22 @@ function tearing_reassemble(state::TearingState, var_eq_matching; simplify=false
195181
end
196182
end
197183

184+
diffeq_idxs = BitSet()
185+
diffeqs = Equation[]
186+
# Solve solvable equations
187+
for (iv, ieq) in enumerate(var_eq_matching)
188+
is_solvable(ieq, iv) || continue
189+
# We don't solve differential equations, but we will need to try to
190+
# convert it into the mass matrix form.
191+
# We cannot solve the differential variable like D(x)
192+
if isdiffvar(iv)
193+
push!(diffeqs, to_mass_matrix_form(ieq))
194+
push!(diffeq_idxs, ieq)
195+
continue
196+
end
197+
push!(solved_equations, ieq); push!(solved_variables, iv)
198+
end
199+
198200
if isempty(solved_equations)
199201
subeqs = Equation[]
200202
deps = Vector{Int}[]
@@ -214,7 +216,7 @@ function tearing_reassemble(state::TearingState, var_eq_matching; simplify=false
214216
# TODO: BLT sorting
215217
# Rewrite remaining equations in terms of solved variables
216218
solved_eq_set = BitSet(solved_equations)
217-
neweqs = Equation[to_mass_matrix_form(ieq) for ieq in 1:length(neweqs) if !(ieq in solved_eq_set)]
219+
neweqs = Equation[to_mass_matrix_form(ieq) for ieq in 1:length(neweqs) if !(ieq in diffeq_idxs || ieq in solved_eq_set)]
218220
filter!(!isnothing, neweqs)
219221
prepend!(neweqs, diffeqs)
220222

test/structural_transformation/index_reduction.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,4 @@ pendulum = ODESystem(eqs, t, [x, y, w, z, T], [L, g], name=:pendulum)
130130
let pss_pendulum = partial_state_selection(pendulum)
131131
# This currently selects `T` rather than `x` at top level. Needs tearing priorities to fix.
132132
@test_broken length(equations(pss_pendulum)) == 3
133-
@test_broken length(equations(ModelingToolkit.ode_order_lowering(pss_pendulum))) == 4
134133
end

0 commit comments

Comments
 (0)