Path: blob/main/examples/tree_2d_dgsem/elixir_advection_basic.jl
2055 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) # 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)2324###############################################################################25# ODE solvers, callbacks etc.2627# Create ODE problem with time span from 0.0 to 1.028ode = semidiscretize(semi, (0.0, 1.0))2930# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup31# and resets the timers32summary_callback = SummaryCallback()3334# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results35analysis_callback = AnalysisCallback(semi, interval = 100)3637# The SaveSolutionCallback allows to save the solution to a file in regular intervals38save_solution = SaveSolutionCallback(interval = 100,39solution_variables = cons2prim)4041# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step42stepsize_callback = StepsizeCallback(cfl = 1.6)4344# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver45callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,46stepsize_callback)4748###############################################################################49# run the simulation5051# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks52sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);53dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback54ode_default_options()..., callback = callbacks);555657