Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SciMLTesting = "09d9d899-5365-40a9-917a-5f67fddea283"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
Expand All @@ -12,8 +13,9 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
Aqua = "0.8"
ExplicitImports = "1"
LaTeXStrings = "1.2"
Pkg = "1.10"
Plots = "1.39"
SafeTestsets = "0.1, 1"
SciMLTesting = "1"
StaticArrays = "1.3"
Test = "1"
UnicodePlots = "3"
708 changes: 708 additions & 0 deletions test/coloredrootedtree_tests.jl

Large diffs are not rendered by default.

294 changes: 294 additions & 0 deletions test/order_conditions_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
using Test
using RootedTrees
using StaticArrays

# Runge-Kutta method SSPRK33 of order 3
@testset "RungeKuttaMethod, SSPRK33" begin
A = [0 0 0; 1 0 0; 1 / 4 1 / 4 0]
b = [1 / 6, 1 / 6, 2 / 3]
rk = RungeKuttaMethod(A, b)
show(IOContext(stdout, :compact => false), rk)

for order in 1:3
for t in RootedTreeIterator(order)
@test residual_order_condition(t, rk) ≈ 0 atol = eps()
end
end

let order = 4
res = 0.0
for t in RootedTreeIterator(order)
res += abs(residual_order_condition(t, rk))
end
@test res > 10 * eps()
end

A = @SArray [0 0 0; 1 0 0; 1 / 4 1 / 4 0]
b = @SArray [1 / 6, 1 / 6, 2 / 3]
rk = RungeKuttaMethod(A, b)
show(IOContext(stdout, :compact => true), rk)
for order in 1:3
@test all(RootedTreeIterator(order)) do t
abs(residual_order_condition(t, rk)) < eps()
end
end

let order = 4
res = 0.0
for t in RootedTreeIterator(order)
res += abs(residual_order_condition(t, rk))
end
@test res > 10 * eps()
end

# deprecations
let order = 4
for t in RootedTreeIterator(order)
@test elementary_weight(t, rk.A, rk.b, rk.c) ≈ elementary_weight(t, rk)
@test derivative_weight(t, RungeKuttaMethod(rk.A, rk.b, rk.c)) ≈
derivative_weight(t, rk)
@test residual_order_condition(t, RungeKuttaMethod(rk.A, rk.b, rk.c)) ≈
residual_order_condition(t, rk)
end
end
end

