|
1 |
| -using JumpProcesses, OrdinaryDiffEq, Test |
| 1 | +using JumpProcesses, OrdinaryDiffEq, Test, SciMLBase |
2 | 2 | using StableRNGs
|
3 | 3 | rng = StableRNG(12345)
|
4 | 4 |
|
5 | 5 | # test that we only save when a jump occurs
|
6 |
| -for alg in (Coevolve(),) |
7 |
| - u0 = [0] |
8 |
| - tspan = (0.0, 30.0) |
| 6 | +let |
| 7 | + for alg in (Coevolve(),) |
| 8 | + u0 = [0] |
| 9 | + tspan = (0.0, 30.0) |
9 | 10 |
|
| 11 | + dprob = DiscreteProblem(u0, tspan) |
| 12 | + # set the rate to 0, so that no jump ever occurs; but urate is positive so |
| 13 | + # Coevolve will consider many candidates before the end of the simmulation. |
| 14 | + # None of these points should be saved. |
| 15 | + jump = VariableRateJump((u, p, t) -> 0, (integrator) -> integrator.u[1] += 1; |
| 16 | + urate = (u, p, t) -> 1.0, rateinterval = (u, p, t) -> 5.0) |
| 17 | + jumpproblem = JumpProblem(dprob, alg, jump; dep_graph = [[1]], |
| 18 | + save_positions = (false, true), rng) |
| 19 | + sol = solve(jumpproblem, SSAStepper()) |
| 20 | + @test sol.t == [0.0, 30.0] |
| 21 | + |
| 22 | + oprob = ODEProblem((du, u, p, t) -> 0, u0, tspan) |
| 23 | + jump = VariableRateJump((u, p, t) -> 0, (integrator) -> integrator.u[1] += 1; |
| 24 | + urate = (u, p, t) -> 1.0, rateinterval = (u, p, t) -> 5.0) |
| 25 | + jumpproblem = JumpProblem(oprob, alg, jump; dep_graph = [[1]], |
| 26 | + save_positions = (false, true), rng) |
| 27 | + sol = solve(jumpproblem, Tsit5(); save_everystep = false) |
| 28 | + @test sol.t == [0.0, 30.0] |
| 29 | + end |
| 30 | +end |
| 31 | + |
| 32 | +# test isdenseplot gives correct values for SSAStepper and non-SSAStepper models |
| 33 | +let |
| 34 | + rate(u, p, t) = max(u[1], 0.0) |
| 35 | + affect!(integ) = (integ.u[1] -= 1; nothing) |
| 36 | + crj = ConstantRateJump(rate, affect!) |
| 37 | + u0 = [10.0] |
| 38 | + tspan = (0.0, 10.0) |
10 | 39 | dprob = DiscreteProblem(u0, tspan)
|
11 |
| - # set the rate to 0, so that no jump ever occurs; but urate is positive so |
12 |
| - # Coevolve will consider many candidates before the end of the simmulation. |
13 |
| - # None of these points should be saved. |
14 |
| - jump = VariableRateJump((u, p, t) -> 0, (integrator) -> integrator.u[1] += 1; |
15 |
| - urate = (u, p, t) -> 1.0, rateinterval = (u, p, t) -> 5.0) |
16 |
| - jumpproblem = JumpProblem(dprob, alg, jump; dep_graph = [[1]], |
17 |
| - save_positions = (false, true)) |
18 |
| - sol = solve(jumpproblem, SSAStepper()) |
19 |
| - @test sol.t == [0.0, 30.0] |
| 40 | + sps = ((true, true), (true, false), (false, true), (false, false)) |
| 41 | + |
| 42 | + # for pure jump problems dense = save_everystep |
| 43 | + vals = (true, true, true, false) |
| 44 | + for (sp, val) in zip(sps, vals) |
| 45 | + jprob = JumpProblem(dprob, Direct(), crj; save_positions = sp, rng) |
| 46 | + sol = solve(jprob, SSAStepper()) |
| 47 | + @test SciMLBase.isdenseplot(sol) == val |
| 48 | + end |
| 49 | + |
| 50 | + # for mixed problems sol.dense currently ignores save_positions |
| 51 | + oprob = ODEProblem((du, u, p, t) -> du[1] = 0.1, u0, tspan) |
| 52 | + for sp in sps |
| 53 | + jprob = JumpProblem(oprob, Direct(), crj; save_positions = sp, rng) |
| 54 | + sol = solve(jprob, Tsit5()) |
| 55 | + @test sol.dense == true |
| 56 | + @test SciMLBase.isdenseplot(sol) == true |
20 | 57 |
|
21 |
| - oprob = ODEProblem((du, u, p, t) -> 0, u0, tspan) |
22 |
| - jump = VariableRateJump((u, p, t) -> 0, (integrator) -> integrator.u[1] += 1; |
23 |
| - urate = (u, p, t) -> 1.0, rateinterval = (u, p, t) -> 5.0) |
24 |
| - jumpproblem = JumpProblem(oprob, alg, jump; dep_graph = [[1]], |
25 |
| - save_positions = (false, true)) |
26 |
| - sol = solve(jumpproblem, Tsit5(); save_everystep = false) |
27 |
| - @test sol.t == [0.0, 30.0] |
| 58 | + sol = solve(jprob, Tsit5(); dense = false) |
| 59 | + @test sol.dense == false |
| 60 | + @test SciMLBase.isdenseplot(sol) == false |
| 61 | + end |
28 | 62 | end
|
0 commit comments