Path: blob/main/examples/tree_1d_dgsem/elixir_advection_extended.jl
5586 views
using OrdinaryDiffEqLowStorageRK1using Trixi2using Plots # For visualization callback34###############################################################################5# semidiscretization of the linear advection equation67advection_velocity = 1.08equations = LinearScalarAdvectionEquation1D(advection_velocity)910initial_condition = initial_condition_convergence_test1112# you can either use a single function to impose the BCs weakly in all13# 1*ndims == 2 directions or you can pass a tuple containing BCs for14# each direction15boundary_conditions = boundary_condition_periodic1617# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux18solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)1920coordinates_min = -1.0 # minimum coordinate21coordinates_max = 1.0 # maximum coordinate2223# Create a uniformly refined mesh with periodic boundaries24mesh = TreeMesh(coordinates_min, coordinates_max,25initial_refinement_level = 4,26n_cells_max = 30_000, # set maximum capacity of tree data structure27periodicity = true)2829# A semidiscretization collects data structures and functions for the spatial discretization30semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;31boundary_conditions = boundary_conditions)3233###############################################################################34# ODE solvers, callbacks etc.3536# Create ODE problem with time span from 0.0 to 1.037tspan = (0.0, 1.0)38ode = semidiscretize(semi, tspan)3940# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup41# and resets the timers42summary_callback = SummaryCallback()4344# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results45analysis_interval = 10046analysis_callback = AnalysisCallback(semi, interval = analysis_interval,47extra_analysis_integrals = (entropy, energy_total))4849# The AliveCallback prints short status information in regular intervals50alive_callback = AliveCallback(analysis_interval = analysis_interval)5152# The SaveRestartCallback allows to save a file from which a Trixi.jl simulation can be restarted53save_restart = SaveRestartCallback(interval = 100,54save_final_restart = true)5556# The SaveSolutionCallback allows to save the solution to a file in regular intervals57save_solution = SaveSolutionCallback(interval = 100,58save_initial_solution = true,59save_final_solution = true,60solution_variables = cons2prim)6162# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step63stepsize_callback = StepsizeCallback(cfl = 1.6)6465# Enable in-situ visualization with a new plot generated at every time step66visualization = VisualizationCallback(semi; interval = 1)6768# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver69callbacks = CallbackSet(summary_callback,70analysis_callback, alive_callback,71save_restart,72save_solution, visualization,73stepsize_callback)7475###############################################################################76# run the simulation7778# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks79sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);80dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback81ode_default_options()..., callback = callbacks);828384