Skip to content

Commit 61bbffc

Browse files
committed
Change how we construct the graph by a bit
1 parent 0a5acd8 commit 61bbffc

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/systems/systemstructure.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ function initialize_system_structure(sys)
8989
end
9090
end
9191

92-
for (i, eq) in enumerate(eqs)
93-
vars = OrderedSet()
92+
vars = OrderedSet()
93+
for (i, eq′) in enumerate(eqs)
94+
if _iszero(eq′.lhs)
95+
eq = eq′
96+
else
97+
eq = 0 ~ eq′.rhs - eq′.lhs
98+
end
9499
vars!(vars, eq)
95100
isalgeq = true
96101
statevars = []
@@ -113,9 +118,10 @@ function initialize_system_structure(sys)
113118
end
114119
push!(symbolic_incidence, copy(statevars))
115120
empty!(statevars)
121+
empty!(vars)
116122
algeqs[i] = isalgeq
117-
if isalgeq && !_iszero(eq.lhs)
118-
eqs[i] = 0 ~ eq.rhs - eq.lhs
123+
if isalgeq
124+
eqs[i] = eq
119125
end
120126
end
121127

test/reduction.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ eqs1 = [
6767
lorenz = name -> ODESystem(eqs1,t,name=name)
6868
lorenz1 = lorenz(:lorenz1)
6969
ss = ModelingToolkit.get_structure(initialize_system_structure(lorenz1))
70-
@test isequal(ss.fullvars, [D(x), F, y, x, D(y), u, z, D(z)])
70+
@test isempty(setdiff(ss.fullvars, [D(x), F, y, x, D(y), u, z, D(z)]))
7171
lorenz2 = lorenz(:lorenz2)
7272

7373
connected = ODESystem([s ~ a + lorenz1.x
@@ -120,11 +120,11 @@ test_equal.(equations(reduced_system), reduced_eqs)
120120

121121
observed_eqs = [
122122
s ~ lorenz2.y
123-
lorenz2.u ~ -((lorenz2.z) - (lorenz2.x) - (lorenz2.y))
124-
lorenz1.u ~ -((lorenz1.z) - (lorenz1.x) - (lorenz1.y))
123+
lorenz1.F ~ -((lorenz2.z) - (lorenz2.x) - (lorenz2.y))
124+
lorenz2.F ~ -((lorenz1.z) - (lorenz1.x) - (lorenz1.y))
125125
a ~ s - (lorenz1.x)
126-
lorenz1.F ~ lorenz2.u
127-
lorenz2.F ~ lorenz1.u
126+
lorenz2.u ~ lorenz1.F
127+
lorenz1.u ~ lorenz2.F
128128
]
129129
test_equal.(observed(reduced_system), observed_eqs)
130130

@@ -165,8 +165,8 @@ let
165165
@test equations(connected) isa Vector{Equation}
166166
reduced_sys = structural_simplify(connected)
167167
ref_eqs = [
168-
D(ol.x) ~ ol.a*ol.x + ol.b*pc.u_c
169-
0 ~ -pc.u_c - (pc.k_P*((-ol.c*(ol.x)) - (ol.d*(pc.u_c))))
168+
D(ol.x) ~ ol.a*ol.x + ol.b*ol.u
169+
0 ~ -ol.u - (pc.k_P*(-ol.c*ol.x - (ol.d*ol.u)))
170170
]
171171
@test ref_eqs == equations(reduced_sys)
172172
end
@@ -192,7 +192,7 @@ eqs = [
192192
]
193193
sys = NonlinearSystem(eqs, [u1, u2, u3], [p])
194194
reducedsys = structural_simplify(sys)
195-
@test observed(reducedsys) == [u2 ~ 0.5(u3 - p); u1 ~ u2]
195+
@test observed(reducedsys) == [u1 ~ 0.5(u3 - p); u2 ~ u1]
196196

197197
u0 = [
198198
u1 => 1

0 commit comments

Comments
 (0)