Skip to content

Commit c48e49c

Browse files
committed
Zero aliased variables are reducible & leave some debug statements
1 parent 9687cb9 commit c48e49c

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/systems/alias_elimination.jl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ end
3434

3535
alias_elimination(sys) = alias_elimination!(TearingState(sys; quick_cancel = true))
3636
function alias_elimination!(state::TearingState)
37+
# Main._state[] = state
3738
sys = state.sys
3839
complete!(state.structure)
3940
ag, mm, updated_diff_vars = alias_eliminate_graph!(state)
@@ -616,12 +617,19 @@ function mark_processed!(processed, var_to_diff, v)
616617
end
617618

618619
function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
619-
# Step 1: Perform bareiss factorization on the adjacency matrix of the linear
620+
# Step 1: Perform Bareiss factorization on the adjacency matrix of the linear
620621
# subsystem of the system we're interested in.
621622
#
622623
nvars = ndsts(graph)
623624
ag = AliasGraph(nvars)
624625
mm = simple_aliases!(ag, graph, var_to_diff, mm_orig)
626+
# state = Main._state[]
627+
# fullvars = state.fullvars
628+
# for (v, (c, a)) in ag
629+
# a = a == 0 ? 0 : c * fullvars[a]
630+
# v = fullvars[v]
631+
# @info "simple alias" v => a
632+
# end
625633

626634
# Step 3: Handle differentiated variables
627635
# At this point, `var_to_diff` and `ag` form a tree structure like the
@@ -711,6 +719,18 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
711719
end
712720
for (i, v) in enumerate(level_to_var)
713721
_alias = get(ag, v, nothing)
722+
723+
# if a chain starts to equal to zero, then all its descendants must
724+
# be zero and reducible
725+
if _alias !== nothing && iszero(_alias[1])
726+
if i < length(level_to_var)
727+
# we have `x = 0`
728+
v = level_to_var[i + 1]
729+
extreme_var(var_to_diff, v, nothing, Val(false), callback = set_v_zero!)
730+
end
731+
break
732+
end
733+
714734
v_eqs = 𝑑neighbors(graph, v)
715735
# if an irreducible appears in only one equation, we need to make
716736
# sure that the other variables don't get eliminated
@@ -722,12 +742,6 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
722742
ag[v] = nothing
723743
end
724744
push!(irreducibles, v)
725-
if _alias !== nothing && iszero(_alias[1]) && i < length(level_to_var)
726-
# we have `x = 0`
727-
v = level_to_var[i + 1]
728-
extreme_var(var_to_diff, v, nothing, Val(false), callback = set_v_zero!)
729-
break
730-
end
731745
end
732746
if nlevels < (new_nlevels = length(level_to_var))
733747
for i in (nlevels + 1):new_nlevels
@@ -737,6 +751,10 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
737751
end
738752
end
739753
end
754+
# for (v, (c, a)) in ag
755+
# a = a == 0 ? 0 : c * fullvars[a]
756+
# @info "differential aliases" fullvars[v] => a
757+
# end
740758

741759
if !isempty(irreducibles)
742760
ag = newag

0 commit comments

Comments
 (0)