Skip to content

Commit dfe28e1

Browse files
test: test nested namedtuples in ImperativeAffect
1 parent a2369ba commit dfe28e1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/symbolic_events.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,3 +1410,21 @@ end
14101410
sol = solve(prob, FBDF())
14111411
@test SciMLBase.successful_retcode(sol)
14121412
end
1413+
1414+
@testset "Nested NamedTuple ImperativeAffect" begin
1415+
@variables x(t) y(t) z(t) w(t)
1416+
obs = (; a = (; b = (x, y)))
1417+
mod = (; p = (; q = y, r = z))
1418+
affect = ModelingToolkit.ImperativeAffect(mod, obs) do mod, obs, ctx, integ
1419+
@test integ[x] obs.a.b[1]
1420+
@test integ[y] obs.a.b[2]
1421+
@test integ[y] mod.p.q
1422+
@test integ[z] mod.p.r
1423+
return (; p = (; q = obs.a.b[1]))
1424+
end
1425+
event = 1.0 => affect
1426+
@mtkcompile sys = System([D(x) ~ x, D(y) ~ y, D(z) ~ z], t; discrete_events = [event])
1427+
prob = ODEProblem(sys, [x => 1.0, y => 2.0, z => 3.0], (0.0, 5.0))
1428+
sol = solve(prob, Tsit5())
1429+
@test SciMLBase.successful_retcode(sol)
1430+
end

0 commit comments

Comments
 (0)