Path: blob/main/examples/tree_2d_dgsem/elixir_advection_basic.jl
2802 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the linear advection equation56advection_velocity = (0.2, -0.7)7equations = LinearScalarAdvectionEquation2D(advection_velocity)89# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux10solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)1112coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))13coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))1415# Create a uniformly refined mesh with periodic boundaries16mesh = TreeMesh(coordinates_min, coordinates_max,17initial_refinement_level = 4,18n_cells_max = 30_000, periodicity = true) # set maximum capacity of tree data structure1920# A semidiscretization collects data structures and functions for the spatial discretization21semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,22solver;23boundary_conditions = boundary_condition_periodic)2425###############################################################################26# ODE solvers, callbacks etc.2728# Create ODE problem with time span from 0.0 to 1.029ode = semidiscretize(semi, (0.0, 1.0))3031# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup32# and resets the timers33summary_callback = SummaryCallback()3435# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results36analysis_callback = AnalysisCallback(semi, interval = 100)3738# The SaveSolutionCallback allows to save the solution to a file in regular intervals39save_solution = SaveSolutionCallback(interval = 100,40solution_variables = cons2prim)4142# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step43stepsize_callback = StepsizeCallback(cfl = 1.6)4445# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver46callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,47stepsize_callback)4849###############################################################################50# run the simulation5152# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks53sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);54dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback55ode_default_options()..., callback = callbacks);565758