Skip to content

Commit 0a5acd8

Browse files
committed
Remove the reduced_states field
1 parent cf85342 commit 0a5acd8

File tree

7 files changed

+10
-13
lines changed

7 files changed

+10
-13
lines changed

src/structural_transformation/StructuralTransformations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using ModelingToolkit: ODESystem, var_from_nested_derivative, Differential,
1616
states, equations, vars, Symbolic, diff2term, value,
1717
operation, arguments, Sym, Term, simplify, solve_for,
1818
isdiffeq, isdifferential,
19-
get_structure, get_reduced_states, defaults
19+
get_structure, defaults
2020

2121
using ModelingToolkit.BipartiteGraphs
2222
using ModelingToolkit.SystemStructures

src/structural_transformation/tearing.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ function tearing_reassemble(sys; simplify=false)
187187
@set! sys.structure = s
188188
@set! sys.eqs = neweqs
189189
@set! sys.states = newstates
190-
@set! sys.reduced_states = [get_reduced_states(sys); solvars]
191-
@set! sys.observed = vcat(observed(sys), obseqs)
190+
@set! sys.observed = [observed(sys); obseqs]
192191
return sys
193192
end
194193

src/systems/abstractsystem.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ for prop in [
153153
:inequality_constraints
154154
:controls
155155
:loss
156-
:reduced_states
157156
:bcs
158157
:domain
159158
:depvars
@@ -524,7 +523,7 @@ topological sort of the observed equations.
524523
"""
525524
function structural_simplify(sys::AbstractSystem)
526525
sys = tearing(alias_elimination(sys))
527-
fullstates = [get_reduced_states(sys); states(sys)]
526+
fullstates = [map(eq->eq.lhs, observed(sys)); states(sys)]
528527
@set! sys.observed = topsort_equations(observed(sys), fullstates)
529528
return sys
530529
end

src/systems/alias_elimination.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ function alias_elimination(sys)
2020
@unpack fullvars, graph = s
2121

2222
n_reduced_states = length(v_eliminated) - n_null_vars
23-
reduced_states = similar(v_eliminated, Any, n_reduced_states)
2423
subs = OrderedDict()
2524
if n_reduced_states > 0
2625
for (i, v) in enumerate(@view v_eliminated[n_null_vars+1:end])
27-
reduced_states[i] = fullvars[v]
2826
subs[fullvars[v]] = iszeroterm(v_types, v) ? 0.0 :
2927
isalias(v_types, v) ? fullvars[alias(v_types, v)] :
3028
-fullvars[negalias(v_types, v)]
@@ -67,8 +65,7 @@ function alias_elimination(sys)
6765

6866
@set! sys.eqs = eqs
6967
@set! sys.states = newstates
70-
@set! sys.reduced_states = [get_reduced_states(sys); reduced_states]
71-
@set! sys.observed = [get_observed(sys); [lhs ~ rhs for (lhs, rhs) in pairs(subs)]]
68+
@set! sys.observed = [observed(sys); [lhs ~ rhs for (lhs, rhs) in pairs(subs)]]
7269
@set! sys.structure = nothing
7370
return sys
7471
end

src/systems/diffeqs/odesystem.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ struct ODESystem <: AbstractODESystem
6969
structure: structural information of the system
7070
"""
7171
structure::Any
72-
reduced_states::Vector
7372
end
7473

7574
function ODESystem(
@@ -99,7 +98,7 @@ function ODESystem(
9998
if length(unique(sysnames)) != length(sysnames)
10099
throw(ArgumentError("System names must be unique."))
101100
end
102-
ODESystem(deqs, iv′, dvs′, ps′, observed, tgrad, jac, Wfact, Wfact_t, name, systems, defaults, nothing, [])
101+
ODESystem(deqs, iv′, dvs′, ps′, observed, tgrad, jac, Wfact, Wfact_t, name, systems, defaults, nothing)
103102
end
104103

105104
iv_from_nested_derivative(x::Term) = operation(x) isa Differential ? iv_from_nested_derivative(arguments(x)[1]) : arguments(x)[1]

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ struct NonlinearSystem <: AbstractSystem
4343
structure: structural information of the system
4444
"""
4545
structure::Any
46-
reduced_states::Any
4746
end
4847

4948
function NonlinearSystem(eqs, states, ps;
@@ -58,7 +57,7 @@ function NonlinearSystem(eqs, states, ps;
5857
end
5958
defaults = todict(defaults)
6059
defaults = Dict(value(k) => value(v) for (k, v) in pairs(defaults))
61-
NonlinearSystem(eqs, value.(states), value.(ps), observed, name, systems, defaults, nothing, [])
60+
NonlinearSystem(eqs, value.(states), value.(ps), observed, name, systems, defaults, nothing)
6261
end
6362

6463
function calculate_jacobian(sys::NonlinearSystem;sparse=false,simplify=false)

test/reduction.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ connected = ODESystem([s ~ a + lorenz1.x
8080
# Reduced Flattened System
8181

8282
reduced_system = structural_simplify(connected)
83+
reduced_system2 = structural_simplify(structural_simplify(structural_simplify(connected)))
8384

85+
@test isempty(setdiff(states(reduced_system), states(reduced_system2)))
86+
@test isequal(equations(reduced_system), equations(reduced_system2))
87+
@test isequal(observed(reduced_system), observed(reduced_system2))
8488
@test setdiff(states(reduced_system), [
8589
s
8690
a

0 commit comments

Comments
 (0)