Path: blob/main/examples/tree_2d_dgsem/elixir_advection_extended.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi23###############################################################################4# semidiscretization of the linear advection equation56advection_velocity = (0.2, -0.7)7equations = LinearScalarAdvectionEquation2D(advection_velocity)89initial_condition = initial_condition_convergence_test1011# you can either use a single function to impose the BCs weakly in all12# 1*ndims == 2 directions or you can pass a tuple containing BCs for13# each direction14boundary_conditions = boundary_condition_periodic1516# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux17solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)1819coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))20coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))2122# Create a uniformly refined mesh with periodic boundaries23mesh = TreeMesh(coordinates_min, coordinates_max,24initial_refinement_level = 4,25n_cells_max = 30_000, # set maximum capacity of tree data structure26periodicity = true)2728# A semidiscretization collects data structures and functions for the spatial discretization29semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;30boundary_conditions = boundary_conditions)3132###############################################################################33# ODE solvers, callbacks etc.3435# Create ODE problem with time span from 0.0 to 1.036tspan = (0.0, 1.0)37ode = semidiscretize(semi, tspan)3839# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup40# and resets the timers41summary_callback = SummaryCallback()4243# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results44analysis_interval = 10045analysis_callback = AnalysisCallback(semi, interval = analysis_interval,46extra_analysis_integrals = (entropy, energy_total))4748# The AliveCallback prints short status information in regular intervals49alive_callback = AliveCallback(analysis_interval = analysis_interval)5051# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted52save_restart = SaveRestartCallback(interval = 40,53save_final_restart = true)5455# The SaveSolutionCallback allows to save the solution to a file in regular intervals56save_solution = SaveSolutionCallback(interval = 100,57save_initial_solution = true,58save_final_solution = true,59solution_variables = cons2prim)6061# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step62stepsize_callback = StepsizeCallback(cfl = 1.6)6364# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver65callbacks = CallbackSet(summary_callback,66analysis_callback, alive_callback,67save_restart, save_solution,68stepsize_callback)6970###############################################################################71# run the simulation7273# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks74alg = CarpenterKennedy2N54(williamson_condition = false)75sol = solve(ode, alg;76dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback77callback = callbacks,78ode_default_options()...);798081