Skip to content

Commit 0badc16

Browse files
committed
handle new operator in shift_discrete_system
1 parent 4f1fe9b commit 0badc16

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/systems/systemstructure.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,23 +457,24 @@ function lower_order_var(dervar, t)
457457
end
458458

459459
function shift_discrete_system(ts::TearingState)
460+
dops = Union{Sample, Hold, ClockChange}
460461
@unpack fullvars, sys = ts
461462
discvars = OrderedSet()
462463
eqs = equations(sys)
463464
for eq in eqs
464-
vars!(discvars, eq; op = Union{Sample, Hold})
465+
vars!(discvars, eq; op = dops)
465466
end
466467
iv = get_iv(sys)
467468
discmap = Dict(k => StructuralTransformations.simplify_shifts(Shift(iv, 1)(k))
468469
for k in discvars
469-
if any(isequal(k), fullvars) && !isa(operation(k), Union{Sample, Hold}))
470+
if any(isequal(k), fullvars) && !isa(operation(k), dops))
470471
for i in eachindex(fullvars)
471472
fullvars[i] = StructuralTransformations.simplify_shifts(fast_substitute(
472-
fullvars[i], discmap; operator = Union{Sample, Hold}))
473+
fullvars[i], discmap; operator = dops))
473474
end
474475
for i in eachindex(eqs)
475476
eqs[i] = StructuralTransformations.simplify_shifts(fast_substitute(
476-
eqs[i], discmap; operator = Union{Sample, Hold}))
477+
eqs[i], discmap; operator = dops))
477478
end
478479
@set! ts.sys.eqs = eqs
479480
@set! ts.fullvars = fullvars

test/clock.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,25 @@ end
549549
@mtkbuild cc = CC()
550550
prob = ODEProblem(cc, [], (0, 10))
551551
sol = solve(prob, Tsit5(); kwargshandle = KeywordArgSilent)
552+
d1 = reduce(vcat, sol.prob.kwargs[:disc_saved_values][1].saveval)
553+
d2 = reduce(vcat, sol.prob.kwargs[:disc_saved_values][2].saveval)
554+
555+
if length(d1) < length(d2)
556+
d1, d2 = d2, d1
557+
end
558+
559+
@test d2 == 1:6 # y
560+
561+
X = [0, 0] # xy
562+
ti = 0
563+
for ti in 0:10
564+
i = ti + 1
565+
x, y = X
566+
if ti % 2 == 0
567+
y = y + 1
568+
end
569+
x = x + y
570+
571+
@test d1[i] == x
572+
X = [x, y]
573+
end

0 commit comments

Comments
 (0)