Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/structured_2d_dgsem/elixir_advection_float32.jl
2055 views
1
# Similar to structured_2d_dgsem/elixir_advection_basic.jl
2
# but using Float32 instead of the default Float64
3
4
using OrdinaryDiffEqLowStorageRK
5
using Trixi
6
7
###############################################################################
8
# semidiscretization of the linear advection equation
9
10
advection_velocity = (0.2f0, -0.7f0)
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, RealT = Float32)
15
16
coordinates_min = (-1.0f0, -1.0f0) # minimum coordinates (min(x), min(y))
17
coordinates_max = (1.0f0, 1.0f0) # maximum coordinates (max(x), max(y))
18
19
cells_per_dimension = (16, 16)
20
21
# Create curved mesh with 16 x 16 elements
22
mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)
23
24
# A semidiscretization collects data structures and functions for the spatial discretization
25
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
26
solver)
27
28
###############################################################################
29
# ODE solvers, callbacks etc.
30
31
# Create ODE problem with time span from 0.0 to 1.0
32
ode = semidiscretize(semi, (0.0f0, 1.0f0))
33
34
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
35
# and resets the timers
36
summary_callback = SummaryCallback()
37
38
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
39
analysis_callback = AnalysisCallback(semi, interval = 100)
40
41
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
42
save_solution = SaveSolutionCallback(interval = 100,
43
solution_variables = cons2prim)
44
45
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
46
stepsize_callback = StepsizeCallback(cfl = 1.6f0)
47
48
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
49
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
50
stepsize_callback)
51
52
###############################################################################
53
# run the simulation
54
55
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
56
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
57
dt = 1.0f0, # solve needs some value here but it will be overwritten by the stepsize_callback
58
ode_default_options()..., callback = callbacks);
59
60