Skip to content

Commit

Permalink
Complete 2D
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyuxie committed Dec 6, 2024
1 parent 47d0425 commit 7e8406e
Show file tree
Hide file tree
Showing 9 changed files with 684 additions and 918 deletions.
178 changes: 76 additions & 102 deletions test/tree_dgsem_2d/euler_source_terms.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module TestEulerSourceTerms2D

using Trixi, TrixiCUDA
using Test

include("../test_macros.jl")

@testset "Euler Source Terms 2D" begin
Expand Down Expand Up @@ -43,108 +46,79 @@ include("../test_macros.jl")
u_gpu = copy(ode_gpu.u0)
du_gpu = similar(u_gpu)

@testset "Components Initialization" begin
@test_approx (u_gpu, u)
# du is initlaizaed as undefined, cannot test now
end

@testset "Semidiscretization Process" begin
@testset "Copy to GPU" begin
du_gpu, u_gpu = TrixiCUDA.copy_to_gpu!(du, u)
Trixi.reset_du!(du, solver, cache)
@test_approx (du_gpu, du)
end

@testset "Volume Integral" begin
TrixiCUDA.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)
end

@testset "Prolong Interfaces" begin
TrixiCUDA.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)
end

@testset "Interface Flux" begin
TrixiCUDA.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)
end

@testset "Prolong Boundaries" begin
TrixiCUDA.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)
end

@testset "Boundary Flux" begin
TrixiCUDA.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)
end

@testset "Prolong Mortars" begin
TrixiCUDA.cuda_prolong2mortars!(u_gpu, mesh_gpu,
TrixiCUDA.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)
end

@testset "Mortar Flux" begin
TrixiCUDA.cuda_mortar_flux!(mesh_gpu, TrixiCUDA.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)
end

@testset "Surface Integral" begin
TrixiCUDA.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)
end

@testset "Apply Jacobian" begin
TrixiCUDA.cuda_jacobian!(du_gpu, mesh_gpu, equations_gpu, cache_gpu)
Trixi.apply_jacobian!(du, mesh, equations, solver, cache)
@test_approx (du_gpu, du)
end

@testset "Apply Sources" begin
TrixiCUDA.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)
end

@testset "Copy to CPU" begin
du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu)
@test_approx (du_cpu, du)
end
end
# Tests for components initialization
@test_approx (u_gpu, u)
# du is initlaizaed as undefined, cannot test now

# Tests for semidiscretization process
TrixiCUDA.reset_du!(du_gpu)
Trixi.reset_du!(du, solver, cache)
@test_approx (du_gpu, du)

TrixiCUDA.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)

TrixiCUDA.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)

TrixiCUDA.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)

TrixiCUDA.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)

TrixiCUDA.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)

TrixiCUDA.cuda_prolong2mortars!(u_gpu, mesh_gpu,
TrixiCUDA.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)

TrixiCUDA.cuda_mortar_flux!(mesh_gpu, TrixiCUDA.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)

TrixiCUDA.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)

TrixiCUDA.cuda_jacobian!(du_gpu, mesh_gpu, equations_gpu, cache_gpu)
Trixi.apply_jacobian!(du, mesh, equations, solver, cache)
@test_approx (du_gpu, du)

TrixiCUDA.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)
end

end # module
178 changes: 76 additions & 102 deletions test/tree_dgsem_2d/euler_source_terms_nonperiodic.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module TestEulerSourceTermsNonperiodic2D

using Trixi, TrixiCUDA
using Test

include("../test_macros.jl")

@testset "Euler Source Terms Nonperiodic 2D" begin
Expand Down Expand Up @@ -53,108 +56,79 @@ include("../test_macros.jl")
u_gpu = copy(ode_gpu.u0)
du_gpu = similar(u_gpu)

@testset "Components Initialization" begin
@test_approx (u_gpu, u)
# du is initlaizaed as undefined, cannot test now
end

@testset "Semidiscretization Process" begin
@testset "Copy to GPU" begin
du_gpu, u_gpu = TrixiCUDA.copy_to_gpu!(du, u)
Trixi.reset_du!(du, solver, cache)
@test_approx (du_gpu, du)
end

@testset "Volume Integral" begin
TrixiCUDA.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)
end

@testset "Prolong Interfaces" begin
TrixiCUDA.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)
end

@testset "Interface Flux" begin
TrixiCUDA.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)
end

@testset "Prolong Boundaries" begin
TrixiCUDA.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)
end

@testset "Boundary Flux" begin
TrixiCUDA.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)
end

@testset "Prolong Mortars" begin
TrixiCUDA.cuda_prolong2mortars!(u_gpu, mesh_gpu,
TrixiCUDA.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)
end

@testset "Mortar Flux" begin
TrixiCUDA.cuda_mortar_flux!(mesh_gpu, TrixiCUDA.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)
end

@testset "Surface Integral" begin
TrixiCUDA.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)
end

@testset "Apply Jacobian" begin
TrixiCUDA.cuda_jacobian!(du_gpu, mesh_gpu, equations_gpu, cache_gpu)
Trixi.apply_jacobian!(du, mesh, equations, solver, cache)
@test_approx (du_gpu, du)
end

@testset "Apply Sources" begin
TrixiCUDA.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)
end

@testset "Copy to CPU" begin
du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu)
@test_approx (du_cpu, du)
end
end
# Tests for components initialization
@test_approx (u_gpu, u)
# du is initlaizaed as undefined, cannot test now

# Tests for semidiscretization process
TrixiCUDA.reset_du!(du_gpu)
Trixi.reset_du!(du, solver, cache)
@test_approx (du_gpu, du)

TrixiCUDA.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)

TrixiCUDA.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)

TrixiCUDA.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)

TrixiCUDA.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)

TrixiCUDA.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)

TrixiCUDA.cuda_prolong2mortars!(u_gpu, mesh_gpu,
TrixiCUDA.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)

TrixiCUDA.cuda_mortar_flux!(mesh_gpu, TrixiCUDA.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)

TrixiCUDA.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)

TrixiCUDA.cuda_jacobian!(du_gpu, mesh_gpu, equations_gpu, cache_gpu)
Trixi.apply_jacobian!(du, mesh, equations, solver, cache)
@test_approx (du_gpu, du)

TrixiCUDA.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)
end

end # module
Loading

0 comments on commit 7e8406e

Please sign in to comment.