From 4d211eb8a421ec6b18b0b63a56052d206e1985e5 Mon Sep 17 00:00:00 2001 From: Joshua Lampert Date: Thu, 19 Sep 2024 13:41:35 +0200 Subject: [PATCH 1/2] Use TestItems.jl --- test/Project.toml | 4 + test/runtests.jl | 35 +- test/test_aqua.jl | 13 +- test/test_bbm_1d.jl | 336 ++++---- test/test_bbm_bbm_1d.jl | 563 +++++++------ test/test_hyperbolic_serre_green_naghdi_1d.jl | 439 +++++----- test/test_serre_green_naghdi_1d.jl | 565 +++++++------ test/test_svaerd_kalisch_1d.jl | 174 ++-- test/test_unit.jl | 778 +++++++++--------- test/test_util.jl | 41 - test/test_visualization.jl | 11 +- 11 files changed, 1455 insertions(+), 1504 deletions(-) diff --git a/test/Project.toml b/test/Project.toml index f6bbeb9e..b9bd8fc1 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -6,6 +6,8 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SummationByPartsOperators = "9f78cca6-572e-554e-b819-917d2f1cf240" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a" +TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe" [compat] Aqua = "0.7, 0.8" @@ -15,3 +17,5 @@ Plots = "1.25" SparseArrays = "1" SummationByPartsOperators = "0.5.63" Test = "1" +TestItemRunner = "1" +TestItems = "1" diff --git a/test/runtests.jl b/test/runtests.jl index 1526bd47..5f30faba 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,12 +1,25 @@ -using Test - -@testset "DispersiveShallowWater.jl" begin - include("test_aqua.jl") - include("test_unit.jl") - include("test_visualization.jl") - include("test_bbm_1d.jl") - include("test_bbm_bbm_1d.jl") - include("test_svaerd_kalisch_1d.jl") - include("test_serre_green_naghdi_1d.jl") - include("test_hyperbolic_serre_green_naghdi_1d.jl") +using TestItems +using TestItemRunner + +@run_package_tests + +@testsnippet Setup begin + using DispersiveShallowWater + using Test + include("test_util.jl") +end + +@testsnippet AdditionalImports begin + using SummationByPartsOperators: PeriodicDerivativeOperator, + UniformPeriodicCoupledOperator, + PeriodicUpwindOperators + using SummationByPartsOperators: derivative_order, periodic_derivative_operator, + legendre_derivative_operator, + UniformPeriodicMesh1D, couple_discontinuously, + upwind_operators, couple_continuously, + legendre_second_derivative_operator, + Mattsson2017 + + using SparseArrays: sparse, SparseMatrixCSC + using OrdinaryDiffEq: solve end diff --git a/test/test_aqua.jl b/test/test_aqua.jl index 532ac601..fe38b092 100644 --- a/test/test_aqua.jl +++ b/test/test_aqua.jl @@ -1,15 +1,8 @@ -module TestAqua - -using Aqua -using ExplicitImports: check_no_implicit_imports, check_no_stale_explicit_imports -using Test -using DispersiveShallowWater - -@testset "Aqua.jl" begin +@testitem "Aqua.jl" setup=[Setup] begin + using Aqua + using ExplicitImports: check_no_implicit_imports, check_no_stale_explicit_imports Aqua.test_all(DispersiveShallowWater, ambiguities = false) @test isnothing(check_no_implicit_imports(DispersiveShallowWater)) @test isnothing(check_no_stale_explicit_imports(DispersiveShallowWater)) end - -end #module diff --git a/test/test_bbm_1d.jl b/test/test_bbm_1d.jl index a4e7c621..e4e20d0b 100644 --- a/test/test_bbm_1d.jl +++ b/test/test_bbm_1d.jl @@ -1,184 +1,170 @@ -module TestBBM1D - -using Test -using DispersiveShallowWater - -include("test_util.jl") - -EXAMPLES_DIR = joinpath(examples_dir(), "bbm_1d") - -@testset "BBMEquation1D" begin - @trixi_testset "bbm_1d_basic" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_1d_basic.jl"), - tspan=(0.0, 100.0), - l2=[0.020905920116663004], - linf=[0.011361008348288737], - cons_error=[1.3322676295501878e-15], - change_waterheight=1.3322676295501878e-15, - change_entropy_modified=-8.852448858398532e-7, - change_hamiltonian=-4.366246803000351e-6) - - @test_allocations(semi, sol, allocs=5_000) - - # test upwind operators - using SummationByPartsOperators: upwind_operators, periodic_derivative_operator - using SparseArrays: sparse - using OrdinaryDiffEq: solve - D1 = upwind_operators(periodic_derivative_operator; derivative_order = 1, - accuracy_order = accuracy_order, xmin = mesh.xmin, - xmax = mesh.xmax, - N = mesh.N) - D2 = sparse(D1.minus) * sparse(D1.plus) - solver = Solver(D1, D2) - semi = Semidiscretization(mesh, equations, initial_condition, solver, - boundary_conditions = boundary_conditions) - ode = semidiscretize(semi, (0.0, 100.0)) - sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7, - save_everystep = false, callback = callbacks, saveat = saveat) - atol = 1e-12 - rtol = 1e-12 - errs = errors(analysis_callback) - l2 = [0.11730278305145693] - l2_measured = errs.l2_error[:, end] - for (l2_expected, l2_actual) in zip(l2, l2_measured) - @test isapprox(l2_expected, l2_actual, atol = atol, rtol = rtol) - end - linf = [0.06433115916307008] - linf_measured = errs.linf_error[:, end] - for (linf_expected, linf_actual) in zip(linf, linf_measured) - @test isapprox(linf_expected, linf_actual, atol = atol, rtol = rtol) - end - - @test_allocations(semi, sol, allocs=5_000) - end +@testsnippet BBMEquation1D begin + EXAMPLES_DIR = joinpath(examples_dir(), "bbm_1d") +end - @trixi_testset "bbm_1d_basic with split_form = false" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_1d_basic.jl"), - tspan=(0.0, 100.0), - split_form=false, - l2=[0.018773238618175637], - linf=[0.0102691348638429], - cons_error=[4.218847493575595e-15], - change_waterheight=4.218847493575595e-15, - change_entropy_modified=-5.764463673341158e-7, - change_hamiltonian=-3.3263833076890847e-6) - - @test_allocations(semi, sol, allocs=5_000) - - # test upwind operators - using SummationByPartsOperators: upwind_operators, periodic_derivative_operator - using SparseArrays: sparse - using OrdinaryDiffEq: solve - D1 = upwind_operators(periodic_derivative_operator; derivative_order = 1, - accuracy_order = accuracy_order, xmin = mesh.xmin, - xmax = mesh.xmax, - N = mesh.N) - D2 = sparse(D1.minus) * sparse(D1.plus) - solver = Solver(D1, D2) - semi = Semidiscretization(mesh, equations, initial_condition, solver, - boundary_conditions = boundary_conditions) - ode = semidiscretize(semi, (0.0, 100.0)) - sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7, - save_everystep = false, callback = callbacks, saveat = saveat) - atol = 1e-12 - rtol = 1e-12 - errs = errors(analysis_callback) - l2 = [0.11994249550267427] - l2_measured = errs.l2_error[:, end] - for (l2_expected, l2_actual) in zip(l2, l2_measured) - @test isapprox(l2_expected, l2_actual, atol = atol, rtol = rtol) - end - linf = [0.06576332657307044] - linf_measured = errs.linf_error[:, end] - for (linf_expected, linf_actual) in zip(linf, linf_measured) - @test isapprox(linf_expected, linf_actual, atol = atol, rtol = rtol) - end - - @test_allocations(semi, sol, allocs=5_000) +@testitem "bbm_1d_basic" setup=[Setup, BBMEquation1D, AdditionalImports] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_1d_basic.jl"), + tspan=(0.0, 100.0), + l2=[0.020905920116663004], + linf=[0.011361008348288737], + cons_error=[1.3322676295501878e-15], + change_waterheight=1.3322676295501878e-15, + change_entropy_modified=-8.852448858398532e-7, + change_hamiltonian=-4.366246803000351e-6) + + @test_allocations(semi, sol, allocs=5_000) + + # test upwind operators + D1 = upwind_operators(periodic_derivative_operator; derivative_order = 1, + accuracy_order = accuracy_order, xmin = mesh.xmin, + xmax = mesh.xmax, + N = mesh.N) + D2 = sparse(D1.minus) * sparse(D1.plus) + solver = Solver(D1, D2) + semi = Semidiscretization(mesh, equations, initial_condition, solver, + boundary_conditions = boundary_conditions) + ode = semidiscretize(semi, (0.0, 100.0)) + sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7, + save_everystep = false, callback = callbacks, saveat = saveat) + atol = 1e-12 + rtol = 1e-12 + errs = errors(analysis_callback) + l2 = [0.11730278305145693] + l2_measured = errs.l2_error[:, end] + for (l2_expected, l2_actual) in zip(l2, l2_measured) + @test isapprox(l2_expected, l2_actual, atol = atol, rtol = rtol) end - - @trixi_testset "bbm_1d_relaxation" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_1d_relaxation.jl"), - tspan=(0.0, 100.0), - l2=[0.020884321819757214], - linf=[0.011350059432479132], - cons_error=[2.220446049250313e-15], - change_waterheight=2.220446049250313e-15, - change_entropy_modified=2.7755575615628914e-17, - change_hamiltonian=-1.039007974656947e-6) - - @test_allocations(semi, sol, allocs=5_000) + linf = [0.06433115916307008] + linf_measured = errs.linf_error[:, end] + for (linf_expected, linf_actual) in zip(linf, linf_measured) + @test isapprox(linf_expected, linf_actual, atol = atol, rtol = rtol) end - @trixi_testset "bbm_1d_hamiltonian_relaxation" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_1d_hamiltonian_relaxation.jl"), - tspan=(0.0, 100.0), - l2=[0.018751641621494324], - linf=[0.010258179709480952], - cons_error=[3.552713678800501e-15], - change_waterheight=3.552713678800501e-15, - change_entropy_modified=3.085709884831367e-7, - change_hamiltonian=4.440892098500626e-16) - - @test_allocations(semi, sol, allocs=5_000) - end + @test_allocations(semi, sol, allocs=5_000) +end - @trixi_testset "bbm_1d_fourier" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_1d_fourier.jl"), - tspan=(0.0, 100.0), - l2=[1.812306511686721e-5], - linf=[1.0044426771715909e-5], - cons_error=[6.439293542825908e-15], - change_waterheight=-6.439293542825908e-15, - change_entropy_modified=-8.734545181576792e-7, - change_hamiltonian=-3.282887288680314e-6) - - @test_allocations(semi, sol, allocs=5_000) +@testitem "bbm_1d_basic with split_form = false" setup=[ + Setup, + BBMEquation1D, + AdditionalImports, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_1d_basic.jl"), + tspan=(0.0, 100.0), + split_form=false, + l2=[0.018773238618175637], + linf=[0.0102691348638429], + cons_error=[4.218847493575595e-15], + change_waterheight=4.218847493575595e-15, + change_entropy_modified=-5.764463673341158e-7, + change_hamiltonian=-3.3263833076890847e-6) + + @test_allocations(semi, sol, allocs=5_000) + + # test upwind operators + D1 = upwind_operators(periodic_derivative_operator; derivative_order = 1, + accuracy_order = accuracy_order, xmin = mesh.xmin, + xmax = mesh.xmax, + N = mesh.N) + D2 = sparse(D1.minus) * sparse(D1.plus) + solver = Solver(D1, D2) + semi = Semidiscretization(mesh, equations, initial_condition, solver, + boundary_conditions = boundary_conditions) + ode = semidiscretize(semi, (0.0, 100.0)) + sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7, + save_everystep = false, callback = callbacks, saveat = saveat) + atol = 1e-12 + rtol = 1e-12 + errs = errors(analysis_callback) + l2 = [0.11994249550267427] + l2_measured = errs.l2_error[:, end] + for (l2_expected, l2_actual) in zip(l2, l2_measured) + @test isapprox(l2_expected, l2_actual, atol = atol, rtol = rtol) end - - @trixi_testset "bbm_1d_manufactured" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_1d_manufactured.jl"), - tspan=(0.0, 1.0), - l2=[6.073756646372025e-9], - linf=[8.869951328982495e-9], - cons_error=[2.60491292165127e-12], - change_waterheight=2.60491292165127e-12, - atol=1e-11) # to make CI pass - - @test_allocations(semi, sol, allocs=5_000) - - # test upwind operators - using SummationByPartsOperators: upwind_operators, periodic_derivative_operator - using SparseArrays: sparse - using OrdinaryDiffEq: solve - D1 = upwind_operators(periodic_derivative_operator; derivative_order = 1, - accuracy_order = accuracy_order, xmin = mesh.xmin, - xmax = mesh.xmax, - N = mesh.N) - D2 = sparse(D1.minus) * sparse(D1.plus) - solver = Solver(D1, D2) - semi = Semidiscretization(mesh, equations, initial_condition, solver, - boundary_conditions = boundary_conditions, - source_terms = source_terms) - ode = semidiscretize(semi, (0.0, 1.0)) - sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7, - save_everystep = false, callback = callbacks, saveat = saveat) - atol = 1e-11 # to make CI pass - rtol = 1e-12 - errs = errors(analysis_callback) - l2 = [9.94432411102018e-8] - l2_measured = errs.l2_error[:, end] - for (l2_expected, l2_actual) in zip(l2, l2_measured) - @test isapprox(l2_expected, l2_actual, atol = atol, rtol = rtol) - end - linf = [1.026056097863659e-7] - linf_measured = errs.linf_error[:, end] - for (linf_expected, linf_actual) in zip(linf, linf_measured) - @test isapprox(linf_expected, linf_actual, atol = atol, rtol = rtol) - end - - @test_allocations(semi, sol, allocs=5_000) + linf = [0.06576332657307044] + linf_measured = errs.linf_error[:, end] + for (linf_expected, linf_actual) in zip(linf, linf_measured) + @test isapprox(linf_expected, linf_actual, atol = atol, rtol = rtol) end + + @test_allocations(semi, sol, allocs=5_000) +end + +@testitem "bbm_1d_relaxation" setup=[Setup, BBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_1d_relaxation.jl"), + tspan=(0.0, 100.0), + l2=[0.020884321819757214], + linf=[0.011350059432479132], + cons_error=[2.220446049250313e-15], + change_waterheight=2.220446049250313e-15, + change_entropy_modified=2.7755575615628914e-17, + change_hamiltonian=-1.039007974656947e-6) + + @test_allocations(semi, sol, allocs=5_000) end -end # module +@testitem "bbm_1d_hamiltonian_relaxation" setup=[Setup, BBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_1d_hamiltonian_relaxation.jl"), + tspan=(0.0, 100.0), + l2=[0.018751641621494324], + linf=[0.010258179709480952], + cons_error=[3.552713678800501e-15], + change_waterheight=3.552713678800501e-15, + change_entropy_modified=3.085709884831367e-7, + change_hamiltonian=4.440892098500626e-16) + + @test_allocations(semi, sol, allocs=5_000) +end + +@testitem "bbm_1d_fourier" setup=[Setup, BBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_1d_fourier.jl"), + tspan=(0.0, 100.0), + l2=[1.812306511686721e-5], + linf=[1.0044426771715909e-5], + cons_error=[6.439293542825908e-15], + change_waterheight=-6.439293542825908e-15, + change_entropy_modified=-8.734545181576792e-7, + change_hamiltonian=-3.282887288680314e-6) + + @test_allocations(semi, sol, allocs=5_000) +end + +@testitem "bbm_1d_manufactured" setup=[Setup, BBMEquation1D, AdditionalImports] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_1d_manufactured.jl"), + tspan=(0.0, 1.0), + l2=[6.073756646372025e-9], + linf=[8.869951328982495e-9], + cons_error=[2.60491292165127e-12], + change_waterheight=2.60491292165127e-12, + atol=1e-11) # to make CI pass + + @test_allocations(semi, sol, allocs=5_000) + + # test upwind operators + D1 = upwind_operators(periodic_derivative_operator; derivative_order = 1, + accuracy_order = accuracy_order, xmin = mesh.xmin, + xmax = mesh.xmax, + N = mesh.N) + D2 = sparse(D1.minus) * sparse(D1.plus) + solver = Solver(D1, D2) + semi = Semidiscretization(mesh, equations, initial_condition, solver, + boundary_conditions = boundary_conditions, + source_terms = source_terms) + ode = semidiscretize(semi, (0.0, 1.0)) + sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7, + save_everystep = false, callback = callbacks, saveat = saveat) + atol = 1e-11 # to make CI pass + rtol = 1e-12 + errs = errors(analysis_callback) + l2 = [9.94432411102018e-8] + l2_measured = errs.l2_error[:, end] + for (l2_expected, l2_actual) in zip(l2, l2_measured) + @test isapprox(l2_expected, l2_actual, atol = atol, rtol = rtol) + end + linf = [1.026056097863659e-7] + linf_measured = errs.linf_error[:, end] + for (linf_expected, linf_actual) in zip(linf, linf_measured) + @test isapprox(linf_expected, linf_actual, atol = atol, rtol = rtol) + end + + @test_allocations(semi, sol, allocs=5_000) +end diff --git a/test/test_bbm_bbm_1d.jl b/test/test_bbm_bbm_1d.jl index 747927fd..87c45c97 100644 --- a/test/test_bbm_bbm_1d.jl +++ b/test/test_bbm_bbm_1d.jl @@ -1,305 +1,294 @@ -module TestBBMBBM1D - -using Test -using DispersiveShallowWater - -include("test_util.jl") - -EXAMPLES_DIR = joinpath(examples_dir(), "bbm_bbm_1d") - -@testset "BBMBBMEquations1D" begin - @trixi_testset "bbm_bbm_1d_basic" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_basic.jl"), - tspan=(0.0, 1.0), - l2=[0.0032743987817220976 0.007246750130235789 0.0], - linf=[0.0027330553477815656 0.0037734958705577526 0.0], - cons_error=[2.7030772060575454e-14 1.4210854715202004e-13 0.0], - change_waterheight=-2.7030772060575454e-14, - change_velocity=-1.4210854715202004e-13, - change_entropy=0.00023829378642403753, - atol_ints=1e-10) # to make CI pass - - @test_allocations(semi, sol, allocs=10_000) - - # test upwind operators - using SummationByPartsOperators: upwind_operators, periodic_derivative_operator - using SparseArrays: sparse - using OrdinaryDiffEq: solve - D1 = upwind_operators(periodic_derivative_operator; derivative_order = 1, - accuracy_order = accuracy_order, xmin = mesh.xmin, - xmax = mesh.xmax, - N = mesh.N) - D2 = sparse(D1.plus) * sparse(D1.minus) - solver = Solver(D1, D2) - semi = Semidiscretization(mesh, equations, initial_condition, solver, - boundary_conditions = boundary_conditions) - ode = semidiscretize(semi, (0.0, 1.0)) - sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7, - save_everystep = false, callback = callbacks, saveat = saveat) - atol = 1e-11 # to make CI pass - rtol = 1e-12 - errs = errors(analysis_callback) - l2 = [0.0026452454364373377 0.005181138085234744 0.0] - l2_measured = errs.l2_error[:, end] - for (l2_expected, l2_actual) in zip(l2, l2_measured) - @test isapprox(l2_expected, l2_actual, atol = atol, rtol = rtol) - end - linf = [0.002240297682717385 0.003138940449190386 0.0] - linf_measured = errs.linf_error[:, end] - for (linf_expected, linf_actual) in zip(linf, linf_measured) - @test isapprox(linf_expected, linf_actual, atol = atol, rtol = rtol) - end - - @test_allocations(semi, sol, allocs=10_000) - end +@testsnippet BBMBBMEquation1D begin + EXAMPLES_DIR = joinpath(examples_dir(), "bbm_bbm_1d") +end - @trixi_testset "bbm_bbm_1d_basic with bathymetry_variable" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_basic.jl"), - bathymetry_type=bathymetry_variable, - tspan=(0.0, 1.0), - l2=[0.002475254552148715 0.005510109246665293 0.0], - linf=[0.0019397546359500861 0.0032957358113563373 0.0], - cons_error=[1.0394561372181596e-13 3.410605131648481e-13 0.0], - change_waterheight=1.0394561372181596e-13, - change_velocity=-3.410605131648481e-13, - change_entropy=0.0006197172569955001, - atol_ints=1e-10) # to make CI pass - - @test_allocations(semi, sol, allocs=10_000) +@testitem "bbm_bbm_1d_basic" setup=[Setup, BBMBBMEquation1D, AdditionalImports] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_basic.jl"), + tspan=(0.0, 1.0), + l2=[0.0032743987817220976 0.007246750130235789 0.0], + linf=[0.0027330553477815656 0.0037734958705577526 0.0], + cons_error=[2.7030772060575454e-14 1.4210854715202004e-13 0.0], + change_waterheight=-2.7030772060575454e-14, + change_velocity=-1.4210854715202004e-13, + change_entropy=0.00023829378642403753, + atol_ints=1e-10) # to make CI pass + + @test_allocations(semi, sol, allocs=10_000) + + # test upwind operators + D1 = upwind_operators(periodic_derivative_operator; derivative_order = 1, + accuracy_order = accuracy_order, xmin = mesh.xmin, + xmax = mesh.xmax, + N = mesh.N) + D2 = sparse(D1.plus) * sparse(D1.minus) + solver = Solver(D1, D2) + semi = Semidiscretization(mesh, equations, initial_condition, solver, + boundary_conditions = boundary_conditions) + ode = semidiscretize(semi, (0.0, 1.0)) + sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7, + save_everystep = false, callback = callbacks, saveat = saveat) + atol = 1e-11 # to make CI pass + rtol = 1e-12 + errs = errors(analysis_callback) + l2 = [0.0026452454364373377 0.005181138085234744 0.0] + l2_measured = errs.l2_error[:, end] + for (l2_expected, l2_actual) in zip(l2, l2_measured) + @test isapprox(l2_expected, l2_actual, atol = atol, rtol = rtol) end - - @trixi_testset "bbm_bbm_1d_dg" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_dg.jl"), - tspan=(0.0, 1.0), - l2=[0.005820370895289719 0.0012483148286926665 0.0], - linf=[0.012036829933978588 0.0022436858082413025 0.0], - cons_error=[2.2555754226055478e-14 7.815970093361102e-14 0.0], - change_waterheight=2.2555754226055478e-14, - change_velocity=-7.815970093361102e-14, - change_entropy=-0.001165974183408025) - - @test_allocations(semi, sol, allocs=10_000) + linf = [0.002240297682717385 0.003138940449190386 0.0] + linf_measured = errs.linf_error[:, end] + for (linf_expected, linf_actual) in zip(linf, linf_measured) + @test isapprox(linf_expected, linf_actual, atol = atol, rtol = rtol) end - @trixi_testset "bbm_bbm_1d_dg with bathymetry_variable" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_dg.jl"), - bathymetry_type=bathymetry_variable, - tspan=(0.0, 1.0), - l2=[0.009197531778215928 0.0015521194273725176 0.0], - linf=[0.012034113656467671 0.0033862062614615773 0.0], - cons_error=[3.364296388121304e-14 9.947598300641403e-14 0.0], - change_waterheight=3.364296388121304e-14, - change_velocity=-9.947598300641403e-14, - change_entropy=-0.000791230828923517) - - @test_allocations(semi, sol, allocs=10_000) - end + @test_allocations(semi, sol, allocs=10_000) +end - @trixi_testset "bbm_bbm_1d_relaxation" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_relaxation.jl"), - tspan=(0.0, 1.0), - l2=[0.0032736306642711533 0.007244906041050075 0.0], - linf=[0.002732472407469544 0.0037722741328174436 0.0], - cons_error=[2.47001411123548e-14 2.842170943040401e-14 0.0], - change_waterheight=-2.47001411123548e-14, - change_velocity=2.842170943040401e-14, - change_entropy=-2.9558577807620168e-12) - - @test_allocations(semi, sol, allocs=10_000) - end +@testitem "bbm_bbm_1d_basic with bathymetry_variable" setup=[Setup, BBMBBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_basic.jl"), + bathymetry_type=bathymetry_variable, + tspan=(0.0, 1.0), + l2=[0.002475254552148715 0.005510109246665293 0.0], + linf=[0.0019397546359500861 0.0032957358113563373 0.0], + cons_error=[1.0394561372181596e-13 3.410605131648481e-13 0.0], + change_waterheight=1.0394561372181596e-13, + change_velocity=-3.410605131648481e-13, + change_entropy=0.0006197172569955001, + atol_ints=1e-10) # to make CI pass + + @test_allocations(semi, sol, allocs=10_000) +end - @trixi_testset "bbm_bbm_1d_relaxation with bathymetry_variable" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_relaxation.jl"), - bathymetry_type=bathymetry_variable, - tspan=(0.0, 1.0), - l2=[0.0024773815236814826 0.005515225594228142 0.0], - linf=[0.001941460860594768 0.0032992043482167333 0.0], - cons_error=[2.864588178487867e-14 5.684341886080802e-14 0.0], - change_waterheight=2.864588178487867e-14, - change_velocity=-5.684341886080802e-14, - change_entropy=-2.2737367544323206e-13) - - @test_allocations(semi, sol, allocs=10_000) - end +@testitem "bbm_bbm_1d_dg" setup=[Setup, BBMBBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_dg.jl"), + tspan=(0.0, 1.0), + l2=[0.005820370895289719 0.0012483148286926665 0.0], + linf=[0.012036829933978588 0.0022436858082413025 0.0], + cons_error=[2.2555754226055478e-14 7.815970093361102e-14 0.0], + change_waterheight=2.2555754226055478e-14, + change_velocity=-7.815970093361102e-14, + change_entropy=-0.001165974183408025) + + @test_allocations(semi, sol, allocs=10_000) +end - @trixi_testset "bbm_bbm_1d_upwind_relaxation" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_upwind_relaxation.jl"), - tspan=(0.0, 1.0), - l2=[0.002644536846506582 0.005179311517589997 0.0], - linf=[0.002239772357125247 0.0031376618560692293 0.0], - cons_error=[3.1799390576478594e-14 3.979039320256561e-13 0.0], - change_waterheight=3.1799390576478594e-14, - change_velocity=3.979039320256561e-13, - change_entropy=6.821210263296962e-13) - - @test_allocations(semi, sol, allocs=10_000) - end +@testitem "bbm_bbm_1d_dg with bathymetry_variable" setup=[Setup, BBMBBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_dg.jl"), + bathymetry_type=bathymetry_variable, + tspan=(0.0, 1.0), + l2=[0.009197531778215928 0.0015521194273725176 0.0], + linf=[0.012034113656467671 0.0033862062614615773 0.0], + cons_error=[3.364296388121304e-14 9.947598300641403e-14 0.0], + change_waterheight=3.364296388121304e-14, + change_velocity=-9.947598300641403e-14, + change_entropy=-0.000791230828923517) + + @test_allocations(semi, sol, allocs=10_000) +end - @trixi_testset "bbm_bbm_1d_upwind_relaxation with bathymetry_variable" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_upwind_relaxation.jl"), - bathymetry_type=bathymetry_variable, - tspan=(0.0, 1.0), - l2=[0.00264453684734065 0.0051793115198710705 0.0], - linf=[0.0022397723578102546 0.0031376618574547877 0.0], - cons_error=[4.234505741492232e-15 4.547473508864641e-13 0.0], - change_waterheight=4.234505741492232e-15, - change_velocity=4.547473508864641e-13, - change_entropy=-2.2737367544323206e-12) - - @test_allocations(semi, sol, allocs=10_000) - end +@testitem "bbm_bbm_1d_relaxation" setup=[Setup, BBMBBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_relaxation.jl"), + tspan=(0.0, 1.0), + l2=[0.0032736306642711533 0.007244906041050075 0.0], + linf=[0.002732472407469544 0.0037722741328174436 0.0], + cons_error=[2.47001411123548e-14 2.842170943040401e-14 0.0], + change_waterheight=-2.47001411123548e-14, + change_velocity=2.842170943040401e-14, + change_entropy=-2.9558577807620168e-12) + + @test_allocations(semi, sol, allocs=10_000) +end - @trixi_testset "bbm_bbm_1d_manufactured" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_manufactured.jl"), - tspan=(0.0, 1.0), - l2=[6.866821527172215e-9 3.4469275186089985e-9 0.0], - linf=[1.1689290868588387e-8 5.928427526669111e-9 0.0], - cons_error=[2.1126156379835948e-12 8.243777181889383e-12 0.0], - change_waterheight=-2.1126156379835948e-12, - change_velocity=-8.243777181889383e-12, - change_entropy=17.817012269328853, - atol=1e-10, - atol_ints=1e-10) # to make CI pass - - @test_allocations(semi, sol, allocs=10_000) - end +@testitem "bbm_bbm_1d_relaxation with bathymetry_variable" setup=[Setup, BBMBBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_relaxation.jl"), + bathymetry_type=bathymetry_variable, + tspan=(0.0, 1.0), + l2=[0.0024773815236814826 0.005515225594228142 0.0], + linf=[0.001941460860594768 0.0032992043482167333 0.0], + cons_error=[2.864588178487867e-14 5.684341886080802e-14 0.0], + change_waterheight=2.864588178487867e-14, + change_velocity=-5.684341886080802e-14, + change_entropy=-2.2737367544323206e-13) + + @test_allocations(semi, sol, allocs=10_000) +end - @trixi_testset "bbm_bbm_1d_manufactured with bathymetry_flat" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_manufactured.jl"), - bathymetry_type=bathymetry_flat, - tspan=(0.0, 1.0), - l2=[5.564654145503227e-9 8.058808980392836e-10 0.0], - linf=[7.905728516277577e-9 1.1420695500419242e-9 0.0], - cons_error=[5.767395241940143e-12 4.184121331471304e-12 0.0], - change_waterheight=-5.767395241940143e-12, - change_velocity=4.184121331471304e-12, - change_entropy=17.38744182699684, - atol=1e-11, - atol_ints=1e-10) # to make CI pass - - @test_allocations(semi, sol, allocs=10_000) - end +@testitem "bbm_bbm_1d_upwind_relaxation" setup=[Setup, BBMBBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_upwind_relaxation.jl"), + tspan=(0.0, 1.0), + l2=[0.002644536846506582 0.005179311517589997 0.0], + linf=[0.002239772357125247 0.0031376618560692293 0.0], + cons_error=[3.1799390576478594e-14 3.979039320256561e-13 0.0], + change_waterheight=3.1799390576478594e-14, + change_velocity=3.979039320256561e-13, + change_entropy=6.821210263296962e-13) + + @test_allocations(semi, sol, allocs=10_000) +end - @trixi_testset "bbm_bbm_1d_basic_reflecting" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_basic_reflecting.jl"), - tspan=(0.0, 1.0), - l2=[0.00022223640611354037 7.626931465504548e-9 0.0], - linf=[0.0002947437933196184 1.7383174233387422e-8 0.0], - cons_error=[9.701410286113879e-10 0.5469460962472683 0.0], - change_waterheight=9.701410286113879e-10, - change_velocity=0.5469460962472683, - change_entropy=132.10935771957952, - atol=1e-10, - atol_ints=1e-10) # to make CI pass - - @test_allocations(semi, sol, allocs=1_500) - - # test upwind operators - using SummationByPartsOperators: upwind_operators, Mattsson2017 - using SparseArrays: sparse - using OrdinaryDiffEq: solve - D1 = upwind_operators(Mattsson2017; derivative_order = 1, - accuracy_order = accuracy_order, xmin = mesh.xmin, - xmax = mesh.xmax, - N = mesh.N) - D2 = sparse(D1.plus) * sparse(D1.minus) - solver = Solver(D1, D2) - semi = Semidiscretization(mesh, equations, initial_condition, solver, - boundary_conditions = boundary_conditions, - source_terms = source_terms) - ode = semidiscretize(semi, (0.0, 1.0)) - sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7, - save_everystep = false, callback = callbacks, saveat = saveat) - atol = 1e-7 # to make CI pass - rtol = 1e-12 - errs = errors(analysis_callback) - l2 = [0.002345799818043513 3.254313503127441e-8 0.0] - l2_measured = errs.l2_error[:, end] - for (l2_expected, l2_actual) in zip(l2, l2_measured) - @test isapprox(l2_expected, l2_actual, atol = atol, rtol = rtol) - end - linf = [0.05625950533062252 6.815531732318192e-7 0.0] - linf_measured = errs.linf_error[:, end] - for (linf_expected, linf_actual) in zip(linf, linf_measured) - @test isapprox(linf_expected, linf_actual, atol = atol, rtol = rtol) - end - - @test_allocations(semi, sol, allocs=1_500) - end +@testitem "bbm_bbm_1d_upwind_relaxation with bathymetry_variable" setup=[ + Setup, + BBMBBMEquation1D, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_upwind_relaxation.jl"), + bathymetry_type=bathymetry_variable, + tspan=(0.0, 1.0), + l2=[0.00264453684734065 0.0051793115198710705 0.0], + linf=[0.0022397723578102546 0.0031376618574547877 0.0], + cons_error=[4.234505741492232e-15 4.547473508864641e-13 0.0], + change_waterheight=4.234505741492232e-15, + change_velocity=4.547473508864641e-13, + change_entropy=-2.2737367544323206e-12) + + @test_allocations(semi, sol, allocs=10_000) +end - @trixi_testset "bbm_bbm_1d_basic_reflecting with bathymetry_flat" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_basic_reflecting.jl"), - bathymetry_type=bathymetry_flat, - tspan=(0.0, 1.0), - l2=[7.585650541014755e-6 5.3346100010644425e-9 0.0], - linf=[1.016759621386143e-5 9.171166714949663e-9 0.0], - cons_error=[1.13200113340443e-10 0.5469460971120386 0.0], - change_waterheight=1.13200113340443e-10, - change_velocity=0.5469460971120386, - change_entropy=132.04866881559724, - atol=1e-10, - atol_ints=1e-10) # to make CI pass - - @test_allocations(semi, sol, allocs=1_500) - - # test upwind operators - using SummationByPartsOperators: upwind_operators, Mattsson2017 - using SparseArrays: sparse - using OrdinaryDiffEq: solve - D1 = upwind_operators(Mattsson2017; derivative_order = 1, - accuracy_order = accuracy_order, xmin = mesh.xmin, - xmax = mesh.xmax, - N = mesh.N) - D2 = sparse(D1.plus) * sparse(D1.minus) - solver = Solver(D1, D2) - semi = Semidiscretization(mesh, equations, initial_condition, solver, - boundary_conditions = boundary_conditions, - source_terms = source_terms) - ode = semidiscretize(semi, (0.0, 1.0)) - sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7, - save_everystep = false, callback = callbacks, saveat = saveat) - atol = 1e-8 # to make CI pass - rtol = 1e-12 - errs = errors(analysis_callback) - l2 = [9.791289242253764e-5 6.608214058228884e-9 0.0] - l2_measured = errs.l2_error[:, end] - for (l2_expected, l2_actual) in zip(l2, l2_measured) - @test isapprox(l2_expected, l2_actual, atol = atol, rtol = rtol) - end - linf = [0.0023482494155127043 8.684315878915161e-8 0.0] - linf_measured = errs.linf_error[:, end] - for (linf_expected, linf_actual) in zip(linf, linf_measured) - @test isapprox(linf_expected, linf_actual, atol = atol, rtol = rtol) - end - - @test_allocations(semi, sol, allocs=1_500) - end +@testitem "bbm_bbm_1d_manufactured" setup=[Setup, BBMBBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_manufactured.jl"), + tspan=(0.0, 1.0), + l2=[6.866821527172215e-9 3.4469275186089985e-9 0.0], + linf=[1.1689290868588387e-8 5.928427526669111e-9 0.0], + cons_error=[2.1126156379835948e-12 8.243777181889383e-12 0.0], + change_waterheight=-2.1126156379835948e-12, + change_velocity=-8.243777181889383e-12, + change_entropy=17.817012269328853, + atol=1e-10, + atol_ints=1e-10) # to make CI pass + + @test_allocations(semi, sol, allocs=10_000) +end + +@testitem "bbm_bbm_1d_manufactured with bathymetry_flat" setup=[Setup, BBMBBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_manufactured.jl"), + bathymetry_type=bathymetry_flat, + tspan=(0.0, 1.0), + l2=[5.564654145503227e-9 8.058808980392836e-10 0.0], + linf=[7.905728516277577e-9 1.1420695500419242e-9 0.0], + cons_error=[5.767395241940143e-12 4.184121331471304e-12 0.0], + change_waterheight=-5.767395241940143e-12, + change_velocity=4.184121331471304e-12, + change_entropy=17.38744182699684, + atol=1e-11, + atol_ints=1e-10) # to make CI pass + + @test_allocations(semi, sol, allocs=10_000) +end - @trixi_testset "bbm_bbm_1d_dingemans" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_dingemans.jl"), - tspan=(0.0, 1.0), - l2=[0.22292157345226027 0.7504924411607958 0.0], - linf=[0.03584030574058168 0.1202292994661 0.0], - cons_error=[2.6129272356900657e-17 2.1141942363467336e-16 0.0], - change_waterheight=-2.6129272356900657e-17, - change_velocity=2.1141942363467336e-16, - change_entropy=3.4175334942543323e-7) - - @test_allocations(semi, sol, allocs=10_000) +@testitem "bbm_bbm_1d_basic_reflecting" setup=[Setup, BBMBBMEquation1D, AdditionalImports] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_basic_reflecting.jl"), + tspan=(0.0, 1.0), + l2=[0.00022223640611354037 7.626931465504548e-9 0.0], + linf=[0.0002947437933196184 1.7383174233387422e-8 0.0], + cons_error=[9.701410286113879e-10 0.5469460962472683 0.0], + change_waterheight=9.701410286113879e-10, + change_velocity=0.5469460962472683, + change_entropy=132.10935771957952, + atol=1e-10, + atol_ints=1e-10) # to make CI pass + + @test_allocations(semi, sol, allocs=1_500) + + # test upwind operators + D1 = upwind_operators(Mattsson2017; derivative_order = 1, + accuracy_order = accuracy_order, xmin = mesh.xmin, + xmax = mesh.xmax, + N = mesh.N) + D2 = sparse(D1.plus) * sparse(D1.minus) + solver = Solver(D1, D2) + semi = Semidiscretization(mesh, equations, initial_condition, solver, + boundary_conditions = boundary_conditions, + source_terms = source_terms) + ode = semidiscretize(semi, (0.0, 1.0)) + sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7, + save_everystep = false, callback = callbacks, saveat = saveat) + atol = 1e-7 # to make CI pass + rtol = 1e-12 + errs = errors(analysis_callback) + l2 = [0.002345799818043513 3.254313503127441e-8 0.0] + l2_measured = errs.l2_error[:, end] + for (l2_expected, l2_actual) in zip(l2, l2_measured) + @test isapprox(l2_expected, l2_actual, atol = atol, rtol = rtol) + end + linf = [0.05625950533062252 6.815531732318192e-7 0.0] + linf_measured = errs.linf_error[:, end] + for (linf_expected, linf_actual) in zip(linf, linf_measured) + @test isapprox(linf_expected, linf_actual, atol = atol, rtol = rtol) end - @trixi_testset "bbm_bbm_1d_well_balanced" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_well_balanced.jl"), - tspan=(0.0, 1.0), - l2=[5.625847040853183e-15 2.7315317493074205e-15 0.0], - linf=[5.995204332975845e-15 1.12866211315047e-14 0.0], - cons_error=[8.881784197001252e-16 1.6076981933671723e-15 0.0], - change_waterheight=-8.881784197001252e-16, - change_velocity=-1.6076981933671723e-15, - change_entropy=-3.1086244689504383e-15) - - @test_allocations(semi, sol, allocs=10_000) + @test_allocations(semi, sol, allocs=2_000) +end + +@testitem "bbm_bbm_1d_basic_reflecting with bathymetry_flat" setup=[ + Setup, + BBMBBMEquation1D, + AdditionalImports, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_basic_reflecting.jl"), + bathymetry_type=bathymetry_flat, + tspan=(0.0, 1.0), + l2=[7.585650541014755e-6 5.3346100010644425e-9 0.0], + linf=[1.016759621386143e-5 9.171166714949663e-9 0.0], + cons_error=[1.13200113340443e-10 0.5469460971120386 0.0], + change_waterheight=1.13200113340443e-10, + change_velocity=0.5469460971120386, + change_entropy=132.04866881559724, + atol=1e-10, + atol_ints=1e-10) # to make CI pass + + @test_allocations(semi, sol, allocs=1_500) + + # test upwind operators + D1 = upwind_operators(Mattsson2017; derivative_order = 1, + accuracy_order = accuracy_order, xmin = mesh.xmin, + xmax = mesh.xmax, + N = mesh.N) + D2 = sparse(D1.plus) * sparse(D1.minus) + solver = Solver(D1, D2) + semi = Semidiscretization(mesh, equations, initial_condition, solver, + boundary_conditions = boundary_conditions, + source_terms = source_terms) + ode = semidiscretize(semi, (0.0, 1.0)) + sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7, + save_everystep = false, callback = callbacks, saveat = saveat) + atol = 1e-8 # to make CI pass + rtol = 1e-12 + errs = errors(analysis_callback) + l2 = [9.791289242253764e-5 6.608214058228884e-9 0.0] + l2_measured = errs.l2_error[:, end] + for (l2_expected, l2_actual) in zip(l2, l2_measured) + @test isapprox(l2_expected, l2_actual, atol = atol, rtol = rtol) end + linf = [0.0023482494155127043 8.684315878915161e-8 0.0] + linf_measured = errs.linf_error[:, end] + for (linf_expected, linf_actual) in zip(linf, linf_measured) + @test isapprox(linf_expected, linf_actual, atol = atol, rtol = rtol) + end + + @test_allocations(semi, sol, allocs=2_000) end -end # module +@testitem "bbm_bbm_1d_dingemans" setup=[Setup, BBMBBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_dingemans.jl"), + tspan=(0.0, 1.0), + l2=[0.22292157345226027 0.7504924411607958 0.0], + linf=[0.03584030574058168 0.1202292994661 0.0], + cons_error=[2.6129272356900657e-17 2.1141942363467336e-16 0.0], + change_waterheight=-2.6129272356900657e-17, + change_velocity=2.1141942363467336e-16, + change_entropy=3.4175334942543323e-7) + + @test_allocations(semi, sol, allocs=10_000) +end + +@testitem "bbm_bbm_1d_well_balanced" setup=[Setup, BBMBBMEquation1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, "bbm_bbm_1d_well_balanced.jl"), + tspan=(0.0, 1.0), + l2=[5.625847040853183e-15 2.7315317493074205e-15 0.0], + linf=[5.995204332975845e-15 1.12866211315047e-14 0.0], + cons_error=[8.881784197001252e-16 1.6076981933671723e-15 0.0], + change_waterheight=-8.881784197001252e-16, + change_velocity=-1.6076981933671723e-15, + change_entropy=-3.1086244689504383e-15) + + @test_allocations(semi, sol, allocs=10_000) +end diff --git a/test/test_hyperbolic_serre_green_naghdi_1d.jl b/test/test_hyperbolic_serre_green_naghdi_1d.jl index 77bd0ea0..f2a75927 100644 --- a/test/test_hyperbolic_serre_green_naghdi_1d.jl +++ b/test/test_hyperbolic_serre_green_naghdi_1d.jl @@ -1,221 +1,234 @@ -module TestHyperbolicSerreGreenNaghdi1D - -using Test -using DispersiveShallowWater - -include("test_util.jl") - -EXAMPLES_DIR = joinpath(examples_dir(), "hyperbolic_serre_green_naghdi_1d") - -@testset "HyperbolicSerreGreenNaghdiEquations1D" begin - @trixi_testset "hyperbolic_serre_green_naghdi_soliton.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "hyperbolic_serre_green_naghdi_soliton.jl"), - tspan=(0.0, 0.1), - l2=[ - 0.0007038714283663042, - 0.006508261273448058, - 0.0, - 0.024517136865274798, - 0.002141907410685252, - ], - linf=[ - 0.0005088046605401519, - 0.0036954890877776703, - 0.0, - 0.015022422297545818, - 0.0013290414555349184, - ], - cons_error=[ - 2.7000623958883807e-13, - 0.00013389587974454997, - 0.0, - 0.005963937086921899, - 4.502801745331908e-5, - ], - change_entropy_modified=-2.3374946067633573e-7) - - @test_allocations(semi, sol, allocs=1_000) - end - @trixi_testset "hyperbolic_serre_green_naghdi_soliton.jl with bathymetry_mild_slope" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "hyperbolic_serre_green_naghdi_soliton.jl"), - bathymetry_type=bathymetry_mild_slope, - tspan=(0.0, 0.1), - l2=[ - 0.0007038714283663042, - 0.006508261273448058, - 0.0, - 0.024517136865274798, - 0.002141907410685252, - ], - linf=[ - 0.0005088046605401519, - 0.0036954890877776703, - 0.0, - 0.015022422297545818, - 0.0013290414555349184, - ], - cons_error=[ - 2.7000623958883807e-13, - 0.00013389587974454997, - 0.0, - 0.005963937086921899, - 4.502801745331908e-5, - ], - change_entropy_modified=-2.3374946067633573e-7) - - @test_allocations(semi, sol, allocs=1_000) - end - - @trixi_testset "hyperbolic_serre_green_naghdi_soliton_relaxation.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "hyperbolic_serre_green_naghdi_soliton_relaxation.jl"), - tspan=(0.0, 0.1), - l2=[ - 0.0007041797674417557, - 0.006510737539763134, - 0.0, - 0.024517447804525746, - 0.002141928791106223, - ], - linf=[ - 0.0005090662088376163, - 0.0036987746989370907, - 0.0, - 0.01502004552088677, - 0.0013289272946777064, - ], - cons_error=[ - 3.126388037344441e-13, - 0.00013409338344283483, - 0.0, - 0.005963706457799891, - 4.504121848469822e-5, - ], - change_entropy_modified=-5.684341886080802e-14, - atol=2.0e-10) # to make CI pass - - @test_allocations(semi, sol, allocs=1_000) - end - - @trixi_testset "hyperbolic_serre_green_naghdi_well_balanced.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "hyperbolic_serre_green_naghdi_well_balanced.jl"), - tspan=(0.0, 0.01), - l2=[ - 1.493401506906233e-14, - 4.5636580728083475e-14, - 4.217312212200215e-15, - 5.399527148467818e-14, - 4.646551952637425e-15, - ], - linf=[ - 3.175237850427948e-14, - 1.2230280990924922e-13, - 6.661338147750939e-15, - 1.2201879375620406e-13, - 2.4646951146678475e-14, - ], - cons_error=[ - 1.509903313490213e-14, - 1.7256186536178874e-16, - 2.220446049250313e-15, - 6.788390857160712e-14, - 2.220446049250313e-15, - ], - change_entropy_modified=-3.197442310920451e-14, - lake_at_rest=1.833689450281284e-14) - - @test_allocations(semi, sol, allocs=1_000) - end +@testsnippet HyperbolicSerreGreenNaghdiEquations1D begin + EXAMPLES_DIR = joinpath(examples_dir(), "hyperbolic_serre_green_naghdi_1d") +end - @trixi_testset "hyperbolic_serre_green_naghdi_manufactured.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "hyperbolic_serre_green_naghdi_manufactured.jl"), - tspan=(0.0, 0.1), - l2=[ - 0.00019628580608347483, - 3.9074713552924354e-5, - 0.0, - 0.003659648461678621, - 0.00020113904201635437, - ], - linf=[ - 0.00033469307712019614, - 8.167556996618863e-5, - 0.0, - 0.006470346460325516, - 0.0003406400402869991, - ], - cons_error=[0.0, - 1.204145701494186e-5, - 0.0, - 1.6023987782225921, - 4.456003127373265e-6], - atol=1e-7) # to make CI pass +@testitem "hyperbolic_serre_green_naghdi_soliton.jl" setup=[ + Setup, + HyperbolicSerreGreenNaghdiEquations1D, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "hyperbolic_serre_green_naghdi_soliton.jl"), + tspan=(0.0, 0.1), + l2=[ + 0.0007038714283663042, + 0.006508261273448058, + 0.0, + 0.024517136865274798, + 0.002141907410685252, + ], + linf=[ + 0.0005088046605401519, + 0.0036954890877776703, + 0.0, + 0.015022422297545818, + 0.0013290414555349184, + ], + cons_error=[ + 2.7000623958883807e-13, + 0.00013389587974454997, + 0.0, + 0.005963937086921899, + 4.502801745331908e-5, + ], + change_entropy_modified=-2.3374946067633573e-7) + + @test_allocations(semi, sol, allocs=1_000) +end - @test_allocations(semi, sol, allocs=1_000) - end +@testitem "hyperbolic_serre_green_naghdi_soliton.jl with bathymetry_mild_slope" setup=[ + Setup, + HyperbolicSerreGreenNaghdiEquations1D, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "hyperbolic_serre_green_naghdi_soliton.jl"), + bathymetry_type=bathymetry_mild_slope, + tspan=(0.0, 0.1), + l2=[ + 0.0007038714283663042, + 0.006508261273448058, + 0.0, + 0.024517136865274798, + 0.002141907410685252, + ], + linf=[ + 0.0005088046605401519, + 0.0036954890877776703, + 0.0, + 0.015022422297545818, + 0.0013290414555349184, + ], + cons_error=[ + 2.7000623958883807e-13, + 0.00013389587974454997, + 0.0, + 0.005963937086921899, + 4.502801745331908e-5, + ], + change_entropy_modified=-2.3374946067633573e-7) + + @test_allocations(semi, sol, allocs=1_000) +end - @trixi_testset "hyperbolic_serre_green_naghdi_dingemans.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "hyperbolic_serre_green_naghdi_dingemans.jl"), - tspan=(0.0, 1.0), - l2=[ - 0.22618134328164993, - 0.7376950780256356, - 3.389954422650516e-15, - 0.5105085009518094, - 0.2270170397315174, - ], - linf=[ - 0.03631632774349847, - 0.11854594481576813, - 3.497202527569243e-15, - 0.08108200376359903, - 0.03645317804157178, - ], - cons_error=[2.3874235921539366e-12, - 0.0006849904339648783, - 1.0658141036401503e-14, - 0.0356135949814768, - 0.00017701343821840965], - change_entropy=-0.0013486980525385661, - change_entropy_modified=-2.7995769187327824e-6) +@testitem "hyperbolic_serre_green_naghdi_soliton_relaxation.jl" setup=[ + Setup, + HyperbolicSerreGreenNaghdiEquations1D, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "hyperbolic_serre_green_naghdi_soliton_relaxation.jl"), + tspan=(0.0, 0.1), + l2=[ + 0.0007041797674417557, + 0.006510737539763134, + 0.0, + 0.024517447804525746, + 0.002141928791106223, + ], + linf=[ + 0.0005090662088376163, + 0.0036987746989370907, + 0.0, + 0.01502004552088677, + 0.0013289272946777064, + ], + cons_error=[ + 3.126388037344441e-13, + 0.00013409338344283483, + 0.0, + 0.005963706457799891, + 4.504121848469822e-5, + ], + change_entropy_modified=-5.684341886080802e-14, + atol=2.0e-10) # to make CI pass + + @test_allocations(semi, sol, allocs=1_000) +end - @test_allocations(semi, sol, allocs=1_000) - end +@testitem "hyperbolic_serre_green_naghdi_well_balanced.jl" setup=[ + Setup, + HyperbolicSerreGreenNaghdiEquations1D, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "hyperbolic_serre_green_naghdi_well_balanced.jl"), + tspan=(0.0, 0.01), + l2=[ + 1.493401506906233e-14, + 4.5636580728083475e-14, + 4.217312212200215e-15, + 5.399527148467818e-14, + 4.646551952637425e-15, + ], + linf=[ + 3.175237850427948e-14, + 1.2230280990924922e-13, + 6.661338147750939e-15, + 1.2201879375620406e-13, + 2.4646951146678475e-14, + ], + cons_error=[ + 1.509903313490213e-14, + 1.7256186536178874e-16, + 2.220446049250313e-15, + 6.788390857160712e-14, + 2.220446049250313e-15, + ], + change_entropy_modified=-3.197442310920451e-14, + lake_at_rest=1.833689450281284e-14) + + @test_allocations(semi, sol, allocs=1_000) +end - @trixi_testset "hyperbolic_serre_green_naghdi_conservation.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "hyperbolic_serre_green_naghdi_conservation.jl"), - l2=[ - 1.3601939454962908, - 2.367812627978776, - 3.565537895102537e-14, - 0.8095219703329345, - 1.3613680507825028, - ], - linf=[ - 1.0010230791351136, - 0.7870081638593119, - 9.325873406851315e-15, - 0.24169078965789928, - 1.0010090485188015, - ], - cons_error=[6.230038707144558e-11, - 0.00029618251641450044, - 4.547473508864641e-13, - 0.00759853016721156, - 0.0014395235644997229], - change_entropy=-0.20915006380346313, - change_entropy_modified=-0.09431070096138683, - atol=1e-11, # to make CI pass - atol_ints=4e-9) # to make CI pass +@testitem "hyperbolic_serre_green_naghdi_manufactured.jl" setup=[ + Setup, + HyperbolicSerreGreenNaghdiEquations1D, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "hyperbolic_serre_green_naghdi_manufactured.jl"), + tspan=(0.0, 0.1), + l2=[ + 0.00019628580608347483, + 3.9074713552924354e-5, + 0.0, + 0.003659648461678621, + 0.00020113904201635437, + ], + linf=[ + 0.00033469307712019614, + 8.167556996618863e-5, + 0.0, + 0.006470346460325516, + 0.0003406400402869991, + ], + cons_error=[0.0, + 1.204145701494186e-5, + 0.0, + 1.6023987782225921, + 4.456003127373265e-6], + atol=1e-7) # to make CI pass + + @test_allocations(semi, sol, allocs=1_000) +end - @test_allocations(semi, sol, allocs=1_000) - end +@testitem "hyperbolic_serre_green_naghdi_dingemans.jl" setup=[ + Setup, + HyperbolicSerreGreenNaghdiEquations1D, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "hyperbolic_serre_green_naghdi_dingemans.jl"), + tspan=(0.0, 1.0), + l2=[ + 0.22618134328164993, + 0.7376950780256356, + 3.389954422650516e-15, + 0.5105085009518094, + 0.2270170397315174, + ], + linf=[ + 0.03631632774349847, + 0.11854594481576813, + 3.497202527569243e-15, + 0.08108200376359903, + 0.03645317804157178, + ], + cons_error=[2.3874235921539366e-12, + 0.0006849904339648783, + 1.0658141036401503e-14, + 0.0356135949814768, + 0.00017701343821840965], + change_entropy=-0.0013486980525385661, + change_entropy_modified=-2.7995769187327824e-6) + + @test_allocations(semi, sol, allocs=1_000) end -end # module +@testitem "hyperbolic_serre_green_naghdi_conservation.jl" setup=[ + Setup, + HyperbolicSerreGreenNaghdiEquations1D, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "hyperbolic_serre_green_naghdi_conservation.jl"), + l2=[ + 1.3601939454962908, + 2.367812627978776, + 3.565537895102537e-14, + 0.8095219703329345, + 1.3613680507825028, + ], + linf=[ + 1.0010230791351136, + 0.7870081638593119, + 9.325873406851315e-15, + 0.24169078965789928, + 1.0010090485188015, + ], + cons_error=[6.230038707144558e-11, + 0.00029618251641450044, + 4.547473508864641e-13, + 0.00759853016721156, + 0.0014395235644997229], + change_entropy=-0.20915006380346313, + change_entropy_modified=-0.09431070096138683, + atol=1e-11, # to make CI pass + atol_ints=4e-9) # to make CI pass + + @test_allocations(semi, sol, allocs=1_000) +end diff --git a/test/test_serre_green_naghdi_1d.jl b/test/test_serre_green_naghdi_1d.jl index 2871e60c..97e594f4 100644 --- a/test/test_serre_green_naghdi_1d.jl +++ b/test/test_serre_green_naghdi_1d.jl @@ -1,271 +1,298 @@ -module TestSerreGreenNaghdi1D - -using Test -using DispersiveShallowWater - -include("test_util.jl") - -EXAMPLES_DIR = joinpath(examples_dir(), "serre_green_naghdi_1d") - -@testset "SerreGreenNaghdiEquations1D" begin - @trixi_testset "serre_green_naghdi_soliton.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_soliton.jl"), - tspan=(0.0, 0.1), - l2=[9.994998669268741e-7, 1.4703973445698635e-6, 0.0], - linf=[6.5496216650196e-7, 1.027617322124641e-6, 0.0], - cons_error=[0.0, 8.174581012099225e-10, 0.0], - change_waterheight=0.0, - change_entropy_modified=-3.1093350116861984e-11) - - @test_allocations(semi, sol, allocs=550_000) - end - - @trixi_testset "serre_green_naghdi_soliton.jl with bathymetry_mild_slope" begin - # same values as serre_green_naghdi_soliton.jl but with more allocations - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_soliton.jl"), - bathymetry_type=bathymetry_mild_slope, - tspan=(0.0, 0.1), - l2=[9.994998669268741e-7, 1.4703973445698635e-6, 0.0], - linf=[6.5496216650196e-7, 1.027617322124641e-6, 0.0], - cons_error=[0.0, 8.174581012099225e-10, 0.0], - change_waterheight=0.0, - change_entropy_modified=-3.1093350116861984e-11) - - @test_allocations(semi, sol, allocs=800_000) - end - - @trixi_testset "serre_green_naghdi_soliton.jl with bathymetry_variable" begin - # same values as serre_green_naghdi_soliton.jl but with more allocations - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_soliton.jl"), - bathymetry_type=bathymetry_variable, - tspan=(0.0, 0.1), - l2=[9.994998669268741e-7, 1.4703973445698635e-6, 0.0], - linf=[6.5496216650196e-7, 1.027617322124641e-6, 0.0], - cons_error=[0.0, 8.174581012099225e-10, 0.0], - change_waterheight=0.0, - change_entropy_modified=-3.1093350116861984e-11) - - @test_allocations(semi, sol, allocs=800_000) - end - - @trixi_testset "serre_green_naghdi_soliton_fourier.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_soliton_fourier.jl"), - tspan=(0.0, 0.1), - l2=[8.252225014546995e-8, 6.724994492548714e-7, 0.0], - linf=[2.672093302180656e-8, 9.642725156897014e-8, 0.0], - cons_error=[2.842170943040401e-14, 4.627409566637652e-13, 0.0], - change_waterheight=2.842170943040401e-14, - change_entropy_modified=-3.097966327914037e-11) - - @test_allocations(semi, sol, allocs=450_000) - end - - @trixi_testset "serre_green_naghdi_soliton_fourier.jl with bathymetry_mild_slope" begin - # same values as serre_green_naghdi_soliton_fourier.jl but with more allocations - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_soliton_fourier.jl"), - bathymetry_type=bathymetry_mild_slope, - tspan=(0.0, 0.1), - l2=[8.252225014546995e-8, 6.724994492548714e-7, 0.0], - linf=[2.672093302180656e-8, 9.642725156897014e-8, 0.0], - cons_error=[2.842170943040401e-14, 4.627409566637652e-13, 0.0], - change_waterheight=2.842170943040401e-14, - change_entropy_modified=-3.097966327914037e-11) - - @test_allocations(semi, sol, allocs=850_000) - end - - @trixi_testset "serre_green_naghdi_soliton_fourier.jl with bathymetry_variable" begin - # same values as serre_green_naghdi_soliton_fourier.jl but with more allocations - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_soliton_fourier.jl"), - bathymetry_type=bathymetry_variable, - tspan=(0.0, 0.1), - l2=[8.252225014546995e-8, 6.724994492548714e-7, 0.0], - linf=[2.672093302180656e-8, 9.642725156897014e-8, 0.0], - cons_error=[2.842170943040401e-14, 4.627409566637652e-13, 0.0], - change_waterheight=2.842170943040401e-14, - change_entropy_modified=-3.097966327914037e-11) - - @test_allocations(semi, sol, allocs=850_000) - end - - @trixi_testset "serre_green_naghdi_soliton_upwind.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_soliton_upwind.jl"), - tspan=(0.0, 0.1), - l2=[1.4876412924488654e-6, 5.9888097605442856e-6, 0.0], - linf=[1.0863034516361836e-6, 4.105927902009476e-6, 0.0], - cons_error=[4.263256414560601e-14, 4.483030568991353e-8, 0.0], - change_waterheight=4.263256414560601e-14, - change_entropy_modified=-3.1036506698001176e-11) - - @test_allocations(semi, sol, allocs=500_000) - end - - @trixi_testset "serre_green_naghdi_soliton_upwind.jl with bathymetry_mild_slope" begin - # same as serre_green_naghdi_soliton_upwind.jl but with more allocations - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_soliton_upwind.jl"), - tspan=(0.0, 0.1), - bathymetry_type=bathymetry_mild_slope, - l2=[1.4876412924488654e-6, 5.9888097605442856e-6, 0.0], - linf=[1.0863034516361836e-6, 4.105927902009476e-6, 0.0], - cons_error=[4.263256414560601e-14, 4.483030568991353e-8, 0.0], - change_waterheight=4.263256414560601e-14, - change_entropy_modified=-3.1036506698001176e-11) - - @test_allocations(semi, sol, allocs=750_000) - end - - @trixi_testset "serre_green_naghdi_soliton_upwind.jl with bathymetry_variable" begin - # same as serre_green_naghdi_soliton_upwind.jl but with more allocations - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_soliton_upwind.jl"), - tspan=(0.0, 0.1), - bathymetry_type=bathymetry_variable, - l2=[1.4876412924488654e-6, 5.9888097605442856e-6, 0.0], - linf=[1.0863034516361836e-6, 4.105927902009476e-6, 0.0], - cons_error=[4.263256414560601e-14, 4.483030568991353e-8, 0.0], - change_waterheight=4.263256414560601e-14, - change_entropy_modified=-3.1036506698001176e-11) - - @test_allocations(semi, sol, allocs=750_000) - end - - @trixi_testset "serre_green_naghdi_soliton_relaxation.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_soliton_relaxation.jl"), - tspan=(0.0, 0.1), - l2=[8.252225169608892e-8, 6.724994488577288e-7, 0.0], - linf=[2.6716495016287922e-8, 9.642466235713909e-8, 0.0], - cons_error=[2.842170943040401e-14, 4.649614027130156e-13, 0.0], - change_waterheight=2.842170943040401e-14, - change_entropy_modified=0.0) - - @test_allocations(semi, sol, allocs=450_000) - end - - @trixi_testset "serre_green_naghdi_soliton_relaxation.jl with bathymetry_mild_slope" begin - # same as serre_green_naghdi_soliton_relaxation.jl but with more allocations - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_soliton_relaxation.jl"), - tspan=(0.0, 0.1), - bathymetry_type=bathymetry_mild_slope, - l2=[8.252225169608892e-8, 6.724994488577288e-7, 0.0], - linf=[2.6716495016287922e-8, 9.642466235713909e-8, 0.0], - cons_error=[2.842170943040401e-14, 4.649614027130156e-13, 0.0], - change_waterheight=2.842170943040401e-14, - change_entropy_modified=0.0) - - @test_allocations(semi, sol, allocs=850_000) - end - - @trixi_testset "serre_green_naghdi_soliton_relaxation.jl with bathymetry_variable" begin - # same as serre_green_naghdi_soliton_relaxation.jl but with more allocations - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_soliton_relaxation.jl"), - tspan=(0.0, 0.1), - bathymetry_type=bathymetry_variable, - l2=[8.252225169608892e-8, 6.724994488577288e-7, 0.0], - linf=[2.6716495016287922e-8, 9.642466235713909e-8, 0.0], - cons_error=[2.842170943040401e-14, 4.649614027130156e-13, 0.0], - change_waterheight=2.842170943040401e-14, - change_entropy_modified=0.0) - - @test_allocations(semi, sol, allocs=850_000) - end - - @trixi_testset "serre_green_naghdi_well_balanced.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_well_balanced.jl"), - tspan=(0.0, 2.0), - l2=[0, 0, 0], - linf=[0, 0, 0], - cons_error=[0, 0, 0], - change_waterheight=0.0, - change_momentum=0.0, - change_entropy_modified=0.0, - lake_at_rest=0.0) - - @test_allocations(semi, sol, allocs=750_000) - end - - @trixi_testset "serre_green_naghdi_well_balanced.jl with bathymetry_mild_slope" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_well_balanced.jl"), - bathymetry_type=bathymetry_mild_slope, - tspan=(0.0, 2.0), - l2=[0, 0, 0], - linf=[0, 0, 0], - cons_error=[0, 0, 0], - change_waterheight=0.0, - change_momentum=0.0, - change_entropy_modified=0.0, - lake_at_rest=0.0) - - @test_allocations(semi, sol, allocs=750_000) - end - - @trixi_testset "serre_green_naghdi_dingemans.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_dingemans.jl"), - tspan=(0.0, 1.0), - l2=[0.22632930215585131, 0.7400070292134782, 0.0], - linf=[0.036351214376643126, 0.11899056101300992, 0.0], - cons_error=[1.4210854715202004e-13, 3.194346928167053e-5, 0.0], - change_waterheight=-1.4210854715202004e-13, - change_entropy=2.282635693973134e-5, - change_entropy_modified=-9.135646905633621e-9) - - @test_allocations(semi, sol, allocs=750_000) - end - - @trixi_testset "serre_green_naghdi_dingemans.jl with bathymetry_mild_slope" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_dingemans.jl"), - tspan=(0.0, 1.0), - bathymetry_type=bathymetry_mild_slope, - l2=[0.22632930215585131, 0.7400070292134782, 0.0], - linf=[0.036351214376643126, 0.11899056101300992, 0.0], - cons_error=[1.4210854715202004e-13, 3.194346928167053e-5, 0.0], - change_waterheight=-1.4210854715202004e-13, - change_entropy=2.282635693973134e-5, - change_entropy_modified=-9.135646905633621e-9) - - @test_allocations(semi, sol, allocs=750_000) - end - - @trixi_testset "serre_green_naghdi_conservation.jl" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_conservation.jl"), - l2=[1.3655498085989206, 2.3967486930606716, 0.0], - linf=[1.001076318001934, 0.8052527556023067, 0.0], - cons_error=[0.0, 0.0002674927404067162, 0.0], - change_entropy=-0.0584189861183404, - change_entropy_modified=0.059273537492344985, - atol=1e-11, # to make CI pass - atol_ints=4e-9) # to make CI pass - - @test_allocations(semi, sol, allocs=900_000) - end - - @trixi_testset "serre_green_naghdi_conservation.jl with bathymetry_mild_slope" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "serre_green_naghdi_conservation.jl"), - bathymetry_type=bathymetry_mild_slope, - l2=[1.3655493671985637, 2.3967828251339003, 0.0], - linf=[1.001075913983051, 0.8052680970114169, 0.0], - cons_error=[1.1368683772161603e-13, 0.00026407261543415217, 0.0], - change_entropy=-0.058352284294869605, - change_entropy_modified=0.05927339747017868) - - @test_allocations(semi, sol, allocs=900_000) - end +@testsnippet SerreGreenNaghdiEquations1D begin + EXAMPLES_DIR = joinpath(examples_dir(), "serre_green_naghdi_1d") end -end # module +@testitem "serre_green_naghdi_soliton.jl" setup=[Setup, SerreGreenNaghdiEquations1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_soliton.jl"), + tspan=(0.0, 0.1), + l2=[9.994998669268741e-7, 1.4703973445698635e-6, 0.0], + linf=[6.5496216650196e-7, 1.027617322124641e-6, 0.0], + cons_error=[0.0, 8.174581012099225e-10, 0.0], + change_waterheight=0.0, + change_entropy_modified=-3.1093350116861984e-11) + + @test_allocations(semi, sol, allocs=550_000) +end + +@testitem "serre_green_naghdi_soliton.jl with bathymetry_mild_slope" setup=[ + Setup, + SerreGreenNaghdiEquations1D, +] begin + # same values as serre_green_naghdi_soliton.jl but with more allocations + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_soliton.jl"), + bathymetry_type=bathymetry_mild_slope, + tspan=(0.0, 0.1), + l2=[9.994998669268741e-7, 1.4703973445698635e-6, 0.0], + linf=[6.5496216650196e-7, 1.027617322124641e-6, 0.0], + cons_error=[0.0, 8.174581012099225e-10, 0.0], + change_waterheight=0.0, + change_entropy_modified=-3.1093350116861984e-11) + + @test_allocations(semi, sol, allocs=800_000) +end + +@testitem "serre_green_naghdi_soliton.jl with bathymetry_variable" setup=[ + Setup, + SerreGreenNaghdiEquations1D, +] begin + # same values as serre_green_naghdi_soliton.jl but with more allocations + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_soliton.jl"), + bathymetry_type=bathymetry_variable, + tspan=(0.0, 0.1), + l2=[9.994998669268741e-7, 1.4703973445698635e-6, 0.0], + linf=[6.5496216650196e-7, 1.027617322124641e-6, 0.0], + cons_error=[0.0, 8.174581012099225e-10, 0.0], + change_waterheight=0.0, + change_entropy_modified=-3.1093350116861984e-11) + + @test_allocations(semi, sol, allocs=800_000) +end + +@testitem "serre_green_naghdi_soliton_fourier.jl" setup=[Setup, SerreGreenNaghdiEquations1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_soliton_fourier.jl"), + tspan=(0.0, 0.1), + l2=[8.252225014546995e-8, 6.724994492548714e-7, 0.0], + linf=[2.672093302180656e-8, 9.642725156897014e-8, 0.0], + cons_error=[2.842170943040401e-14, 4.627409566637652e-13, 0.0], + change_waterheight=2.842170943040401e-14, + change_entropy_modified=-3.097966327914037e-11) + + @test_allocations(semi, sol, allocs=450_000) +end + +@testitem "serre_green_naghdi_soliton_fourier.jl with bathymetry_mild_slope" setup=[ + Setup, + SerreGreenNaghdiEquations1D, +] begin + # same values as serre_green_naghdi_soliton_fourier.jl but with more allocations + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_soliton_fourier.jl"), + bathymetry_type=bathymetry_mild_slope, + tspan=(0.0, 0.1), + l2=[8.252225014546995e-8, 6.724994492548714e-7, 0.0], + linf=[2.672093302180656e-8, 9.642725156897014e-8, 0.0], + cons_error=[2.842170943040401e-14, 4.627409566637652e-13, 0.0], + change_waterheight=2.842170943040401e-14, + change_entropy_modified=-3.097966327914037e-11) + + @test_allocations(semi, sol, allocs=850_000) +end + +@testitem "serre_green_naghdi_soliton_fourier.jl with bathymetry_variable" setup=[ + Setup, + SerreGreenNaghdiEquations1D, +] begin + # same values as serre_green_naghdi_soliton_fourier.jl but with more allocations + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_soliton_fourier.jl"), + bathymetry_type=bathymetry_variable, + tspan=(0.0, 0.1), + l2=[8.252225014546995e-8, 6.724994492548714e-7, 0.0], + linf=[2.672093302180656e-8, 9.642725156897014e-8, 0.0], + cons_error=[2.842170943040401e-14, 4.627409566637652e-13, 0.0], + change_waterheight=2.842170943040401e-14, + change_entropy_modified=-3.097966327914037e-11) + + @test_allocations(semi, sol, allocs=850_000) +end + +@testitem "serre_green_naghdi_soliton_upwind.jl" setup=[Setup, SerreGreenNaghdiEquations1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_soliton_upwind.jl"), + tspan=(0.0, 0.1), + l2=[1.4876412924488654e-6, 5.9888097605442856e-6, 0.0], + linf=[1.0863034516361836e-6, 4.105927902009476e-6, 0.0], + cons_error=[4.263256414560601e-14, 4.483030568991353e-8, 0.0], + change_waterheight=4.263256414560601e-14, + change_entropy_modified=-3.1036506698001176e-11) + + @test_allocations(semi, sol, allocs=500_000) +end + +@testitem "serre_green_naghdi_soliton_upwind.jl with bathymetry_mild_slope" setup=[ + Setup, + SerreGreenNaghdiEquations1D, +] begin + # same as serre_green_naghdi_soliton_upwind.jl but with more allocations + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_soliton_upwind.jl"), + tspan=(0.0, 0.1), + bathymetry_type=bathymetry_mild_slope, + l2=[1.4876412924488654e-6, 5.9888097605442856e-6, 0.0], + linf=[1.0863034516361836e-6, 4.105927902009476e-6, 0.0], + cons_error=[4.263256414560601e-14, 4.483030568991353e-8, 0.0], + change_waterheight=4.263256414560601e-14, + change_entropy_modified=-3.1036506698001176e-11) + + @test_allocations(semi, sol, allocs=750_000) +end + +@testitem "serre_green_naghdi_soliton_upwind.jl with bathymetry_variable" setup=[ + Setup, + SerreGreenNaghdiEquations1D, +] begin + # same as serre_green_naghdi_soliton_upwind.jl but with more allocations + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_soliton_upwind.jl"), + tspan=(0.0, 0.1), + bathymetry_type=bathymetry_variable, + l2=[1.4876412924488654e-6, 5.9888097605442856e-6, 0.0], + linf=[1.0863034516361836e-6, 4.105927902009476e-6, 0.0], + cons_error=[4.263256414560601e-14, 4.483030568991353e-8, 0.0], + change_waterheight=4.263256414560601e-14, + change_entropy_modified=-3.1036506698001176e-11) + + @test_allocations(semi, sol, allocs=750_000) +end + +@testitem "serre_green_naghdi_soliton_relaxation.jl" setup=[ + Setup, + SerreGreenNaghdiEquations1D, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_soliton_relaxation.jl"), + tspan=(0.0, 0.1), + l2=[8.252225169608892e-8, 6.724994488577288e-7, 0.0], + linf=[2.6716495016287922e-8, 9.642466235713909e-8, 0.0], + cons_error=[2.842170943040401e-14, 4.649614027130156e-13, 0.0], + change_waterheight=2.842170943040401e-14, + change_entropy_modified=0.0) + + @test_allocations(semi, sol, allocs=450_000) +end + +@testitem "serre_green_naghdi_soliton_relaxation.jl with bathymetry_mild_slope" setup=[ + Setup, + SerreGreenNaghdiEquations1D, +] begin + # same as serre_green_naghdi_soliton_relaxation.jl but with more allocations + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_soliton_relaxation.jl"), + tspan=(0.0, 0.1), + bathymetry_type=bathymetry_mild_slope, + l2=[8.252225169608892e-8, 6.724994488577288e-7, 0.0], + linf=[2.6716495016287922e-8, 9.642466235713909e-8, 0.0], + cons_error=[2.842170943040401e-14, 4.649614027130156e-13, 0.0], + change_waterheight=2.842170943040401e-14, + change_entropy_modified=0.0) + + @test_allocations(semi, sol, allocs=850_000) +end + +@testitem "serre_green_naghdi_soliton_relaxation.jl with bathymetry_variable" setup=[ + Setup, + SerreGreenNaghdiEquations1D, +] begin + # same as serre_green_naghdi_soliton_relaxation.jl but with more allocations + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_soliton_relaxation.jl"), + tspan=(0.0, 0.1), + bathymetry_type=bathymetry_variable, + l2=[8.252225169608892e-8, 6.724994488577288e-7, 0.0], + linf=[2.6716495016287922e-8, 9.642466235713909e-8, 0.0], + cons_error=[2.842170943040401e-14, 4.649614027130156e-13, 0.0], + change_waterheight=2.842170943040401e-14, + change_entropy_modified=0.0) + + @test_allocations(semi, sol, allocs=850_000) +end + +@testitem "serre_green_naghdi_well_balanced.jl" setup=[Setup, SerreGreenNaghdiEquations1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_well_balanced.jl"), + tspan=(0.0, 2.0), + l2=[0, 0, 0], + linf=[0, 0, 0], + cons_error=[0, 0, 0], + change_waterheight=0.0, + change_momentum=0.0, + change_entropy_modified=0.0, + lake_at_rest=0.0) + + @test_allocations(semi, sol, allocs=750_000) +end + +@testitem "serre_green_naghdi_well_balanced.jl with bathymetry_mild_slope" setup=[ + Setup, + SerreGreenNaghdiEquations1D, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_well_balanced.jl"), + bathymetry_type=bathymetry_mild_slope, + tspan=(0.0, 2.0), + l2=[0, 0, 0], + linf=[0, 0, 0], + cons_error=[0, 0, 0], + change_waterheight=0.0, + change_momentum=0.0, + change_entropy_modified=0.0, + lake_at_rest=0.0) + + @test_allocations(semi, sol, allocs=750_000) +end + +@testitem "serre_green_naghdi_dingemans.jl" setup=[Setup, SerreGreenNaghdiEquations1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_dingemans.jl"), + tspan=(0.0, 1.0), + l2=[0.22632930215585131, 0.7400070292134782, 0.0], + linf=[0.036351214376643126, 0.11899056101300992, 0.0], + cons_error=[1.4210854715202004e-13, 3.194346928167053e-5, 0.0], + change_waterheight=-1.4210854715202004e-13, + change_entropy=2.282635693973134e-5, + change_entropy_modified=-9.135646905633621e-9) + + @test_allocations(semi, sol, allocs=750_000) +end + +@testitem "serre_green_naghdi_dingemans.jl with bathymetry_mild_slope" setup=[ + Setup, + SerreGreenNaghdiEquations1D, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_dingemans.jl"), + tspan=(0.0, 1.0), + bathymetry_type=bathymetry_mild_slope, + l2=[0.22632930215585131, 0.7400070292134782, 0.0], + linf=[0.036351214376643126, 0.11899056101300992, 0.0], + cons_error=[1.4210854715202004e-13, 3.194346928167053e-5, 0.0], + change_waterheight=-1.4210854715202004e-13, + change_entropy=2.282635693973134e-5, + change_entropy_modified=-9.135646905633621e-9) + + @test_allocations(semi, sol, allocs=750_000) +end + +@testitem "serre_green_naghdi_conservation.jl" setup=[Setup, SerreGreenNaghdiEquations1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_conservation.jl"), + l2=[1.3655498085989206, 2.3967486930606716, 0.0], + linf=[1.001076318001934, 0.8052527556023067, 0.0], + cons_error=[0.0, 0.0002674927404067162, 0.0], + change_entropy=-0.0584189861183404, + change_entropy_modified=0.059273537492344985, + atol=1e-11, # to make CI pass + atol_ints=4e-9) # to make CI pass + + @test_allocations(semi, sol, allocs=900_000) +end + +@testitem "serre_green_naghdi_conservation.jl with bathymetry_mild_slope" setup=[ + Setup, + SerreGreenNaghdiEquations1D, +] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "serre_green_naghdi_conservation.jl"), + bathymetry_type=bathymetry_mild_slope, + l2=[1.3655493671985637, 2.3967828251339003, 0.0], + linf=[1.001075913983051, 0.8052680970114169, 0.0], + cons_error=[1.1368683772161603e-13, 0.00026407261543415217, 0.0], + change_entropy=-0.058352284294869605, + change_entropy_modified=0.05927339747017868) + + @test_allocations(semi, sol, allocs=900_000) +end diff --git a/test/test_svaerd_kalisch_1d.jl b/test/test_svaerd_kalisch_1d.jl index 85550773..48389bae 100644 --- a/test/test_svaerd_kalisch_1d.jl +++ b/test/test_svaerd_kalisch_1d.jl @@ -1,99 +1,91 @@ -module TestSvaerdKalisch1D -using Test -using DispersiveShallowWater - -include("test_util.jl") - -EXAMPLES_DIR = joinpath(examples_dir(), "svaerd_kalisch_1d") - -@testset "SvaerdKalischEquations1D" begin - @trixi_testset "svaerd_kalisch_1d_manufactured" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "svaerd_kalisch_1d_manufactured.jl"), - tspan=(0.0, 0.1), - l2=[3.3755102050606554e-6 2.320896961343125e-7 0.0], - linf=[4.908886917176503e-6 3.888671399332466e-7 0.0], - cons_error=[2.42861286636753e-16 1.9224170696150768e-7 0.0], - change_waterheight=-2.42861286636753e-16, - change_entropy=0.1868146724821993, - atol=1e-9) # to make CI pass - - @test_allocations(semi, sol, allocs=90_000) - end - - @trixi_testset "svaerd_kalisch_1d_dingemans" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "svaerd_kalisch_1d_dingemans.jl"), - tspan=(0.0, 1.0), - N=512, - l2=[0.22796106962338855 0.7519327063662515 0.0], - linf=[0.036708347831218346 0.12141172207472928 0.0], - cons_error=[3.979039320256561e-13 4.937137540373564e-5 0.0], - change_waterheight=-3.979039320256561e-13, - change_entropy=-0.00024362648639453255, - change_entropy_modified=-6.311893230304122e-9) - - @test_allocations(semi, sol, allocs=350_000) - end - - @trixi_testset "svaerd_kalisch_1d_dingemans_cg" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "svaerd_kalisch_1d_dingemans_cg.jl"), - tspan=(0.0, 1.0), - l2=[0.22798490823942433 0.7520004851600044 0.0], - linf=[0.03673010870720128 0.12074632168110239 0.0], - cons_error=[1.4210854715202004e-13 4.953054817174909e-5 0.0], - change_waterheight=-1.4210854715202004e-13, - change_entropy=-0.0002425303440531934, - change_entropy_modified=-2.6815314413397573e-9) - - @test_allocations(semi, sol, allocs=750_000) - end - - @trixi_testset "svaerd_kalisch_1d_dingemans_upwind" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "svaerd_kalisch_1d_dingemans_upwind.jl"), - tspan=(0.0, 1.0), - l2=[0.2280370308166863 0.7521344942401095 0.0], - linf=[0.03673101553812019 0.12116306036094074 0.0], - cons_error=[1.1368683772161603e-13 4.871598417571836e-5 0.0], - change_waterheight=-1.1368683772161603e-13, - change_entropy=-0.00023645232727176335, - change_entropy_modified=-6.654090611846186e-9) +@testsnippet SvaerdKalischEquations1D begin + EXAMPLES_DIR = joinpath(examples_dir(), "svaerd_kalisch_1d") +end - @test_allocations(semi, sol, allocs=350_000) - end +@testitem "svaerd_kalisch_1d_manufactured" setup=[Setup, SvaerdKalischEquations1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "svaerd_kalisch_1d_manufactured.jl"), + tspan=(0.0, 0.1), + l2=[3.3755102050606554e-6 2.320896961343125e-7 0.0], + linf=[4.908886917176503e-6 3.888671399332466e-7 0.0], + cons_error=[2.42861286636753e-16 1.9224170696150768e-7 0.0], + change_waterheight=-2.42861286636753e-16, + change_entropy=0.1868146724821993, + atol=1e-9) # to make CI pass + + @test_allocations(semi, sol, allocs=90_000) +end - @trixi_testset "svaerd_kalisch_1d_dingemans_relaxation" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "svaerd_kalisch_1d_dingemans_relaxation.jl"), - tspan=(0.0, 1.0), - N=512, - l2=[0.22796107242561717 0.7519327155905444 0.0], - linf=[0.03670834831604197 0.12141172368792873 0.0], - cons_error=[3.979039320256561e-13 4.937137655207271e-5 0.0], - change_waterheight=-3.979039320256561e-13, - change_entropy=-0.00024362054875837202, - change_entropy_modified=0.0) +@testitem "svaerd_kalisch_1d_dingemans" setup=[Setup, SvaerdKalischEquations1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "svaerd_kalisch_1d_dingemans.jl"), + tspan=(0.0, 1.0), + N=512, + l2=[0.22796106962338855 0.7519327063662515 0.0], + linf=[0.036708347831218346 0.12141172207472928 0.0], + cons_error=[3.979039320256561e-13 4.937137540373564e-5 0.0], + change_waterheight=-3.979039320256561e-13, + change_entropy=-0.00024362648639453255, + change_entropy_modified=-6.311893230304122e-9) + + @test_allocations(semi, sol, allocs=350_000) +end - @test_allocations(semi, sol, allocs=350_000) - end +@testitem "svaerd_kalisch_1d_dingemans_cg" setup=[Setup, SvaerdKalischEquations1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "svaerd_kalisch_1d_dingemans_cg.jl"), + tspan=(0.0, 1.0), + l2=[0.22798490823942433 0.7520004851600044 0.0], + linf=[0.03673010870720128 0.12074632168110239 0.0], + cons_error=[1.4210854715202004e-13 4.953054817174909e-5 0.0], + change_waterheight=-1.4210854715202004e-13, + change_entropy=-0.0002425303440531934, + change_entropy_modified=-2.6815314413397573e-9) + + @test_allocations(semi, sol, allocs=750_000) +end - @trixi_testset "svaerd_kalisch_1d_well_balanced" begin - @test_trixi_include(joinpath(EXAMPLES_DIR, - "svaerd_kalisch_1d_well_balanced.jl"), - tspan=(0.0, 1.0), - l2=[0.0 1.135448143093612e-14 0.0], - linf=[0.0 8.133477278069499e-15 0.0], - cons_error=[0.0 1.6056589579882354e-14 0.0], - change_waterheight=0.0, - change_momentum=1.5679986322667355e-14, - change_entropy=0.0, - lake_at_rest=0.0) +@testitem "svaerd_kalisch_1d_dingemans_upwind" setup=[Setup, SvaerdKalischEquations1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "svaerd_kalisch_1d_dingemans_upwind.jl"), + tspan=(0.0, 1.0), + l2=[0.2280370308166863 0.7521344942401095 0.0], + linf=[0.03673101553812019 0.12116306036094074 0.0], + cons_error=[1.1368683772161603e-13 4.871598417571836e-5 0.0], + change_waterheight=-1.1368683772161603e-13, + change_entropy=-0.00023645232727176335, + change_entropy_modified=-6.654090611846186e-9) + + @test_allocations(semi, sol, allocs=350_000) +end - @test_allocations(semi, sol, allocs=150_000) - end +@testitem "svaerd_kalisch_1d_dingemans_relaxation" setup=[Setup, SvaerdKalischEquations1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "svaerd_kalisch_1d_dingemans_relaxation.jl"), + tspan=(0.0, 1.0), + N=512, + l2=[0.22796107242561717 0.7519327155905444 0.0], + linf=[0.03670834831604197 0.12141172368792873 0.0], + cons_error=[3.979039320256561e-13 4.937137655207271e-5 0.0], + change_waterheight=-3.979039320256561e-13, + change_entropy=-0.00024362054875837202, + change_entropy_modified=0.0) + + @test_allocations(semi, sol, allocs=350_000) end -end # module +@testitem "svaerd_kalisch_1d_well_balanced" setup=[Setup, SvaerdKalischEquations1D] begin + @test_trixi_include(joinpath(EXAMPLES_DIR, + "svaerd_kalisch_1d_well_balanced.jl"), + tspan=(0.0, 1.0), + l2=[0.0 1.135448143093612e-14 0.0], + linf=[0.0 8.133477278069499e-15 0.0], + cons_error=[0.0 1.6056589579882354e-14 0.0], + change_waterheight=0.0, + change_momentum=1.5679986322667355e-14, + change_entropy=0.0, + lake_at_rest=0.0) + + @test_allocations(semi, sol, allocs=150_000) +end diff --git a/test/test_unit.jl b/test/test_unit.jl index 32f8211a..de65ff64 100644 --- a/test/test_unit.jl +++ b/test/test_unit.jl @@ -1,435 +1,417 @@ -module TestUnit +@testitem "Mesh1D" setup=[Setup] begin + mesh = @test_nowarn Mesh1D(-1, 1, 10) + @test_nowarn print(mesh) + @test_nowarn display(mesh) + @test ndims(mesh) == 1 + @test xmin(mesh) == -1 + @test xmax(mesh) == 1 + @test nnodes(mesh) == 10 + @test real(mesh) == Int64 +end -using Test -using DispersiveShallowWater -using SummationByPartsOperators: PeriodicDerivativeOperator, UniformPeriodicCoupledOperator, - PeriodicUpwindOperators -using SummationByPartsOperators: derivative_order, periodic_derivative_operator, - legendre_derivative_operator, - UniformPeriodicMesh1D, couple_discontinuously, - upwind_operators, couple_continuously, - legendre_second_derivative_operator +@testitem "Solver" setup=[Setup, AdditionalImports] begin + mesh = Mesh1D(-1.0, 1.0, 10) + p = 3 + solver = @test_nowarn Solver(mesh, p) + @test_nowarn print(solver) + @test_nowarn display(solver) + @test solver.D1 isa PeriodicDerivativeOperator + @test solver.D2 isa PeriodicDerivativeOperator + @test derivative_order(solver.D1) == 1 + @test derivative_order(solver.D2) == 2 + @test grid(solver) == grid(solver.D1) == grid(solver.D2) + @test real(solver) == Float64 -using SparseArrays: sparse, SparseMatrixCSC + D_legendre = legendre_derivative_operator(-1.0, 1.0, p + 1) + uniform_mesh = UniformPeriodicMesh1D(-1.0, 1.0, 512 ÷ (p + 1)) + central = couple_discontinuously(D_legendre, uniform_mesh) + minus = couple_discontinuously(D_legendre, uniform_mesh, Val(:minus)) + plus = couple_discontinuously(D_legendre, uniform_mesh, Val(:plus)) + D2 = sparse(plus) * sparse(minus) + solver = @test_nowarn Solver(central, D2) + @test solver.D1 isa UniformPeriodicCoupledOperator + @test solver.D2 isa SparseMatrixCSC + D1 = PeriodicUpwindOperators(minus, central, plus) + solver = @test_nowarn Solver(D1, D2) + @test solver.D1 isa PeriodicUpwindOperators + @test solver.D2 isa SparseMatrixCSC -@testset "Unit tests" begin - @testset "Mesh1D" begin - mesh = @test_nowarn Mesh1D(-1, 1, 10) - @test_nowarn print(mesh) - @test_nowarn display(mesh) - @test ndims(mesh) == 1 - @test xmin(mesh) == -1 - @test xmax(mesh) == 1 - @test nnodes(mesh) == 10 - @test real(mesh) == Int64 - end + D1 = upwind_operators(periodic_derivative_operator; derivative_order = 1, + accuracy_order = p, xmin = -1.0, xmax = 1.0, N = 10) + D2 = sparse(D1.plus) * sparse(D1.minus) + solver = @test_nowarn Solver(D1, D2) + @test solver.D1 isa PeriodicUpwindOperators + @test solver.D2 isa SparseMatrixCSC + @test derivative_order(solver.D1) == 1 - @testset "Solver" begin - mesh = Mesh1D(-1.0, 1.0, 10) - p = 3 - solver = @test_nowarn Solver(mesh, p) - @test_nowarn print(solver) - @test_nowarn display(solver) - @test solver.D1 isa PeriodicDerivativeOperator - @test solver.D2 isa PeriodicDerivativeOperator - @test derivative_order(solver.D1) == 1 - @test derivative_order(solver.D2) == 2 - @test grid(solver) == grid(solver.D1) == grid(solver.D2) - @test real(solver) == Float64 + p = 4 # N needs to be divisible by p + D_legendre = legendre_derivative_operator(-1.0, 1.0, p + 1) + uniform_mesh = UniformPeriodicMesh1D(-1.0, 1.0, div(12, p)) + D1 = couple_continuously(D_legendre, uniform_mesh) + D2_legendre = legendre_second_derivative_operator(-1.0, 1.0, p + 1) + D2 = couple_continuously(D2_legendre, uniform_mesh) + solver = @test_nowarn Solver(D1, D2) + @test solver.D1 isa UniformPeriodicCoupledOperator + @test solver.D2 isa UniformPeriodicCoupledOperator +end - D_legendre = legendre_derivative_operator(-1.0, 1.0, p + 1) - uniform_mesh = UniformPeriodicMesh1D(-1.0, 1.0, 512 ÷ (p + 1)) - central = couple_discontinuously(D_legendre, uniform_mesh) - minus = couple_discontinuously(D_legendre, uniform_mesh, Val(:minus)) - plus = couple_discontinuously(D_legendre, uniform_mesh, Val(:plus)) - D2 = sparse(plus) * sparse(minus) - solver = @test_nowarn Solver(central, D2) - @test solver.D1 isa UniformPeriodicCoupledOperator - @test solver.D2 isa SparseMatrixCSC - D1 = PeriodicUpwindOperators(minus, central, plus) - solver = @test_nowarn Solver(D1, D2) - @test solver.D1 isa PeriodicUpwindOperators - @test solver.D2 isa SparseMatrixCSC +@testitem "Semidiscretization" setup=[Setup] begin + equations = BBMBBMEquations1D(gravity_constant = 9.81) + initial_condition = initial_condition_convergence_test + boundary_conditions = boundary_condition_periodic + mesh = Mesh1D(-1, 1, 10) + solver = Solver(mesh, 4) + semi = @test_nowarn Semidiscretization(mesh, equations, initial_condition, solver, + boundary_conditions = boundary_conditions) + @test_nowarn print(semi) + @test_nowarn display(semi) + @test ndims(semi) == ndims(mesh) == 1 + @test DispersiveShallowWater.eachnode(semi) == DispersiveShallowWater.eachnode(mesh) + @test grid(semi) == grid(solver) + mesh, equations, solver, cache = @test_nowarn DispersiveShallowWater.mesh_equations_solver_cache(semi) + @test mesh == mesh + @test equations == equations + @test solver == solver - D1 = upwind_operators(periodic_derivative_operator; derivative_order = 1, - accuracy_order = p, xmin = -1.0, xmax = 1.0, N = 10) - D2 = sparse(D1.plus) * sparse(D1.minus) - solver = @test_nowarn Solver(D1, D2) - @test solver.D1 isa PeriodicUpwindOperators - @test solver.D2 isa SparseMatrixCSC - @test derivative_order(solver.D1) == 1 + equations_flat = BBMBBMEquations1D(bathymetry_type = bathymetry_flat, + gravity_constant = 9.81) + initial_condition = initial_condition_dingemans + mesh = Mesh1D(-138, 46, 10) + solver = Solver(mesh, 4) + semi_flat = Semidiscretization(mesh, equations_flat, initial_condition, solver) + @test_throws ArgumentError semidiscretize(semi_flat, (0.0, 1.0)) +end - p = 4 # N needs to be divisible by p - D_legendre = legendre_derivative_operator(-1.0, 1.0, p + 1) - uniform_mesh = UniformPeriodicMesh1D(-1.0, 1.0, div(12, p)) - D1 = couple_continuously(D_legendre, uniform_mesh) - D2_legendre = legendre_second_derivative_operator(-1.0, 1.0, p + 1) - D2 = couple_continuously(D2_legendre, uniform_mesh) - solver = @test_nowarn Solver(D1, D2) - @test solver.D1 isa UniformPeriodicCoupledOperator - @test solver.D2 isa UniformPeriodicCoupledOperator - end +@testitem "Boundary conditions" setup=[Setup] begin + boundary_conditions = boundary_condition_periodic + @test_nowarn print(boundary_conditions) + @test_nowarn display(boundary_conditions) + boundary_conditions = boundary_condition_reflecting + @test_nowarn print(boundary_conditions) + @test_nowarn display(boundary_conditions) +end - @testset "Semidiscretization" begin - equations = BBMBBMEquations1D(gravity_constant = 9.81) - initial_condition = initial_condition_convergence_test +@testitem "BBMEquation1D" setup=[Setup] begin + equations = @test_nowarn @inferred BBMEquation1D(gravity_constant = 1.0) + @test_nowarn print(equations) + @test_nowarn display(equations) + conversion_functions = [ + waterheight_total, + waterheight, + entropy, + energy_total, + prim2cons, + prim2prim, + prim2phys, + energy_total_modified, + entropy_modified, + hamiltonian, + ] + for conversion in conversion_functions + @test DispersiveShallowWater.varnames(conversion, equations) isa Tuple + end + q = [42.0] + @test @inferred(prim2prim(q, equations)) == q + @test isapprox(@inferred(cons2prim(prim2cons(q, equations), equations)), q) + @test @inferred(waterheight_total(q, equations)) == 42.0 + @test @inferred(waterheight(q, equations)) == 43.0 + @test @inferred(still_water_surface(q, equations)) == 0.0 + @test @inferred(prim2phys(q, equations)) == @inferred(prim2prim(q, equations)) + @testset "energy_total_modified and hamiltonian" begin + initial_condition = initial_condition_manufactured boundary_conditions = boundary_condition_periodic - mesh = Mesh1D(-1, 1, 10) + mesh = @inferred Mesh1D(-1.0, 1.0, 10) solver = Solver(mesh, 4) - semi = @test_nowarn Semidiscretization(mesh, equations, initial_condition, solver, - boundary_conditions = boundary_conditions) - @test_nowarn print(semi) - @test_nowarn display(semi) - @test ndims(semi) == ndims(mesh) == 1 - @test DispersiveShallowWater.eachnode(semi) == DispersiveShallowWater.eachnode(mesh) - @test grid(semi) == grid(solver) - mesh, equations, solver, cache = @test_nowarn DispersiveShallowWater.mesh_equations_solver_cache(semi) - @test mesh == mesh - @test equations == equations - @test solver == solver + semi = @inferred Semidiscretization(mesh, equations, initial_condition, + solver; boundary_conditions) + q = @inferred DispersiveShallowWater.compute_coefficients(initial_condition, + 0.0, semi) + _, _, _, cache = @inferred DispersiveShallowWater.mesh_equations_solver_cache(semi) + e_modified = @inferred energy_total_modified(q, equations, cache) + e_modified_total = @inferred DispersiveShallowWater.integrate(e_modified, semi) + @test isapprox(e_modified_total, 3.710663574870101) + U_modified = @inferred entropy_modified(q, equations, cache) + U_modified_total = @inferred DispersiveShallowWater.integrate(U_modified, semi) + @test isapprox(U_modified_total, e_modified_total) + h = @inferred hamiltonian(q, equations, cache) + h_total = @inferred DispersiveShallowWater.integrate(h, semi) + @test isapprox(h_total, 0.5) + end +end - equations_flat = BBMBBMEquations1D(bathymetry_type = bathymetry_flat, - gravity_constant = 9.81) - initial_condition = initial_condition_dingemans - mesh = Mesh1D(-138, 46, 10) - solver = Solver(mesh, 4) - semi_flat = Semidiscretization(mesh, equations_flat, initial_condition, solver) - @test_throws ArgumentError semidiscretize(semi_flat, (0.0, 1.0)) +@testitem "BBMBBMEquations1D" setup=[Setup] begin + equations = @test_nowarn @inferred BBMBBMEquations1D(gravity_constant = 9.81) + @test_nowarn print(equations) + @test_nowarn display(equations) + conversion_functions = [ + waterheight_total, + waterheight, + velocity, + momentum, + discharge, + entropy, + energy_total, + prim2cons, + prim2prim, + prim2phys, + energy_total_modified, + entropy_modified, + ] + for conversion in conversion_functions + @test DispersiveShallowWater.varnames(conversion, equations) isa Tuple end + q = [42.0, 2.0, 2.0] + @test @inferred(prim2prim(q, equations)) == q + @test isapprox(@inferred(cons2prim(prim2cons(q, equations), equations)), q) + @test @inferred(waterheight_total(q, equations)) == 42.0 + @test @inferred(waterheight(q, equations)) == 44.0 + @test @inferred(velocity(q, equations)) == 2.0 + @test @inferred(momentum(q, equations)) == 88.0 + @test @inferred(discharge(q, equations)) == 88.0 + @test @inferred(still_water_surface(q, equations)) == 0.0 + @test isapprox(@inferred(energy_total(q, equations)), 8740.42) + @test @inferred(energy_total(q, equations)) == @inferred(entropy(q, equations)) + @test @inferred(prim2phys(q, equations)) == @inferred(prim2prim(q, equations)) - @testset "Boundary conditions" begin + @testset "default implementation of energy_total_modified" begin + initial_condition = initial_condition_convergence_test boundary_conditions = boundary_condition_periodic - @test_nowarn print(boundary_conditions) - @test_nowarn display(boundary_conditions) - boundary_conditions = boundary_condition_reflecting - @test_nowarn print(boundary_conditions) - @test_nowarn display(boundary_conditions) + mesh = @inferred Mesh1D(-1.0, 1.0, 10) + solver = Solver(mesh, 4) + semi = @inferred Semidiscretization(mesh, equations, initial_condition, + solver; boundary_conditions) + q = @inferred DispersiveShallowWater.compute_coefficients(initial_condition, + 0.0, semi) + _, _, _, cache = @inferred DispersiveShallowWater.mesh_equations_solver_cache(semi) + e_modified = @inferred energy_total_modified(q, equations, cache) + e_modified_total = @inferred DispersiveShallowWater.integrate(e_modified, semi) + e_total = @inferred DispersiveShallowWater.integrate_quantity(energy_total, + q, semi) + @test isapprox(e_modified_total, e_total) + U_modified = @inferred entropy_modified(q, equations, cache) + U_modified_total = @inferred DispersiveShallowWater.integrate(U_modified, semi) + @test isapprox(U_modified_total, e_modified_total) end +end - @testset "BBMEquation1D" begin - equations = @test_nowarn @inferred BBMEquation1D(gravity_constant = 1.0) - @test_nowarn print(equations) - @test_nowarn display(equations) - conversion_functions = [ - waterheight_total, - waterheight, - entropy, - energy_total, - prim2cons, - prim2prim, - prim2phys, - energy_total_modified, - entropy_modified, - hamiltonian, - ] - for conversion in conversion_functions - @test DispersiveShallowWater.varnames(conversion, equations) isa Tuple - end - q = [42.0] - @test @inferred(prim2prim(q, equations)) == q - @test isapprox(@inferred(cons2prim(prim2cons(q, equations), equations)), q) - @test @inferred(waterheight_total(q, equations)) == 42.0 - @test @inferred(waterheight(q, equations)) == 43.0 - @test @inferred(still_water_surface(q, equations)) == 0.0 - @test @inferred(prim2phys(q, equations)) == @inferred(prim2prim(q, equations)) - @testset "energy_total_modified and hamiltonian" begin - initial_condition = initial_condition_manufactured - boundary_conditions = boundary_condition_periodic - mesh = @inferred Mesh1D(-1.0, 1.0, 10) - solver = Solver(mesh, 4) - semi = @inferred Semidiscretization(mesh, equations, initial_condition, - solver; boundary_conditions) - q = @inferred DispersiveShallowWater.compute_coefficients(initial_condition, - 0.0, semi) - _, _, _, cache = @inferred DispersiveShallowWater.mesh_equations_solver_cache(semi) - e_modified = @inferred energy_total_modified(q, equations, cache) - e_modified_total = @inferred DispersiveShallowWater.integrate(e_modified, semi) - @test isapprox(e_modified_total, 3.710663574870101) - U_modified = @inferred entropy_modified(q, equations, cache) - U_modified_total = @inferred DispersiveShallowWater.integrate(U_modified, semi) - @test isapprox(U_modified_total, e_modified_total) - h = @inferred hamiltonian(q, equations, cache) - h_total = @inferred DispersiveShallowWater.integrate(h, semi) - @test isapprox(h_total, 0.5) - end +@testitem "SvaerdKalischEquations1D" setup=[Setup] begin + equations = @test_nowarn SvaerdKalischEquations1D(gravity_constant = 9.81, + alpha = 0.0004040404040404049, + beta = 0.49292929292929294, + gamma = 0.15707070707070708) + @test_nowarn print(equations) + @test_nowarn display(equations) + conversion_functions = [ + waterheight_total, + waterheight, + velocity, + momentum, + discharge, + entropy, + energy_total, + prim2cons, + prim2prim, + prim2phys, + energy_total_modified, + entropy_modified, + ] + for conversion in conversion_functions + @test DispersiveShallowWater.varnames(conversion, equations) isa Tuple end + q = [42.0, 2.0, 2.0] + @test @inferred(prim2prim(q, equations)) == q + @test isapprox(@inferred(cons2prim(prim2cons(q, equations), equations)), q) + @test @inferred(waterheight_total(q, equations)) == 42.0 + @test @inferred(waterheight(q, equations)) == 44.0 + @test @inferred(velocity(q, equations)) == 2.0 + @test @inferred(momentum(q, equations)) == 88.0 + @test @inferred(discharge(q, equations)) == 88.0 + @test @inferred(still_water_surface(q, equations)) == 0.0 + @test isapprox(@inferred(energy_total(q, equations)), 8740.42) + @test @inferred(prim2phys(q, equations)) == @inferred(prim2prim(q, equations)) - @testset "BBMBBMEquations1D" begin - equations = @test_nowarn @inferred BBMBBMEquations1D(gravity_constant = 9.81) - @test_nowarn print(equations) - @test_nowarn display(equations) - conversion_functions = [ - waterheight_total, - waterheight, - velocity, - momentum, - discharge, - entropy, - energy_total, - prim2cons, - prim2prim, - prim2phys, - energy_total_modified, - entropy_modified, - ] - for conversion in conversion_functions - @test DispersiveShallowWater.varnames(conversion, equations) isa Tuple - end - q = [42.0, 2.0, 2.0] - @test @inferred(prim2prim(q, equations)) == q - @test isapprox(@inferred(cons2prim(prim2cons(q, equations), equations)), q) - @test @inferred(waterheight_total(q, equations)) == 42.0 - @test @inferred(waterheight(q, equations)) == 44.0 - @test @inferred(velocity(q, equations)) == 2.0 - @test @inferred(momentum(q, equations)) == 88.0 - @test @inferred(discharge(q, equations)) == 88.0 - @test @inferred(still_water_surface(q, equations)) == 0.0 - @test isapprox(@inferred(energy_total(q, equations)), 8740.42) - @test @inferred(energy_total(q, equations)) == @inferred(entropy(q, equations)) - @test @inferred(prim2phys(q, equations)) == @inferred(prim2prim(q, equations)) - - @testset "default implementation of energy_total_modified" begin - initial_condition = initial_condition_convergence_test - boundary_conditions = boundary_condition_periodic - mesh = @inferred Mesh1D(-1.0, 1.0, 10) - solver = Solver(mesh, 4) - semi = @inferred Semidiscretization(mesh, equations, initial_condition, - solver; boundary_conditions) - q = @inferred DispersiveShallowWater.compute_coefficients(initial_condition, - 0.0, semi) - _, _, _, cache = @inferred DispersiveShallowWater.mesh_equations_solver_cache(semi) - e_modified = @inferred energy_total_modified(q, equations, cache) - e_modified_total = @inferred DispersiveShallowWater.integrate(e_modified, semi) - e_total = @inferred DispersiveShallowWater.integrate_quantity(energy_total, - q, semi) - @test isapprox(e_modified_total, e_total) - U_modified = @inferred entropy_modified(q, equations, cache) - U_modified_total = @inferred DispersiveShallowWater.integrate(U_modified, semi) - @test isapprox(U_modified_total, e_modified_total) - end + @testset "energy_total_modified" begin + initial_condition = initial_condition_manufactured + boundary_conditions = boundary_condition_periodic + mesh = @inferred Mesh1D(-1.0, 1.0, 10) + solver = Solver(mesh, 4) + semi = @inferred Semidiscretization(mesh, equations, initial_condition, + solver; boundary_conditions) + q = @inferred DispersiveShallowWater.compute_coefficients(initial_condition, + 0.0, semi) + _, _, _, cache = @inferred DispersiveShallowWater.mesh_equations_solver_cache(semi) + e_modified = @inferred energy_total_modified(q, equations, cache) + e_modified_total = @inferred DispersiveShallowWater.integrate(e_modified, semi) + e_total = @inferred DispersiveShallowWater.integrate_quantity(energy_total, + q, semi) + @test isapprox(e_modified_total, 1450.0018635214328) + @test isapprox(e_total, 7.405000000000001) + U_modified = @inferred entropy_modified(q, equations, cache) + U_modified_total = @inferred DispersiveShallowWater.integrate(U_modified, semi) + @test isapprox(U_modified_total, e_modified_total) end +end - @testset "SvaerdKalischEquations1D" begin - equations = @test_nowarn SvaerdKalischEquations1D(gravity_constant = 9.81, - alpha = 0.0004040404040404049, - beta = 0.49292929292929294, - gamma = 0.15707070707070708) - @test_nowarn print(equations) - @test_nowarn display(equations) - conversion_functions = [ - waterheight_total, - waterheight, - velocity, - momentum, - discharge, - entropy, - energy_total, - prim2cons, - prim2prim, - prim2phys, - energy_total_modified, - entropy_modified, - ] - for conversion in conversion_functions - @test DispersiveShallowWater.varnames(conversion, equations) isa Tuple - end - q = [42.0, 2.0, 2.0] - @test @inferred(prim2prim(q, equations)) == q - @test isapprox(@inferred(cons2prim(prim2cons(q, equations), equations)), q) - @test @inferred(waterheight_total(q, equations)) == 42.0 - @test @inferred(waterheight(q, equations)) == 44.0 - @test @inferred(velocity(q, equations)) == 2.0 - @test @inferred(momentum(q, equations)) == 88.0 - @test @inferred(discharge(q, equations)) == 88.0 - @test @inferred(still_water_surface(q, equations)) == 0.0 - @test isapprox(@inferred(energy_total(q, equations)), 8740.42) - @test @inferred(prim2phys(q, equations)) == @inferred(prim2prim(q, equations)) - - @testset "energy_total_modified" begin - initial_condition = initial_condition_manufactured - boundary_conditions = boundary_condition_periodic - mesh = @inferred Mesh1D(-1.0, 1.0, 10) - solver = Solver(mesh, 4) - semi = @inferred Semidiscretization(mesh, equations, initial_condition, - solver; boundary_conditions) - q = @inferred DispersiveShallowWater.compute_coefficients(initial_condition, - 0.0, semi) - _, _, _, cache = @inferred DispersiveShallowWater.mesh_equations_solver_cache(semi) - e_modified = @inferred energy_total_modified(q, equations, cache) - e_modified_total = @inferred DispersiveShallowWater.integrate(e_modified, semi) - e_total = @inferred DispersiveShallowWater.integrate_quantity(energy_total, - q, semi) - @test isapprox(e_modified_total, 1450.0018635214328) - @test isapprox(e_total, 7.405000000000001) - U_modified = @inferred entropy_modified(q, equations, cache) - U_modified_total = @inferred DispersiveShallowWater.integrate(U_modified, semi) - @test isapprox(U_modified_total, e_modified_total) - end +@testitem "SerreGreenNaghdiEquations1D" setup=[Setup] begin + equations = @test_nowarn @inferred SerreGreenNaghdiEquations1D(gravity_constant = 9.81) + @test_nowarn print(equations) + @test_nowarn display(equations) + conversion_functions = [ + waterheight_total, + waterheight, + velocity, + momentum, + discharge, + entropy, + energy_total, + prim2cons, + prim2prim, + prim2phys, + energy_total_modified, + entropy_modified, + ] + for conversion in conversion_functions + @test DispersiveShallowWater.varnames(conversion, equations) isa Tuple end + q = [42.0, 2.0, 0.0] + @test @inferred(prim2prim(q, equations)) == q + @test isapprox(@inferred(cons2prim(prim2cons(q, equations), equations)), q) + @test @inferred(waterheight_total(q, equations)) == 42.0 + @test @inferred(waterheight(q, equations)) == 42.0 + @test @inferred(velocity(q, equations)) == 2.0 + @test @inferred(momentum(q, equations)) == 84.0 + @test @inferred(discharge(q, equations)) == 84.0 + @test @inferred(still_water_surface(q, equations)) == 0.0 + @test @inferred(prim2phys(q, equations)) == @inferred(prim2prim(q, equations)) - @testset "SerreGreenNaghdiEquations1D" begin - equations = @test_nowarn @inferred SerreGreenNaghdiEquations1D(gravity_constant = 9.81) - @test_nowarn print(equations) - @test_nowarn display(equations) - conversion_functions = [ - waterheight_total, - waterheight, - velocity, - momentum, - discharge, - entropy, - energy_total, - prim2cons, - prim2prim, - prim2phys, - energy_total_modified, - entropy_modified, - ] - for conversion in conversion_functions - @test DispersiveShallowWater.varnames(conversion, equations) isa Tuple - end - q = [42.0, 2.0, 0.0] - @test @inferred(prim2prim(q, equations)) == q - @test isapprox(@inferred(cons2prim(prim2cons(q, equations), equations)), q) - @test @inferred(waterheight_total(q, equations)) == 42.0 - @test @inferred(waterheight(q, equations)) == 42.0 - @test @inferred(velocity(q, equations)) == 2.0 - @test @inferred(momentum(q, equations)) == 84.0 - @test @inferred(discharge(q, equations)) == 84.0 - @test @inferred(still_water_surface(q, equations)) == 0.0 - @test @inferred(prim2phys(q, equations)) == @inferred(prim2prim(q, equations)) - - @testset "energy_total_modified" begin - initial_condition = initial_condition_convergence_test - boundary_conditions = boundary_condition_periodic - mesh = @inferred Mesh1D(-1.0, 1.0, 10) - solver = Solver(mesh, 4) - semi = @inferred Semidiscretization(mesh, equations, initial_condition, - solver; boundary_conditions) - q = @inferred DispersiveShallowWater.compute_coefficients(initial_condition, - 0.0, semi) - _, _, _, cache = @inferred DispersiveShallowWater.mesh_equations_solver_cache(semi) - e_modified = @inferred energy_total_modified(q, equations, cache) - e_modified_total = @inferred DispersiveShallowWater.integrate(e_modified, semi) - e_total = @inferred DispersiveShallowWater.integrate_quantity(energy_total, - q, semi) - @test isapprox(e_modified_total, 14.303587674490101) - @test isapprox(e_total, 14.301514636021535) - U_modified = @inferred entropy_modified(q, equations, cache) - U_modified_total = @inferred DispersiveShallowWater.integrate(U_modified, semi) - @test isapprox(U_modified_total, e_modified_total) - end + @testset "energy_total_modified" begin + initial_condition = initial_condition_convergence_test + boundary_conditions = boundary_condition_periodic + mesh = @inferred Mesh1D(-1.0, 1.0, 10) + solver = Solver(mesh, 4) + semi = @inferred Semidiscretization(mesh, equations, initial_condition, + solver; boundary_conditions) + q = @inferred DispersiveShallowWater.compute_coefficients(initial_condition, + 0.0, semi) + _, _, _, cache = @inferred DispersiveShallowWater.mesh_equations_solver_cache(semi) + e_modified = @inferred energy_total_modified(q, equations, cache) + e_modified_total = @inferred DispersiveShallowWater.integrate(e_modified, semi) + e_total = @inferred DispersiveShallowWater.integrate_quantity(energy_total, + q, semi) + @test isapprox(e_modified_total, 14.303587674490101) + @test isapprox(e_total, 14.301514636021535) + U_modified = @inferred entropy_modified(q, equations, cache) + U_modified_total = @inferred DispersiveShallowWater.integrate(U_modified, semi) + @test isapprox(U_modified_total, e_modified_total) end +end - @testset "HyperbolicSerreGreenNaghdiEquations1D" begin - equations = @test_nowarn @inferred HyperbolicSerreGreenNaghdiEquations1D(gravity_constant = 9.81, - lambda = 500.0) - @test_nowarn print(equations) - @test_nowarn display(equations) - conversion_functions = [ - waterheight_total, - waterheight, - velocity, - momentum, - discharge, - entropy, - energy_total, - prim2cons, - prim2prim, - prim2phys, - energy_total_modified, - entropy_modified, - ] - for conversion in conversion_functions - @test DispersiveShallowWater.varnames(conversion, equations) isa Tuple - end - q = [42.0, 2.0, 0.0, -0.5, 43.0] - @test @inferred(prim2prim(q, equations)) == q - @test isapprox(@inferred(cons2prim(prim2cons(q, equations), equations)), q) - @test @inferred(waterheight_total(q, equations)) == 42.0 - @test @inferred(waterheight(q, equations)) == 42.0 - @test @inferred(velocity(q, equations)) == 2.0 - @test @inferred(momentum(q, equations)) == 84.0 - @test @inferred(discharge(q, equations)) == 84.0 - @test @inferred(still_water_surface(q, equations)) == 0.0 - @test @inferred(prim2phys(q, equations)) == [42.0, 2.0, 0.0] - - @testset "energy_total_modified" begin - initial_condition = initial_condition_soliton - boundary_conditions = boundary_condition_periodic - mesh = @inferred Mesh1D(-1.0, 1.0, 10) - solver = Solver(mesh, 4) - semi = @inferred Semidiscretization(mesh, equations, initial_condition, - solver; boundary_conditions) - q = @inferred DispersiveShallowWater.compute_coefficients(initial_condition, - 0.0, semi) - _, _, _, cache = @inferred DispersiveShallowWater.mesh_equations_solver_cache(semi) - e_modified = @inferred energy_total_modified(q, equations, cache) - e_modified_total = @inferred DispersiveShallowWater.integrate(e_modified, semi) - e_total = @inferred DispersiveShallowWater.integrate_quantity(energy_total, - q, semi) - @test isapprox(e_modified_total, 14.303814990428117) - @test isapprox(e_total, 14.301514636021535) - U_modified = @inferred entropy_modified(q, equations, cache) - U_modified_total = @inferred DispersiveShallowWater.integrate(U_modified, semi) - @test isapprox(U_modified_total, e_modified_total) - end +@testitem "HyperbolicSerreGreenNaghdiEquations1D" setup=[Setup] begin + equations = @test_nowarn @inferred HyperbolicSerreGreenNaghdiEquations1D(gravity_constant = 9.81, + lambda = 500.0) + @test_nowarn print(equations) + @test_nowarn display(equations) + conversion_functions = [ + waterheight_total, + waterheight, + velocity, + momentum, + discharge, + entropy, + energy_total, + prim2cons, + prim2prim, + prim2phys, + energy_total_modified, + entropy_modified, + ] + for conversion in conversion_functions + @test DispersiveShallowWater.varnames(conversion, equations) isa Tuple end + q = [42.0, 2.0, 0.0, -0.5, 43.0] + @test @inferred(prim2prim(q, equations)) == q + @test isapprox(@inferred(cons2prim(prim2cons(q, equations), equations)), q) + @test @inferred(waterheight_total(q, equations)) == 42.0 + @test @inferred(waterheight(q, equations)) == 42.0 + @test @inferred(velocity(q, equations)) == 2.0 + @test @inferred(momentum(q, equations)) == 84.0 + @test @inferred(discharge(q, equations)) == 84.0 + @test @inferred(still_water_surface(q, equations)) == 0.0 + @test @inferred(prim2phys(q, equations)) == [42.0, 2.0, 0.0] - @testset "AnalysisCallback" begin - equations = SvaerdKalischEquations1D(gravity_constant = 9.81) - initial_condition = initial_condition_dingemans + @testset "energy_total_modified" begin + initial_condition = initial_condition_soliton boundary_conditions = boundary_condition_periodic - mesh = Mesh1D(-1, 1, 10) + mesh = @inferred Mesh1D(-1.0, 1.0, 10) solver = Solver(mesh, 4) - semi = Semidiscretization(mesh, equations, initial_condition, solver, - boundary_conditions = boundary_conditions) - analysis_callback = AnalysisCallback(semi; interval = 10, - extra_analysis_errors = (:conservation_error,), - extra_analysis_integrals = (waterheight_total, - velocity, momentum, - discharge, entropy, - energy_total, - entropy_modified, - energy_total_modified, - lake_at_rest_error)) - @test_nowarn print(analysis_callback) - @test_nowarn display(analysis_callback) + semi = @inferred Semidiscretization(mesh, equations, initial_condition, + solver; boundary_conditions) + q = @inferred DispersiveShallowWater.compute_coefficients(initial_condition, + 0.0, semi) + _, _, _, cache = @inferred DispersiveShallowWater.mesh_equations_solver_cache(semi) + e_modified = @inferred energy_total_modified(q, equations, cache) + e_modified_total = @inferred DispersiveShallowWater.integrate(e_modified, semi) + e_total = @inferred DispersiveShallowWater.integrate_quantity(energy_total, + q, semi) + @test isapprox(e_modified_total, 14.303814990428117) + @test isapprox(e_total, 14.301514636021535) + U_modified = @inferred entropy_modified(q, equations, cache) + U_modified_total = @inferred DispersiveShallowWater.integrate(U_modified, semi) + @test isapprox(U_modified_total, e_modified_total) end +end - @testset "RelaxationCallback" begin - relaxation_callback = RelaxationCallback(invariant = entropy) - @test_nowarn print(relaxation_callback) - @test_nowarn display(relaxation_callback) - end +@testitem "AnalysisCallback" setup=[Setup] begin + equations = SvaerdKalischEquations1D(gravity_constant = 9.81) + initial_condition = initial_condition_dingemans + boundary_conditions = boundary_condition_periodic + mesh = Mesh1D(-1, 1, 10) + solver = Solver(mesh, 4) + semi = Semidiscretization(mesh, equations, initial_condition, solver, + boundary_conditions = boundary_conditions) + analysis_callback = AnalysisCallback(semi; interval = 10, + extra_analysis_errors = (:conservation_error,), + extra_analysis_integrals = (waterheight_total, + velocity, momentum, + discharge, entropy, + energy_total, + entropy_modified, + energy_total_modified, + lake_at_rest_error)) + @test_nowarn print(analysis_callback) + @test_nowarn display(analysis_callback) +end - @testset "SummaryCallback" begin - summary_callback = SummaryCallback() - @test_nowarn print(summary_callback) - @test_nowarn display(summary_callback) - end +@testitem "RelaxationCallback" setup=[Setup] begin + relaxation_callback = RelaxationCallback(invariant = entropy) + @test_nowarn print(relaxation_callback) + @test_nowarn display(relaxation_callback) +end - @testset "util" begin - @test_nowarn get_examples() +@testitem "SummaryCallback" setup=[Setup] begin + summary_callback = SummaryCallback() + @test_nowarn print(summary_callback) + @test_nowarn display(summary_callback) +end - accuracy_orders = [2, 4, 6] - for accuracy_order in accuracy_orders - eoc_mean_values, _ = convergence_test(default_example(), 2, N = 512, - tspan = (0.0, 1.0), - accuracy_order = accuracy_order) - @test isapprox(eoc_mean_values[:l2][1], accuracy_order, atol = 0.5) - @test isapprox(eoc_mean_values[:linf][2], accuracy_order, atol = 0.5) - @test isapprox(eoc_mean_values[:l2][1], accuracy_order, atol = 0.5) - @test isapprox(eoc_mean_values[:linf][2], accuracy_order, atol = 0.5) +@testitem "util" setup=[Setup] begin + @test_nowarn get_examples() - eoc_mean_values2, _ = convergence_test(default_example(), [512, 1024], - tspan = (0.0, 1.0), - accuracy_order = accuracy_order) - for kind in (:l2, :linf), variable in (1, 2) - eoc_mean_values[kind][variable] == eoc_mean_values2[kind][variable] - end + accuracy_orders = [2, 4, 6] + for accuracy_order in accuracy_orders + eoc_mean_values, _ = convergence_test(default_example(), 2, N = 512, + tspan = (0.0, 1.0), + accuracy_order = accuracy_order) + @test isapprox(eoc_mean_values[:l2][1], accuracy_order, atol = 0.5) + @test isapprox(eoc_mean_values[:linf][2], accuracy_order, atol = 0.5) + @test isapprox(eoc_mean_values[:l2][1], accuracy_order, atol = 0.5) + @test isapprox(eoc_mean_values[:linf][2], accuracy_order, atol = 0.5) + + eoc_mean_values2, _ = convergence_test(default_example(), [512, 1024], + tspan = (0.0, 1.0), + accuracy_order = accuracy_order) + for kind in (:l2, :linf), variable in (1, 2) + eoc_mean_values[kind][variable] == eoc_mean_values2[kind][variable] end end end - -end # module diff --git a/test/test_util.jl b/test/test_util.jl index 41dbf632..c4fe13af 100644 --- a/test/test_util.jl +++ b/test/test_util.jl @@ -160,47 +160,6 @@ function get_kwarg(args, keyword, default_value) return val end -""" - @trixi_testset "name of the testset" #= code to test #= - -Similar to `@testset`, but wraps the code inside a temporary module to avoid -namespace pollution. -""" -macro trixi_testset(name, expr) - @assert name isa String - # TODO: `@eval` is evil - # We would like to use - # mod = gensym(name) - # ... - # module $mod - # to create new module names for every test set. However, this is not - # compatible with the dirty hack using `@eval` to get the mapping when - # loading structured, curvilinear meshes. Thus, we need to use a plain - # module name here. - quote - local time_start = time_ns() - @eval module TrixiTestModule - using Test - using DispersiveShallowWater - include(@__FILE__) - # We define `EXAMPLES_DIR` in (nearly) all test modules and use it to - # get the path to the examples to be tested. However, that's not required - # and we want to fail gracefully if it's not defined. - try - import ..EXAMPLES_DIR - catch - nothing - end - @testset $name $expr - end - local time_stop = time_ns() - flush(stdout) - @info("Testset "*$name*" finished in " - *string(1.0e-9 * (time_stop - time_start))*" seconds.\n") - nothing - end -end - """ @test_allocations(semi, sol, allocs) diff --git a/test/test_visualization.jl b/test/test_visualization.jl index f7e1a9be..3ffde2a5 100644 --- a/test/test_visualization.jl +++ b/test/test_visualization.jl @@ -1,10 +1,5 @@ -module TestVisualization - -using Test -using DispersiveShallowWater -using Plots - -@testset "Visualization" begin +@testitem "Visualization" setup=[Setup] begin + using Plots custom_integral(q, equations) = q[1]^2 DispersiveShallowWater.pretty_form_utf(::typeof(custom_integral)) = "∫η²" trixi_include(@__MODULE__, default_example(), tspan = (0.0, 1.0), @@ -18,5 +13,3 @@ using Plots @test_nowarn plot(analysis_callback, what = (:errors,)) @test_nowarn plot(analysis_callback, what = (:integrals, :errors)) end - -end # module From 327a9b0a094dd59835f42bfcbe7f7fad869fc87f Mon Sep 17 00:00:00 2001 From: Joshua Lampert Date: Sun, 22 Sep 2024 19:44:39 +0200 Subject: [PATCH 2/2] remove unnecessary imports --- test/runtests.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 5f30faba..99ffa9a1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,8 +4,6 @@ using TestItemRunner @run_package_tests @testsnippet Setup begin - using DispersiveShallowWater - using Test include("test_util.jl") end