@testset "AdditiveRungeKuttaMethod, IMEX Euler" begin
ex_euler = RungeKuttaMethod(@SMatrix([0 // 1]), @SVector [1])
im_euler = RungeKuttaMethod(@SMatrix([1 // 1]), @SVector [1])
ark = AdditiveRungeKuttaMethod([ex_euler, im_euler])
show(IOContext(stdout, :compact => true), ark)
show(IOContext(stdout, :compact => false), ark)

@test elementary_weight(rootedtree(Int[], Bool[]), ark) ≈ 1

for order in 1:1
for t in BicoloredRootedTreeIterator(order)
@test residual_order_condition(t, ark) ≈ 0 atol = eps()
end
end

let order = 2
res = 0.0
for t in BicoloredRootedTreeIterator(order)
res += abs(residual_order_condition(t, ark))
end
@test res > 10 * eps()
end
end

@testset "AdditiveRungeKuttaMethod, Störmer-Verlet" begin
# Hairer, Lubich, Wanner (2002)
# Geometric numerical integration
# Table II.2.1
As = [
[0 0; 1 // 2 1 // 2],
[1 // 2 0; 1 // 2 0],
]
bs = [
[1 // 2, 1 // 2],
[1 // 2, 1 // 2],
]
ark = AdditiveRungeKuttaMethod(As, bs)

for order in 1:2
for t in BicoloredRootedTreeIterator(order)
@test residual_order_condition(t, ark) ≈ 0 atol = eps()
end
end

let order = 3
res = 0.0
for t in BicoloredRootedTreeIterator(order)
res += abs(residual_order_condition(t, ark))
end
@test res > 10 * eps()
end
end

@testset "AdditiveRungeKuttaMethod, Lobatto IIIA-IIIB pair (s = 3)" begin
# Hairer, Lubich, Wanner (2002)
# Geometric numerical integration
# Table II.2.2
As = [
[0 0 0; 5 // 24 1 // 3 -1 // 24; 1 // 6 2 // 3 1 // 6],
[1 // 6 -1 // 6 0; 1 // 6 1 // 3 0; 1 // 6 5 // 6 0],
]
bs = [
[1 // 6, 2 // 3, 1 // 6],
[1 // 6, 2 // 3, 1 // 6],
]
ark = AdditiveRungeKuttaMethod(As, bs)

for order in 1:4
for t in BicoloredRootedTreeIterator(order)
@test residual_order_condition(t, ark) ≈ 0 atol = eps()
end
end

let order = 5
res = 0.0
for t in BicoloredRootedTreeIterator(order)
res += abs(residual_order_condition(t, ark))
end
@test res > 10 * eps()
end
end

@testset "AdditiveRungeKuttaMethod, Griep3" begin
# Oswald Knoth and J. Wensch (2014)
# "Generalized Split-Explicit Runge-Kutta Methods for the
# Compressible Euler Equations".
# Monthly Weather Review, 142, 2067-2081
A_explicit = @SArray [0 0 0; 1 // 2 0 0; -1 2 0]
b_explicit = @SArray [1 // 6, 2 // 3, 1 // 6]
rk_explicit = RungeKuttaMethod(A_explicit, b_explicit)
β = sqrt(3) / 3
A_implicit = @SArray [0 0 0; -β / 2 (1 + β) / 2 0; (3 + 5β) / 2 -1 - 3β (1 + β) / 2]
b_implicit = @SArray [1 // 6, 2 // 3, 1 // 6]
rk_implicit = RungeKuttaMethod(A_implicit, b_implicit)
ark = AdditiveRungeKuttaMethod([rk_explicit, rk_implicit])

for order in 1:3
for t in BicoloredRootedTreeIterator(order)
@test residual_order_condition(t, ark) ≈ 0 atol = eps()
end
end

let order = 4
res = 0.0
for t in BicoloredRootedTreeIterator(order)
res += abs(residual_order_condition(t, ark))
end
@test res > 10 * eps()
end
end

@testset "AdditiveRungeKuttaMethod, ARK3(2)4L[2]SA" begin
# Kennedy, Christopher A., and Mark H. Carpenter.
# "Additive Runge-Kutta schemes for convection-diffusion-reaction equations."
# Applied Numerical Mathematics 44, no. 1-2 (2003): 139-181.
# https://doi.org/10.1016/S0168-9274(02)00138-1
A_explicit = @SArray [
0 0 0 0
1767732205903 / 2027836641118 0 0 0
5535828885825 / 10492691773637 788022342437 / 10882634858940 0 0
6485989280629 / 16251701735622 -4246266847089 / 9704473918619 10755448449292 / 10357097424841 0
]
b_explicit = @SArray [
1471266399579 / 7840856788654,
-4482444167858 / 7529755066697,
11266239266428 / 11593286722821,
1767732205903 / 4055673282236,
]
rk_explicit = RungeKuttaMethod(A_explicit, b_explicit)
A_implicit = @SArray [
0 0 0 0
1767732205903 / 4055673282236 1767732205903 / 4055673282236 0 0
2746238789719 / 10658868560708 -640167445237 / 6845629431997 1767732205903 / 4055673282236 0
1471266399579 / 7840856788654 -4482444167858 / 7529755066697 11266239266428 / 11593286722821 1767732205903 / 4055673282236
]
b_implicit = @SArray [
1471266399579 / 7840856788654,
-4482444167858 / 7529755066697,
11266239266428 / 11593286722821,
1767732205903 / 4055673282236,
]
rk_implicit = RungeKuttaMethod(A_implicit, b_implicit)
ark = AdditiveRungeKuttaMethod([rk_explicit, rk_implicit])

for order in 1:3
for t in BicoloredRootedTreeIterator(order)
@test residual_order_condition(t, ark) ≈ 0 atol = eps()
end
end

let order = 4
res = 0.0
for t in BicoloredRootedTreeIterator(order)
res += abs(residual_order_condition(t, ark))
end
@test res > 10 * eps()
end
end

@testset "AdditiveRungeKuttaMethod, SSPRK33 three times" begin
# Using the same method multiple times is equivalent to using a plain RK
# method without any splitting/partitioning/decomposition
A = @SArray [0 0 0; 1 0 0; 1 / 4 1 / 4 0]
b = @SArray [1 / 6, 1 / 6, 2 / 3]
rk = RungeKuttaMethod(A, b)
ark = AdditiveRungeKuttaMethod([rk, rk, rk])

let t = rootedtree([1, 2, 2], [1, 2, 3])
@test residual_order_condition(t, ark) ≈ 0 atol = eps()
end

let t = rootedtree([1, 2, 3, 2], [1, 2, 3, 1])
@test abs(residual_order_condition(t, ark)) > 10 * eps()
end
end

@testset "RosenbrockMethod, original Rosenbrock" begin
γ = [
1 - sqrt(2) / 2 0;
0 1 - sqrt(2) / 2
]
A = [
0 0;
(sqrt(2) - 1) / 2 0
]
b = [0, 1]
ros = @inferred RosenbrockMethod(γ, A, b)

# second-order accurate
@test abs(@inferred(residual_order_condition(rootedtree(Int[]), ros))) <
10 * eps()
@test abs(@inferred(residual_order_condition(rootedtree(Int[1]), ros))) <
10 * eps()
@test abs(@inferred(residual_order_condition(rootedtree(Int[1, 2]), ros))) <
10 * eps()
@test abs(@inferred(residual_order_condition(rootedtree(Int[1, 2, 3]), ros))) >
0.04
@test abs(@inferred(residual_order_condition(rootedtree(Int[1, 2, 2]), ros))) >
0.14
end

@testset "RosenbrockMethod, GRK4A (Kaps and Rentrop, 1979)" begin
# Kaps, Rentrop (1979)
# Generalized Runge-Kutta methods of order four with stepsize control
# for stiff ordinary differential equations
# https://doi.org/10.1007/BF01396495
γ = [
0.395 0 0 0;
-0.767672395484 0.395 0 0;
-0.851675323742 0.522967289188 0.395 0;
0.288463109545 0.880214273381e-1 -0.337389840627 0.395
]
A = [
0 0 0 0;
0.438 0 0 0;
0.796920457938 0.730795420615e-1 0 0;
0.796920457938 0.730795420615e-1 0 0
]
b = [0.199293275701, 0.482645235674, 0.680614886256e-1, 0.25]
ros = @inferred RosenbrockMethod(γ, A, b)

@test_nowarn show(ros)
@test_nowarn show(IOContext(stdout, :compact => true), ros)

# fourth-order accurate
for o in 0:4
for t in RootedTreeIterator(o)
val = @inferred residual_order_condition(t, ros)
@test abs(val) < 3000 * eps()
end
end

# not fifth-order accurate
s = 0.0
for t in RootedTreeIterator(5)
s += abs(residual_order_condition(t, ros))
end
@test s > 0.06
end
57 changes: 57 additions & 0 deletions test/plots_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Test
using RootedTrees
using Plots: Plots, plot

Plots.unicodeplots()

@testset "RootedTree" begin
plot(rootedtree(Int[]))

for order in 1:4
for t in RootedTreeIterator(order)
plot(t)
end
end
end

@testset "ColoredRootedTree" begin
let t = rootedtree(Int[], Bool[])
plot(t)
end

let t = rootedtree([1], [1])
plot(t)
end

let t = rootedtree([1], [2])
plot(t)
end

let t = rootedtree([1], [3])
plot(t)
end

let t = rootedtree([1, 2], [1, 1])
plot(t)
end

let t = rootedtree([1, 2], [1, 2])
plot(t)
end

let t = rootedtree([1, 2], [3, 1])
plot(t)
end

let t = rootedtree([1, 2, 2], [2, 1, 1])
plot(t)
end

let t = rootedtree([1, 2, 2], [2, 1, 2])
plot(t)
end

let t = rootedtree([1, 2, 3], [3, 2, 1])
plot(t)
end
end
4 changes: 4 additions & 0 deletions test/qa/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
RootedTrees = "47965b36-3f3e-11e9-0dcf-4570dfd42a8c"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SciMLTesting = "09d9d899-5365-40a9-917a-5f67fddea283"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[sources]
Expand All @@ -12,5 +14,7 @@ RootedTrees = { path = "../.." }
Aqua = "0.8"
ExplicitImports = "1"
JET = "0.9, 0.10, 0.11"
SafeTestsets = "0.1, 1"
SciMLTesting = "1"
Test = "1"
julia = "1.10"
Loading
Loading