Skip to content

Commit ce2edd3

Browse files
authored
fix + test trajectory (#80)
1 parent 75c647a commit ce2edd3

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

src/continuous.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export CDS_KWARGS
88
using SimpleDiffEq: SimpleATsit5
99
const DEFAULT_SOLVER = SimpleATsit5()
1010
const DEFAULT_DIFFEQ_KWARGS = (abstol = 1e-6, reltol = 1e-6)
11-
12-
1311
const CDS_KWARGS = (alg = DEFAULT_SOLVER, DEFAULT_DIFFEQ_KWARGS...)
1412

1513
_get_solver(a) = haskey(a, :alg) ? a[:alg] : DEFAULT_SOLVER
@@ -132,7 +130,7 @@ function trajectory(ds::ContinuousDynamicalSystem, T, u = ds.u0;
132130
t0 = ds.t0
133131
tvec = (t0+Ttr):dt:(T+t0+Ttr)
134132
sol = Vector{SVector{dimension(ds), stateeltype(ds)}}(undef, length(tvec))
135-
integ = integrator(ds, u; dt = dt, tfinal = tvec[end]+2dt, diffeq...)
133+
integ = integrator(ds, u; dt = dt, diffeq...)
136134
step!(integ, Ttr)
137135
for (i, t) in enumerate(tvec)
138136
while t > integ.t

test/continuous_systems.jl

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ println("\nTesting continuous system evolution...")
66

77
@testset "Lorenz System" begin
88

9-
lo11 = Systems.lorenz() #with Jac
10-
# lo33 = Systems.lorenz(big.([0.0, 10.0, 0.0]))
11-
12-
@testset "trajectory" begin
9+
lo11 = Systems.lorenz() #with Jac
10+
# lo33 = Systems.lorenz(big.([0.0, 10.0, 0.0]))
1311
# trajectory pure:
1412
ts1 = trajectory(lo11, 1.0, dt = 0.01)
1513
# ts3 = trajectory(lo33, 1.0)
1614
# @test eltype(ts3[1]) == BigFloat
1715
@test size(ts1) == (101, 3)
1816
# @test ts1[1, :] ≈ ts3[end,:]
1917
@test ts1[1, :] == SVector{3}(lo11.u0)
18+
@test !any(x -> abs(x) > 1e3, ts1[end])
2019
# trajectory with diff_eq_kwargs and dt:
2120
ts1 = trajectory(lo11, 1.0; dt=0.1,
2221
diff_eq_kwargs=Dict(:abstol=>1e-8, :reltol=>1e-8))
@@ -25,32 +24,29 @@ println("\nTesting continuous system evolution...")
2524
@test size(ts1) == (11, 3)
2625
@test ts1[1, :] == SVector{3}(lo11.u0)
2726
# @test ts1[end, :] ≈ ts3[end,:]
28-
end
2927

3028
end
3129

3230
@testset "Lorenz96" begin
3331
u = ones(5)
3432
lo11 = Systems.lorenz96(5, u)
3533
# lo33 = Systems.lorenz96(5, big.(ones(5)))
36-
37-
@testset "trajectory" begin
38-
# trajectory pure:
39-
ts1 = trajectory(lo11, 2.0, dt = 0.01)
40-
# ts3 = trajectory(lo33, 2.0)
41-
# @test eltype(ts3[1]) == BigFloat
42-
@test size(ts1) == (201, 5)
43-
# @test ts1[end, :] ≈ ts3[end,:]
44-
@test ts1[1, :] == SVector{5}(u)
45-
# trajectory with diff_eq_kwargs and dt:
46-
ts1 = trajectory(lo11, 2.0; dt=0.1,
47-
diff_eq_kwargs=Dict(:abstol=>1e-9, :reltol=>1e-9))
48-
# ts3 = trajectory(lo33, 2.0; dt=0.1,
49-
# diff_eq_kwargs=Dict(:abstol=>1e-9, :reltol=>1e-9))
50-
@test size(ts1) == (21, 5)
51-
# @test ts1[end, :] ≈ ts3[end,:]
52-
@test ts1[1, :] == SVector{5}(u)
53-
end
34+
# trajectory pure:
35+
ts1 = trajectory(lo11, 2.0, dt = 0.01)
36+
# ts3 = trajectory(lo33, 2.0)
37+
# @test eltype(ts3[1]) == BigFloat
38+
@test size(ts1) == (201, 5)
39+
# @test ts1[end, :] ≈ ts3[end,:]
40+
@test ts1[1, :] == SVector{5}(u)
41+
# trajectory with diff_eq_kwargs and dt:
42+
ts1 = trajectory(lo11, 2.0; dt=0.1,
43+
diff_eq_kwargs=Dict(:abstol=>1e-9, :reltol=>1e-9))
44+
# ts3 = trajectory(lo33, 2.0; dt=0.1,
45+
# diff_eq_kwargs=Dict(:abstol=>1e-9, :reltol=>1e-9))
46+
@test size(ts1) == (21, 5)
47+
# @test ts1[end, :] ≈ ts3[end,:]
48+
@test ts1[1, :] == SVector{5}(u)
49+
@test !any(x -> abs(x) > 1e3, ts1[end])
5450
end
5551

5652
@testset "Gissinger Columns" begin
@@ -69,4 +65,14 @@ end
6965
ds = Systems.qbh()
7066
tr = trajectory(ds, 20.0)
7167
@test size(tr) == (2001, 4)
68+
@test !any(x -> abs(x) > 1e3, tr[end])
7269
end
70+
71+
@testset "Finite trajectory HH" begin
72+
ds = Systems.henonheiles()
73+
u0 = [0, -0.25, 0.42081, 0]
74+
tr = trajectory(ds, 100.0, u0; dt = 0.05)
75+
@test !any(x -> abs(x) > 1e3, tr[end])
76+
tr = trajectory(ds, 100.0, u0; dt = 0.05, alg = Vern9())
77+
@test !any(x -> abs(x) > 1e3, tr[end])
78+
end

0 commit comments

Comments
 (0)