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
6 changes: 6 additions & 0 deletions src/structural_transformation/symbolics_tearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,14 @@ function codegen_equation!(eg::EquationGenerator,
dx = D(simplify_shifts(fullvars[lv]))

neweq = make_differential_equation(var, dx, eq, total_sub)
# We will add `neweq.lhs` to `total_sub`, so any equation involving it won't be
# incident on it. Remove the edges incident on `iv` from the graph, and add
# the replacement vertices from `ieq` so that the incidence is still correct.
for e in 𝑑neighbors(graph, iv)
e == ieq && continue
for v in 𝑠neighbors(graph, ieq)
add_edge!(graph, e, v)
end
rem_edge!(graph, e, iv)
end

Expand Down
5 changes: 2 additions & 3 deletions src/systems/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,8 @@ end
Return the sparsity pattern of the jacobian of `sys` as a matrix.
"""
function jacobian_sparsity(sys::System)
# disable to fix https://github.com/SciML/ModelingToolkit.jl/issues/3871
#sparsity = torn_system_jacobian_sparsity(sys)
#sparsity === nothing || return sparsity
sparsity = torn_system_jacobian_sparsity(sys)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this related?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how jacobian_sparsity was prior to #3871. That PR commented out the use of torn_system_jacobian_sparsity due to incorrect results. This PR fixes torn_system_jacobian_sparsity, which means we can use it again.

sparsity === nothing || return sparsity

Symbolics.jacobian_sparsity([eq.rhs for eq in full_equations(sys)],
[dv for dv in unknowns(sys)])
Expand Down
6 changes: 6 additions & 0 deletions test/jacobiansparsity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,10 @@ end
prob = ODEProblem(sys, [x => 1.0, y => 0.0], (0.0, 1.0); jac = true, sparse = true)
sol = solve(prob, FBDF())
@test SciMLBase.successful_retcode(sol)
ts = ModelingToolkit.get_tearing_state(sys)
for ieq in 1:2
vars1 = ts.fullvars[ModelingToolkit.BipartiteGraphs.𝑠neighbors(ts.structure.graph, ieq)]
vars2 = ModelingToolkit.vars(equations(sys)[ieq])
@test issetequal(vars1, vars2)
end
end
Loading