diff --git a/src/systems/callbacks.jl b/src/systems/callbacks.jl index 0b758a6e86..ef1b2e3cd6 100644 --- a/src/systems/callbacks.jl +++ b/src/systems/callbacks.jl @@ -550,7 +550,7 @@ end """ compile_condition(cb::SymbolicDiscreteCallback, sys, dvs, ps; expression, kwargs...) -Returns a function `condition(u,p,t)` returning the `condition(cb)`. +Returns a function `condition(u,t,integrator)` returning the `condition(cb)`. Notes @@ -571,7 +571,8 @@ function compile_condition(cb::SymbolicDiscreteCallback, sys, dvs, ps; end expr = build_function( condit, u, t, p...; expression = Val{true}, - wrap_code = condition_header(sys) .∘ wrap_array_vars(sys, condit; dvs, ps) .∘ + wrap_code = condition_header(sys) .∘ + wrap_array_vars(sys, condit; dvs, ps, inputs = true) .∘ wrap_parameter_dependencies(sys, !(condit isa AbstractArray)), kwargs...) if expression == Val{true} diff --git a/test/dde.jl b/test/dde.jl index aa4536e604..2030a90d06 100644 --- a/test/dde.jl +++ b/test/dde.jl @@ -74,7 +74,7 @@ pmul = [1.0, prob = SDDEProblem(hayes_modelf, hayes_modelg, [1.0], h, tspan, pmul; constant_lags = (pmul[1],)); -sol = solve(prob, RKMil()) +sol = solve(prob, RKMil(), seed = 100) @variables x(..) @parameters a=-4.0 b=-2.0 c=10.0 α=-1.3 β=-1.2 γ=1.1 @@ -87,7 +87,7 @@ eqs = [D(x(t)) ~ a * x(t) + b * x(t - τ) + c + (α * x(t) + γ) * η] @test equations(sys) == [D(x(t)) ~ a * x(t) + b * x(t - τ) + c] @test isequal(ModelingToolkit.get_noiseeqs(sys), [α * x(t) + γ]) prob_mtk = SDDEProblem(sys, [x(t) => 1.0 + t], tspan; constant_lags = (τ,)); -@test_nowarn sol_mtk = solve(prob_mtk, RKMil()) +@test_nowarn sol_mtk = solve(prob_mtk, RKMil(), seed = 100) prob_sa = SDDEProblem( sys, [x(t) => 1.0 + t], tspan; constant_lags = (τ,), u0_constructor = SVector{1}) diff --git a/test/symbolic_events.jl b/test/symbolic_events.jl index b58d5911f4..61690acdce 100644 --- a/test/symbolic_events.jl +++ b/test/symbolic_events.jl @@ -1075,3 +1075,24 @@ end prob = ODEProblem(pend, [x => 1], (0.0, 3.0), guesses = [y => x]) @test all(≈(0.0; atol = 1e-9), solve(prob, Rodas5())[[x, y]][end]) end + +@testset "Issue#3154 Array variable in discrete condition" begin + @mtkmodel DECAY begin + @parameters begin + unrelated[1:2] = zeros(2) + k = 0.0 + end + @variables begin + x(t) = 10.0 + end + @equations begin + D(x) ~ -k * x + end + @discrete_events begin + (t == 1.0) => [k ~ 1.0] + end + end + @mtkbuild decay = DECAY() + prob = ODEProblem(decay, [], (0.0, 10.0), []) + @test_nowarn solve(prob, Tsit5(), tstops = [1.0]) +end