Skip to content

Commit 0d4f1a1

Browse files
committed
add test
1 parent ba84c49 commit 0d4f1a1

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,47 @@ 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 = [
238+
D(pos) ~ vel
239+
D(vel) ~ f / mass
240+
]
241+
242+
return ODESystem(eqs; name)
243+
end
244+
245+
function PDController(; kp=0, kd=0, name=:controller)
246+
@variables x(t) v(t) f(t)
247+
@parameters kp=kp kd=kd
248+
249+
eqs = [
250+
f ~ -kp*x - kd*v
251+
]
252+
253+
return ODESystem(eqs; name)
254+
end
255+
256+
function ControlledCart(; cart, cont, name=:sys)
257+
eqs = [
258+
cart.pos ~ cont.x
259+
cart.vel ~ cont.v
260+
cart.f ~ cont.f
261+
]
262+
return ODESystem(eqs; name, systems=[cart, cont])
263+
end
264+
265+
cart = Cart(init_pos=0.0, init_vel=1.0, mass=0.5)
266+
cont = PDController(kp=1.0, kd=0.5)
267+
controlled_cart = ControlledCart(; cart, cont)
268+
s1 = states(structural_simplify(controlled_cart))
269+
s2 = states(structural_simplify(controlled_cart, priorities = [cart.pos => 2, cart.vel => 2]))
270+
@test_broken Set(s1) != Set(s2)

0 commit comments

Comments
 (0)