Skip to content

Commit d002a03

Browse files
committed
Compute complete_ag that contains irreducible alias information
```julia julia> @variables t x(t) y(t) z(t); julia> D = Differential(t) (::Differential) (generic function with 2 methods) julia> eqs = [x - y + 2 ~ 0; D(y) ~ 0; z - D(x) ~ 0]; @nAmed sys = ODESystem(eqs, t); julia> alias_elimination(sys); ┌ Info: └ vv => aa = Differential(t)(y(t)) => 0 ┌ Info: └ vv => aa = z(t) => Differential(t)(x(t)) ```
1 parent 3b16c9c commit d002a03

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/systems/alias_elimination.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ alias_elimination(sys) = alias_elimination!(TearingState(sys; quick_cancel = tru
3939
function alias_elimination!(state::TearingState)
4040
sys = state.sys
4141
complete!(state.structure)
42-
ag, mm, updated_diff_vars = alias_eliminate_graph!(state)
42+
ag, complete_ag, mm, updated_diff_vars = alias_eliminate_graph!(state)
4343
isempty(ag) && return sys
4444

4545
fullvars = state.fullvars
@@ -543,6 +543,7 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
543543
#
544544
nvars = ndsts(graph)
545545
ag = AliasGraph(nvars)
546+
complete_ag = AliasGraph(nvars)
546547
mm, echelon_mm = simple_aliases!(ag, graph, var_to_diff, mm_orig)
547548

548549
# Step 3: Handle differentiated variables
@@ -702,6 +703,7 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
702703
while (iv = diff_to_var[v]) in zero_vars_set
703704
v = iv
704705
end
706+
complete_ag[v] = 0
705707
if diff_to_var[v] === nothing # `v` is reducible
706708
dag[v] = 0
707709
end
@@ -729,6 +731,13 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
729731
# Step 4: Merge dag and ag
730732
removed_aliases = BitSet()
731733
merged_ag = AliasGraph(nvars)
734+
for (v, (c, a)) in dag
735+
complete_ag[v] = c => a
736+
end
737+
for (v, (c, a)) in ag
738+
(processed[v] || (!iszero(a) && processed[a])) && continue
739+
complete_ag[v] = c => a
740+
end
732741
for (v, (c, a)) in dag
733742
# D(x) ~ D(y) cannot be removed if x and y are not aliases
734743
if v != a && !iszero(a)
@@ -789,7 +798,7 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
789798
update_graph_neighbors!(graph, ag)
790799
end
791800

792-
return ag, mm, updated_diff_vars
801+
return ag, complete_ag, mm, updated_diff_vars
793802
end
794803

795804
function update_graph_neighbors!(graph, ag)

0 commit comments

Comments
 (0)