Skip to content

Commit

Permalink
refactor: rename SelectedState to SelectedUnknown
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Jan 29, 2024
1 parent 3150dab commit ff1382a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/structural_transformation/partial_state_selection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function pss_graph_modia!(structure::SystemStructure, maximal_top_matching, varl
# Find Strongly connected components. Note that after pantelides, we expect
# a balanced system, so a maximal matching should be possible.
var_sccs::Vector{Union{Vector{Int}, Int}} = find_var_sccs(graph, maximal_top_matching)
var_eq_matching = Matching{Union{Unassigned, SelectedState}}(ndsts(graph))
var_eq_matching = Matching{Union{Unassigned, SelectedUnknown}}(ndsts(graph))

Check warning on line 38 in src/structural_transformation/partial_state_selection.jl

View check run for this annotation

Codecov / codecov/patch

src/structural_transformation/partial_state_selection.jl#L38

Added line #L38 was not covered by tests
for vars in var_sccs
# TODO: We should have a way to not have the scc code look at unassigned vars.
if length(vars) == 1 && maximal_top_matching[vars[1]] === unassigned
Expand Down Expand Up @@ -71,7 +71,7 @@ function pss_graph_modia!(structure::SystemStructure, maximal_top_matching, varl
removed_vars = Int[]
for var in old_level_vars
old_assign = var_eq_matching[var]
if isa(old_assign, SelectedState)
if isa(old_assign, SelectedUnknown)

Check warning on line 74 in src/structural_transformation/partial_state_selection.jl

View check run for this annotation

Codecov / codecov/patch

src/structural_transformation/partial_state_selection.jl#L74

Added line #L74 was not covered by tests
push!(removed_vars, var)
continue
elseif !isa(old_assign, Int) ||
Expand Down Expand Up @@ -112,7 +112,7 @@ function pss_graph_modia!(structure::SystemStructure, maximal_top_matching, varl
for var in remaining_vars
if nlsolve_matching[var] === unassigned &&
var_eq_matching[var] === unassigned
var_eq_matching[var] = SelectedState()
var_eq_matching[var] = SelectedUnknown()

Check warning on line 115 in src/structural_transformation/partial_state_selection.jl

View check run for this annotation

Codecov / codecov/patch

src/structural_transformation/partial_state_selection.jl#L115

Added line #L115 was not covered by tests
end
end
end
Expand All @@ -125,7 +125,7 @@ function pss_graph_modia!(structure::SystemStructure, maximal_top_matching, varl
return complete(var_eq_matching)
end

struct SelectedState end
struct SelectedUnknown end
function partial_state_selection_graph!(structure::SystemStructure, var_eq_matching)
@unpack eq_to_diff, var_to_diff, graph, solvable_graph = structure
eq_to_diff = complete(eq_to_diff)
Expand Down Expand Up @@ -346,13 +346,13 @@ function tearing_with_dummy_derivatives(structure, dummy_derivatives)
end
var_eq_matching, full_var_eq_matching, var_sccs = tear_graph_modia(structure,
Base.Fix1(isdiffed, (structure, dummy_derivatives)),
Union{Unassigned, SelectedState};
Union{Unassigned, SelectedUnknown};
varfilter = Base.Fix1(getindex, can_eliminate))
for v in eachindex(var_eq_matching)
is_present(structure, v) || continue
dv = var_to_diff[v]
(dv === nothing || !is_some_diff(structure, dummy_derivatives, dv)) && continue
var_eq_matching[v] = SelectedState()
var_eq_matching[v] = SelectedUnknown()

Check warning on line 355 in src/structural_transformation/partial_state_selection.jl

View check run for this annotation

Codecov / codecov/patch

src/structural_transformation/partial_state_selection.jl#L355

Added line #L355 was not covered by tests
end
return var_eq_matching, full_var_eq_matching, var_sccs, can_eliminate
end
12 changes: 6 additions & 6 deletions src/structural_transformation/symbolics_tearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function substitution_graph(graph, slist, dlist, var_eq_matching)

newmatching = Matching(ns)
for (v, e) in enumerate(var_eq_matching)
(e === unassigned || e === SelectedState()) && continue
(e === unassigned || e === SelectedUnknown()) && continue

Check warning on line 21 in src/structural_transformation/symbolics_tearing.jl

View check run for this annotation

Codecov / codecov/patch

src/structural_transformation/symbolics_tearing.jl#L21

Added line #L21 was not covered by tests
iv = vrename[v]
ie = erename[e]
iv == 0 && continue
Expand Down Expand Up @@ -228,7 +228,7 @@ function tearing_reassemble(state::TearingState, var_eq_matching;
# A general DAE is in the form of `F(u'(t), u(t), p, t) == 0`. We can
# characterize variables in `u(t)` into two classes: differential variables
# (denoted `v(t)`) and algebraic variables (denoted `z(t)`). Differential
# variables are marked as `SelectedState` and they are differentiated in the
# variables are marked as `SelectedUnknown` and they are differentiated in the
# DAE system, i.e. `v'(t)` are all the variables in `u'(t)` that actually
# appear in the system. Algebraic variables are variables that are not
# differential variables.
Expand All @@ -255,7 +255,7 @@ function tearing_reassemble(state::TearingState, var_eq_matching;
for var in 1:length(fullvars)
dv = var_to_diff[var]
dv === nothing && continue
if var_eq_matching[var] !== SelectedState()
if var_eq_matching[var] !== SelectedUnknown()

Check warning on line 258 in src/structural_transformation/symbolics_tearing.jl

View check run for this annotation

Codecov / codecov/patch

src/structural_transformation/symbolics_tearing.jl#L258

Added line #L258 was not covered by tests
dd = fullvars[dv]
v_t = setio(diff2term(unwrap(dd)), false, false)
for eq in 𝑑neighbors(graph, dv)
Expand Down Expand Up @@ -283,7 +283,7 @@ function tearing_reassemble(state::TearingState, var_eq_matching;
end
end

# `SelectedState` information is no longer needed past here. State selection
# `SelectedUnknown` information is no longer needed past here. State selection
# is done. All non-differentiated variables are algebraic variables, and all
# variables that appear differentiated are differential variables.

Expand Down Expand Up @@ -567,10 +567,10 @@ function tearing(state::TearingState; kwargs...)
var_eq_matching′, = tear_graph_modia(state.structure;
varfilter = var -> var in algvars,
eqfilter = eq -> eq in aeqs)
var_eq_matching = Matching{Union{Unassigned, SelectedState}}(var_eq_matching′)
var_eq_matching = Matching{Union{Unassigned, SelectedUnknown}}(var_eq_matching′)

Check warning on line 570 in src/structural_transformation/symbolics_tearing.jl

View check run for this annotation

Codecov / codecov/patch

src/structural_transformation/symbolics_tearing.jl#L570

Added line #L570 was not covered by tests
for var in 1:ndsts(graph)
if isdiffvar(state.structure, var)
var_eq_matching[var] = SelectedState()
var_eq_matching[var] = SelectedUnknown()

Check warning on line 573 in src/structural_transformation/symbolics_tearing.jl

View check run for this annotation

Codecov / codecov/patch

src/structural_transformation/symbolics_tearing.jl#L573

Added line #L573 was not covered by tests
end
end
var_eq_matching
Expand Down
2 changes: 1 addition & 1 deletion src/systems/diffeqs/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct ODESystem <: AbstractODESystem
Dependent (unknown) variables. Must not contain the independent variable.
N.B.: If `torn_matching !== nothing`, this includes all variables. Actual
ODE unknowns are determined by the `SelectedState()` entries in `torn_matching`.
ODE unknowns are determined by the `SelectedUnknown()` entries in `torn_matching`.
"""
unknowns::Vector
"""Parameter variables. Must not contain the independent variable."""
Expand Down
2 changes: 1 addition & 1 deletion src/systems/systemstructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ function Base.show(io::IO, mime::MIME"text/plain", ms::MatchedSystemStructure)
printstyled(io, "(Unsolvable + Matched)", color = :magenta)
print(io, " | ")
printstyled(io, "", color = :cyan)
printstyled(io, " SelectedState")
printstyled(io, " SelectedUnknown")

Check warning on line 541 in src/systems/systemstructure.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/systemstructure.jl#L541

Added line #L541 was not covered by tests
end

# TODO: clean up
Expand Down

0 comments on commit ff1382a

Please sign in to comment.