@@ -676,23 +676,23 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::NonlinearSystem, u0map,
676
676
scc_cacheexprs = Dict{TypeT, Vector{Any}}[]
677
677
scc_eqs = Vector{Equation}[]
678
678
scc_obs = Vector{Equation}[]
679
+ # variables solved in previous SCCs
680
+ available_vars = Set ()
679
681
for (i, (escc, vscc)) in enumerate (zip (eq_sccs, var_sccs))
680
682
# subset unknowns and equations
681
683
_dvs = dvs[vscc]
682
684
_eqs = eqs[escc]
683
685
# get observed equations required by this SCC
684
- obsidxs = observed_equations_used_by (sys, _eqs)
686
+ union! (available_vars, _dvs)
687
+ obsidxs = observed_equations_used_by (sys, _eqs; available_vars)
685
688
# the ones used by previous SCCs can be precomputed into the cache
686
689
setdiff! (obsidxs, prevobsidxs)
687
690
_obs = obs[obsidxs]
691
+ union! (available_vars, getproperty .(_obs, (:lhs ,)))
688
692
689
693
# get all subexpressions in the RHS which we can precompute in the cache
690
694
# precomputed subexpressions should not contain `banned_vars`
691
695
banned_vars = Set {Any} (vcat (_dvs, getproperty .(_obs, (:lhs ,))))
692
- filter! (banned_vars) do var
693
- symbolic_type (var) != ArraySymbolic () ||
694
- all (j -> var[j] in banned_vars, eachindex (var))
695
- end
696
696
state = Dict ()
697
697
for i in eachindex (_obs)
698
698
_obs[i] = _obs[i]. lhs ~ subexpressions_not_involving_vars! (
@@ -753,9 +753,12 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::NonlinearSystem, u0map,
753
753
_obs = scc_obs[i]
754
754
cachevars = scc_cachevars[i]
755
755
cacheexprs = scc_cacheexprs[i]
756
+ available_vars = [dvs[reduce (vcat, var_sccs[1 : (i - 1 )]; init = Int[])];
757
+ getproperty .(
758
+ reduce (vcat, scc_obs[1 : (i - 1 )]; init = []), (:lhs ,))]
756
759
_prevobsidxs = vcat (_prevobsidxs,
757
- observed_equations_used_by (sys, reduce (vcat, values (cacheexprs); init = [])))
758
-
760
+ observed_equations_used_by (
761
+ sys, reduce (vcat, values (cacheexprs); init = []); available_vars))
759
762
if isempty (cachevars)
760
763
push! (explicitfuns, Returns (nothing ))
761
764
else
0 commit comments