Skip to content

Commit 8c08b36

Browse files
authored
added test for symbolic continuous_events (#1728)
1 parent 9e03874 commit 8c08b36

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using SafeTestsets, Test
55
@safetestset "AbstractSystem Test" begin include("abstractsystem.jl") end
66
@safetestset "Variable scope tests" begin include("variable_scope.jl") end
77
@safetestset "Symbolic parameters test" begin include("symbolic_parameters.jl") end
8+
@safetestset "Symbolic event test" begin include("symbolic_events.jl") end
89
@safetestset "Parsing Test" begin include("variable_parsing.jl") end
910
@safetestset "Simplify Test" begin include("simplify.jl") end
1011
@safetestset "Direct Usage Test" begin include("direct.jl") end
@@ -41,7 +42,6 @@ println("Last test requires gcc available in the path!")
4142
@testset "Serialization" begin include("serialization.jl") end
4243
@safetestset "print_tree" begin include("print_tree.jl") end
4344
@safetestset "error_handling" begin include("error_handling.jl") end
44-
@safetestset "root_equations" begin include("root_equations.jl") end
4545
@safetestset "state_selection" begin include("state_selection.jl") end
4646
@safetestset "Modelingtoolkitize Test" begin include("modelingtoolkitize.jl") end
4747
@safetestset "OptimizationSystem Test" begin include("optimizationsystem.jl") end

test/root_equations.jl renamed to test/symbolic_events.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,29 @@ let rng = rng
555555
@named jsys6 = JumpSystem(eqs, t, [A], [k, t1, t2], discrete_events = [cb2‵‵‵, cb1])
556556
testsol(jsys6, u0, p, tspan; tstops = [1.0, 2.0], rng)
557557
end
558+
559+
let
560+
@variables t
561+
D = Differential(t)
562+
563+
function oscillator_ce(k = 1.0; name)
564+
sts = @variables x(t)=1.0 v(t)=0.0 F(t)
565+
ps = @parameters k=k Θ=0.5
566+
eqs = [D(x) ~ v, D(v) ~ -k * x + F]
567+
ev = [x ~ Θ] => [x ~ 1.0, v ~ 0.0]
568+
ODESystem(eqs, t, sts, ps, continuous_events = [ev]; name)
569+
end
570+
571+
@named oscce = oscillator_ce()
572+
eqs = [oscce.F ~ 0]
573+
@named eqs_sys = ODESystem(eqs, t)
574+
@named oneosc_ce = compose(eqs_sys, oscce)
575+
oneosc_ce_simpl = structural_simplify(oneosc_ce)
576+
577+
prob = ODEProblem(oneosc_ce_simpl, [], (0.0, 2.0), [])
578+
sol = solve(prob, Tsit5(), saveat = 0.1)
579+
580+
@test typeof(oneosc_ce_simpl) == ODESystem
581+
@test sol[1, 6] < 1.0 # test whether x(t) decreases over time
582+
@test sol[1, 18] > 0.5 # test whether event happened
583+
end

0 commit comments

Comments
 (0)