Skip to content

Commit

Permalink
Test VCC initialization/finalization
Browse files Browse the repository at this point in the history
  • Loading branch information
BenChung committed Oct 29, 2024
1 parent 98a2bea commit e9ec43c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/symbolic_events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,25 @@ end
@test sol[x][1] 1.0
@test sol[x][2] 1.5 # the initialize affect has been applied
@test seen == true


@variables x(t)
seen = false
f = ModelingToolkit.FunctionalAffect(f=(i,u,p,c)->seen=true, sts=[], pars=[], discretes=[])
cb1 = ModelingToolkit.SymbolicContinuousCallback([x ~ 0], Equation[], initialize=[x~1.5], finalize=f)
inited = false
finaled = false
a = ModelingToolkit.FunctionalAffect(f=(i,u,p,c)->inited=true, sts=[], pars=[], discretes=[])
b = ModelingToolkit.FunctionalAffect(f=(i,u,p,c)->finaled=true, sts=[], pars=[], discretes=[])
cb2= ModelingToolkit.SymbolicContinuousCallback([x ~ 0.1], Equation[], initialize=a, finalize=b)
@mtkbuild sys = ODESystem(D(x) ~ -1, t, [x], []; continuous_events = [cb1, cb2])
prob = ODEProblem(sys, [x => 1.0], (0.0, 2), [])
sol = solve(prob, Tsit5())
@test sol[x][1] 1.0
@test sol[x][2] 1.5 # the initialize affect has been applied
@test seen == true
@test inited == true
@test finaled == true
end

@testset "Bump" begin
Expand Down

0 comments on commit e9ec43c

Please sign in to comment.