Path: blob/main/examples/tree_1d_dgsem/elixir_advection_perk2.jl
2055 views
# Convex and ECOS are imported because they are used for finding the optimal time step and optimal1# monomial coefficients in the stability polynomial of PERK time integrators.2using Convex, ECOS3using Trixi45###############################################################################6# semidiscretization of the linear advection equation78advection_velocity = 1.09equations = LinearScalarAdvectionEquation1D(advection_velocity)1011# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux12solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)1314coordinates_min = -1.0 # minimum coordinate15coordinates_max = 1.0 # maximum coordinate1617# Create a uniformly refined mesh with periodic boundaries18mesh = TreeMesh(coordinates_min, coordinates_max,19initial_refinement_level = 4,20n_cells_max = 30_000) # set maximum capacity of tree data structure2122# A semidiscretization collects data structures and functions for the spatial discretization23semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,24solver)2526###############################################################################27# ODE solvers, callbacks etc.2829# Create ODE problem with time span from 0.0 to 20.030tspan = (0.0, 20.0)31ode = semidiscretize(semi, tspan)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_interval = 10039analysis_callback = AnalysisCallback(semi, interval = analysis_interval)4041# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step42stepsize_callback = StepsizeCallback(cfl = 2.5)4344alive_callback = AliveCallback(alive_interval = analysis_interval)4546save_solution = SaveSolutionCallback(dt = 0.1,47save_initial_solution = true,48save_final_solution = true,49solution_variables = cons2prim)5051# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver52callbacks = CallbackSet(summary_callback,53alive_callback,54save_solution,55analysis_callback,56stepsize_callback)5758###############################################################################59# run the simulation6061# Construct second order paired explicit Runge-Kutta method with 6 stages for given simulation setup.62# Pass `tspan` to calculate maximum time step allowed for the bisection algorithm used63# in calculating the polynomial coefficients in the ODE algorithm.64ode_algorithm = Trixi.PairedExplicitRK2(6, tspan, semi)6566sol = Trixi.solve(ode, ode_algorithm;67dt = 1.0, # Manual time step value, will be overwritten by the stepsize_callback when it is specified.68ode_default_options()..., callback = callbacks);697071