Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/p4est_2d_dgsem/elixir_advection_basic_gpu.jl
2794 views
1
# The same setup as tree_2d_dgsem/elixir_advection_basic.jl
2
# to verify GPU support and Adapt.jl support.
3
4
using 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
periodicity = true)
26
27
# A semidiscretization collects data structures and functions for the spatial discretization
28
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
29
solver;
30
boundary_conditions = boundary_condition_periodic)
31
32
###############################################################################
33
# ODE solvers, callbacks etc.
34
35
# Create ODE problem with time span from 0.0 to 1.0
36
ode = semidiscretize(semi, (0.0, 1.0); real_type = nothing, storage_type = nothing)
37
38
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
39
# and resets the timers
40
summary_callback = SummaryCallback()
41
42
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
43
analysis_callback = AnalysisCallback(semi, interval = 100)
44
45
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
46
save_solution = SaveSolutionCallback(interval = 100,
47
solution_variables = cons2prim)
48
49
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
50
stepsize_callback = StepsizeCallback(cfl = 1.6)
51
52
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
53
callbacks = CallbackSet(summary_callback, stepsize_callback)
54
# TODO: GPU. The `analysis_callback` needs to be updated for GPU support
55
# analysis_callback, save_solution, stepsize_callback)
56
57
###############################################################################
58
# run the simulation
59
60
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
61
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
62
dt = 1e-2, # solve needs some value here but it will be overwritten by the stepsize_callback
63
ode_default_options()..., callback = callbacks);
64
65