Skip to content

Commit b8e2ba1

Browse files
test: test scalarized array passed to discrete_parameters of symbolic affect
1 parent 171edd0 commit b8e2ba1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/symbolic_events.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,3 +1455,43 @@ end
14551455
Pre(X) +
14561456
10.0])
14571457
end
1458+
1459+
@testset "Issue#3990: Scalarized array passed to `discrete_parameters` of symbolic affect" begin
1460+
N = 2
1461+
@parameters v(t)[1:N]
1462+
@parameters M(t)[1:N, 1:N]
1463+
1464+
@variables x(t)
1465+
1466+
Mini = rand(N, N) ./ (N^2)
1467+
vini = vec(sum(Mini, dims = 1))
1468+
1469+
v_eq = [D(x) ~ x * Symbolics.scalarize(sum(v))]
1470+
M_eq = [D(x) ~ x * Symbolics.scalarize(sum(M))]
1471+
1472+
v_event = ModelingToolkit.SymbolicDiscreteCallback(
1473+
1.0,
1474+
[v ~ -Pre(v)],
1475+
discrete_parameters = [v]
1476+
)
1477+
1478+
M_event = ModelingToolkit.SymbolicDiscreteCallback(
1479+
1.0,
1480+
[M ~ -Pre(M)],
1481+
discrete_parameters = [M]
1482+
)
1483+
1484+
@mtkcompile v_sys = System(v_eq, t; discrete_events = v_event)
1485+
@mtkcompile M_sys = System(M_eq, t; discrete_events = M_event)
1486+
1487+
u0p0_map = Dict(x => 1.0, M => Mini, v => vini)
1488+
1489+
v_prob = ODEProblem(v_sys, u0p0_map, (0.0, 2.5))
1490+
M_prob = ODEProblem(M_sys, u0p0_map, (0.0, 2.5))
1491+
1492+
v_sol = solve(v_prob, Tsit5())
1493+
M_sol = solve(M_prob, Tsit5())
1494+
1495+
@test v_sol[v] [vini, -vini, vini]
1496+
@test M_sol[M] [Mini, -Mini, Mini]
1497+
end

0 commit comments

Comments
 (0)