-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
605824a
commit 7ff39ae
Showing
2 changed files
with
21 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
using ModelingToolkit, OrdinaryDiffEq, Test | ||
|
||
@variables t, x(t) | ||
@variables t, x(t), y(t) | ||
D = Differential(t) | ||
|
||
@named sys1 = ODESystem([D(x) ~ 1.1*x]) | ||
@named sys2 = ODESystem([D(x) ~ 1.2*x]) | ||
@named sys1 = ODESystem([D(x) ~ x, | ||
D(y) ~ -y]) | ||
@named sys2 = ODESystem([D(x) ~ 2x, | ||
D(y) ~ -2y]) | ||
@named sys3 = ODESystem([D(x) ~ 3x, | ||
D(y) ~ -3y]) | ||
|
||
prob1 = ODEProblem(sys1, [2.0], (0.0, 1.0)) | ||
prob2 = ODEProblem(sys2, [1.0], (0.0, 1.0)) | ||
prob1 = ODEProblem(sys1, [1.0, 1.0], (0.0, 1.0)) | ||
prob2 = ODEProblem(sys2, [2.0, 2.0], (0.0, 1.0)) | ||
prob3 = ODEProblem(sys3, [3.0, 3.0], (0.0, 1.0)) | ||
|
||
# test that when passing a vector of problems, trajectories and the prob_func are chosen appropriately | ||
ensemble_prob = EnsembleProblem([prob1, prob2]) | ||
ensemble_prob = EnsembleProblem([prob1, prob2, prob3]) | ||
sol = solve(ensemble_prob, Tsit5(), EnsembleThreads()) | ||
@test isapprox(sol[:, x], [2,1] .* map(Base.Fix1(map, exp), [1.1, 1.2] .* sol[:, t]), rtol=1e-4) | ||
for i in 1:3 | ||
@test sol[x, :][i] == sol[i][x] | ||
@test sol[y, :][i] == sol[i][y] | ||
end | ||
# Ensemble is a recursive array | ||
@test sol(0.0, idxs=[x]) == sol[:, 1] == first.(sol[:, x], 1) | ||
@test Matrix(sol(0.0, idxs=[x])) == sol[1:1, 1, :] == Matrix(first(eachrow(sol[x, :]))') | ||
# TODO: fix the interpolation | ||
@test sol(1.0, idxs=[x]) ≈ last.(sol[:, x], 1) | ||
@test vec(sol(1.0, idxs=[x])) ≈ last.(sol[x, :].u) |