From ded2864bcf66bc11e339afa3c7fc34d366c629af Mon Sep 17 00:00:00 2001 From: Huiyu Xie Date: Fri, 6 Dec 2024 00:42:38 -1000 Subject: [PATCH] Parallelization of compute coefficients functions on GPU (#63) * Start * Compute coefficients * Complete 1D * Remove StrideArrays * Fix noncons mortar flux 2D * Complete 2D * Fix noncons mortar flux 3D * Complete 3D --- Project.toml | 2 - src/TrixiCUDA.jl | 5 +- src/semidiscretization/semidiscretization.jl | 19 ++ .../semidiscretization_hyperbolic.jl | 11 +- src/solvers/cache.jl | 44 ++- src/solvers/common.jl | 17 +- src/solvers/containers_1d.jl | 1 + src/solvers/containers_2d.jl | 1 + src/solvers/containers_3d.jl | 1 + src/solvers/dg.jl | 122 ++++++++ src/solvers/dg_1d.jl | 7 +- src/solvers/dg_2d.jl | 140 +++++---- src/solvers/dg_3d.jl | 280 ++++++++++++------ src/solvers/solvers.jl | 12 +- test/test_macros.jl | 59 ++-- test/test_script.jl | 52 ++-- test/tree_dgsem_1d/advection_amr.jl | 133 --------- .../advection_amr_nonperiodic.jl | 141 --------- test/tree_dgsem_1d/advection_basic.jl | 178 +++++------ test/tree_dgsem_1d/advection_extended.jl | 178 +++++------ test/tree_dgsem_1d/burgers_basic.jl | 178 +++++------ .../tree_dgsem_1d/burgers_linear_stability.jl | 139 --------- test/tree_dgsem_1d/burgers_rarefraction.jl | 178 +++++------ test/tree_dgsem_1d/burgers_shock.jl | 178 +++++------ test/tree_dgsem_1d/euler_blast_wave.jl | 178 +++++------ test/tree_dgsem_1d/euler_ec.jl | 178 +++++------ test/tree_dgsem_1d/euler_shock.jl | 178 +++++------ test/tree_dgsem_1d/euler_source_terms.jl | 176 +++++------ .../euler_source_terms_nonperiodic.jl | 178 +++++------ test/tree_dgsem_1d/eulermulti_ec.jl | 185 +++++------- test/tree_dgsem_1d/eulermulti_es.jl | 176 +++++------ test/tree_dgsem_1d/eulerquasi_ec.jl | 176 +++++------ test/tree_dgsem_1d/eulerquasi_source_terms.jl | 176 +++++------ .../hypdiff_harmonic_nonperiodic.jl | 174 +++++------ test/tree_dgsem_1d/hypdiff_nonperiodic.jl | 176 +++++------ test/tree_dgsem_1d/mhd_alfven_wave.jl | 176 +++++------ test/tree_dgsem_1d/mhd_ec.jl | 176 +++++------ test/tree_dgsem_1d/shallowwater_shock.jl | 174 +++++------ test/tree_dgsem_1d/tree_dgsem_1d.jl | 3 - test/tree_dgsem_2d/advection_basic.jl | 216 ++++++-------- test/tree_dgsem_2d/advection_mortar.jl | 216 ++++++-------- test/tree_dgsem_2d/euler_blob_mortar.jl | 169 +++++++++++ test/tree_dgsem_2d/euler_shock.jl | 216 ++++++-------- test/tree_dgsem_2d/euler_source_terms.jl | 216 ++++++-------- .../euler_source_terms_nonperiodic.jl | 216 ++++++-------- test/tree_dgsem_2d/euler_vortex_mortar.jl | 185 ------------ test/tree_dgsem_2d/eulermulti_ec.jl | 216 ++++++-------- test/tree_dgsem_2d/eulermulti_es.jl | 225 +++++++------- test/tree_dgsem_2d/hypdiff_nonperiodic.jl | 216 ++++++-------- test/tree_dgsem_2d/mhd_alfven_wave.jl | 216 ++++++-------- test/tree_dgsem_2d/mhd_alfven_wave_mortar.jl | 216 ++++++-------- test/tree_dgsem_2d/mhd_shock.jl | 216 ++++++-------- test/tree_dgsem_2d/shallowwater_ec.jl | 216 ++++++-------- .../shallowwater_source_terms.jl | 216 ++++++-------- .../shawllowwater_source_terms_nonperiodic.jl | 216 ++++++-------- test/tree_dgsem_2d/tree_dgsem_2d.jl | 2 +- test/tree_dgsem_3d/advection_basic.jl | 220 ++++++-------- test/tree_dgsem_3d/advection_mortar.jl | 220 ++++++-------- test/tree_dgsem_3d/euler_convergence.jl | 220 ++++++-------- test/tree_dgsem_3d/euler_ec.jl | 220 ++++++-------- test/tree_dgsem_3d/euler_mortar.jl | 220 ++++++-------- test/tree_dgsem_3d/euler_shock.jl | 220 ++++++-------- test/tree_dgsem_3d/euler_source_terms.jl | 220 ++++++-------- test/tree_dgsem_3d/hypdiff_nonperiodic.jl | 220 ++++++-------- test/tree_dgsem_3d/mhd_alfven_wave.jl | 220 ++++++-------- test/tree_dgsem_3d/mhd_alfven_wave_mortar.jl | 220 ++++++-------- test/tree_dgsem_3d/mhd_ec.jl | 220 ++++++-------- test/tree_dgsem_3d/mhd_shock.jl | 220 ++++++-------- 68 files changed, 4552 insertions(+), 6033 deletions(-) create mode 100644 src/solvers/dg.jl delete mode 100644 test/tree_dgsem_1d/advection_amr.jl delete mode 100644 test/tree_dgsem_1d/advection_amr_nonperiodic.jl delete mode 100644 test/tree_dgsem_1d/burgers_linear_stability.jl create mode 100644 test/tree_dgsem_2d/euler_blob_mortar.jl delete mode 100644 test/tree_dgsem_2d/euler_vortex_mortar.jl diff --git a/Project.toml b/Project.toml index 62bd331..4607e89 100644 --- a/Project.toml +++ b/Project.toml @@ -8,7 +8,6 @@ BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" -StrideArrays = "d1fa6d79-ef01-42a6-86c9-f7c551f8593b" Trixi = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb" TrixiBase = "9a0f1c46-06d5-4909-a5a3-ce25d3fa3284" @@ -17,7 +16,6 @@ BenchmarkTools = "1" CUDA = "5" SciMLBase = "2" StaticArrays = "1" -StrideArrays = "0.1" Trixi = "0.8, 0.9" TrixiBase = "0.1" julia = "1.10" diff --git a/src/TrixiCUDA.jl b/src/TrixiCUDA.jl index 067b05a..40f3e7b 100644 --- a/src/TrixiCUDA.jl +++ b/src/TrixiCUDA.jl @@ -7,7 +7,7 @@ using CUDA using CUDA: @cuda, CuArray, HostKernel, threadIdx, blockIdx, blockDim, similar, launch_configuration -using Trixi: AbstractEquations, AbstractContainer, +using Trixi: AbstractEquations, AbstractContainer, AbstractSemidiscretization, AbstractMesh, ElementContainer1D, ElementContainer2D, ElementContainer3D, InterfaceContainer1D, InterfaceContainer2D, InterfaceContainer3D, BoundaryContainer1D, BoundaryContainer2D, BoundaryContainer3D, @@ -18,6 +18,7 @@ using Trixi: AbstractEquations, AbstractContainer, BoundaryConditionPeriodic, BoundaryConditionDirichlet, VolumeIntegralWeakForm, VolumeIntegralFluxDifferencing, VolumeIntegralShockCapturingHG, LobattoLegendreMortarL2, + allocate_coefficients, mesh_equations_solver_cache, flux, ntuple, nvariables, nnodes, nelements, nmortars, local_leaf_cells, init_elements, init_interfaces, init_boundaries, init_mortars, wrap_array, compute_coefficients, have_nonconservative_terms, @@ -30,8 +31,6 @@ import Trixi: get_node_vars, get_node_coords, get_surface_node_vars, using SciMLBase: ODEProblem, FullSpecialize -using StrideArrays: PtrArray - using StaticArrays: SVector # Include other source files diff --git a/src/semidiscretization/semidiscretization.jl b/src/semidiscretization/semidiscretization.jl index 11391c3..a76e632 100644 --- a/src/semidiscretization/semidiscretization.jl +++ b/src/semidiscretization/semidiscretization.jl @@ -1 +1,20 @@ include("semidiscretization_hyperbolic.jl") + +# Similar to `compute_coefficients` in Trixi.jl but calls GPU kernel +function compute_coefficients_gpu(func, t, semi::AbstractSemidiscretization) + u_ode = allocate_coefficients(mesh_equations_solver_cache(semi)...) + + # Call `compute_coefficients_gpu` defined below + u_ode = compute_coefficients_gpu(u_ode, func, t, semi) + return u_ode +end + +# Compute the coefficients for 1D problems on the GPU +function compute_coefficients_gpu(u_ode, func, t, semi::AbstractSemidiscretization) + u = wrap_array(u_ode, semi) + u = CuArray(u) + + # Call `compute_coefficients_gpu` defined in `src/solvers/dg.jl` + u_computed = compute_coefficients_gpu(u, func, t, mesh_equations_solver_cache(semi)...) + return u_computed +end diff --git a/src/semidiscretization/semidiscretization_hyperbolic.jl b/src/semidiscretization/semidiscretization_hyperbolic.jl index a924b43..17d622a 100644 --- a/src/semidiscretization/semidiscretization_hyperbolic.jl +++ b/src/semidiscretization/semidiscretization_hyperbolic.jl @@ -1,5 +1,6 @@ -# This file is part of the package `Semidiscretizations.jl`. +# Everything specific about semidiscretization hyperbolic for PDE solvers. +# Similar to `SemidiscretizationHyperbolic` in Trixi.jl but for GPU cache function SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver; source_terms = nothing, boundary_conditions = boundary_condition_periodic, @@ -16,6 +17,7 @@ function SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, sol check_periodicity_mesh_boundary_conditions(mesh, _boundary_conditions) + # Return the CPU type SemidiscretizationHyperbolic{typeof(mesh), typeof(equations), typeof(initial_condition), typeof(_boundary_conditions), typeof(source_terms), @@ -25,3 +27,10 @@ function SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, sol source_terms, solver, cache) end + +# Similar to `compute_coefficients` in Trixi.jl but calls GPU kernel +function compute_coefficients_gpu(t, semi::SemidiscretizationHyperbolic) + + # Call `compute_coefficients_gpu` defined in `src/semidiscretization/semidiscretization.jl` + compute_coefficients_gpu(semi.initial_condition, t, semi) +end diff --git a/src/solvers/cache.jl b/src/solvers/cache.jl index 4f141ab..ada2ebd 100644 --- a/src/solvers/cache.jl +++ b/src/solvers/cache.jl @@ -121,12 +121,16 @@ end function create_cache_gpu(mesh::TreeMesh{2}, equations, mortar_l2::LobattoLegendreMortarL2, uEltype, cache) - fstar_upper = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), - nmortars(cache.mortars)) - fstar_lower = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), - nmortars(cache.mortars)) - - (; fstar_upper, fstar_lower) + fstar_primary_upper = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), + nmortars(cache.mortars)) + fstar_primary_lower = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), + nmortars(cache.mortars)) + fstar_secondary_upper = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), + nmortars(cache.mortars)) + fstar_secondary_lower = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), + nmortars(cache.mortars)) + + (; fstar_primary_upper, fstar_primary_lower, fstar_secondary_upper, fstar_secondary_lower) end # Create cache specialized for 3D tree mesh @@ -194,15 +198,25 @@ end function create_cache_gpu(mesh::TreeMesh{3}, equations, mortar_l2::LobattoLegendreMortarL2, uEltype, cache) - fstar_upper_left = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), - nnodes(mortar_l2), nmortars(cache.mortars)) - fstar_upper_right = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), - nnodes(mortar_l2), nmortars(cache.mortars)) - fstar_lower_left = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), - nnodes(mortar_l2), nmortars(cache.mortars)) - fstar_lower_right = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), - nnodes(mortar_l2), nmortars(cache.mortars)) + fstar_primary_upper_left = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), + nnodes(mortar_l2), nmortars(cache.mortars)) + fstar_primary_upper_right = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), + nnodes(mortar_l2), nmortars(cache.mortars)) + fstar_primary_lower_left = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), + nnodes(mortar_l2), nmortars(cache.mortars)) + fstar_primary_lower_right = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), + nnodes(mortar_l2), nmortars(cache.mortars)) + fstar_secondary_upper_left = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), + nnodes(mortar_l2), nmortars(cache.mortars)) + fstar_secondary_upper_right = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), + nnodes(mortar_l2), nmortars(cache.mortars)) + fstar_secondary_lower_left = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), + nnodes(mortar_l2), nmortars(cache.mortars)) + fstar_secondary_lower_right = CUDA.zeros(Float64, nvariables(equations), nnodes(mortar_l2), + nnodes(mortar_l2), nmortars(cache.mortars)) # Temporary arrays can also be created here - (; fstar_upper_left, fstar_upper_right, fstar_lower_left, fstar_lower_right) + (; fstar_primary_upper_left, fstar_primary_upper_right, fstar_primary_lower_left, + fstar_primary_lower_right, fstar_secondary_upper_left, fstar_secondary_upper_right, + fstar_secondary_lower_left, fstar_secondary_lower_right) end diff --git a/src/solvers/common.jl b/src/solvers/common.jl index 15f9c40..47a28c7 100644 --- a/src/solvers/common.jl +++ b/src/solvers/common.jl @@ -1,20 +1,11 @@ # Some common functions that are shared between the solvers. # Copy data from CPU to GPU -function copy_to_gpu!(du::PtrArray, u::PtrArray) - du = CUDA.zeros(Float64, size(du)...) - u = CuArray{Float64}(u) +function reset_du!(du::CuArray{Float64}) + du_zero = zero(du) + du .= du_zero # no scalar indexing - return (du, u) -end - -# Copy data from GPU to CPU -function copy_to_cpu!(du::CuArray, u::CuArray) - # TODO: Direct CuArray to PtrArray - du = PtrArray(Array{Float64}(du)) - u = PtrArray(Array{Float64}(u)) - - return (du, u) + return nothing end # Set diagonal entries of a matrix to zeros diff --git a/src/solvers/containers_1d.jl b/src/solvers/containers_1d.jl index 5ee9006..b302ea8 100644 --- a/src/solvers/containers_1d.jl +++ b/src/solvers/containers_1d.jl @@ -27,6 +27,7 @@ mutable struct ElementContainerGPU1D{RealT <: Real, uEltype <: Real} <: Abstract end end +Base.eltype(elements::ElementContainerGPU1D) = eltype(elements.surface_flux_values) @inline nelements(elements::ElementContainerGPU1D) = length(elements.cell_ids) # Copy arrays from DG elements to GPU diff --git a/src/solvers/containers_2d.jl b/src/solvers/containers_2d.jl index 2fae9bd..219e861 100644 --- a/src/solvers/containers_2d.jl +++ b/src/solvers/containers_2d.jl @@ -27,6 +27,7 @@ mutable struct ElementContainerGPU2D{RealT <: Real, uEltype <: Real} <: Abstract end end +Base.eltype(elements::ElementContainerGPU2D) = eltype(elements.surface_flux_values) @inline nelements(elements::ElementContainerGPU2D) = length(elements.cell_ids) # Copy arrays from DG elements to GPU diff --git a/src/solvers/containers_3d.jl b/src/solvers/containers_3d.jl index c353e61..4120a5e 100644 --- a/src/solvers/containers_3d.jl +++ b/src/solvers/containers_3d.jl @@ -27,6 +27,7 @@ mutable struct ElementContainerGPU3D{RealT <: Real, uEltype <: Real} <: Abstract end end +Base.eltype(elements::ElementContainerGPU3D) = eltype(elements.surface_flux_values) @inline nelements(elements::ElementContainerGPU3D) = length(elements.cell_ids) # Copy arrays from DG elements to GPU diff --git a/src/solvers/dg.jl b/src/solvers/dg.jl new file mode 100644 index 0000000..d89b5d3 --- /dev/null +++ b/src/solvers/dg.jl @@ -0,0 +1,122 @@ +# Kernel for computing the coefficients for 1D problems +function compute_coefficients_kernel!(u, node_coordinates, func::Any, t, + equations::AbstractEquations{1}) + j = (blockIdx().x - 1) * blockDim().x + threadIdx().x + k = (blockIdx().y - 1) * blockDim().y + threadIdx().y + + if (j <= size(u, 2) && k <= size(u, 3)) + x_node = get_node_coords(node_coordinates, equations, j, k) + + if j == 1 # bad + x_node = SVector(nextfloat(x_node[1])) + elseif j == size(u, 2) # bad + x_node = SVector(prevfloat(x_node[1])) + end + + u_node = func(x_node, t, equations) + + @inbounds begin + for ii in axes(u, 1) + u[ii, j, k] = u_node[ii] + end + end + end + + return nothing +end + +# Kernel for computing the coefficients for 2D problems +function compute_coefficients_kernel!(u, node_coordinates, func::Any, t, + equations::AbstractEquations{2}) + j = (blockIdx().x - 1) * blockDim().x + threadIdx().x + k = (blockIdx().y - 1) * blockDim().y + threadIdx().y + + if (j <= size(u, 2)^2 && k <= size(u, 4)) + j1 = div(j - 1, size(u, 2)) + 1 + j2 = rem(j - 1, size(u, 2)) + 1 + + x_node = get_node_coords(node_coordinates, equations, j1, j2, k) + + u_node = func(x_node, t, equations) + + @inbounds begin + for ii in axes(u, 1) + u[ii, j1, j2, k] = u_node[ii] + end + end + end + + return nothing +end + +# Kernel for computing the coefficients for 3D problems +function compute_coefficients_kernel!(u, node_coordinates, func::Any, t, + equations::AbstractEquations{3}) + j = (blockIdx().x - 1) * blockDim().x + threadIdx().x + k = (blockIdx().y - 1) * blockDim().y + threadIdx().y + + if (j <= size(u, 2)^3 && k <= size(u, 5)) + u2 = size(u, 2) + + j1 = div(j - 1, u2^2) + 1 + j2 = div(rem(j - 1, u2^2), u2) + 1 + j3 = rem(rem(j - 1, u2^2), u2) + 1 + + x_node = get_node_coords(node_coordinates, equations, j1, j2, j3, k) + + u_node = func(x_node, t, equations) + + @inbounds begin + for ii in axes(u, 1) + u[ii, j1, j2, j3, k] = u_node[ii] + end + end + end + + return nothing +end + +# Call kernels to compute the coefficients for 1D problems +function compute_coefficients_gpu(u, func, t, mesh::AbstractMesh{1}, equations, dg::DGSEM, cache) + node_coordinates = cache.elements.node_coordinates + + compute_coefficients_kernel = @cuda launch=false compute_coefficients_kernel!(u, + node_coordinates, + func, t, + equations) + compute_coefficients_kernel(u, node_coordinates, func, t, equations; + kernel_configurator_2d(compute_coefficients_kernel, size(u, 2), + size(u, 3))...) + + return u +end + +# Call kernels to compute the coefficients for 2D problems +function compute_coefficients_gpu(u, func, t, mesh::AbstractMesh{2}, equations, dg::DGSEM, cache) + node_coordinates = cache.elements.node_coordinates + + compute_coefficients_kernel = @cuda launch=false compute_coefficients_kernel!(u, + node_coordinates, + func, t, + equations) + compute_coefficients_kernel(u, node_coordinates, func, t, equations; + kernel_configurator_2d(compute_coefficients_kernel, size(u, 2)^2, + size(u, 4))...) + + return u +end + +# Call kernels to compute the coefficients for 2D problems +function compute_coefficients_gpu(u, func, t, mesh::AbstractMesh{3}, equations, dg::DGSEM, cache) + node_coordinates = cache.elements.node_coordinates + + compute_coefficients_kernel = @cuda launch=false compute_coefficients_kernel!(u, + node_coordinates, + func, t, + equations) + compute_coefficients_kernel(u, node_coordinates, func, t, equations; + kernel_configurator_2d(compute_coefficients_kernel, size(u, 2)^3, + size(u, 5))...) + + return u +end diff --git a/src/solvers/dg_1d.jl b/src/solvers/dg_1d.jl index f9be04f..92a62d7 100644 --- a/src/solvers/dg_1d.jl +++ b/src/solvers/dg_1d.jl @@ -1075,9 +1075,9 @@ end # Put everything together into a single function. # See also `rhs!` function in Trixi.jl -function rhs_gpu!(du_cpu, u_cpu, t, mesh::TreeMesh{1}, equations, boundary_conditions, +function rhs_gpu!(du, u, t, mesh::TreeMesh{1}, equations, boundary_conditions, source_terms::Source, dg::DGSEM, cache) where {Source} - du, u = copy_to_gpu!(du_cpu, u_cpu) + reset_du!(du) cuda_volume_integral!(du, u, mesh, have_nonconservative_terms(equations), equations, dg.volume_integral, dg, cache) @@ -1097,8 +1097,5 @@ function rhs_gpu!(du_cpu, u_cpu, t, mesh::TreeMesh{1}, equations, boundary_condi cuda_sources!(du, u, t, source_terms, equations, cache) - du_computed, _ = copy_to_cpu!(du, u) - du_cpu .= du_computed - return nothing end diff --git a/src/solvers/dg_2d.jl b/src/solvers/dg_2d.jl index c01c251..d9dfbbc 100644 --- a/src/solvers/dg_2d.jl +++ b/src/solvers/dg_2d.jl @@ -815,7 +815,8 @@ function prolong_mortars_large2small_kernel!(u_upper, u_lower, u, forward_upper, end # Kernel for calculating mortar fluxes -function mortar_flux_kernel!(fstar_upper, fstar_lower, u_upper, u_lower, orientations, +function mortar_flux_kernel!(fstar_primary_upper, fstar_primary_lower, fstar_secondary_upper, + fstar_secondary_lower, u_upper, u_lower, orientations, equations::AbstractEquations{2}, surface_flux::Any) j = (blockIdx().x - 1) * blockDim().x + threadIdx().x k = (blockIdx().y - 1) * blockDim().y + threadIdx().y @@ -829,9 +830,11 @@ function mortar_flux_kernel!(fstar_upper, fstar_lower, u_upper, u_lower, orienta flux_lower_node = surface_flux(u_lower_ll, u_lower_rr, orientation, equations) @inbounds begin - for ii in axes(fstar_upper, 1) - fstar_upper[ii, j, k] = flux_upper_node[ii] - fstar_lower[ii, j, k] = flux_lower_node[ii] + for ii in axes(fstar_primary_upper, 1) + fstar_primary_upper[ii, j, k] = flux_upper_node[ii] + fstar_primary_lower[ii, j, k] = flux_lower_node[ii] + fstar_secondary_upper[ii, j, k] = flux_upper_node[ii] + fstar_secondary_lower[ii, j, k] = flux_lower_node[ii] end end end @@ -840,7 +843,8 @@ function mortar_flux_kernel!(fstar_upper, fstar_lower, u_upper, u_lower, orienta end # Kernel for calculating mortar fluxes and adding nonconservative fluxes -function mortar_flux_kernel!(fstar_upper, fstar_lower, u_upper, u_lower, orientations, large_sides, +function mortar_flux_kernel!(fstar_primary_upper, fstar_primary_lower, fstar_secondary_upper, + fstar_secondary_lower, u_upper, u_lower, orientations, large_sides, equations::AbstractEquations{2}, surface_flux::Any, nonconservative_flux::Any) j = (blockIdx().x - 1) * blockDim().x + threadIdx().x @@ -857,9 +861,11 @@ function mortar_flux_kernel!(fstar_upper, fstar_lower, u_upper, u_lower, orienta flux_lower_node = surface_flux(u_lower_ll, u_lower_rr, orientation, equations) @inbounds begin - for ii in axes(fstar_upper, 1) - fstar_upper[ii, j, k] = flux_upper_node[ii] - fstar_lower[ii, j, k] = flux_lower_node[ii] + for ii in axes(fstar_primary_upper, 1) + fstar_primary_upper[ii, j, k] = flux_upper_node[ii] + fstar_primary_lower[ii, j, k] = flux_lower_node[ii] + fstar_secondary_upper[ii, j, k] = flux_upper_node[ii] + fstar_secondary_lower[ii, j, k] = flux_lower_node[ii] end end @@ -869,13 +875,21 @@ function mortar_flux_kernel!(fstar_upper, fstar_lower, u_upper, u_lower, orienta u_lower1 = (2 - large_side) * u_lower_ll + (large_side - 1) * u_lower_rr u_lower2 = (large_side - 1) * u_lower_ll + (2 - large_side) * u_lower_rr - noncons_flux_upper = nonconservative_flux(u_upper1, u_upper2, orientation, equations) - noncons_flux_lower = nonconservative_flux(u_lower1, u_lower2, orientation, equations) + noncons_flux_primary_upper = nonconservative_flux(u_upper1, u_upper2, orientation, + equations) + noncons_flux_primary_lower = nonconservative_flux(u_lower1, u_lower2, orientation, + equations) + noncons_flux_secondary_upper = nonconservative_flux(u_upper2, u_upper1, orientation, + equations) + noncons_flux_secondary_lower = nonconservative_flux(u_lower2, u_lower1, orientation, + equations) @inbounds begin - for ii in axes(fstar_upper, 1) - fstar_upper[ii, j, k] += 0.5 * noncons_flux_upper[ii] - fstar_lower[ii, j, k] += 0.5 * noncons_flux_lower[ii] + for ii in axes(fstar_primary_upper, 1) + fstar_primary_upper[ii, j, k] += 0.5 * noncons_flux_primary_upper[ii] + fstar_primary_lower[ii, j, k] += 0.5 * noncons_flux_primary_lower[ii] + fstar_secondary_upper[ii, j, k] += 0.5 * noncons_flux_secondary_upper[ii] + fstar_secondary_lower[ii, j, k] += 0.5 * noncons_flux_secondary_lower[ii] end end end @@ -884,9 +898,11 @@ function mortar_flux_kernel!(fstar_upper, fstar_lower, u_upper, u_lower, orienta end # Kernel for copying mortar fluxes small to small and small to large -function mortar_flux_copy_to_kernel!(surface_flux_values, tmp_surface_flux_values, fstar_upper, - fstar_lower, reverse_upper, reverse_lower, neighbor_ids, - large_sides, orientations) +function mortar_flux_copy_to_kernel!(surface_flux_values, tmp_surface_flux_values, + fstar_primary_upper, fstar_primary_lower, + fstar_secondary_upper, fstar_secondary_lower, + reverse_upper, reverse_lower, neighbor_ids, large_sides, + orientations, equations::AbstractEquations{2}) i = (blockIdx().x - 1) * blockDim().x + threadIdx().x j = (blockIdx().y - 1) * blockDim().y + threadIdx().y k = (blockIdx().z - 1) * blockDim().z + threadIdx().z @@ -907,8 +923,8 @@ function mortar_flux_copy_to_kernel!(surface_flux_values, tmp_surface_flux_value # (large_side - 1) * (orientation - 1) * 4`. direction = large_side + 2 * orientation - 2 - surface_flux_values[i, j, direction, upper_element] = fstar_upper[i, j, k] - surface_flux_values[i, j, direction, lower_element] = fstar_lower[i, j, k] + surface_flux_values[i, j, direction, upper_element] = fstar_primary_upper[i, j, k] + surface_flux_values[i, j, direction, lower_element] = fstar_primary_lower[i, j, k] # Use math expression to enhance performance (against control flow), it is equivalent to, # `(2 - large_side) * (2 - orientation) * 2 + @@ -919,10 +935,14 @@ function mortar_flux_copy_to_kernel!(surface_flux_values, tmp_surface_flux_value @inbounds begin for ii in axes(reverse_upper, 2) # i.e., ` for ii in axes(reverse_lower, 2)` - tmp_surface_flux_values[i, j, direction, large_element] += reverse_upper[j, ii] * - fstar_upper[i, ii, k] + - reverse_lower[j, ii] * - fstar_lower[i, ii, k] + tmp_surface_flux_values[i, j, direction, large_element] += fstar_secondary_upper[i, + ii, + k] * + reverse_upper[j, ii] + + fstar_secondary_lower[i, + ii, + k] * + reverse_lower[j, ii] end surface_flux_values[i, j, direction, large_element] = tmp_surface_flux_values[i, j, @@ -1566,29 +1586,39 @@ function cuda_mortar_flux!(mesh::TreeMesh{2}, cache_mortars::True, nonconservati surface_flux_values = cache.elements.surface_flux_values tmp_surface_flux_values = zero(similar(surface_flux_values)) - fstar_upper = cache.fstar_upper - fstar_lower = cache.fstar_lower - - mortar_flux_kernel = @cuda launch=false mortar_flux_kernel!(fstar_upper, fstar_lower, u_upper, - u_lower, orientations, equations, - surface_flux) - mortar_flux_kernel(fstar_upper, fstar_lower, u_upper, u_lower, orientations, equations, + fstar_primary_upper = cache.fstar_primary_upper + fstar_primary_lower = cache.fstar_primary_lower + fstar_secondary_upper = cache.fstar_secondary_upper + fstar_secondary_lower = cache.fstar_secondary_lower + + mortar_flux_kernel = @cuda launch=false mortar_flux_kernel!(fstar_primary_upper, + fstar_primary_lower, + fstar_secondary_upper, + fstar_secondary_lower, + u_upper, u_lower, orientations, + equations, surface_flux) + mortar_flux_kernel(fstar_primary_upper, fstar_primary_lower, fstar_secondary_upper, + fstar_secondary_lower, u_upper, u_lower, orientations, equations, surface_flux; kernel_configurator_2d(mortar_flux_kernel, size(u_upper, 3), length(orientations))...) mortar_flux_copy_to_kernel = @cuda launch=false mortar_flux_copy_to_kernel!(surface_flux_values, tmp_surface_flux_values, - fstar_upper, - fstar_lower, + fstar_primary_upper, + fstar_primary_lower, + fstar_secondary_upper, + fstar_secondary_lower, reverse_upper, reverse_lower, neighbor_ids, large_sides, - orientations) - mortar_flux_copy_to_kernel(surface_flux_values, tmp_surface_flux_values, fstar_upper, - fstar_lower, reverse_upper, reverse_lower, neighbor_ids, large_sides, - orientations; + orientations, + equations) + mortar_flux_copy_to_kernel(surface_flux_values, tmp_surface_flux_values, fstar_primary_upper, + fstar_primary_lower, fstar_secondary_upper, fstar_secondary_lower, + reverse_upper, reverse_lower, neighbor_ids, large_sides, + orientations, equations; kernel_configurator_3d(mortar_flux_copy_to_kernel, size(surface_flux_values, 1), size(surface_flux_values, 2), @@ -1614,30 +1644,41 @@ function cuda_mortar_flux!(mesh::TreeMesh{2}, cache_mortars::True, nonconservati surface_flux_values = cache.elements.surface_flux_values tmp_surface_flux_values = zero(similar(surface_flux_values)) - fstar_upper = cache.fstar_upper - fstar_lower = cache.fstar_lower - - mortar_flux_kernel = @cuda launch=false mortar_flux_kernel!(fstar_upper, fstar_lower, u_upper, + fstar_primary_upper = cache.fstar_primary_upper + fstar_primary_lower = cache.fstar_primary_lower + fstar_secondary_upper = cache.fstar_secondary_upper + fstar_secondary_lower = cache.fstar_secondary_lower + + mortar_flux_kernel = @cuda launch=false mortar_flux_kernel!(fstar_primary_upper, + fstar_primary_lower, + fstar_secondary_upper, + fstar_secondary_lower, + u_upper, u_lower, orientations, large_sides, equations, surface_flux, nonconservative_flux) - mortar_flux_kernel(fstar_upper, fstar_lower, u_upper, u_lower, orientations, large_sides, + mortar_flux_kernel(fstar_primary_upper, fstar_primary_lower, fstar_secondary_upper, + fstar_secondary_lower, u_upper, u_lower, orientations, large_sides, equations, surface_flux, nonconservative_flux; kernel_configurator_2d(mortar_flux_kernel, size(u_upper, 3), length(orientations))...) mortar_flux_copy_to_kernel = @cuda launch=false mortar_flux_copy_to_kernel!(surface_flux_values, tmp_surface_flux_values, - fstar_upper, - fstar_lower, + fstar_primary_upper, + fstar_primary_lower, + fstar_secondary_upper, + fstar_secondary_lower, reverse_upper, reverse_lower, neighbor_ids, large_sides, - orientations) - mortar_flux_copy_to_kernel(surface_flux_values, tmp_surface_flux_values, fstar_upper, - fstar_lower, reverse_upper, reverse_lower, neighbor_ids, large_sides, - orientations; + orientations, + equations) + mortar_flux_copy_to_kernel(surface_flux_values, tmp_surface_flux_values, fstar_primary_upper, + fstar_primary_lower, fstar_secondary_upper, fstar_secondary_lower, + reverse_upper, reverse_lower, neighbor_ids, large_sides, + orientations, equations; kernel_configurator_3d(mortar_flux_copy_to_kernel, size(surface_flux_values, 1), size(surface_flux_values, 2), @@ -1696,9 +1737,9 @@ end # Put everything together into a single function. # See also `rhs!` function in Trixi.jl -function rhs_gpu!(du_cpu, u_cpu, t, mesh::TreeMesh{2}, equations, boundary_conditions, +function rhs_gpu!(du, u, t, mesh::TreeMesh{2}, equations, boundary_conditions, source_terms::Source, dg::DGSEM, cache) where {Source} - du, u = copy_to_gpu!(du_cpu, u_cpu) + reset_du!(du) cuda_volume_integral!(du, u, mesh, have_nonconservative_terms(equations), equations, dg.volume_integral, dg, cache) @@ -1723,8 +1764,5 @@ function rhs_gpu!(du_cpu, u_cpu, t, mesh::TreeMesh{2}, equations, boundary_condi cuda_sources!(du, u, t, source_terms, equations, cache) - du_computed, _ = copy_to_cpu!(du, u) - du_cpu .= du_computed - return nothing end diff --git a/src/solvers/dg_3d.jl b/src/solvers/dg_3d.jl index 7fbf3b1..b7a696d 100644 --- a/src/solvers/dg_3d.jl +++ b/src/solvers/dg_3d.jl @@ -1041,10 +1041,12 @@ function prolong_mortars_large2small_kernel!(u_upper_left, u_upper_right, u_lowe end # Kernel for calculating mortar fluxes -function mortar_flux_kernel!(fstar_upper_left, fstar_upper_right, fstar_lower_left, - fstar_lower_right, u_upper_left, u_upper_right, u_lower_left, - u_lower_right, orientations, equations::AbstractEquations{3}, - surface_flux::Any) +function mortar_flux_kernel!(fstar_primary_upper_left, fstar_primary_upper_right, + fstar_primary_lower_left, fstar_primary_lower_right, + fstar_secondary_upper_left, fstar_secondary_upper_right, + fstar_secondary_lower_left, fstar_seondary_lower_right, + u_upper_left, u_upper_right, u_lower_left, u_lower_right, orientations, + equations::AbstractEquations{3}, surface_flux::Any) i = (blockIdx().x - 1) * blockDim().x + threadIdx().x j = (blockIdx().y - 1) * blockDim().y + threadIdx().y k = (blockIdx().z - 1) * blockDim().z + threadIdx().z @@ -1069,11 +1071,15 @@ function mortar_flux_kernel!(fstar_upper_left, fstar_upper_right, fstar_lower_le equations) @inbounds begin - for ii in axes(fstar_upper_left, 1) - fstar_upper_left[ii, i, j, k] = flux_upper_left_node[ii] - fstar_upper_right[ii, i, j, k] = flux_upper_right_node[ii] - fstar_lower_left[ii, i, j, k] = flux_lower_left_node[ii] - fstar_lower_right[ii, i, j, k] = flux_lower_right_node[ii] + for ii in axes(fstar_primary_upper_left, 1) + fstar_primary_upper_left[ii, i, j, k] = flux_upper_left_node[ii] + fstar_primary_upper_right[ii, i, j, k] = flux_upper_right_node[ii] + fstar_primary_lower_left[ii, i, j, k] = flux_lower_left_node[ii] + fstar_primary_lower_right[ii, i, j, k] = flux_lower_right_node[ii] + fstar_secondary_upper_left[ii, i, j, k] = flux_upper_left_node[ii] + fstar_secondary_upper_right[ii, i, j, k] = flux_upper_right_node[ii] + fstar_secondary_lower_left[ii, i, j, k] = flux_lower_left_node[ii] + fstar_seondary_lower_right[ii, i, j, k] = flux_lower_right_node[ii] end end end @@ -1082,10 +1088,12 @@ function mortar_flux_kernel!(fstar_upper_left, fstar_upper_right, fstar_lower_le end # Kernel for calculating mortar fluxes and adding nonconservative fluxes -function mortar_flux_kernel!(fstar_upper_left, fstar_upper_right, fstar_lower_left, - fstar_lower_right, u_upper_left, u_upper_right, u_lower_left, - u_lower_right, orientations, large_sides, - equations::AbstractEquations{3}, surface_flux::Any, +function mortar_flux_kernel!(fstar_primary_upper_left, fstar_primary_upper_right, + fstar_primary_lower_left, fstar_primary_lower_right, + fstar_secondary_upper_left, fstar_secondary_upper_right, + fstar_secondary_lower_left, fstar_seondary_lower_right, + u_upper_left, u_upper_right, u_lower_left, u_lower_right, orientations, + large_sides, equations::AbstractEquations{3}, surface_flux::Any, nonconservative_flux::Any) i = (blockIdx().x - 1) * blockDim().x + threadIdx().x j = (blockIdx().y - 1) * blockDim().y + threadIdx().y @@ -1112,11 +1120,15 @@ function mortar_flux_kernel!(fstar_upper_left, fstar_upper_right, fstar_lower_le equations) @inbounds begin - for ii in axes(fstar_upper_left, 1) - fstar_upper_left[ii, i, j, k] = flux_upper_left_node[ii] - fstar_upper_right[ii, i, j, k] = flux_upper_right_node[ii] - fstar_lower_left[ii, i, j, k] = flux_lower_left_node[ii] - fstar_lower_right[ii, i, j, k] = flux_lower_right_node[ii] + for ii in axes(fstar_primary_upper_left, 1) + fstar_primary_upper_left[ii, i, j, k] = flux_upper_left_node[ii] + fstar_primary_upper_right[ii, i, j, k] = flux_upper_right_node[ii] + fstar_primary_lower_left[ii, i, j, k] = flux_lower_left_node[ii] + fstar_primary_lower_right[ii, i, j, k] = flux_lower_right_node[ii] + fstar_secondary_upper_left[ii, i, j, k] = flux_upper_left_node[ii] + fstar_secondary_upper_right[ii, i, j, k] = flux_upper_right_node[ii] + fstar_secondary_lower_left[ii, i, j, k] = flux_lower_left_node[ii] + fstar_seondary_lower_right[ii, i, j, k] = flux_lower_right_node[ii] end end @@ -1132,21 +1144,45 @@ function mortar_flux_kernel!(fstar_upper_left, fstar_upper_right, fstar_lower_le u_lower_right1 = (2 - large_side) * u_lower_right_ll + (large_side - 1) * u_lower_right_rr u_lower_right2 = (large_side - 1) * u_lower_right_ll + (2 - large_side) * u_lower_right_rr - noncons_flux_upper_left = nonconservative_flux(u_upper_left1, u_upper_left2, orientation, - equations) - noncons_flux_upper_right = nonconservative_flux(u_upper_right1, u_upper_right2, orientation, - equations) - noncons_flux_lower_left = nonconservative_flux(u_lower_left1, u_lower_left2, orientation, - equations) - noncons_flux_lower_right = nonconservative_flux(u_lower_right1, u_lower_right2, orientation, - equations) + noncons_flux_primary_upper_left = nonconservative_flux(u_upper_left1, u_upper_left2, + orientation, + equations) + noncons_flux_primary_upper_right = nonconservative_flux(u_upper_right1, u_upper_right2, + orientation, + equations) + noncons_flux_primary_lower_left = nonconservative_flux(u_lower_left1, u_lower_left2, + orientation, + equations) + noncons_flux_primary_lower_right = nonconservative_flux(u_lower_right1, u_lower_right2, + orientation, + equations) + noncons_flux_secondary_upper_left = nonconservative_flux(u_upper_left2, u_upper_left1, + orientation, + equations) + noncons_flux_secondary_upper_right = nonconservative_flux(u_upper_right2, u_upper_right1, + orientation, + equations) + noncons_flux_secondary_lower_left = nonconservative_flux(u_lower_left2, u_lower_left1, + orientation, + equations) + noncons_flux_secondary_lower_right = nonconservative_flux(u_lower_right2, u_lower_right1, + orientation, + equations) @inbounds begin - for ii in axes(fstar_upper_left, 1) - fstar_upper_left[ii, i, j, k] += 0.5 * noncons_flux_upper_left[ii] - fstar_upper_right[ii, i, j, k] += 0.5 * noncons_flux_upper_right[ii] - fstar_lower_left[ii, i, j, k] += 0.5 * noncons_flux_lower_left[ii] - fstar_lower_right[ii, i, j, k] += 0.5 * noncons_flux_lower_right[ii] + for ii in axes(fstar_primary_upper_left, 1) + fstar_primary_upper_left[ii, i, j, k] += 0.5 * noncons_flux_primary_upper_left[ii] + fstar_primary_upper_right[ii, i, j, k] += 0.5 * noncons_flux_primary_upper_right[ii] + fstar_primary_lower_left[ii, i, j, k] += 0.5 * noncons_flux_primary_lower_left[ii] + fstar_primary_lower_right[ii, i, j, k] += 0.5 * noncons_flux_primary_lower_right[ii] + fstar_secondary_upper_left[ii, i, j, k] += 0.5 * + noncons_flux_secondary_upper_left[ii] + fstar_secondary_upper_right[ii, i, j, k] += 0.5 * + noncons_flux_secondary_upper_right[ii] + fstar_secondary_lower_left[ii, i, j, k] += 0.5 * + noncons_flux_secondary_lower_left[ii] + fstar_seondary_lower_right[ii, i, j, k] += 0.5 * + noncons_flux_secondary_lower_right[ii] end end end @@ -1154,10 +1190,13 @@ function mortar_flux_kernel!(fstar_upper_left, fstar_upper_right, fstar_lower_le return nothing end -# Kernel for copying mortar fluxes small to small and small to large - step 1 +# # Kernel for copying mortar fluxes small to small and small to large - step 1 function mortar_flux_copy_to_kernel!(surface_flux_values, tmp_upper_left, tmp_upper_right, - tmp_lower_left, tmp_lower_right, fstar_upper_left, - fstar_upper_right, fstar_lower_left, fstar_lower_right, + tmp_lower_left, tmp_lower_right, + fstar_primary_upper_left, fstar_primary_upper_right, + fstar_primary_lower_left, fstar_primary_lower_right, + fstar_secondary_upper_left, fstar_secondary_upper_right, + fstar_secondary_lower_left, fstar_secondary_lower_right, reverse_upper, reverse_lower, neighbor_ids, large_sides, orientations) i = (blockIdx().x - 1) * blockDim().x + threadIdx().x @@ -1188,14 +1227,22 @@ function mortar_flux_copy_to_kernel!(surface_flux_values, tmp_upper_left, tmp_up # Please also check the original code in Trixi.jl when you modify this code. direction = 2 * orientation + large_side - 2 - surface_flux_values[i, j1, j2, direction, upper_left_element] = fstar_upper_left[i, j1, j2, - k] - surface_flux_values[i, j1, j2, direction, upper_right_element] = fstar_upper_right[i, j1, - j2, k] - surface_flux_values[i, j1, j2, direction, lower_left_element] = fstar_lower_left[i, j1, j2, - k] - surface_flux_values[i, j1, j2, direction, lower_right_element] = fstar_lower_right[i, j1, - j2, k] + surface_flux_values[i, j1, j2, direction, upper_left_element] = fstar_primary_upper_left[i, + j1, + j2, + k] + surface_flux_values[i, j1, j2, direction, upper_right_element] = fstar_primary_upper_right[i, + j1, + j2, + k] + surface_flux_values[i, j1, j2, direction, lower_left_element] = fstar_primary_lower_left[i, + j1, + j2, + k] + surface_flux_values[i, j1, j2, direction, lower_right_element] = fstar_primary_lower_right[i, + j1, + j2, + k] # Use simple math expression to enhance the performance (against control flow), # it is equivalent to, `isequal(large_side, 1) * isequal(orientation, 1) * 2 + @@ -1210,17 +1257,25 @@ function mortar_flux_copy_to_kernel!(surface_flux_values, tmp_upper_left, tmp_up @inbounds begin for j1j1 in axes(reverse_upper, 2) tmp_upper_left[i, j1, j2, direction, large_element] += reverse_lower[j1, j1j1] * - fstar_upper_left[i, j1j1, j2, - k] + fstar_secondary_upper_left[i, + j1j1, + j2, + k] tmp_upper_right[i, j1, j2, direction, large_element] += reverse_upper[j1, j1j1] * - fstar_upper_right[i, j1j1, - j2, k] + fstar_secondary_upper_right[i, + j1j1, + j2, + k] tmp_lower_left[i, j1, j2, direction, large_element] += reverse_lower[j1, j1j1] * - fstar_lower_left[i, j1j1, j2, - k] + fstar_secondary_lower_left[i, + j1j1, + j2, + k] tmp_lower_right[i, j1, j2, direction, large_element] += reverse_upper[j1, j1j1] * - fstar_lower_right[i, j1j1, - j2, k] + fstar_secondary_lower_right[i, + j1j1, + j2, + k] end end end @@ -1232,7 +1287,7 @@ end function mortar_flux_copy_to_kernel!(surface_flux_values, tmp_surface_flux_values, tmp_upper_left, tmp_upper_right, tmp_lower_left, tmp_lower_right, reverse_upper, reverse_lower, neighbor_ids, large_sides, - orientations) + orientations, equations::AbstractEquations{3}) i = (blockIdx().x - 1) * blockDim().x + threadIdx().x j = (blockIdx().y - 1) * blockDim().y + threadIdx().y k = (blockIdx().z - 1) * blockDim().z + threadIdx().z @@ -1939,8 +1994,7 @@ function cuda_prolong2mortars!(u, mesh::TreeMesh{3}, cache_mortars::True, dg::DG large_sides) prolong_mortars_large2small_kernel(u_upper_left, u_upper_right, u_lower_left, u_lower_right, tmp_upper_left, tmp_upper_right, tmp_lower_left, - tmp_lower_right, - forward_upper, forward_lower, large_sides; + tmp_lower_right, forward_upper, forward_lower, large_sides; kernel_configurator_3d(prolong_mortars_large2small_kernel, size(u_upper_left, 2), size(u_upper_left, 3)^2, @@ -1975,18 +2029,31 @@ function cuda_mortar_flux!(mesh::TreeMesh{3}, cache_mortars::True, nonconservati surface_flux_values = cache.elements.surface_flux_values tmp_surface_flux_values = zero(similar(surface_flux_values)) # undef to zero - fstar_upper_left = cache.fstar_upper_left - fstar_upper_right = cache.fstar_upper_right - fstar_lower_left = cache.fstar_lower_left - fstar_lower_right = cache.fstar_lower_right - - mortar_flux_kernel = @cuda launch=false mortar_flux_kernel!(fstar_upper_left, fstar_upper_right, - fstar_lower_left, fstar_lower_right, + fstar_primary_upper_left = cache.fstar_primary_upper_left + fstar_primary_upper_right = cache.fstar_primary_upper_right + fstar_primary_lower_left = cache.fstar_primary_lower_left + fstar_primary_lower_right = cache.fstar_primary_lower_right + fstar_secondary_upper_left = cache.fstar_secondary_upper_left + fstar_secondary_upper_right = cache.fstar_secondary_upper_right + fstar_secondary_lower_left = cache.fstar_secondary_lower_left + fstar_secondary_lower_right = cache.fstar_secondary_lower_right + + mortar_flux_kernel = @cuda launch=false mortar_flux_kernel!(fstar_primary_upper_left, + fstar_primary_upper_right, + fstar_primary_lower_left, + fstar_primary_lower_right, + fstar_secondary_upper_left, + fstar_secondary_upper_right, + fstar_secondary_lower_left, + fstar_secondary_lower_right, u_upper_left, u_upper_right, u_lower_left, u_lower_right, orientations, equations, surface_flux) - mortar_flux_kernel(fstar_upper_left, fstar_upper_right, fstar_lower_left, fstar_lower_right, + mortar_flux_kernel(fstar_primary_upper_left, fstar_primary_upper_right, + fstar_primary_lower_left, fstar_primary_lower_right, + fstar_secondary_upper_left, fstar_secondary_upper_right, + fstar_secondary_lower_left, fstar_secondary_lower_right, u_upper_left, u_upper_right, u_lower_left, u_lower_right, orientations, equations, surface_flux; kernel_configurator_3d(mortar_flux_kernel, size(u_upper_left, 3), @@ -1998,25 +2065,32 @@ function cuda_mortar_flux!(mesh::TreeMesh{3}, cache_mortars::True, nonconservati tmp_lower_left = zero(similar(surface_flux_values)) # undef to zero tmp_lower_right = zero(similar(surface_flux_values)) # undef to zero - # TODO: Combine these two kernels into one (synchronization) + # TODO: Combine these two copy kernels into one (synchronization) mortar_flux_copy_to_kernel = @cuda launch=false mortar_flux_copy_to_kernel!(surface_flux_values, tmp_upper_left, tmp_upper_right, tmp_lower_left, tmp_lower_right, - fstar_upper_left, - fstar_upper_right, - fstar_lower_left, - fstar_lower_right, + fstar_primary_upper_left, + fstar_primary_upper_right, + fstar_primary_lower_left, + fstar_primary_lower_right, + fstar_secondary_upper_left, + fstar_secondary_upper_right, + fstar_secondary_lower_left, + fstar_secondary_lower_right, reverse_upper, reverse_lower, neighbor_ids, large_sides, orientations) mortar_flux_copy_to_kernel(surface_flux_values, tmp_upper_left, tmp_upper_right, tmp_lower_left, - tmp_lower_right, fstar_upper_left, fstar_upper_right, - fstar_lower_left, fstar_lower_right, reverse_upper, reverse_lower, - neighbor_ids, large_sides, orientations; + tmp_lower_right, fstar_primary_upper_left, fstar_primary_upper_right, + fstar_primary_lower_left, fstar_primary_lower_right, + fstar_secondary_upper_left, fstar_secondary_upper_right, + fstar_secondary_lower_left, fstar_secondary_lower_right, + reverse_upper, reverse_lower, neighbor_ids, large_sides, + orientations; kernel_configurator_3d(mortar_flux_copy_to_kernel, size(surface_flux_values, 1), size(surface_flux_values, 2)^2, @@ -2032,10 +2106,11 @@ function cuda_mortar_flux!(mesh::TreeMesh{3}, cache_mortars::True, nonconservati reverse_lower, neighbor_ids, large_sides, - orientations) + orientations, + equations) mortar_flux_copy_to_kernel(surface_flux_values, tmp_surface_flux_values, tmp_upper_left, tmp_upper_right, tmp_lower_left, tmp_lower_right, reverse_upper, - reverse_lower, neighbor_ids, large_sides, orientations; + reverse_lower, neighbor_ids, large_sides, orientations, equations; kernel_configurator_3d(mortar_flux_copy_to_kernel, size(surface_flux_values, 1), size(surface_flux_values, 2)^2, @@ -2063,19 +2138,33 @@ function cuda_mortar_flux!(mesh::TreeMesh{3}, cache_mortars::True, nonconservati surface_flux_values = cache.elements.surface_flux_values tmp_surface_flux_values = zero(similar(surface_flux_values)) # undef to zero - fstar_upper_left = cache.fstar_upper_left - fstar_upper_right = cache.fstar_upper_right - fstar_lower_left = cache.fstar_lower_left - fstar_lower_right = cache.fstar_lower_right - mortar_flux_kernel = @cuda launch=false mortar_flux_kernel!(fstar_upper_left, fstar_upper_right, - fstar_lower_left, fstar_lower_right, + fstar_primary_upper_left = cache.fstar_primary_upper_left + fstar_primary_upper_right = cache.fstar_primary_upper_right + fstar_primary_lower_left = cache.fstar_primary_lower_left + fstar_primary_lower_right = cache.fstar_primary_lower_right + fstar_secondary_upper_left = cache.fstar_secondary_upper_left + fstar_secondary_upper_right = cache.fstar_secondary_upper_right + fstar_secondary_lower_left = cache.fstar_secondary_lower_left + fstar_secondary_lower_right = cache.fstar_secondary_lower_right + + mortar_flux_kernel = @cuda launch=false mortar_flux_kernel!(fstar_primary_upper_left, + fstar_primary_upper_right, + fstar_primary_lower_left, + fstar_primary_lower_right, + fstar_secondary_upper_left, + fstar_secondary_upper_right, + fstar_secondary_lower_left, + fstar_secondary_lower_right, u_upper_left, u_upper_right, u_lower_left, u_lower_right, orientations, large_sides, equations, surface_flux, nonconservative_flux) - mortar_flux_kernel(fstar_upper_left, fstar_upper_right, fstar_lower_left, fstar_lower_right, + mortar_flux_kernel(fstar_primary_upper_left, fstar_primary_upper_right, + fstar_primary_lower_left, fstar_primary_lower_right, + fstar_secondary_upper_left, fstar_secondary_upper_right, + fstar_secondary_lower_left, fstar_secondary_lower_right, u_upper_left, u_upper_right, u_lower_left, u_lower_right, orientations, large_sides, equations, surface_flux, nonconservative_flux; kernel_configurator_3d(mortar_flux_kernel, size(u_upper_left, 3), @@ -2087,25 +2176,32 @@ function cuda_mortar_flux!(mesh::TreeMesh{3}, cache_mortars::True, nonconservati tmp_lower_left = zero(similar(surface_flux_values)) # undef to zero tmp_lower_right = zero(similar(surface_flux_values)) # undef to zero - # TODO: Combine these two kernels into one (synchronization) + # TODO: Combine these two copy kernels into one (synchronization) mortar_flux_copy_to_kernel = @cuda launch=false mortar_flux_copy_to_kernel!(surface_flux_values, tmp_upper_left, tmp_upper_right, tmp_lower_left, tmp_lower_right, - fstar_upper_left, - fstar_upper_right, - fstar_lower_left, - fstar_lower_right, + fstar_primary_upper_left, + fstar_primary_upper_right, + fstar_primary_lower_left, + fstar_primary_lower_right, + fstar_secondary_upper_left, + fstar_secondary_upper_right, + fstar_secondary_lower_left, + fstar_secondary_lower_right, reverse_upper, reverse_lower, neighbor_ids, large_sides, orientations) mortar_flux_copy_to_kernel(surface_flux_values, tmp_upper_left, tmp_upper_right, tmp_lower_left, - tmp_lower_right, fstar_upper_left, fstar_upper_right, - fstar_lower_left, fstar_lower_right, reverse_upper, reverse_lower, - neighbor_ids, large_sides, orientations; + tmp_lower_right, fstar_primary_upper_left, fstar_primary_upper_right, + fstar_primary_lower_left, fstar_primary_lower_right, + fstar_secondary_upper_left, fstar_secondary_upper_right, + fstar_secondary_lower_left, fstar_secondary_lower_right, + reverse_upper, reverse_lower, neighbor_ids, large_sides, + orientations; kernel_configurator_3d(mortar_flux_copy_to_kernel, size(surface_flux_values, 1), size(surface_flux_values, 2)^2, @@ -2121,10 +2217,11 @@ function cuda_mortar_flux!(mesh::TreeMesh{3}, cache_mortars::True, nonconservati reverse_lower, neighbor_ids, large_sides, - orientations) + orientations, + equations) mortar_flux_copy_to_kernel(surface_flux_values, tmp_surface_flux_values, tmp_upper_left, tmp_upper_right, tmp_lower_left, tmp_lower_right, reverse_upper, - reverse_lower, neighbor_ids, large_sides, orientations; + reverse_lower, neighbor_ids, large_sides, orientations, equations; kernel_configurator_3d(mortar_flux_copy_to_kernel, size(surface_flux_values, 1), size(surface_flux_values, 2)^2, @@ -2183,9 +2280,9 @@ end # Put everything together into a single function. # See also `rhs!` function in Trixi.jl -function rhs_gpu!(du_cpu, u_cpu, t, mesh::TreeMesh{3}, equations, boundary_conditions, +function rhs_gpu!(du, u, t, mesh::TreeMesh{3}, equations, boundary_conditions, source_terms::Source, dg::DGSEM, cache) where {Source} - du, u = copy_to_gpu!(du_cpu, u_cpu) + reset_du!(du) cuda_volume_integral!(du, u, mesh, have_nonconservative_terms(equations), equations, dg.volume_integral, dg, cache) @@ -2210,8 +2307,5 @@ function rhs_gpu!(du_cpu, u_cpu, t, mesh::TreeMesh{3}, equations, boundary_condi cuda_sources!(du, u, t, source_terms, equations, cache) - du_computed, _ = copy_to_cpu!(du, u) - du_cpu .= du_computed - return nothing end diff --git a/src/solvers/solvers.jl b/src/solvers/solvers.jl index c60bd2e..60a827c 100644 --- a/src/solvers/solvers.jl +++ b/src/solvers/solvers.jl @@ -6,22 +6,24 @@ include("containers_3d.jl") include("dg_1d.jl") include("dg_2d.jl") include("dg_3d.jl") +include("dg.jl") # See also `rhs!` function in Trixi.jl function rhs_gpu!(du_ode, u_ode, semi::SemidiscretizationHyperbolic, t) - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi - u = wrap_array(u_ode, mesh, equations, solver, cache) - du = wrap_array(du_ode, mesh, equations, solver, cache) + # No need to wrap arrays here + # u = wrap_array(u_ode, mesh, equations, solver, cache) + # du = wrap_array(du_ode, mesh, equations, solver, cache) - rhs_gpu!(du, u, t, mesh, equations, boundary_conditions, source_terms, solver, cache) + rhs_gpu!(du_ode, u_ode, t, mesh, equations, boundary_conditions, source_terms, solver, cache) return nothing end # See also `semidiscretize` function in Trixi.jl function semidiscretizeGPU(semi::SemidiscretizationHyperbolic, tspan) - u0_ode = compute_coefficients(first(tspan), semi) + u0_ode = compute_coefficients_gpu(first(tspan), semi) iip = true specialize = FullSpecialize diff --git a/test/test_macros.jl b/test/test_macros.jl index f3de377..af040c6 100644 --- a/test/test_macros.jl +++ b/test/test_macros.jl @@ -1,31 +1,4 @@ -# Create some macros to simplify the testing process. -using Trixi, TrixiCUDA -using CUDA -using Test: @test, @testset - -# Macro to test the type Float64 or Float32 ? - -# Macro to test the exact equality of two arrays, which can be from the CPU, GPU, -# or a combination of both -macro test_equal(expr) - # Parse the expression and check that it is of the form - # @test_equal (array1, array2) - if expr.head != :tuple || length(expr.args) != 2 - error("Incorrect usage. Expected syntax: @test_approx(array1, array2)") - end - - local array1 = esc(expr.args[1]) - local array2 = esc(expr.args[2]) - - quote - # Convert to arrays to avoid using CUDA.@allowscalar - # to access the elements of some arrays - local _array1 = Array($array1) - local _array2 = Array($array2) - - @test _array1 == _array2 - end -end +# Create some macros to assist the testing process # Macro to test the approximate equality of arrays from GPU and CPU with NaNs macro test_approx(expr) @@ -100,12 +73,24 @@ macro test_approx(expr) end end -# Truth table -# ------------------------------- -# Entry | Entry | Result -# ------------------------------- -# NaN | zero | 1 -# NaN | non-zero | 0 -# non-NaN | zero | 1 -# non-NaN | non-zero | 1 -# ------------------------------- +# Macro to test the exact equality of two arrays, which can be from the CPU, GPU, +# or a combination of both +macro test_equal(expr) + # Parse the expression and check that it is of the form + # @test_equal (array1, array2) + if expr.head != :tuple || length(expr.args) != 2 + error("Incorrect usage. Expected syntax: @test_approx(array1, array2)") + end + + local array1 = esc(expr.args[1]) + local array2 = esc(expr.args[2]) + + quote + # Convert to arrays to avoid using CUDA.@allowscalar + # to access the elements of some arrays + local _array1 = Array($array1) + local _array2 = Array($array2) + + @test _array1 == _array2 + end +end diff --git a/test/test_script.jl b/test/test_script.jl index 613e744..cf50e6f 100644 --- a/test/test_script.jl +++ b/test/test_script.jl @@ -1,5 +1,8 @@ include("test_macros.jl") +using Trixi, TrixiCUDA +using Test + advection_velocity = (0.2, -0.7, 0.5) equations = LinearScalarAdvectionEquation3D(advection_velocity) @@ -18,41 +21,34 @@ semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition_co solver) tspan = (0.0, 1.0) +t = t_gpu = 0.0 -ode = semidiscretize(semi, tspan) -u_ode = copy(ode.u0) -du_ode = similar(u_ode) - -# Get CPU data -t = 0.0 -(; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi -u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) -du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) +# Semi on CPU +(; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi -# Get GPU data -t_gpu = 0.0 +# Semi on GPU equations_gpu = semi_gpu.equations mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache -initial_condition_gpu = semi_gpu.initial_condition boundary_conditions_gpu = semi_gpu.boundary_conditions source_terms_gpu = semi_gpu.source_terms -u_gpu = CuArray(u) -du_gpu = CuArray(du) -# Copy data to device -du_gpu, u_gpu = TrixiCUDA.copy_to_gpu!(du, u) -# Reset data on host -Trixi.reset_du!(du, solver, cache) - -derivative_dhat = CuArray{Float64}(solver_gpu.basis.derivative_dhat) -flux_arr1 = similar(u_gpu) -flux_arr2 = similar(u_gpu) -flux_arr3 = similar(u_gpu) +# ODE on CPU +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) -size_arr = CuArray{Float64}(undef, size(u, 2)^3, size(u, 5)) +# ODE on GPU +ode_gpu = semidiscretizeGPU(semi_gpu, tspan) +u_gpu = copy(ode_gpu.u0) +du_gpu = similar(u_gpu) -flux_kernel = @cuda launch=false TrixiCUDA.flux_kernel!(flux_arr1, flux_arr2, flux_arr3, u_gpu, - equations, - flux) +# Tests for components initialization +@test_approx (u_gpu, u) -config = launch_configuration(flux_kernel.fun) +# Test `rhs!` function as a whole +Trixi.rhs!(du, u, t, mesh, equations, boundary_conditions, source_terms, solver, cache) +TrixiCUDA.rhs_gpu!(du_gpu, u_gpu, t_gpu, mesh_gpu, equations_gpu, boundary_conditions_gpu, + source_terms_gpu, solver_gpu, cache_gpu) +@test_approx (du_gpu, du) diff --git a/test/tree_dgsem_1d/advection_amr.jl b/test/tree_dgsem_1d/advection_amr.jl deleted file mode 100644 index 95060d2..0000000 --- a/test/tree_dgsem_1d/advection_amr.jl +++ /dev/null @@ -1,133 +0,0 @@ -module TestAdvectionAMR1D - -include("../test_macros.jl") - -@testset "Advection AMR 1D" begin - advection_velocity = 1.0 - equations = LinearScalarAdvectionEquation1D(advection_velocity) - - initial_condition = initial_condition_gauss - - solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs) - - coordinates_min = (-5.0,) - coordinates_max = (5.0,) - mesh = TreeMesh(coordinates_min, coordinates_max, - initial_refinement_level = 4, - n_cells_max = 30_000) - - semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver) - semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) - - tspan = (0.0, 10.0) - - ode = semidiscretize(semi, tspan) - u_ode = copy(ode.u0) - du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi - u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) - du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end -end - -end # module diff --git a/test/tree_dgsem_1d/advection_amr_nonperiodic.jl b/test/tree_dgsem_1d/advection_amr_nonperiodic.jl deleted file mode 100644 index 8981c7d..0000000 --- a/test/tree_dgsem_1d/advection_amr_nonperiodic.jl +++ /dev/null @@ -1,141 +0,0 @@ -module TestAdvectionAMRNonperiodic1D - -include("../test_macros.jl") - -@testset "Advection AMR Nonperiodic 1D" begin - advection_velocity = 1.0 - equations = LinearScalarAdvectionEquation1D(advection_velocity) - - initial_condition = initial_condition_gauss - boundary_conditions = BoundaryConditionDirichlet(initial_condition) - - solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs) - - coordinates_min = (0.0,) - coordinates_max = (5.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, - boundary_conditions = boundary_conditions) - semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, - initial_condition, - solver, - boundary_conditions = boundary_conditions) - - tspan = (0.0, 5.0) - - ode = semidiscretize(semi, tspan) - u_ode = copy(ode.u0) - du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi - u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) - du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end -end - -end # module diff --git a/test/tree_dgsem_1d/advection_basic.jl b/test/tree_dgsem_1d/advection_basic.jl index 2d84d7c..c9fd491 100644 --- a/test/tree_dgsem_1d/advection_basic.jl +++ b/test/tree_dgsem_1d/advection_basic.jl @@ -1,4 +1,7 @@ -module TestAdvectionBasic1D +module AdvectionBasic1D + +using Trixi, TrixiCUDA +using Test include("../test_macros.jl") @@ -21,114 +24,85 @@ include("../test_macros.jl") solver) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/advection_extended.jl b/test/tree_dgsem_1d/advection_extended.jl index f84921d..91fa26d 100644 --- a/test/tree_dgsem_1d/advection_extended.jl +++ b/test/tree_dgsem_1d/advection_extended.jl @@ -1,4 +1,7 @@ -module TestAdvectionExtended1D +module AdvectionExtended1D + +using Trixi, TrixiCUDA +using Test include("../test_macros.jl") @@ -26,114 +29,85 @@ include("../test_macros.jl") boundary_conditions = boundary_conditions) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/burgers_basic.jl b/test/tree_dgsem_1d/burgers_basic.jl index d84087b..a02e03d 100644 --- a/test/tree_dgsem_1d/burgers_basic.jl +++ b/test/tree_dgsem_1d/burgers_basic.jl @@ -1,4 +1,7 @@ -module TestBugersBasic1D +module MainBurgersBasic1D + +using Trixi, TrixiCUDA +using Test include("../test_macros.jl") @@ -21,114 +24,85 @@ include("../test_macros.jl") source_terms = source_terms_convergence_test) tspan = (0.0, 2.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/burgers_linear_stability.jl b/test/tree_dgsem_1d/burgers_linear_stability.jl deleted file mode 100644 index 8267dc1..0000000 --- a/test/tree_dgsem_1d/burgers_linear_stability.jl +++ /dev/null @@ -1,139 +0,0 @@ -module TestBurgersLinearStability1D - -include("../test_macros.jl") - -@testset "Burgers Linear Stability 1D" begin - equations = InviscidBurgersEquation1D() - - function initial_condition_linear_stability(x, t, equation::InviscidBurgersEquation1D) - k = 1 - 2 + sinpi(k * (x[1] - 0.7)) |> SVector - end - - volume_flux = flux_ec - solver = DGSEM(polydeg = 3, surface_flux = flux_ec, - volume_integral = VolumeIntegralFluxDifferencing(volume_flux)) - - coordinates_min = -1.0 - coordinates_max = 1.0 - mesh = TreeMesh(coordinates_min, coordinates_max, - initial_refinement_level = 4, - n_cells_max = 10_000) - - semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_linear_stability, - solver) - semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition_linear_stability, - solver) - - tspan = (0.0, 2.0) - - ode = semidiscretize(semi, tspan) - u_ode = copy(ode.u0) - du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi - u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) - du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end -end - -end # module diff --git a/test/tree_dgsem_1d/burgers_rarefraction.jl b/test/tree_dgsem_1d/burgers_rarefraction.jl index 5aa7aa3..8fea555 100644 --- a/test/tree_dgsem_1d/burgers_rarefraction.jl +++ b/test/tree_dgsem_1d/burgers_rarefraction.jl @@ -1,4 +1,7 @@ -module TestBurgersRarefaction1D +module BurgersRarefaction1D + +using Trixi, TrixiCUDA +using Test include("../test_macros.jl") @@ -59,114 +62,85 @@ include("../test_macros.jl") boundary_conditions = boundary_conditions) tspan = (0.0, 0.2) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/burgers_shock.jl b/test/tree_dgsem_1d/burgers_shock.jl index 554c7f4..416a031 100644 --- a/test/tree_dgsem_1d/burgers_shock.jl +++ b/test/tree_dgsem_1d/burgers_shock.jl @@ -1,4 +1,7 @@ -module TestBurgersShock1D +module BurgersShock1D + +using Trixi, TrixiCUDA +using Test include("../test_macros.jl") @@ -60,114 +63,85 @@ include("../test_macros.jl") boundary_conditions = boundary_conditions) tspan = (0.0, 0.2) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/euler_blast_wave.jl b/test/tree_dgsem_1d/euler_blast_wave.jl index a2a209a..505422e 100644 --- a/test/tree_dgsem_1d/euler_blast_wave.jl +++ b/test/tree_dgsem_1d/euler_blast_wave.jl @@ -1,4 +1,7 @@ -module TestEulerBlastWave1D +module EulerBlastWave1D + +using Trixi, TrixiCUDA +using Test include("../test_macros.jl") @@ -44,114 +47,85 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 12.5) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/euler_ec.jl b/test/tree_dgsem_1d/euler_ec.jl index b8c6890..edc1b93 100644 --- a/test/tree_dgsem_1d/euler_ec.jl +++ b/test/tree_dgsem_1d/euler_ec.jl @@ -1,4 +1,7 @@ -module TestEulerEC1D +module EulerEC1D + +using Trixi, TrixiCUDA +using Test include("../test_macros.jl") @@ -21,114 +24,85 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 0.4) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/euler_shock.jl b/test/tree_dgsem_1d/euler_shock.jl index 1b12981..0be0578 100644 --- a/test/tree_dgsem_1d/euler_shock.jl +++ b/test/tree_dgsem_1d/euler_shock.jl @@ -1,4 +1,7 @@ -module TestEulerShock1D +module EulerShock1D + +using Trixi, TrixiCUDA +using Test include("../test_macros.jl") @@ -30,114 +33,85 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/euler_source_terms.jl b/test/tree_dgsem_1d/euler_source_terms.jl index 25100a8..5dac728 100644 --- a/test/tree_dgsem_1d/euler_source_terms.jl +++ b/test/tree_dgsem_1d/euler_source_terms.jl @@ -1,5 +1,8 @@ module TestEulerSourceTerms1D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Source Terms 1D" begin @@ -21,114 +24,85 @@ include("../test_macros.jl") source_terms = source_terms_convergence_test) tspan = (0.0, 2.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/euler_source_terms_nonperiodic.jl b/test/tree_dgsem_1d/euler_source_terms_nonperiodic.jl index c984cb9..e7702cf 100644 --- a/test/tree_dgsem_1d/euler_source_terms_nonperiodic.jl +++ b/test/tree_dgsem_1d/euler_source_terms_nonperiodic.jl @@ -1,4 +1,7 @@ -module TestEulerSourceTermsNonperiodic1D +module EulerSourceTermsNonperiodic1D + +using Trixi, TrixiCUDA +using Test include("../test_macros.jl") @@ -28,114 +31,85 @@ include("../test_macros.jl") boundary_conditions = boundary_conditions) tspan = (0.0, 2.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/eulermulti_ec.jl b/test/tree_dgsem_1d/eulermulti_ec.jl index bbbb556..62e8d98 100644 --- a/test/tree_dgsem_1d/eulermulti_ec.jl +++ b/test/tree_dgsem_1d/eulermulti_ec.jl @@ -1,11 +1,19 @@ module TestEulerMultiEC1D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Multi EC 1D" begin - equations = CompressibleEulerMulticomponentEquations1D(gammas = (1.4, 1.4, 1.4), - gas_constants = (0.4, 0.4, 0.4)) + # More than two components are not supported, this is a bug + # equations = CompressibleEulerMulticomponentEquations1D(gammas = (1.4, 1.4, 1.4), + # gas_constants = (0.4, 0.4, 0.4)) + + equations = CompressibleEulerMulticomponentEquations1D(gammas = (1.4, 1.4), + gas_constants = (0.4, 0.4)) + # This cannot handle multicomponent equations and will cause kernel compilation errors initial_condition = initial_condition_weak_blast_wave volume_flux = flux_ranocha @@ -22,114 +30,85 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 0.4) + t = t_gpu = 0.0 + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/eulermulti_es.jl b/test/tree_dgsem_1d/eulermulti_es.jl index ed11a41..d5ba4d3 100644 --- a/test/tree_dgsem_1d/eulermulti_es.jl +++ b/test/tree_dgsem_1d/eulermulti_es.jl @@ -1,5 +1,8 @@ module TestEulerMultiES1D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Multi ES 1D" begin @@ -22,114 +25,85 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 0.4) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/eulerquasi_ec.jl b/test/tree_dgsem_1d/eulerquasi_ec.jl index dddaa52..a12e596 100644 --- a/test/tree_dgsem_1d/eulerquasi_ec.jl +++ b/test/tree_dgsem_1d/eulerquasi_ec.jl @@ -1,5 +1,8 @@ module TestEulerQuasiEC1D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Quasi EC 1D" begin @@ -31,114 +34,85 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 0.4) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/eulerquasi_source_terms.jl b/test/tree_dgsem_1d/eulerquasi_source_terms.jl index 5ed078f..bc1f336 100644 --- a/test/tree_dgsem_1d/eulerquasi_source_terms.jl +++ b/test/tree_dgsem_1d/eulerquasi_source_terms.jl @@ -1,5 +1,8 @@ module TestEulerQuasiSourceTerms1D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Quasi Source Terms 1D" begin @@ -24,114 +27,85 @@ include("../test_macros.jl") source_terms = source_terms_convergence_test) tspan = (0.0, 2.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/hypdiff_harmonic_nonperiodic.jl b/test/tree_dgsem_1d/hypdiff_harmonic_nonperiodic.jl index f2e4fa2..cf4acde 100644 --- a/test/tree_dgsem_1d/hypdiff_harmonic_nonperiodic.jl +++ b/test/tree_dgsem_1d/hypdiff_harmonic_nonperiodic.jl @@ -1,5 +1,8 @@ module TestHypdiffHarmonicNonperiodic1D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Hypdiff Harmonic Nonperiodic 1D" begin @@ -40,114 +43,85 @@ include("../test_macros.jl") source_terms = source_terms_harmonic) tspan = (0.0, 30.0) + t = t_gpu = 0.0 - ode = semidiscretize(semi, tspan) - u_ode = copy(ode.u0) - du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi - u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) - du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi - # Get GPU data - t_gpu = 0.0 + # Semi on GPU equations_gpu = semi_gpu.equations mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition boundary_conditions_gpu = semi_gpu.boundary_conditions source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end + # ODE on CPU + 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) - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/hypdiff_nonperiodic.jl b/test/tree_dgsem_1d/hypdiff_nonperiodic.jl index c13e30e..3db78e5 100644 --- a/test/tree_dgsem_1d/hypdiff_nonperiodic.jl +++ b/test/tree_dgsem_1d/hypdiff_nonperiodic.jl @@ -1,5 +1,8 @@ module TestHypdiffNonperiodic1D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Hypdiff Nonperiodic 1D" begin @@ -26,114 +29,85 @@ include("../test_macros.jl") source_terms = source_terms_poisson_nonperiodic) tspan = (0.0, 5.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/mhd_alfven_wave.jl b/test/tree_dgsem_1d/mhd_alfven_wave.jl index 7ff92f1..6199bad 100644 --- a/test/tree_dgsem_1d/mhd_alfven_wave.jl +++ b/test/tree_dgsem_1d/mhd_alfven_wave.jl @@ -1,5 +1,8 @@ module TestMHDAlfvenWave1D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "MHD Alfven Wave 1D" begin @@ -22,114 +25,85 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 2.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/mhd_ec.jl b/test/tree_dgsem_1d/mhd_ec.jl index b3e0904..8e984fb 100644 --- a/test/tree_dgsem_1d/mhd_ec.jl +++ b/test/tree_dgsem_1d/mhd_ec.jl @@ -1,5 +1,8 @@ module TestMHDEC1D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "MHD EC 1D" begin @@ -22,114 +25,85 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 0.4) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/shallowwater_shock.jl b/test/tree_dgsem_1d/shallowwater_shock.jl index 540212d..5062328 100644 --- a/test/tree_dgsem_1d/shallowwater_shock.jl +++ b/test/tree_dgsem_1d/shallowwater_shock.jl @@ -1,5 +1,8 @@ module TestShallowWaterShock1D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Shallow Water Shock 1D" begin @@ -63,114 +66,85 @@ include("../test_macros.jl") boundary_conditions = boundary_condition) tspan = (0.0, 3.0) + t = t_gpu = 0.0 - ode = semidiscretize(semi, tspan) - u_ode = copy(ode.u0) - du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi - u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) - du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi - # Get GPU data - t_gpu = 0.0 + # Semi on GPU equations_gpu = semi_gpu.equations mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition boundary_conditions_gpu = semi_gpu.boundary_conditions source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end + # ODE on CPU + 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) - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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 diff --git a/test/tree_dgsem_1d/tree_dgsem_1d.jl b/test/tree_dgsem_1d/tree_dgsem_1d.jl index 941d89a..667bcb3 100644 --- a/test/tree_dgsem_1d/tree_dgsem_1d.jl +++ b/test/tree_dgsem_1d/tree_dgsem_1d.jl @@ -1,9 +1,6 @@ -include("advection_amr_nonperiodic.jl") -include("advection_amr.jl") include("advection_basic.jl") include("advection_extended.jl") include("burgers_basic.jl") -include("burgers_linear_stability.jl") include("burgers_rarefraction.jl") include("burgers_shock.jl") include("euler_blast_wave.jl") diff --git a/test/tree_dgsem_2d/advection_basic.jl b/test/tree_dgsem_2d/advection_basic.jl index fd054f5..4e32a37 100644 --- a/test/tree_dgsem_2d/advection_basic.jl +++ b/test/tree_dgsem_2d/advection_basic.jl @@ -1,5 +1,8 @@ module TestAdvectionBasic2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Advection Basic 2D" begin @@ -21,137 +24,102 @@ include("../test_macros.jl") solver) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/advection_mortar.jl b/test/tree_dgsem_2d/advection_mortar.jl index d9339ad..48560ff 100644 --- a/test/tree_dgsem_2d/advection_mortar.jl +++ b/test/tree_dgsem_2d/advection_mortar.jl @@ -1,5 +1,8 @@ module TestAdvectionMortar2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Advection Mortar 2D" begin @@ -22,137 +25,102 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/euler_blob_mortar.jl b/test/tree_dgsem_2d/euler_blob_mortar.jl new file mode 100644 index 0000000..5eec55b --- /dev/null +++ b/test/tree_dgsem_2d/euler_blob_mortar.jl @@ -0,0 +1,169 @@ +module TestEulerBlobMortar2D + +using Trixi, TrixiCUDA +using Test + +include("../test_macros.jl") + +@testset "Euler Blob Mortar 2D" begin + gamma = 5 / 3 + equations = CompressibleEulerEquations2D(gamma) + + function initial_condition_blob(x, t, equations::CompressibleEulerEquations2D) + R = 1.0 # radius of the blob + + dens0 = 1.0 + Chi = 10.0 # density contrast + + tau_kh = 1.0 + tau_cr = tau_kh / 1.6 # crushing time + + velx0 = 2 * R * sqrt(Chi) / tau_cr + vely0 = 0.0 + Ma0 = 2.7 # background flow Mach number Ma=v/c + c = velx0 / Ma0 # sound speed + + p0 = c * c * dens0 / equations.gamma + inicenter = SVector(-15, 0) + x_rel = x - inicenter + r = sqrt(x_rel[1]^2 + x_rel[2]^2) + + slope = 2 + dens = dens0 + + (Chi - 1) * 0.5 * (1 + (tanh(slope * (r + R)) - (tanh(slope * (r - R)) + 1))) + # velocity blob is zero + velx = velx0 - velx0 * 0.5 * (1 + (tanh(slope * (r + R)) - (tanh(slope * (r - R)) + 1))) + return prim2cons(SVector(dens, velx, vely0, p0), equations) + end + initial_condition = initial_condition_blob + + surface_flux = flux_lax_friedrichs + volume_flux = flux_ranocha + basis = LobattoLegendreBasis(3) + + indicator_sc = IndicatorHennemannGassner(equations, basis, + alpha_max = 0.05, + alpha_min = 0.0001, + alpha_smooth = true, + variable = pressure) + + volume_integral = VolumeIntegralShockCapturingHG(indicator_sc; + volume_flux_dg = volume_flux, + volume_flux_fv = surface_flux) + + solver = DGSEM(basis, surface_flux, volume_integral) + + coordinates_min = (-32.0, -32.0) + coordinates_max = (32.0, 32.0) + refinement_patches = ((type = "box", coordinates_min = (-40.0, -5.0), + coordinates_max = (40.0, 5.0)), + (type = "box", coordinates_min = (-40.0, -5.0), + coordinates_max = (40.0, 5.0))) + mesh = TreeMesh(coordinates_min, coordinates_max, + initial_refinement_level = 4, + refinement_patches = refinement_patches, + n_cells_max = 100_000) + + semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver) + semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) + + tspan = (0.0, 16.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + + # ODE on CPU + 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) + + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/euler_shock.jl b/test/tree_dgsem_2d/euler_shock.jl index 82ba8d8..b169151 100644 --- a/test/tree_dgsem_2d/euler_shock.jl +++ b/test/tree_dgsem_2d/euler_shock.jl @@ -1,5 +1,8 @@ module TestEulerShock2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Shock 2D" begin @@ -30,137 +33,102 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/euler_source_terms.jl b/test/tree_dgsem_2d/euler_source_terms.jl index 9280204..c7ed8f1 100644 --- a/test/tree_dgsem_2d/euler_source_terms.jl +++ b/test/tree_dgsem_2d/euler_source_terms.jl @@ -1,5 +1,8 @@ module TestEulerSourceTerms2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Source Terms 2D" begin @@ -20,137 +23,102 @@ include("../test_macros.jl") source_terms = source_terms_convergence_test) tspan = (0.0, 2.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/euler_source_terms_nonperiodic.jl b/test/tree_dgsem_2d/euler_source_terms_nonperiodic.jl index 3c98a0b..e8ed461 100644 --- a/test/tree_dgsem_2d/euler_source_terms_nonperiodic.jl +++ b/test/tree_dgsem_2d/euler_source_terms_nonperiodic.jl @@ -1,5 +1,8 @@ module TestEulerSourceTermsNonperiodic2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Source Terms Nonperiodic 2D" begin @@ -30,137 +33,102 @@ include("../test_macros.jl") boundary_conditions = boundary_conditions) tspan = (0.0, 2.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/euler_vortex_mortar.jl b/test/tree_dgsem_2d/euler_vortex_mortar.jl deleted file mode 100644 index 054a190..0000000 --- a/test/tree_dgsem_2d/euler_vortex_mortar.jl +++ /dev/null @@ -1,185 +0,0 @@ -module TestEulerVortexMortar2D - -include("../test_macros.jl") - -@testset "Euler Vortex Mortar 2D" begin - equations = CompressibleEulerEquations2D(1.4) - - function initial_condition_isentropic_vortex(x, t, equations::CompressibleEulerEquations2D) - inicenter = SVector(0.0, 0.0) - # size and strength of the vortex - iniamplitude = 5.0 - # base flow - rho = 1.0 - v1 = 1.0 - v2 = 1.0 - vel = SVector(v1, v2) - p = 25.0 - rt = p / rho # ideal gas equation - t_loc = 0.0 - cent = inicenter + vel * t_loc # advection of center - - cent = x - cent # distance to center point - - cent = SVector(-cent[2], cent[1]) - r2 = cent[1]^2 + cent[2]^2 - du = iniamplitude / (2 * π) * exp(0.5 * (1 - r2)) # vel. perturbation - dtemp = -(equations.gamma - 1) / (2 * equations.gamma * rt) * du^2 # isentropic - rho = rho * (1 + dtemp)^(1 / (equations.gamma - 1)) - vel = vel + du * cent - v1, v2 = vel - p = p * (1 + dtemp)^(equations.gamma / (equations.gamma - 1)) - prim = SVector(rho, v1, v2, p) - return prim2cons(prim, equations) - end - - initial_condition = initial_condition_isentropic_vortex - solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs) - - coordinates_min = (-10.0, -10.0) - coordinates_max = (10.0, 10.0) - refinement_patches = ((type = "box", coordinates_min = (0.0, -10.0), - coordinates_max = (10.0, 10.0)),) - mesh = TreeMesh(coordinates_min, coordinates_max, - initial_refinement_level = 4, - refinement_patches = refinement_patches, - n_cells_max = 10_000) - - semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver) - semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) - - tspan = (0.0, 1.0) - - ode = semidiscretize(semi, tspan) - u_ode = copy(ode.u0) - du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi - u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) - du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end -end - -end # module diff --git a/test/tree_dgsem_2d/eulermulti_ec.jl b/test/tree_dgsem_2d/eulermulti_ec.jl index e433524..2f1ba07 100644 --- a/test/tree_dgsem_2d/eulermulti_ec.jl +++ b/test/tree_dgsem_2d/eulermulti_ec.jl @@ -1,5 +1,8 @@ module TestEulerMultiEC2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Multi EC 2D" begin @@ -22,137 +25,102 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 0.4) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/eulermulti_es.jl b/test/tree_dgsem_2d/eulermulti_es.jl index 67fc71b..87c3de0 100644 --- a/test/tree_dgsem_2d/eulermulti_es.jl +++ b/test/tree_dgsem_2d/eulermulti_es.jl @@ -1,11 +1,19 @@ module TestEulerMultiES2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Multi ES 2D" begin - equations = CompressibleEulerMulticomponentEquations2D(gammas = (1.4, 1.4, 1.4, 1.4), - gas_constants = (0.4, 0.4, 0.4, 0.4)) + # More than three components are not supported, this is a bug + # equations = CompressibleEulerMulticomponentEquations2D(gammas = (1.4, 1.4, 1.4, 1.4), + # gas_constants = (0.4, 0.4, 0.4, 0.4)) + + equations = CompressibleEulerMulticomponentEquations2D(gammas = (1.4, 1.4), + gas_constants = (0.4, 0.4)) + # This cannot handle multicomponent equations and will cause kernel compilation errors initial_condition = initial_condition_weak_blast_wave volume_flux = flux_ranocha @@ -22,137 +30,102 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 0.4) + t = t_gpu = 0.0 + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/hypdiff_nonperiodic.jl b/test/tree_dgsem_2d/hypdiff_nonperiodic.jl index 9545794..6377deb 100644 --- a/test/tree_dgsem_2d/hypdiff_nonperiodic.jl +++ b/test/tree_dgsem_2d/hypdiff_nonperiodic.jl @@ -1,5 +1,8 @@ module TestHypdiffNonperiodic2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Hypdiff Nonperiodic 2D" begin @@ -29,137 +32,102 @@ include("../test_macros.jl") source_terms = source_terms_poisson_nonperiodic) tspan = (0.0, 5.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/mhd_alfven_wave.jl b/test/tree_dgsem_2d/mhd_alfven_wave.jl index e18fcff..c3bd46a 100644 --- a/test/tree_dgsem_2d/mhd_alfven_wave.jl +++ b/test/tree_dgsem_2d/mhd_alfven_wave.jl @@ -1,5 +1,8 @@ module TestMHDAlfvenWave2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "MHD Alfven Wave 2D" begin @@ -23,137 +26,102 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 2.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/mhd_alfven_wave_mortar.jl b/test/tree_dgsem_2d/mhd_alfven_wave_mortar.jl index e4c81ee..7a947c6 100644 --- a/test/tree_dgsem_2d/mhd_alfven_wave_mortar.jl +++ b/test/tree_dgsem_2d/mhd_alfven_wave_mortar.jl @@ -1,5 +1,8 @@ module TestMHDAlfvenWaveMortar2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "MHD Alfven Wave Mortar 2D" begin @@ -27,137 +30,102 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 2.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/mhd_shock.jl b/test/tree_dgsem_2d/mhd_shock.jl index 6d3103a..daf4261 100644 --- a/test/tree_dgsem_2d/mhd_shock.jl +++ b/test/tree_dgsem_2d/mhd_shock.jl @@ -1,5 +1,8 @@ module TestMHDShock2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "MHD Shock 2D" begin @@ -33,137 +36,102 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/shallowwater_ec.jl b/test/tree_dgsem_2d/shallowwater_ec.jl index a664a01..f6ff841 100644 --- a/test/tree_dgsem_2d/shallowwater_ec.jl +++ b/test/tree_dgsem_2d/shallowwater_ec.jl @@ -1,5 +1,8 @@ module TestShallowWaterEC2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Shallow Water EC 2D" begin @@ -22,137 +25,102 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 2.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/shallowwater_source_terms.jl b/test/tree_dgsem_2d/shallowwater_source_terms.jl index 81373ac..e05a74f 100644 --- a/test/tree_dgsem_2d/shallowwater_source_terms.jl +++ b/test/tree_dgsem_2d/shallowwater_source_terms.jl @@ -1,5 +1,8 @@ module TestShallowWaterSourceTerms2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Shallow Water Source Terms 2D" begin @@ -25,137 +28,102 @@ include("../test_macros.jl") source_terms = source_terms_convergence_test) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/shawllowwater_source_terms_nonperiodic.jl b/test/tree_dgsem_2d/shawllowwater_source_terms_nonperiodic.jl index 935506b..e8e42f0 100644 --- a/test/tree_dgsem_2d/shawllowwater_source_terms_nonperiodic.jl +++ b/test/tree_dgsem_2d/shawllowwater_source_terms_nonperiodic.jl @@ -1,5 +1,8 @@ module TestShallowWaterSourceTermsNonperiodic2D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Shallow Water Source Terms Nonperiodic 2D" begin @@ -29,137 +32,102 @@ include("../test_macros.jl") source_terms = source_terms_convergence_test) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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 diff --git a/test/tree_dgsem_2d/tree_dgsem_2d.jl b/test/tree_dgsem_2d/tree_dgsem_2d.jl index 7520f58..8eaaa2d 100644 --- a/test/tree_dgsem_2d/tree_dgsem_2d.jl +++ b/test/tree_dgsem_2d/tree_dgsem_2d.jl @@ -1,9 +1,9 @@ include("advection_basic.jl") include("advection_mortar.jl") +include("euler_blob_mortar.jl") include("euler_shock.jl") include("euler_source_terms_nonperiodic.jl") include("euler_source_terms.jl") -include("euler_vortex_mortar.jl") include("eulermulti_ec.jl") include("eulermulti_es.jl") include("hypdiff_nonperiodic.jl") diff --git a/test/tree_dgsem_3d/advection_basic.jl b/test/tree_dgsem_3d/advection_basic.jl index 906ddfa..69a3a73 100644 --- a/test/tree_dgsem_3d/advection_basic.jl +++ b/test/tree_dgsem_3d/advection_basic.jl @@ -1,5 +1,8 @@ module TestAdvectionBasic3D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Advection Basic 3D" begin @@ -21,139 +24,104 @@ include("../test_macros.jl") solver) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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_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_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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) + + 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 diff --git a/test/tree_dgsem_3d/advection_mortar.jl b/test/tree_dgsem_3d/advection_mortar.jl index eee3d0f..c8bacbf 100644 --- a/test/tree_dgsem_3d/advection_mortar.jl +++ b/test/tree_dgsem_3d/advection_mortar.jl @@ -1,5 +1,8 @@ module TestAdvectionMortar3D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Advection Mortar 3D" begin @@ -24,139 +27,104 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 5.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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_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_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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) + + 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 diff --git a/test/tree_dgsem_3d/euler_convergence.jl b/test/tree_dgsem_3d/euler_convergence.jl index 3e648ac..66f0cd7 100644 --- a/test/tree_dgsem_3d/euler_convergence.jl +++ b/test/tree_dgsem_3d/euler_convergence.jl @@ -1,5 +1,8 @@ module TestEulerConvergence3D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Convergence 3D" begin @@ -22,139 +25,104 @@ include("../test_macros.jl") source_terms = source_terms_eoc_test_euler) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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_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_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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) + + 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 diff --git a/test/tree_dgsem_3d/euler_ec.jl b/test/tree_dgsem_3d/euler_ec.jl index d5dbc12..3f5e981 100644 --- a/test/tree_dgsem_3d/euler_ec.jl +++ b/test/tree_dgsem_3d/euler_ec.jl @@ -1,5 +1,8 @@ module TestEulerEC3D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler EC 3D" begin @@ -21,139 +24,104 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 0.4) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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_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_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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) + + 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 diff --git a/test/tree_dgsem_3d/euler_mortar.jl b/test/tree_dgsem_3d/euler_mortar.jl index efec512..95189ea 100644 --- a/test/tree_dgsem_3d/euler_mortar.jl +++ b/test/tree_dgsem_3d/euler_mortar.jl @@ -1,5 +1,8 @@ module TestEulerMortar3D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Mortar 3D" begin @@ -23,139 +26,104 @@ include("../test_macros.jl") source_terms = source_terms_convergence_test) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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_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_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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) + + 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 diff --git a/test/tree_dgsem_3d/euler_shock.jl b/test/tree_dgsem_3d/euler_shock.jl index 42a3efc..8444e47 100644 --- a/test/tree_dgsem_3d/euler_shock.jl +++ b/test/tree_dgsem_3d/euler_shock.jl @@ -1,5 +1,8 @@ module TestEulerShock3D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Shock 3D" begin @@ -32,139 +35,104 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 0.4) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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_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_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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) + + 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 diff --git a/test/tree_dgsem_3d/euler_source_terms.jl b/test/tree_dgsem_3d/euler_source_terms.jl index 6668e3e..817c1e1 100644 --- a/test/tree_dgsem_3d/euler_source_terms.jl +++ b/test/tree_dgsem_3d/euler_source_terms.jl @@ -1,5 +1,8 @@ module TestEulerSourceTerms3D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Euler Source Terms 3D" begin @@ -22,139 +25,104 @@ include("../test_macros.jl") source_terms = source_terms_convergence_test) tspan = (0.0, 5.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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_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_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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) + + 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 diff --git a/test/tree_dgsem_3d/hypdiff_nonperiodic.jl b/test/tree_dgsem_3d/hypdiff_nonperiodic.jl index 381b94c..74b9594 100644 --- a/test/tree_dgsem_3d/hypdiff_nonperiodic.jl +++ b/test/tree_dgsem_3d/hypdiff_nonperiodic.jl @@ -1,5 +1,8 @@ module TestHypdiffNonperiodic3D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "Hypdiff Nonperiodic 3D" begin @@ -30,139 +33,104 @@ include("../test_macros.jl") boundary_conditions = boundary_conditions) tspan = (0.0, 5.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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_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_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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) + + 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 diff --git a/test/tree_dgsem_3d/mhd_alfven_wave.jl b/test/tree_dgsem_3d/mhd_alfven_wave.jl index c245046..97e33a1 100644 --- a/test/tree_dgsem_3d/mhd_alfven_wave.jl +++ b/test/tree_dgsem_3d/mhd_alfven_wave.jl @@ -1,5 +1,8 @@ module TestMHDAlfvenWave3D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "MHD Alfven Wave 3D" begin @@ -22,139 +25,104 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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_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_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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) + + 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 diff --git a/test/tree_dgsem_3d/mhd_alfven_wave_mortar.jl b/test/tree_dgsem_3d/mhd_alfven_wave_mortar.jl index fab88dc..7c2d253 100644 --- a/test/tree_dgsem_3d/mhd_alfven_wave_mortar.jl +++ b/test/tree_dgsem_3d/mhd_alfven_wave_mortar.jl @@ -1,5 +1,8 @@ module TestMHDAlfvenWaveMortar3D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "MHD Alfven Wave Mortar 3D" begin @@ -26,139 +29,104 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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_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_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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) + + 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 diff --git a/test/tree_dgsem_3d/mhd_ec.jl b/test/tree_dgsem_3d/mhd_ec.jl index e4f5186..e1bf1e8 100644 --- a/test/tree_dgsem_3d/mhd_ec.jl +++ b/test/tree_dgsem_3d/mhd_ec.jl @@ -1,5 +1,8 @@ module TestMHDEC3D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "MHD EC 3D" begin @@ -22,139 +25,104 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 0.4) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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_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_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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) + + 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 diff --git a/test/tree_dgsem_3d/mhd_shock.jl b/test/tree_dgsem_3d/mhd_shock.jl index a07ae38..9cc4313 100644 --- a/test/tree_dgsem_3d/mhd_shock.jl +++ b/test/tree_dgsem_3d/mhd_shock.jl @@ -1,5 +1,8 @@ module TestMHDShock3D +using Trixi, TrixiCUDA +using Test + include("../test_macros.jl") @testset "MHD Shock 3D" begin @@ -33,139 +36,104 @@ include("../test_macros.jl") semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver) tspan = (0.0, 1.0) + t = t_gpu = 0.0 + + # Semi on CPU + (; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi + + # Semi on GPU + equations_gpu = semi_gpu.equations + mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache + boundary_conditions_gpu = semi_gpu.boundary_conditions + source_terms_gpu = semi_gpu.source_terms + # ODE on CPU ode = semidiscretize(semi, tspan) u_ode = copy(ode.u0) du_ode = similar(u_ode) - - # Get CPU data - t = 0.0 - (; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache) du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache) - # Get GPU data - t_gpu = 0.0 - equations_gpu = semi_gpu.equations - mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache - initial_condition_gpu = semi_gpu.initial_condition - boundary_conditions_gpu = semi_gpu.boundary_conditions - source_terms_gpu = semi_gpu.source_terms - u_gpu = CuArray(u) - du_gpu = CuArray(du) - - # Begin tests - @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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, 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) - @test_equal (u_gpu, u) - 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_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_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - 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) - @test_equal (u_gpu, u) - end - - @testset "Copy to CPU" begin - du_cpu, u_cpu = TrixiCUDA.copy_to_cpu!(du_gpu, u_gpu) - @test_approx (du_cpu, du) - @test_equal (u_cpu, u) - end - end + # ODE on GPU + ode_gpu = semidiscretizeGPU(semi_gpu, tspan) + u_gpu = copy(ode_gpu.u0) + du_gpu = similar(u_gpu) + + # 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_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) + + 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