Skip to content

Commit ac1eda7

Browse files
committed
Update both graph and solvable_graph in substitute_vars! together
1 parent f628e55 commit ac1eda7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/structural_transformation/symbolics_tearing.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ function solve_equation(eq, var, simplify)
137137
var ~ rhs
138138
end
139139

140-
function substitute_vars!(graph::BipartiteGraph, subs, cache = Int[], callback! = nothing;
140+
function substitute_vars!(structure, subs, cache = Int[], callback! = nothing;
141141
exclude = ())
142+
@unpack graph, solvable_graph = structure
142143
for su in subs
143144
su === nothing && continue
144145
v, v′ = su
@@ -150,10 +151,15 @@ function substitute_vars!(graph::BipartiteGraph, subs, cache = Int[], callback!
150151
eq in exclude && continue
151152
rem_edge!(graph, eq, v)
152153
add_edge!(graph, eq, v′)
154+
155+
if BipartiteEdge(eq, v) in solvable_graph
156+
rem_edge!(solvable_graph, eq, v)
157+
add_edge!(solvable_graph, eq, v′)
158+
end
153159
callback! !== nothing && callback!(eq, su)
154160
end
155161
end
156-
graph
162+
return structure
157163
end
158164

159165
function to_mass_matrix_form(neweqs, ieq, graph, fullvars, isdervar::F,
@@ -212,8 +218,8 @@ end
212218
=#
213219

214220
function tearing_reassemble(state::TearingState, var_eq_matching; simplify = false)
215-
@unpack fullvars, sys = state
216-
@unpack solvable_graph, var_to_diff, eq_to_diff, graph = state.structure
221+
@unpack fullvars, sys, structure = state
222+
@unpack solvable_graph, var_to_diff, eq_to_diff, graph = structure
217223

218224
neweqs = collect(equations(state))
219225
# substitution utilities
@@ -468,9 +474,7 @@ function tearing_reassemble(state::TearingState, var_eq_matching; simplify = fal
468474
if var_eq_matching[idx] isa Int
469475
var_eq_matching[x_t_idx] = var_eq_matching[idx]
470476
end
471-
substitute_vars!(graph, subidx, idx_buffer, sub_callback!;
472-
exclude = order_lowering_eqs)
473-
substitute_vars!(solvable_graph, subidx, idx_buffer;
477+
substitute_vars!(structure, subidx, idx_buffer, sub_callback!;
474478
exclude = order_lowering_eqs)
475479
end
476480
end

0 commit comments

Comments
 (0)