Skip to content

Commit 766354b

Browse files
committed
add tests with integrator callbacks
1 parent 93d7322 commit 766354b

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

test/REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DiffEqCallbacks 2.1

test/integrators_with_callbacks.jl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,56 @@
11
using DiffEqCallbacks
2+
using DynamicalSystemsBase
3+
using OrdinaryDiffEq: Vern7, Tsit5
4+
using LinearAlgebra
5+
6+
@testset "SavingCallback parallel" begin
7+
8+
kwargs = (abstol=1e-14, reltol=1e-14, solver=Vern7(), maxiters=1e9)
9+
ds = Systems.lorenz()
10+
d0 = 1e-9
11+
T = 100.0
12+
13+
save_func(u, t, integrator) = LinearAlgebra.norm(u[1] - u[2])
14+
saved_values = SavedValues(eltype(ds.t0), eltype(ds.u0[1]))
15+
cb = SavingCallback(save_func, saved_values)
16+
17+
u0 = get_state(ds)
18+
pinteg = parallel_integrator(ds, [u0, u0 + rand(SVector{3})*d0];
19+
kwargs..., callback = cb)
20+
step!(pinteg, T)
21+
n = saved_values.saveval
22+
t = saved_values.t
23+
@test length(n) > 1000
24+
# test that norm increases:
25+
@test n[2] > n[1]
26+
@test n[end] > n[5]
27+
@test length(pinteg.sol.u) == 1
28+
end
29+
30+
31+
@testset "SavingCallback tangent" begin
32+
33+
kwargs = (abstol=1e-14, reltol=1e-14, solver=Tsit5())
34+
ds = Systems.lorenz()
35+
d0 = 1e-9
36+
T = 100.0
37+
38+
save_func(u, t, integrator) = LinearAlgebra.norm(get_deviations(integrator)[1, :])
39+
saved_values = SavedValues(eltype(ds.t0), eltype(ds.u0[1]))
40+
cb = SavingCallback(save_func, saved_values)
41+
42+
u0 = get_state(ds)
43+
pinteg = tangent_integrator(ds; kwargs..., callback = cb)
44+
step!(pinteg, T)
45+
n = saved_values.saveval
46+
t = saved_values.t
47+
@test length(n) > 1000
48+
# test that norm increases:
49+
@test mean(n[10000:11000]) > mean(n[1:100])
50+
@test n[end] > n[5]
51+
@test length(pinteg.sol.u) == 1
52+
53+
end
254

355
#=
456
@testset "ManifoldProjection" begin

test/math_tests.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
if current_module() != DynamicalSystemsBase
2-
using DynamicalSystemsBase
3-
end
1+
using DynamicalSystemsBase
42
using Test, StaticArrays
53
println("Testing custom QR-decomposition...")
64

0 commit comments

Comments
 (0)