Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/systems/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions test/dde.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
Expand Down
21 changes: 21 additions & 0 deletions test/symbolic_events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading