|
1 | 1 | using ModelingToolkit, OrdinaryDiffEq, Test
|
2 | 2 |
|
3 |
| -@variables t, x(t) |
| 3 | +@variables t, x(t), y(t) |
4 | 4 | D = Differential(t)
|
5 | 5 |
|
6 |
| -@named sys1 = ODESystem([D(x) ~ 1.1*x]) |
7 |
| -@named sys2 = ODESystem([D(x) ~ 1.2*x]) |
| 6 | +@named sys1 = ODESystem([D(x) ~ x, |
| 7 | + D(y) ~ -y]) |
| 8 | +@named sys2 = ODESystem([D(x) ~ 2x, |
| 9 | + D(y) ~ -2y]) |
| 10 | +@named sys3 = ODESystem([D(x) ~ 3x, |
| 11 | + D(y) ~ -3y]) |
8 | 12 |
|
9 |
| -prob1 = ODEProblem(sys1, [2.0], (0.0, 1.0)) |
10 |
| -prob2 = ODEProblem(sys2, [1.0], (0.0, 1.0)) |
| 13 | +prob1 = ODEProblem(sys1, [1.0, 1.0], (0.0, 1.0)) |
| 14 | +prob2 = ODEProblem(sys2, [2.0, 2.0], (0.0, 1.0)) |
| 15 | +prob3 = ODEProblem(sys3, [3.0, 3.0], (0.0, 1.0)) |
11 | 16 |
|
12 | 17 | # test that when passing a vector of problems, trajectories and the prob_func are chosen appropriately
|
13 |
| -ensemble_prob = EnsembleProblem([prob1, prob2]) |
| 18 | +ensemble_prob = EnsembleProblem([prob1, prob2, prob3]) |
14 | 19 | sol = solve(ensemble_prob, Tsit5(), EnsembleThreads())
|
15 |
| -@test isapprox(sol[:, x], [2,1] .* map(Base.Fix1(map, exp), [1.1, 1.2] .* sol[:, t]), rtol=1e-4) |
| 20 | +for i in 1:3 |
| 21 | + @test sol[x, :][i] == sol[i][x] |
| 22 | + @test sol[y, :][i] == sol[i][y] |
| 23 | +end |
16 | 24 | # Ensemble is a recursive array
|
17 |
| -@test sol(0.0, idxs=[x]) == sol[:, 1] == first.(sol[:, x], 1) |
| 25 | +@test only.(sol(0.0, idxs=[x])) == sol[1, 1, :] == first.(sol[x, :]) |
18 | 26 | # TODO: fix the interpolation
|
19 |
| -@test sol(1.0, idxs=[x]) ≈ last.(sol[:, x], 1) |
| 27 | +@test only.(sol(1.0, idxs=[x])) ≈ last.(sol[x, :]) |
0 commit comments