Path: blob/main/examples/p4est_3d_dgsem/elixir_advection_basic_gpu.jl
5586 views
# The same setup as tree_3d_dgsem/elixir_advection_basic.jl1# to verify GPU support and Adapt.jl support.23using OrdinaryDiffEqLowStorageRK4using Trixi56###############################################################################7# semidiscretization of the linear advection equation89advection_velocity = (0.2, -0.7, 0.5)10equations = LinearScalarAdvectionEquation3D(advection_velocity)1112# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux13solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)1415coordinates_min = (-1.0, -1.0, -1.0) # minimum coordinates (min(x), min(y), min(z))16coordinates_max = (1.0, 1.0, 1.0) # maximum coordinates (max(x), max(y), max(z))1718# Create P4estMesh with 8 x 8 x 8 elements (note `refinement_level=1`)19trees_per_dimension = (4, 4, 4)20mesh = P4estMesh(trees_per_dimension, polydeg = 3,21coordinates_min = coordinates_min, coordinates_max = coordinates_max,22initial_refinement_level = 1,23periodicity = true)2425# A semidiscretization collects data structures and functions for the spatial discretization26semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,27solver;28boundary_conditions = boundary_condition_periodic)2930###############################################################################31# ODE solvers, callbacks etc.3233# Create ODE problem with time span from 0.0 to 1.034# Change `storage_type` to, e.g., `CuArray` to actually run on GPU35tspan = (0.0, 1.0)36ode = semidiscretize(semi, tspan; real_type = nothing, storage_type = nothing)3738# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup39# and resets the timers40summary_callback = SummaryCallback()4142# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results43analysis_callback = AnalysisCallback(semi, interval = 100)4445# The SaveSolutionCallback allows to save the solution to a file in regular intervals46save_solution = SaveSolutionCallback(interval = 100,47solution_variables = cons2prim)4849# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step50stepsize_callback = StepsizeCallback(cfl = 1.2)5152# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver53callbacks = CallbackSet(summary_callback, analysis_callback,54save_solution, stepsize_callback)5556###############################################################################57# run the simulation5859# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks60sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);61dt = 0.05, # solve needs some value here but it will be overwritten by the stepsize_callback62ode_default_options()..., callback = callbacks);636465