Skip to content

Commit 9e63823

Browse files
committed
Test VCC initialization/finalization
1 parent 3e5cbde commit 9e63823

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/symbolic_events.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,25 @@ end
982982
@test sol[x][1] 1.0
983983
@test sol[x][2] 1.5 # the initialize affect has been applied
984984
@test seen == true
985+
986+
987+
@variables x(t)
988+
seen = false
989+
f = ModelingToolkit.FunctionalAffect(f=(i,u,p,c)->seen=true, sts=[], pars=[], discretes=[])
990+
cb1 = ModelingToolkit.SymbolicContinuousCallback([x ~ 0], Equation[], initialize=[x~1.5], finalize=f)
991+
inited = false
992+
finaled = false
993+
a = ModelingToolkit.FunctionalAffect(f=(i,u,p,c)->inited=true, sts=[], pars=[], discretes=[])
994+
b = ModelingToolkit.FunctionalAffect(f=(i,u,p,c)->finaled=true, sts=[], pars=[], discretes=[])
995+
cb2= ModelingToolkit.SymbolicContinuousCallback([x ~ 0.1], Equation[], initialize=a, finalize=b)
996+
@mtkbuild sys = ODESystem(D(x) ~ -1, t, [x], []; continuous_events = [cb1, cb2])
997+
prob = ODEProblem(sys, [x => 1.0], (0.0, 2), [])
998+
sol = solve(prob, Tsit5())
999+
@test sol[x][1] 1.0
1000+
@test sol[x][2] 1.5 # the initialize affect has been applied
1001+
@test seen == true
1002+
@test inited == true
1003+
@test finaled == true
9851004
end
9861005

9871006
@testset "Bump" begin

0 commit comments

Comments
 (0)