Skip to content

Commit 5702b61

Browse files
committed
add GPU construction test
1 parent 73060dd commit 5702b61

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# The same setup as tree_2d_dgsem/elixir_advection_basic.jl
2+
# to verify the StructuredMesh implementation against TreeMesh
3+
4+
using OrdinaryDiffEqSSPRK, OrdinaryDiffEqLowStorageRK
5+
using Trixi
6+
7+
###############################################################################
8+
# semidiscretization of the linear advection equation
9+
10+
advection_velocity = (0.2, -0.7)
11+
equations = LinearScalarAdvectionEquation2D(advection_velocity)
12+
13+
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
14+
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
15+
16+
coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))
17+
coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))
18+
19+
trees_per_dimension = (8, 8)
20+
21+
# Create P4estMesh with 8 x 8 trees and 16 x 16 elements
22+
mesh = P4estMesh(trees_per_dimension, polydeg = 3,
23+
coordinates_min = coordinates_min, coordinates_max = coordinates_max,
24+
initial_refinement_level = 1)
25+
26+
# A semidiscretization collects data structures and functions for the spatial discretization
27+
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
28+
solver)
29+
30+
###############################################################################
31+
# ODE solvers, callbacks etc.
32+
33+
# Create ODE problem with time span from 0.0 to 1.0
34+
ode = semidiscretize(semi, (0.0, 1.0); real_type = nothing, storage_type = nothing)
35+
36+
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
37+
# and resets the timers
38+
summary_callback = SummaryCallback()
39+
40+
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
41+
analysis_callback = AnalysisCallback(semi, interval = 100)
42+
43+
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
44+
save_solution = SaveSolutionCallback(interval = 100,
45+
solution_variables = cons2prim)
46+
47+
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
48+
stepsize_callback = StepsizeCallback(cfl = 1.6)
49+
50+
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
51+
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
52+
stepsize_callback)
53+
54+
###############################################################################
55+
# run the simulation
56+
57+
# # OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
58+
# sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
59+
# dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
60+
# ode_default_options()..., callback = callbacks);

test/test_cuda.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,29 @@ include("test_trixi.jl")
1212
outdir = "out"
1313
isdir(outdir) && rm(outdir, recursive = true)
1414

15-
# TODO:
15+
EXAMPLES_DIR = joinpath(examples_dir(), "p4est_2d_dgsem")
16+
17+
@trixi_testset "elixir_advection_basic.jl (Float32)" begin
18+
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_basic.jl"),
19+
# Expected errors are exactly the same as with TreeMesh!
20+
l2=[8.311947673061856e-6],
21+
linf=[6.627000273229378e-5],
22+
real_type=Float32,
23+
storage_type=CuArray)
24+
# # Ensure that we do not have excessive memory allocations
25+
# # (e.g., from type instabilities)
26+
# let
27+
# t = sol.t[end]
28+
# u_ode = sol.u[end]
29+
# du_ode = similar(u_ode)
30+
# @test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
31+
# end
32+
@test real(ode.p.solver) == Float32
33+
@test real(ode.p.solver.basis) == Float32
34+
@test real(ode.p.solver.mortar) == Float32
35+
# TODO: remake ignores the mesh itself as well
36+
@test real(ode.p.mesh) == Float64
37+
end
1638

1739
# Clean up afterwards: delete Trixi.jl output directory
1840
@test_nowarn isdir(outdir) && rm(outdir, recursive = true)

0 commit comments

Comments
 (0)