Skip to content

Commit 3c7afd8

Browse files
committed
Test some simple initialization affects
1 parent 8edef14 commit 3c7afd8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/symbolic_events.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,26 @@ end
10741074
prob = ODEProblem(ss, [temp => 0.0, furnace_on => true], (0.0, 100.0))
10751075
sol = solve(prob, Tsit5(); dtmax = 0.01)
10761076
@test all(sol[temp][sol.t .> 1.0] .<= 0.79) && all(sol[temp][sol.t .> 1.0] .>= 0.49)
1077+
1078+
furnace_off = ModelingToolkit.SymbolicContinuousCallback(
1079+
[temp ~ furnace_off_threshold],
1080+
ModelingToolkit.MutatingFunctionalAffect(modified = (; furnace_on)) do x
1081+
x.furnace_on = false
1082+
end; initialize = ModelingToolkit.MutatingFunctionalAffect(modified = (; temp)) do x
1083+
x.temp = 0.2
1084+
end)
1085+
furnace_enable = ModelingToolkit.SymbolicContinuousCallback(
1086+
[temp ~ furnace_on_threshold],
1087+
ModelingToolkit.MutatingFunctionalAffect(modified = (; furnace_on)) do x, o, c, i
1088+
x.furnace_on = true
1089+
end)
1090+
@named sys = ODESystem(
1091+
eqs, t, [temp], params; continuous_events = [furnace_off, furnace_enable])
1092+
ss = structural_simplify(sys)
1093+
prob = ODEProblem(ss, [temp => 0.0, furnace_on => true], (0.0, 100.0))
1094+
sol = solve(prob, Tsit5(); dtmax = 0.01)
1095+
@test all(sol[temp][sol.t .> 1.0] .<= 0.79) && all(sol[temp][sol.t .> 1.0] .>= 0.49)
1096+
@test all(sol[temp][sol.t .!= 0.0] .<= 0.79) && all(sol[temp][sol.t .!= 0.0] .>= 0.2)
10771097
end
10781098

10791099
@testset "MutatingFunctionalAffect errors and warnings" begin

0 commit comments

Comments
 (0)