Skip to content

Commit

Permalink
Start
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyuxie committed Sep 23, 2024
1 parent d8deac8 commit bc952d7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 119 deletions.
1 change: 1 addition & 0 deletions src/TrixiCUDA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using StaticArrays: SVector

# Include other source files
include("auxiliary/auxiliary.jl")
include("semidiscretization/semidiscretization.jl")
include("solvers/solvers.jl")

set_log_type!("log_Base")
Expand Down
1 change: 1 addition & 0 deletions src/semidiscretization/semidiscretization.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include("semidiscretization_hyperbolic.jl")
25 changes: 25 additions & 0 deletions src/semidiscretization/semidiscretization_hyperbolic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function SemidiscretizationHyperbolic_gpu(mesh, equations, initial_condition, solver;
source_terms = nothing,
boundary_conditions = boundary_condition_periodic,
# `RealT` is used as real type for node locations etc.
# while `uEltype` is used as element type of solutions etc.
RealT = real(solver), uEltype = RealT,
initial_cache = NamedTuple())
@assert ndims(mesh) == ndims(equations)

# cache = (; create_cache(mesh, equations, solver, RealT, uEltype)...,
# initial_cache...)
# _boundary_conditions = digest_boundary_conditions(boundary_conditions, mesh, solver,
# cache)

# check_periodicity_mesh_boundary_conditions(mesh, _boundary_conditions)

# SemidiscretizationHyperbolic{typeof(mesh), typeof(equations),
# typeof(initial_condition),
# typeof(_boundary_conditions), typeof(source_terms),
# typeof(solver), typeof(cache)}(mesh, equations,
# initial_condition,
# _boundary_conditions,
# source_terms, solver,
# cache)
end
1 change: 1 addition & 0 deletions src/solvers/cache.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions src/solvers/solvers.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include("cache.jl")
include("common.jl")
include("dg_1d.jl")
include("dg_2d.jl")
Expand Down
128 changes: 9 additions & 119 deletions test/test_script.jl
Original file line number Diff line number Diff line change
@@ -1,125 +1,15 @@
include("test_trixicuda.jl")

equations = IdealGlmMhdEquations1D(1.4)
advection_velocity = 1.0
equations = LinearScalarAdvectionEquation1D(advection_velocity)

initial_condition = initial_condition_weak_blast_wave
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

surface_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)
volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)
polydeg = 4
basis = LobattoLegendreBasis(polydeg)
indicator_sc = IndicatorHennemannGassner(equations, basis,
alpha_max = 0.5,
alpha_min = 0.001,
alpha_smooth = true,
variable = density_pressure)
volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;
volume_flux_dg = volume_flux,
volume_flux_fv = surface_flux)
coordinates_min = -1.0
coordinates_max = 1.0

solver = DGSEM(polydeg = polydeg, surface_flux = surface_flux,
volume_integral = volume_integral)
mesh = TreeMesh(coordinates_min, coordinates_max, initial_refinement_level = 4,
n_cells_max = 30_000)

coordinates_min = -2.0
coordinates_max = 2.0
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 3,
n_cells_max = 10_000)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)

tspan = (0.0, 1.0)

# Get CPU data
(; mesh, equations, initial_condition, boundary_conditions, source_terms, solver, cache) = semi

# Get GPU data
equations_gpu = deepcopy(equations)
mesh_gpu, solver_gpu, cache_gpu = deepcopy(mesh), deepcopy(solver), deepcopy(cache)
boundary_conditions_gpu, source_terms_gpu = deepcopy(boundary_conditions),
deepcopy(source_terms)

# Set initial time
t = t_gpu = 0.0

# Get initial data
ode = semidiscretize(semi, tspan)
u_ode = copy(ode.u0)
du_ode = similar(u_ode)
u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache)
du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache)

# Copy data to device
du_gpu, u_gpu = TrixiCUDA.copy_to_device!(du, u)
# Reset data on host
Trixi.reset_du!(du, solver, cache)

# Test `cuda_volume_integral!`
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 `cuda_prolong2interfaces!`
# 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 `cuda_interface_flux!`
# 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 `cuda_prolong2boundaries!`
# 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 `cuda_boundary_flux!`
# 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 `cuda_prolong2mortars!`
# 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 `cuda_mortar_flux!`
# 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 `cuda_surface_integral!`
# 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 `cuda_jacobian!`
# 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 `cuda_sources!`
# 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
semi = TrixiCUDA.SemidiscretizationHyperbolic_gpu(mesh, equations,
initial_condition_convergence_test, solver)

0 comments on commit bc952d7

Please sign in to comment.