Skip to content

Commit ae94782

Browse files
fix: fix discrete callback condition with array variable
1 parent f4d3974 commit ae94782

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/systems/callbacks.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ end
435435
"""
436436
compile_condition(cb::SymbolicDiscreteCallback, sys, dvs, ps; expression, kwargs...)
437437
438-
Returns a function `condition(u,p,t)` returning the `condition(cb)`.
438+
Returns a function `condition(u,t,integrator)` returning the `condition(cb)`.
439439
440440
Notes
441441
@@ -456,7 +456,8 @@ function compile_condition(cb::SymbolicDiscreteCallback, sys, dvs, ps;
456456
end
457457
expr = build_function(
458458
condit, u, t, p...; expression = Val{true},
459-
wrap_code = condition_header(sys) .∘ wrap_array_vars(sys, condit; dvs, ps) .∘
459+
wrap_code = condition_header(sys) .∘
460+
wrap_array_vars(sys, condit; dvs, ps, inputs = true) .∘
460461
wrap_parameter_dependencies(sys, !(condit isa AbstractArray)),
461462
kwargs...)
462463
if expression == Val{true}

test/symbolic_events.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,3 +988,24 @@ end
988988
prob = ODEProblem(pend, [x => 1], (0.0, 3.0), guesses = [y => x])
989989
@test all((0.0; atol = 1e-9), solve(prob, Rodas5())[[x, y]][end])
990990
end
991+
992+
@test "Issue#3154 Array variable in discrete condition" begin
993+
@mtkmodel DECAY begin
994+
@parameters begin
995+
unrelated[1:2] = zeros(2)
996+
k = 0.0
997+
end
998+
@variables begin
999+
x(t) = 10.0
1000+
end
1001+
@equations begin
1002+
D(x) ~ -k * x
1003+
end
1004+
@discrete_events begin
1005+
(t == 1.0) => [k ~ 1.0]
1006+
end
1007+
end
1008+
@mtkbuild decay = DECAY()
1009+
prob = ODEProblem(decay, [], (0.0, 10.0), [])
1010+
@test_nowarn solve(prob, Tsit5(), tstops = [1.0])
1011+
end

0 commit comments

Comments
 (0)