Skip to content

Commit 6ce9e85

Browse files
fix: fix handling of SCC observed equations in SCCNonlinearProblem
1 parent 1febdae commit 6ce9e85

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::NonlinearSystem, u0map,
695695
scc_cachevars = Dict{TypeT, Vector{Any}}[]
696696
scc_cacheexprs = Dict{TypeT, Vector{Any}}[]
697697
scc_eqs = Vector{Equation}[]
698+
scc_obs = Vector{Equation}[]
698699
for (i, (escc, vscc)) in enumerate(zip(eq_sccs, var_sccs))
699700
# subset unknowns and equations
700701
_dvs = dvs[vscc]
@@ -708,10 +709,8 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::NonlinearSystem, u0map,
708709
# get all subexpressions in the RHS which we can precompute in the cache
709710
# precomputed subexpressions should not contain `banned_vars`
710711
banned_vars = Set{Any}(vcat(_dvs, getproperty.(_obs, (:lhs,))))
711-
for var in banned_vars
712-
iscall(var) || continue
713-
operation(var) === getindex || continue
714-
push!(banned_vars, arguments(var)[1])
712+
filter!(banned_vars) do var
713+
symbolic_type(var) != ArraySymbolic() || all(x -> var[i] in banned_vars, eachindex(var))
715714
end
716715
state = Dict()
717716
for i in eachindex(_obs)
@@ -762,15 +761,15 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::NonlinearSystem, u0map,
762761
push!(scc_cachevars, cachevars)
763762
push!(scc_cacheexprs, cacheexprs)
764763
push!(scc_eqs, _eqs)
764+
push!(scc_obs, _obs)
765765
blockpush!(prevobsidxs, obsidxs)
766766
end
767767

768768
for (i, (escc, vscc)) in enumerate(zip(eq_sccs, var_sccs))
769769
_dvs = dvs[vscc]
770770
_eqs = scc_eqs[i]
771-
obsidxs = prevobsidxs[Block(i)]
772771
_prevobsidxs = reduce(vcat, blocks(prevobsidxs)[1:(i - 1)]; init = Int[])
773-
_obs = obs[obsidxs]
772+
_obs = scc_obs[i]
774773
cachevars = scc_cachevars[i]
775774
cacheexprs = scc_cacheexprs[i]
776775

0 commit comments

Comments
 (0)