34
34
35
35
alias_elimination (sys) = alias_elimination! (TearingState (sys; quick_cancel = true ))
36
36
function alias_elimination! (state:: TearingState )
37
+ # Main._state[] = state
37
38
sys = state. sys
38
39
complete! (state. structure)
39
40
ag, mm, updated_diff_vars = alias_eliminate_graph! (state)
@@ -616,12 +617,19 @@ function mark_processed!(processed, var_to_diff, v)
616
617
end
617
618
618
619
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
620
621
# subsystem of the system we're interested in.
621
622
#
622
623
nvars = ndsts (graph)
623
624
ag = AliasGraph (nvars)
624
625
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
625
633
626
634
# Step 3: Handle differentiated variables
627
635
# 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)
711
719
end
712
720
for (i, v) in enumerate (level_to_var)
713
721
_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
+
714
734
v_eqs = 𝑑neighbors (graph, v)
715
735
# if an irreducible appears in only one equation, we need to make
716
736
# sure that the other variables don't get eliminated
@@ -722,12 +742,6 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
722
742
ag[v] = nothing
723
743
end
724
744
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
731
745
end
732
746
if nlevels < (new_nlevels = length (level_to_var))
733
747
for i in (nlevels + 1 ): new_nlevels
@@ -737,6 +751,10 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
737
751
end
738
752
end
739
753
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
740
758
741
759
if ! isempty (irreducibles)
742
760
ag = newag
0 commit comments