Skip to content

Commit 74d3f9f

Browse files
committed
finish ODE discrete tests
1 parent b1eeb83 commit 74d3f9f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

test/root_equations.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ sys = structural_simplify(model)
336336
@test isempty(ModelingToolkit.continuous_events(sys))
337337

338338
let
339-
function testsol(osys, u0, p, tspan; tstops = Float64[], kwargs...)
339+
function testsol(osys, u0, p, tspan; tstops = Float64[], skipparamtest = false, kwargs...)
340340
oprob = ODEProblem(osys, u0, tspan, p; kwargs...)
341341
sol = solve(oprob, Tsit5(); tstops = tstops, abstol = 1e-10, reltol = 1e-10)
342342
@test isapprox(sol(1.0000000001)[1] - sol(0.999999999)[1], 1.0; rtol = 1e-6)
343-
@test oprob.p[1] == 1.0
343+
!skipparamtest && (@test oprob.p[1] == 1.0)
344344
@test isapprox(sol(4.0)[1], 2 * exp(-2.0))
345345
sol
346346
end
@@ -390,8 +390,20 @@ let
390390
@named osys4 = ODESystem(eqs, t, [A], [k, t1], discrete_events = [cb1, cb2‵‵])
391391
oprob4 = ODEProblem(osys4, u0, tspan, p)
392392
testsol(osys4, u0, p, tspan; tstops = [1.0])
393+
393394
# mixing with symbolic condition in the func affect
394395
cb2‵‵‵ = (t == t2) => (affect!, [], [k], nothing)
395396
@named osys5 = ODESystem(eqs, t, [A], [k, t1, t2], discrete_events = [cb1, cb2‵‵‵])
396397
testsol(osys5, u0, p, tspan; tstops = [1.0, 2.0])
398+
@named osys6 = ODESystem(eqs, t, [A], [k, t1, t2], discrete_events = [cb2‵‵‵, cb1])
399+
testsol(osys6, u0, p, tspan; tstops = [1.0, 2.0])
400+
401+
# mix a continuous event too
402+
cond3 = A ~ .1
403+
affect3 = [k ~ 0.0]
404+
cb3 = cond3 => affect3
405+
@named osys7 = ODESystem(eqs, t, [A], [k, t1, t2], discrete_events = [cb1, cb2‵‵‵],
406+
continuous_events = [cb3])
407+
sol = testsol(osys7, u0, p, (0.0, 10.0); tstops = [1.0, 2.0], skipparamtest = true)
408+
@test isapprox(sol(10.0)[1], .1; atol=1e-10, rtol=1e-10)
397409
end

0 commit comments

Comments
 (0)