From fdd5d4c4b990748fb745406f1f7108f3532dbd8c Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Sat, 14 Sep 2024 12:18:45 -1000 Subject: [PATCH] Start --- src/solvers/dg_1d.jl | 14 +- src/solvers/dg_2d.jl | 28 +- test/test_adevction_mortar.jl | 10 +- test/test_advection_basic.jl | 9 + test/test_euler_dirichlet.jl | 367 +++++++++++++++++++++++ test/test_euler_ec.jl | 10 +- test/test_euler_shockcapturing.jl | 10 +- test/test_euler_source_terms.jl | 8 + test/test_eulermulti_ec.jl | 10 +- test/test_hypdiff_nonperiodic.jl | 13 +- test/test_script.jl | 106 ++++++- test/test_shallowwater_dirichlet.jl | 11 +- test/test_shallowwater_ec.jl | 10 +- test/test_shallowwater_shockcapturing.jl | 10 +- test/test_shallowwater_source_terms.jl | 10 +- 15 files changed, 589 insertions(+), 37 deletions(-) create mode 100644 test/test_euler_dirichlet.jl diff --git a/src/solvers/dg_1d.jl b/src/solvers/dg_1d.jl index c9edb520..1ff1b530 100644 --- a/src/solvers/dg_1d.jl +++ b/src/solvers/dg_1d.jl @@ -526,13 +526,15 @@ function boundary_flux_kernel!(surface_flux_values, boundaries_u, node_coordinat # TODO: Improve this part if direction == 1 - u_boundary = boundary_conditions[1].boundary_value_function(x, t, equations) - flux_node = surface_flux(u_boundary, u_inner, orientation, equations) - noncons_flux_node = nonconservative_flux(u_boundary, u_inner, orientation, equations) + flux_node = boundary_conditions[1](u_inner, orientation, direction, x, t, surface_flux, + equations) + noncons_flux_node = boundary_conditions[1](u_inner, orientation, direction, x, t, + nonconservative_flux, equations) else - u_boundary = boundary_conditions[2].boundary_value_function(x, t, equations) - flux_node = surface_flux(u_inner, u_boundary, orientation, equations) - noncons_flux_node = nonconservative_flux(u_inner, u_boundary, orientation, equations) + flux_node = boundary_conditions[2](u_inner, orientation, direction, x, t, surface_flux, + equations) + noncons_flux_node = boundary_conditions[2](u_inner, orientation, direction, x, t, + nonconservative_flux, equations) end @inbounds begin diff --git a/src/solvers/dg_2d.jl b/src/solvers/dg_2d.jl index 2b727689..3c6b0158 100644 --- a/src/solvers/dg_2d.jl +++ b/src/solvers/dg_2d.jl @@ -553,21 +553,25 @@ function boundary_flux_kernel!(surface_flux_values, boundaries_u, node_coordinat # TODO: Improve this part if direction == 1 - u_boundary = boundary_conditions[1].boundary_value_function(x, t, equations) - flux_node = surface_flux(u_boundary, u_inner, orientation, equations) - noncons_flux_node = nonconservative_flux(u_boundary, u_inner, orientation, equations) + flux_node = boundary_conditions[1](u_inner, orientation, direction, x, t, surface_flux, + equations) + noncons_flux_node = boundary_conditions[1](u_inner, orientation, direction, x, t, + nonconservative_flux, equations) elseif direction == 2 - u_boundary = boundary_conditions[2].boundary_value_function(x, t, equations) - flux_node = surface_flux(u_inner, u_boundary, orientation, equations) - noncons_flux_node = nonconservative_flux(u_inner, u_boundary, orientation, equations) + flux_node = boundary_conditions[2](u_inner, orientation, direction, x, t, surface_flux, + equations) + noncons_flux_node = boundary_conditions[2](u_inner, orientation, direction, x, t, + nonconservative_flux, equations) elseif direction == 3 - u_boundary = boundary_conditions[3].boundary_value_function(x, t, equations) - flux_node = surface_flux(u_boundary, u_inner, orientation, equations) - noncons_flux_node = nonconservative_flux(u_boundary, u_inner, orientation, equations) + flux_node = boundary_conditions[3](u_inner, orientation, direction, x, t, surface_flux, + equations) + noncons_flux_node = boundary_conditions[3](u_inner, orientation, direction, x, t, + nonconservative_flux, equations) else - u_boundary = boundary_conditions[4].boundary_value_function(x, t, equations) - flux_node = surface_flux(u_inner, u_boundary, orientation, equations) - noncons_flux_node = nonconservative_flux(u_inner, u_boundary, orientation, equations) + flux_node = boundary_conditions[4](u_inner, orientation, direction, x, t, surface_flux, + equations) + noncons_flux_node = boundary_conditions[4](u_inner, orientation, direction, x, t, + nonconservative_flux, equations) end @inbounds begin diff --git a/test/test_adevction_mortar.jl b/test/test_adevction_mortar.jl index e4a1ccfa..b3cda184 100644 --- a/test/test_adevction_mortar.jl +++ b/test/test_adevction_mortar.jl @@ -1,4 +1,12 @@ -module TestLinearAdvectionMortar # with `nonconservative_terms::False` +module TestLinearAdvectionMortar + +####################################################################### Tags +# Kernels: +# -`cuda_prolong2mortars!` +# - `cuda_mortar_flux!` +# Conditions: +# - `nonconservative_terms::False` +####################################################################### include("test_trixigpu.jl") diff --git a/test/test_advection_basic.jl b/test/test_advection_basic.jl index c4ae8d82..66ecbd94 100644 --- a/test/test_advection_basic.jl +++ b/test/test_advection_basic.jl @@ -1,5 +1,14 @@ module TestLinearAdvectionBasic +####################################################################### Tags +# Kernels: +# - `cuda_xx!` (most basic kernels) +# Conditions: +# - `nonconservative_terms::False` +# - `volume_integral::VolumeIntegralWeakForm` +# - `periodicity = true` 1D, 2D, 3D +####################################################################### + include("test_trixigpu.jl") # Test precision of the semidiscretization process diff --git a/test/test_euler_dirichlet.jl b/test/test_euler_dirichlet.jl new file mode 100644 index 00000000..23c5f76a --- /dev/null +++ b/test/test_euler_dirichlet.jl @@ -0,0 +1,367 @@ +module TestCompressibleEulerBoundary + +####################################################################### Tags +# Kernels: +# -`cuda_prolong2boundaries!` +# - `cuda_boundary_flux!` +# Conditions: +# - `nonconservative_terms::False` +# - `periodicity = false` 1D, 2D, 3D - `BoundaryConditionDirichlet` +# - `source_terms` +####################################################################### + +include("test_trixigpu.jl") + +# Test precision of the semidiscretization process +@testset "Test Compressible Euler" begin + @testset "Compressible Euler 1D" begin + equations = CompressibleEulerEquations1D(1.4) + + initial_condition = initial_condition_convergence_test + + boundary_condition = BoundaryConditionDirichlet(initial_condition) + + solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs) + + coordinates_min = (0.0,) + coordinates_max = (2.0,) + mesh = TreeMesh(coordinates_min, coordinates_max, + initial_refinement_level = 4, + n_cells_max = 10_000, + periodicity = false) + + semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, + source_terms = source_terms_convergence_test, + boundary_conditions = boundary_condition) + + tspan = (0.0, 2.0) + + # Get CPU data + (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi + + # Get GPU data + equations_gpu = deepcopy(equations) + mesh_gpu, solver_gpu, cache_gpu = deepcopy(mesh), deepcopy(solver), deepcopy(cache) + boundary_conditions_gpu, source_terms_gpu = deepcopy(boundary_conditions), + deepcopy(source_terms) + + # Set initial time + t = t_gpu = 0.0 + + # Get initial data + ode = semidiscretize(semi, tspan) + u_ode = copy(ode.u0) + du_ode = similar(u_ode) + u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) + du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) + + # Copy data to device + du_gpu, u_gpu = TrixiGPU.copy_to_device!(du, u) + # Reset data on host + Trixi.reset_du!(du, solver, cache) + + # Test `cuda_volume_integral!` + TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu, + Trixi.have_nonconservative_terms(equations_gpu), + equations_gpu, solver_gpu.volume_integral, solver_gpu, + cache_gpu) + Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations), + equations, solver.volume_integral, solver, cache) + @test_approx du_gpu ≈ du + + # Test `cuda_prolong2interfaces!` + TrixiGPU.cuda_prolong2interfaces!(u_gpu, mesh_gpu, equations_gpu, cache_gpu) + Trixi.prolong2interfaces!(cache, u, mesh, equations, solver.surface_integral, solver) + @test_approx cache_gpu.interfaces.u ≈ cache.interfaces.u + + # Test `cuda_interface_flux!` + TrixiGPU.cuda_interface_flux!(mesh_gpu, Trixi.have_nonconservative_terms(equations_gpu), + equations_gpu, solver_gpu, cache_gpu) + Trixi.calc_interface_flux!(cache.elements.surface_flux_values, mesh, + Trixi.have_nonconservative_terms(equations), equations, + solver.surface_integral, solver, cache) + @test_approx cache_gpu.elements.surface_flux_values ≈ cache.elements.surface_flux_values + + # Test `cuda_prolong2boundaries!` + TrixiGPU.cuda_prolong2boundaries!(u_gpu, mesh_gpu, boundary_conditions_gpu, equations_gpu, + cache_gpu) + Trixi.prolong2boundaries!(cache, u, mesh, equations, solver.surface_integral, solver) + @test_approx cache_gpu.boundaries.u ≈ cache.boundaries.u + + # Test `cuda_boundary_flux!` + TrixiGPU.cuda_boundary_flux!(t_gpu, mesh_gpu, boundary_conditions_gpu, + Trixi.have_nonconservative_terms(equations_gpu), equations_gpu, + solver_gpu, cache_gpu) + Trixi.calc_boundary_flux!(cache, t, boundary_conditions, mesh, equations, + solver.surface_integral, solver) + @test_approx cache_gpu.elements.surface_flux_values ≈ cache.elements.surface_flux_values + + # Test `cuda_surface_integral!` + TrixiGPU.cuda_surface_integral!(du_gpu, mesh_gpu, equations_gpu, solver_gpu, cache_gpu) + Trixi.calc_surface_integral!(du, u, mesh, equations, solver.surface_integral, solver, cache) + @test_approx du_gpu ≈ du + + # Test `cuda_jacobian!` + TrixiGPU.cuda_jacobian!(du_gpu, mesh_gpu, equations_gpu, cache_gpu) + Trixi.apply_jacobian!(du, mesh, equations, solver, cache) + @test_approx du_gpu ≈ du + + # Test `cuda_sources!` + TrixiGPU.cuda_sources!(du_gpu, u_gpu, t_gpu, source_terms_gpu, equations_gpu, cache_gpu) + Trixi.calc_sources!(du, u, t, source_terms, equations, solver, cache) + @test_approx du_gpu ≈ du + + # Copy data back to host + du_cpu, u_cpu = TrixiGPU.copy_to_host!(du_gpu, u_gpu) + end + + @testset "Compressible Euler 2D" begin + equations = CompressibleEulerEquations2D(1.4) + + initial_condition = initial_condition_convergence_test + + boundary_condition = BoundaryConditionDirichlet(initial_condition) + boundary_conditions = (x_neg = boundary_condition, + x_pos = boundary_condition, + y_neg = boundary_condition, + y_pos = boundary_condition) + + solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs) + + coordinates_min = (0.0, 0.0) + coordinates_max = (2.0, 2.0) + mesh = TreeMesh(coordinates_min, coordinates_max, + initial_refinement_level = 4, + n_cells_max = 10_000, + periodicity = false) + + semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, + source_terms = source_terms_convergence_test, + boundary_conditions = boundary_conditions) + + tspan = (0.0, 2.0) + + # Get CPU data + (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi + + # Get GPU data + equations_gpu = deepcopy(equations) + mesh_gpu, solver_gpu, cache_gpu = deepcopy(mesh), deepcopy(solver), deepcopy(cache) + boundary_conditions_gpu, source_terms_gpu = deepcopy(boundary_conditions), + deepcopy(source_terms) + + # Set initial time + t = t_gpu = 0.0 + + # Get initial data + ode = semidiscretize(semi, tspan) + u_ode = copy(ode.u0) + du_ode = similar(u_ode) + u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) + du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) + + # Copy data to device + du_gpu, u_gpu = TrixiGPU.copy_to_device!(du, u) + # Reset data on host + Trixi.reset_du!(du, solver, cache) + + # Test `cuda_volume_integral!` + TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu, + Trixi.have_nonconservative_terms(equations_gpu), + equations_gpu, solver_gpu.volume_integral, solver_gpu, + cache_gpu) + Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations), + equations, solver.volume_integral, solver, cache) + @test_approx du_gpu ≈ du + + # Test `cuda_prolong2interfaces!` + TrixiGPU.cuda_prolong2interfaces!(u_gpu, mesh_gpu, equations_gpu, cache_gpu) + Trixi.prolong2interfaces!(cache, u, mesh, equations, solver.surface_integral, solver) + @test_approx cache_gpu.interfaces.u ≈ cache.interfaces.u + + # Test `cuda_interface_flux!` + TrixiGPU.cuda_interface_flux!(mesh_gpu, Trixi.have_nonconservative_terms(equations_gpu), + equations_gpu, solver_gpu, cache_gpu) + Trixi.calc_interface_flux!(cache.elements.surface_flux_values, mesh, + Trixi.have_nonconservative_terms(equations), equations, + solver.surface_integral, solver, cache) + @test_approx cache_gpu.elements.surface_flux_values ≈ cache.elements.surface_flux_values + + # Test `cuda_prolong2boundaries!` + TrixiGPU.cuda_prolong2boundaries!(u_gpu, mesh_gpu, boundary_conditions_gpu, equations_gpu, + cache_gpu) + Trixi.prolong2boundaries!(cache, u, mesh, equations, solver.surface_integral, solver) + @test_approx cache_gpu.boundaries.u ≈ cache.boundaries.u + + # Test `cuda_boundary_flux!` + TrixiGPU.cuda_boundary_flux!(t_gpu, mesh_gpu, boundary_conditions_gpu, + Trixi.have_nonconservative_terms(equations_gpu), equations_gpu, + solver_gpu, cache_gpu) + Trixi.calc_boundary_flux!(cache, t, boundary_conditions, mesh, equations, + solver.surface_integral, solver) + @test_approx cache_gpu.elements.surface_flux_values ≈ cache.elements.surface_flux_values + + # Test `cuda_prolong2mortars!` + TrixiGPU.cuda_prolong2mortars!(u_gpu, mesh_gpu, TrixiGPU.check_cache_mortars(cache_gpu), + solver_gpu, cache_gpu) + Trixi.prolong2mortars!(cache, u, mesh, equations, + solver.mortar, solver.surface_integral, solver) + @test_approx cache_gpu.mortars.u_upper ≈ cache.mortars.u_upper + @test_approx cache_gpu.mortars.u_lower ≈ cache.mortars.u_lower + + # Test `cuda_mortar_flux!` + TrixiGPU.cuda_mortar_flux!(mesh_gpu, TrixiGPU.check_cache_mortars(cache_gpu), + Trixi.have_nonconservative_terms(equations_gpu), equations_gpu, + solver_gpu, cache_gpu) + Trixi.calc_mortar_flux!(cache.elements.surface_flux_values, mesh, + Trixi.have_nonconservative_terms(equations), equations, + solver.mortar, solver.surface_integral, solver, cache) + @test_approx cache_gpu.elements.surface_flux_values ≈ cache.elements.surface_flux_values + + # Test `cuda_surface_integral!` + TrixiGPU.cuda_surface_integral!(du_gpu, mesh_gpu, equations_gpu, solver_gpu, cache_gpu) + Trixi.calc_surface_integral!(du, u, mesh, equations, solver.surface_integral, solver, cache) + @test_approx du_gpu ≈ du + + # Test `cuda_jacobian!` + TrixiGPU.cuda_jacobian!(du_gpu, mesh_gpu, equations_gpu, cache_gpu) + Trixi.apply_jacobian!(du, mesh, equations, solver, cache) + @test_approx du_gpu ≈ du + + # Test `cuda_sources!` + TrixiGPU.cuda_sources!(du_gpu, u_gpu, t_gpu, source_terms_gpu, equations_gpu, cache_gpu) + Trixi.calc_sources!(du, u, t, source_terms, equations, solver, cache) + @test_approx du_gpu ≈ du + + # Copy data back to host + du_cpu, u_cpu = TrixiGPU.copy_to_host!(du_gpu, u_gpu) + end + + @testset "Compressible Euler 3D" begin + equations = CompressibleEulerEquations3D(1.4) + + initial_condition = initial_condition_convergence_test + + boundary_condition = BoundaryConditionDirichlet(initial_condition) + boundary_conditions = (x_neg = boundary_condition, + x_pos = boundary_condition, + y_neg = boundary_condition, + y_pos = boundary_condition, + z_neg = boundary_condition, + z_pos = boundary_condition) + + solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs) + + coordinates_min = (0.0, 0.0, 0.0) + coordinates_max = (2.0, 2.0, 2.0) + mesh = TreeMesh(coordinates_min, coordinates_max, + initial_refinement_level = 4, + n_cells_max = 10_000, + periodicity = false) + + semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, + source_terms = source_terms_convergence_test, + boundary_conditions = boundary_conditions) + + tspan = (0.0, 2.0) + + # Get CPU data + (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi + + # Get GPU data + equations_gpu = deepcopy(equations) + mesh_gpu, solver_gpu, cache_gpu = deepcopy(mesh), deepcopy(solver), deepcopy(cache) + boundary_conditions_gpu, source_terms_gpu = deepcopy(boundary_conditions), + deepcopy(source_terms) + + # Set initial time + t = t_gpu = 0.0 + + # Get initial data + ode = semidiscretize(semi, tspan) + u_ode = copy(ode.u0) + du_ode = similar(u_ode) + u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) + du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) + + # Copy data to device + du_gpu, u_gpu = TrixiGPU.copy_to_device!(du, u) + # Reset data on host + Trixi.reset_du!(du, solver, cache) + + # Test `cuda_volume_integral!` + TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu, + Trixi.have_nonconservative_terms(equations_gpu), + equations_gpu, solver_gpu.volume_integral, solver_gpu, + cache_gpu) + Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations), + equations, solver.volume_integral, solver, cache) + @test_approx du_gpu ≈ du + + # Test `cuda_prolong2interfaces!` + TrixiGPU.cuda_prolong2interfaces!(u_gpu, mesh_gpu, equations_gpu, cache_gpu) + Trixi.prolong2interfaces!(cache, u, mesh, equations, solver.surface_integral, solver) + @test_approx cache_gpu.interfaces.u ≈ cache.interfaces.u + + # Test `cuda_interface_flux!` + TrixiGPU.cuda_interface_flux!(mesh_gpu, Trixi.have_nonconservative_terms(equations_gpu), + equations_gpu, solver_gpu, cache_gpu) + Trixi.calc_interface_flux!(cache.elements.surface_flux_values, mesh, + Trixi.have_nonconservative_terms(equations), equations, + solver.surface_integral, solver, cache) + @test_approx cache_gpu.elements.surface_flux_values ≈ cache.elements.surface_flux_values + + # Test `cuda_prolong2boundaries!` + TrixiGPU.cuda_prolong2boundaries!(u_gpu, mesh_gpu, boundary_conditions_gpu, equations_gpu, + cache_gpu) + Trixi.prolong2boundaries!(cache, u, mesh, equations, solver.surface_integral, solver) + @test_approx cache_gpu.boundaries.u ≈ cache.boundaries.u + + # Test `cuda_boundary_flux!` + TrixiGPU.cuda_boundary_flux!(t_gpu, mesh_gpu, boundary_conditions_gpu, + Trixi.have_nonconservative_terms(equations_gpu), equations_gpu, + solver_gpu, cache_gpu) + Trixi.calc_boundary_flux!(cache, t, boundary_conditions, mesh, equations, + solver.surface_integral, solver) + @test_approx cache_gpu.elements.surface_flux_values ≈ cache.elements.surface_flux_values + + # Test `cuda_prolong2mortars!` + TrixiGPU.cuda_prolong2mortars!(u_gpu, mesh_gpu, TrixiGPU.check_cache_mortars(cache_gpu), + solver_gpu, cache_gpu) + Trixi.prolong2mortars!(cache, u, mesh, equations, + solver.mortar, solver.surface_integral, solver) + @test_approx cache_gpu.mortars.u_upper_left ≈ cache.mortars.u_upper_left + @test_approx cache_gpu.mortars.u_upper_right ≈ cache.mortars.u_upper_right + @test_approx cache_gpu.mortars.u_lower_left ≈ cache.mortars.u_lower_left + @test_approx cache_gpu.mortars.u_lower_right ≈ cache.mortars.u_lower_right + + # Test `cuda_mortar_flux!` + TrixiGPU.cuda_mortar_flux!(mesh_gpu, TrixiGPU.check_cache_mortars(cache_gpu), + Trixi.have_nonconservative_terms(equations_gpu), equations_gpu, + solver_gpu, cache_gpu) + Trixi.calc_mortar_flux!(cache.elements.surface_flux_values, mesh, + Trixi.have_nonconservative_terms(equations), equations, + solver.mortar, solver.surface_integral, solver, cache) + @test_approx cache_gpu.elements.surface_flux_values ≈ cache.elements.surface_flux_values + + # Test `cuda_surface_integral!` + TrixiGPU.cuda_surface_integral!(du_gpu, mesh_gpu, equations_gpu, solver_gpu, cache_gpu) + Trixi.calc_surface_integral!(du, u, mesh, equations, solver.surface_integral, solver, cache) + @test_approx du_gpu ≈ du + + # Test `cuda_jacobian!` + TrixiGPU.cuda_jacobian!(du_gpu, mesh_gpu, equations_gpu, cache_gpu) + Trixi.apply_jacobian!(du, mesh, equations, solver, cache) + @test_approx du_gpu ≈ du + + # Test `cuda_sources!` + TrixiGPU.cuda_sources!(du_gpu, u_gpu, t_gpu, source_terms_gpu, equations_gpu, cache_gpu) + Trixi.calc_sources!(du, u, t, source_terms, equations, solver, cache) + @test_approx du_gpu ≈ du + + # Copy data back to host + du_cpu, u_cpu = TrixiGPU.copy_to_host!(du_gpu, u_gpu) + end +end + +end # module diff --git a/test/test_euler_ec.jl b/test/test_euler_ec.jl index 4a5f9bed..ec77fef2 100644 --- a/test/test_euler_ec.jl +++ b/test/test_euler_ec.jl @@ -1,4 +1,12 @@ -module TestCompressibleEulerFluxDifferencing # with `nonconservative_terms::False` +module TestCompressibleEulerFluxDifferencing + +####################################################################### Tags +# Kernels: +# -`cuda_volume_integral!` +# Conditions: +# - `nonconservative_terms::False` +# - `volume_integral::VolumeIntegralFluxDifferencing` +####################################################################### include("test_trixigpu.jl") diff --git a/test/test_euler_shockcapturing.jl b/test/test_euler_shockcapturing.jl index 5a4ed3a9..b81ca1d1 100644 --- a/test/test_euler_shockcapturing.jl +++ b/test/test_euler_shockcapturing.jl @@ -1,5 +1,13 @@ -module TestCompressibleEulerShock # with `nonconservative_terms::False` +module TestCompressibleEulerShock + +####################################################################### Tags +# Kernels: +# -`cuda_volume_integral!` +# Conditions: +# - `nonconservative_terms::False` +# - `volume_integral::VolumeIntegralShockCapturingHG` +####################################################################### include("test_trixigpu.jl") diff --git a/test/test_euler_source_terms.jl b/test/test_euler_source_terms.jl index 3dfa5f41..d7795bc6 100644 --- a/test/test_euler_source_terms.jl +++ b/test/test_euler_source_terms.jl @@ -1,5 +1,13 @@ module TestCompressibleEulerSourceTerms +####################################################################### Tags +# Kernels: +# -`cuda_sources!` +# Conditions: +# - `nonconservative_terms::False` +# - `source_terms` +####################################################################### + include("test_trixigpu.jl") # Test precision of the semidiscretization process diff --git a/test/test_eulermulti_ec.jl b/test/test_eulermulti_ec.jl index 7b9f697b..7433605a 100644 --- a/test/test_eulermulti_ec.jl +++ b/test/test_eulermulti_ec.jl @@ -1,4 +1,12 @@ -module TestCompressibleEulerMultiFluxDifferencing # with `nonconservative_terms::False` +module TestCompressibleEulerMultiFluxDifferencing + +####################################################################### Tags +# Kernels: +# -`cuda_volume_integral!` +# Conditions: +# - `nonconservative_terms::False` +# - `volume_integral::VolumeIntegralFluxDifferencing` +####################################################################### include("test_trixigpu.jl") diff --git a/test/test_hypdiff_nonperiodic.jl b/test/test_hypdiff_nonperiodic.jl index 58ee6cd2..afb1722d 100644 --- a/test/test_hypdiff_nonperiodic.jl +++ b/test/test_hypdiff_nonperiodic.jl @@ -1,4 +1,15 @@ -module TestHyperbolicDiffusionBoundary # with `nonconservative_terms::False` +module TestHyperbolicDiffusionBoundary + +####################################################################### Tags +# Kernels: +# -`cuda_prolong2boundaries!` +# - `cuda_boundary_flux!` +# Conditions: +# - `nonconservative_terms::False` +# - `periodicity = false` 1D +# - `periodicity = (false, true)` 2D +# - `periodicity = (false, true, true)` 3D +####################################################################### include("test_trixigpu.jl") diff --git a/test/test_script.jl b/test/test_script.jl index fe184c90..3907398f 100644 --- a/test/test_script.jl +++ b/test/test_script.jl @@ -1,26 +1,53 @@ include("test_trixigpu.jl") -equations = IdealGlmMhdEquations2D(1.4) +equations = ShallowWaterEquations2D(gravity_constant = 9.81, H0 = 3.25) -initial_condition = initial_condition_weak_blast_wave +# An initial condition with a bottom topography and a perturbation in the waterheight to test +# boundary_condition_slip_wall +function initial_condition_perturbation(x, t, equations::ShallowWaterEquations2D) + # Set the background values + H = equations.H0 + v1 = 0.0 + v2 = 0.0 -volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell) -solver = DGSEM(polydeg = 3, - surface_flux = (flux_hindenlang_gassner, flux_nonconservative_powell), + # Bottom topography + b = 1.5 * exp(-0.5 * ((x[1])^2 + (x[2])^2)) + # Waterheight perturbation + H = H + 0.5 * exp(-10.0 * ((x[1])^2 + (x[2])^2)) + + return prim2cons(SVector(H, v1, v2, b), equations) +end + +initial_condition = initial_condition_perturbation + +boundary_condition = boundary_condition_slip_wall + +############################################################################### +# Get the DG approximation space + +volume_flux = (flux_wintermeyer_etal, flux_nonconservative_wintermeyer_etal) +surface_flux = (flux_lax_friedrichs, flux_nonconservative_wintermeyer_etal) +solver = DGSEM(polydeg = 3, surface_flux = surface_flux, volume_integral = VolumeIntegralFluxDifferencing(volume_flux)) -coordinates_min = (-2.0, -2.0) -coordinates_max = (2.0, 2.0) +############################################################################### +# Get the TreeMesh and setup a non-periodic mesh + +coordinates_min = (-1.0, -1.0) +coordinates_max = (1.0, 1.0) mesh = TreeMesh(coordinates_min, coordinates_max, initial_refinement_level = 4, - n_cells_max = 10_000) + n_cells_max = 10_000, + periodicity = false) -semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver) +# create the semi discretization object +semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, + boundary_conditions = boundary_condition) ############################################################################### # ODE solvers, callbacks etc. -tspan = (0.0, 0.4) +tspan = (0.0, 0.25) # Get CPU data (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi @@ -54,3 +81,62 @@ TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu, Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations), equations, solver.volume_integral, solver, cache) @test_approx du_gpu ≈ du + +# Test `cuda_prolong2interfaces!` +TrixiGPU.cuda_prolong2interfaces!(u_gpu, mesh_gpu, equations_gpu, cache_gpu) +Trixi.prolong2interfaces!(cache, u, mesh, equations, solver.surface_integral, solver) +@test_approx cache_gpu.interfaces.u ≈ cache.interfaces.u + +# Test `cuda_interface_flux!` +TrixiGPU.cuda_interface_flux!(mesh_gpu, Trixi.have_nonconservative_terms(equations_gpu), + equations_gpu, solver_gpu, cache_gpu) +Trixi.calc_interface_flux!(cache.elements.surface_flux_values, mesh, + Trixi.have_nonconservative_terms(equations), equations, + solver.surface_integral, solver, cache) +@test_approx cache_gpu.elements.surface_flux_values ≈ cache.elements.surface_flux_values + +# Test `cuda_prolong2boundaries!` +TrixiGPU.cuda_prolong2boundaries!(u_gpu, mesh_gpu, boundary_conditions_gpu, equations_gpu, + cache_gpu) +Trixi.prolong2boundaries!(cache, u, mesh, equations, solver.surface_integral, solver) +@test_approx cache_gpu.boundaries.u ≈ cache.boundaries.u + +# Test `cuda_boundary_flux!` +TrixiGPU.cuda_boundary_flux!(t_gpu, mesh_gpu, boundary_conditions_gpu, + Trixi.have_nonconservative_terms(equations_gpu), equations_gpu, + solver_gpu, cache_gpu) +Trixi.calc_boundary_flux!(cache, t, boundary_conditions, mesh, equations, + solver.surface_integral, solver) +@test_approx cache_gpu.elements.surface_flux_values ≈ cache.elements.surface_flux_values + +# Test `cuda_prolong2mortars!` +TrixiGPU.cuda_prolong2mortars!(u_gpu, mesh_gpu, TrixiGPU.check_cache_mortars(cache_gpu), + solver_gpu, cache_gpu) +Trixi.prolong2mortars!(cache, u, mesh, equations, + solver.mortar, solver.surface_integral, solver) +@test_approx cache_gpu.mortars.u_upper ≈ cache.mortars.u_upper +@test_approx cache_gpu.mortars.u_lower ≈ cache.mortars.u_lower + +# Test `cuda_mortar_flux!` +TrixiGPU.cuda_mortar_flux!(mesh_gpu, TrixiGPU.check_cache_mortars(cache_gpu), + Trixi.have_nonconservative_terms(equations_gpu), equations_gpu, + solver_gpu, cache_gpu) +Trixi.calc_mortar_flux!(cache.elements.surface_flux_values, mesh, + Trixi.have_nonconservative_terms(equations), equations, + solver.mortar, solver.surface_integral, solver, cache) +@test_approx cache_gpu.elements.surface_flux_values ≈ cache.elements.surface_flux_values + +# Test `cuda_surface_integral!` +TrixiGPU.cuda_surface_integral!(du_gpu, mesh_gpu, equations_gpu, solver_gpu, cache_gpu) +Trixi.calc_surface_integral!(du, u, mesh, equations, solver.surface_integral, solver, cache) +@test_approx du_gpu ≈ du + +# Test `cuda_jacobian!` +TrixiGPU.cuda_jacobian!(du_gpu, mesh_gpu, equations_gpu, cache_gpu) +Trixi.apply_jacobian!(du, mesh, equations, solver, cache) +@test_approx du_gpu ≈ du + +# Test `cuda_sources!` +TrixiGPU.cuda_sources!(du_gpu, u_gpu, t_gpu, source_terms_gpu, equations_gpu, cache_gpu) +Trixi.calc_sources!(du, u, t, source_terms, equations, solver, cache) +@test_approx du_gpu ≈ du diff --git a/test/test_shallowwater_dirichlet.jl b/test/test_shallowwater_dirichlet.jl index f15908ee..aeef55ea 100644 --- a/test/test_shallowwater_dirichlet.jl +++ b/test/test_shallowwater_dirichlet.jl @@ -1,4 +1,13 @@ -module TestShallowWaterBoundary # with `nonconservative_terms::True` +module TestShallowWaterBoundary + +####################################################################### Tags +# Kernels: +# -`cuda_prolong2boundaries!` +# - `cuda_boundary_flux!` +# Conditions: +# - `nonconservative_terms::True` +# - `periodicity = false` 1D, 2D, 3D - `BoundaryConditionDirichlet` +####################################################################### include("test_trixigpu.jl") diff --git a/test/test_shallowwater_ec.jl b/test/test_shallowwater_ec.jl index 1ca0c4a7..a23674dd 100644 --- a/test/test_shallowwater_ec.jl +++ b/test/test_shallowwater_ec.jl @@ -1,4 +1,12 @@ -module TestShallowWaterFluxDifferencing # with `nonconservative_terms::True` +module TestShallowWaterFluxDifferencing + +####################################################################### Tags +# Kernels: +# -`cuda_volume_integral!` +# Conditions: +# - `nonconservative_terms::True` +# - `volume_integral::VolumeIntegralFluxDifferencing` +####################################################################### include("test_trixigpu.jl") diff --git a/test/test_shallowwater_shockcapturing.jl b/test/test_shallowwater_shockcapturing.jl index 7f8a4d9e..0cc701cf 100644 --- a/test/test_shallowwater_shockcapturing.jl +++ b/test/test_shallowwater_shockcapturing.jl @@ -1,4 +1,12 @@ -module TestShallowWaterShock # with `nonconservative_terms::True` +module TestShallowWaterShock + +####################################################################### Tags +# Kernels: +# -`cuda_volume_integral!` +# Conditions: +# - `nonconservative_terms::True` +# - `volume_integral::VolumeIntegralShockCapturingHG` +####################################################################### include("test_trixigpu.jl") diff --git a/test/test_shallowwater_source_terms.jl b/test/test_shallowwater_source_terms.jl index 0d725306..7afa6485 100644 --- a/test/test_shallowwater_source_terms.jl +++ b/test/test_shallowwater_source_terms.jl @@ -1,4 +1,12 @@ -module TestShallowWaterSourceTerms # with `nonconservative_terms::True` +module TestShallowWaterSourceTerms + +####################################################################### Tags +# Kernels: +# -`cuda_sources!` +# Conditions: +# - `nonconservative_terms::True` +# - `source_terms` +####################################################################### include("test_trixigpu.jl")