Path: blob/main/examples/structured_2d_dgsem/elixir_advection_float32.jl
2055 views
# Similar to structured_2d_dgsem/elixir_advection_basic.jl1# but using Float32 instead of the default Float6423using OrdinaryDiffEqLowStorageRK4using Trixi56###############################################################################7# semidiscretization of the linear advection equation89advection_velocity = (0.2f0, -0.7f0)10equations = LinearScalarAdvectionEquation2D(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, RealT = Float32)1415coordinates_min = (-1.0f0, -1.0f0) # minimum coordinates (min(x), min(y))16coordinates_max = (1.0f0, 1.0f0) # maximum coordinates (max(x), max(y))1718cells_per_dimension = (16, 16)1920# Create curved mesh with 16 x 16 elements21mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)2223# A semidiscretization collects data structures and functions for the spatial discretization24semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,25solver)2627###############################################################################28# ODE solvers, callbacks etc.2930# Create ODE problem with time span from 0.0 to 1.031ode = semidiscretize(semi, (0.0f0, 1.0f0))3233# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup34# and resets the timers35summary_callback = SummaryCallback()3637# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results38analysis_callback = AnalysisCallback(semi, interval = 100)3940# The SaveSolutionCallback allows to save the solution to a file in regular intervals41save_solution = SaveSolutionCallback(interval = 100,42solution_variables = cons2prim)4344# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step45stepsize_callback = StepsizeCallback(cfl = 1.6f0)4647# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver48callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,49stepsize_callback)5051###############################################################################52# run the simulation5354# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks55sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);56dt = 1.0f0, # solve needs some value here but it will be overwritten by the stepsize_callback57ode_default_options()..., callback = callbacks);585960