Skip to content

Commit 3097cbb

Browse files
committed
add test
1 parent ba84c49 commit 3097cbb

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/systems/abstractsystem.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,8 +1406,9 @@ end
14061406

14071407
function set_priorities!(state, priorities)
14081408
fullvars = state.fullvars
1409+
prio_dict = Dict(priorities)
14091410
for (i, v) in enumerate(fullvars)
1410-
p = get(priorities, v, nothing)
1411+
p = get(prio_dict, v, nothing)
14111412
p === nothing && continue
14121413
v = setmetadata(v, VariableStatePriority, p)
14131414
fullvars[i] = v

test/structural_transformation/tearing.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,44 @@ sys = structural_simplify(ms_model)
224224
prob_complex = ODAEProblem(sys, u0, (0, 1.0))
225225
sol = solve(prob_complex, Tsit5())
226226
@test all(sol[mass.v] .== 1)
227+
228+
## Test priorities
229+
@parameters t
230+
D = Differential(t)
231+
232+
function Cart(; init_pos, init_vel, mass, name = :cart)
233+
@variables pos(t)=init_pos vel(t)=init_vel
234+
@variables f(t)
235+
@parameters mass = mass
236+
237+
eqs = [D(pos) ~ vel
238+
D(vel) ~ f / mass]
239+
240+
return ODESystem(eqs; name)
241+
end
242+
243+
function PDController(; kp = 0, kd = 0, name = :controller)
244+
@variables x(t) v(t) f(t)
245+
@parameters kp=kp kd=kd
246+
247+
eqs = [
248+
f ~ -kp * x - kd * v,
249+
]
250+
251+
return ODESystem(eqs; name)
252+
end
253+
254+
function ControlledCart(; cart, cont, name = :sys)
255+
eqs = [cart.pos ~ cont.x
256+
cart.vel ~ cont.v
257+
cart.f ~ cont.f]
258+
return ODESystem(eqs; name, systems = [cart, cont])
259+
end
260+
261+
cart = Cart(init_pos = 0.0, init_vel = 1.0, mass = 0.5)
262+
cont = PDController(kp = 1.0, kd = 0.5)
263+
controlled_cart = ControlledCart(; cart, cont)
264+
s1 = states(structural_simplify(controlled_cart))
265+
s2 = states(structural_simplify(controlled_cart,
266+
priorities = [cart.pos => 2, cart.vel => 2]))
267+
@test_broken Set(s1) != Set(s2)

0 commit comments

Comments
 (0)