Skip to content

Commit 2eb6d0c

Browse files
committed
Add tests for 'regressed'
1 parent 680271a commit 2eb6d0c

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

test/L96m/data/regressed.npy

152 Bytes
Binary file not shown.

test/L96m/runtests.jl

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,49 @@ const z0 = NPZ.npzread(joinpath(data_dir, "ic.npy"))
1616
const Yk_test = NPZ.npzread(joinpath(data_dir, "Yk.npy"))
1717
const full_test = NPZ.npzread(joinpath(data_dir, "full.npy"))
1818
const balanced_test = NPZ.npzread(joinpath(data_dir, "balanced.npy"))
19+
const regressed_test = NPZ.npzread(joinpath(data_dir, "regressed.npy"))
1920
const dp5_test = NPZ.npzread(joinpath(data_dir, "dp5_full.npy"))
2021
const tp8_test = NPZ.npzread(joinpath(data_dir, "tsitpap8_full.npy"))
2122
const bal_test = NPZ.npzread(joinpath(data_dir, "dp5_bal.npy"))
2223

2324
################################################################################
2425
# unit testing #################################################################
2526
################################################################################
26-
Yk_comp = compute_Yk(l96, z0)
27-
full_comp = similar(z0)
28-
full(full_comp, z0, l96, 0.0)
29-
balanced_comp = similar(z0[1:l96.K])
30-
balanced(balanced_comp, z0[1:l96.K], l96, 0.0)
3127
@testset "unit testing" begin
28+
Yk_comp = compute_Yk(l96, z0)
3229
@test isapprox(Yk_test, Yk_comp, atol=1e-15)
30+
31+
full_comp = similar(z0)
32+
full(full_comp, z0, l96, 0.0)
3333
@test isapprox(full_test, full_comp, atol=1e-15)
34+
35+
balanced_comp = similar(z0[1:l96.K])
36+
balanced(balanced_comp, z0[1:l96.K], l96, 0.0)
3437
@test isapprox(balanced_test, balanced_comp, atol=1e-15)
38+
39+
set_G0(l96)
40+
regressed_comp = similar(z0[1:l96.K])
41+
regressed(regressed_comp, z0[1:l96.K], l96, 0.0)
42+
@test isapprox(balanced_test, regressed_comp, atol=1e-13)
43+
set_G0(l96, slope = -0.7)
44+
regressed(regressed_comp, z0[1:l96.K], l96, 0.0)
45+
@test isapprox(regressed_test, regressed_comp, atol=1e-15)
46+
47+
@testset "G0 testing" begin
48+
v1 = Vector(1.0:20.0)
49+
v2 = Vector(1:3:21)
50+
set_G0(l96)
51+
@test l96.hy * 5.0 == l96.G(5.0)
52+
@test l96.hy * v1 == l96.G(v1)
53+
@test l96.hy * v2 == l96.G(v2)
54+
set_G0(l96, 1.0)
55+
@test 5.0 == l96.G(5.0)
56+
@test v1 == l96.G(v1)
57+
@test v2 == l96.G(v2)
58+
set_G0(l96, slope = -0.5)
59+
@test -0.5 * v1 == l96.G(v1)
60+
@test -0.5 * v2 == l96.G(v2)
61+
end
3562
end
3663
println("")
3764

@@ -43,6 +70,7 @@ const dtmax = 1e-5
4370
const saveat = 1e-2
4471
pb_full = DE.ODEProblem(full, z0, (0.0, T), l96)
4572
pb_bal = DE.ODEProblem(balanced, z0[1:l96.K], (0.0, T), l96)
73+
pb_reg = DE.ODEProblem(regressed, z0[1:l96.K], (0.0, T), l96)
4674

4775
# full, DP5
4876
print(rpad("(full, DP5)", RPAD))
@@ -68,10 +96,20 @@ end
6896
println("steps:", lpad(length(sol_bal.t), LPAD_INTEGER),
6997
"\telapsed:", lpad(elapsed_bal, LPAD_FLOAT))
7098

99+
# regressed, DP5
100+
set_G0(l96) # this has a side effect on `pb_reg` through `l96` object
101+
print(rpad("(regressed, DP5)", RPAD))
102+
elapsed_reg = @elapsed begin
103+
sol_reg = DE.solve(pb_reg, DE.DP5(), dtmax = dtmax, saveat = saveat)
104+
end
105+
println("steps:", lpad(length(sol_reg.t), LPAD_INTEGER),
106+
"\telapsed:", lpad(elapsed_reg, LPAD_FLOAT))
107+
71108
@testset "integration testing" begin
72109
@test isapprox(sol_dp5[:,1:end], dp5_test, atol=1e-3)
73110
@test isapprox(sol_tp8[:,1:end], tp8_test, atol=1e-3)
74111
@test isapprox(sol_bal[:,1:end], bal_test, atol=1e-5)
112+
@test isapprox(sol_reg[:,1:end], bal_test, atol=1e-5) # reg + G0 == bal
75113
end
76114
println("")
77115

0 commit comments

Comments
 (0)