Skip to content

Commit caa236a

Browse files
fix: fix discrete callback condition with array variable
1 parent c30dc61 commit caa236a

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
@@ -550,7 +550,7 @@ end
550550
"""
551551
compile_condition(cb::SymbolicDiscreteCallback, sys, dvs, ps; expression, kwargs...)
552552
553-
Returns a function `condition(u,p,t)` returning the `condition(cb)`.
553+
Returns a function `condition(u,t,integrator)` returning the `condition(cb)`.
554554
555555
Notes
556556
@@ -571,7 +571,8 @@ function compile_condition(cb::SymbolicDiscreteCallback, sys, dvs, ps;
571571
end
572572
expr = build_function(
573573
condit, u, t, p...; expression = Val{true},
574-
wrap_code = condition_header(sys) .∘ wrap_array_vars(sys, condit; dvs, ps) .∘
574+
wrap_code = condition_header(sys) .∘
575+
wrap_array_vars(sys, condit; dvs, ps, inputs = true) .∘
575576
wrap_parameter_dependencies(sys, !(condit isa AbstractArray)),
576577
kwargs...)
577578
if expression == Val{true}

test/symbolic_events.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,3 +1075,24 @@ end
10751075
prob = ODEProblem(pend, [x => 1], (0.0, 3.0), guesses = [y => x])
10761076
@test all((0.0; atol = 1e-9), solve(prob, Rodas5())[[x, y]][end])
10771077
end
1078+
1079+
@testset "Issue#3154 Array variable in discrete condition" begin
1080+
@mtkmodel DECAY begin
1081+
@parameters begin
1082+
unrelated[1:2] = zeros(2)
1083+
k = 0.0
1084+
end
1085+
@variables begin
1086+
x(t) = 10.0
1087+
end
1088+
@equations begin
1089+
D(x) ~ -k * x
1090+
end
1091+
@discrete_events begin
1092+
(t == 1.0) => [k ~ 1.0]
1093+
end
1094+
end
1095+
@mtkbuild decay = DECAY()
1096+
prob = ODEProblem(decay, [], (0.0, 10.0), [])
1097+
@test_nowarn solve(prob, Tsit5(), tstops = [1.0])
1098+
end

0 commit comments

Comments
 (0)