Path: blob/main/examples/tree_1d_dgsem/elixir_advection_finite_volume.jl
5586 views
using OrdinaryDiffEqLowOrderRK1using Trixi23###############################################################################4# semidiscretization of the linear advection equation56advection_velocity = 1.07equations = LinearScalarAdvectionEquation1D(advection_velocity)89# Create DG solver with polynomial degree = 0, i.e., a first order finite volume solver,10# with (local) Lax-Friedrichs/Rusanov flux as surface flux11solver = DGSEM(polydeg = 0, surface_flux = flux_lax_friedrichs)1213coordinates_min = -1.0 # minimum coordinate14coordinates_max = 1.0 # maximum coordinate1516# Create a uniformly refined mesh with periodic boundaries17mesh = TreeMesh(coordinates_min, coordinates_max,18initial_refinement_level = 5,19n_cells_max = 30_000, periodicity = true) # set maximum capacity of tree data structure2021# A semidiscretization collects data structures and functions for the spatial discretization22semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,23solver;24boundary_conditions = boundary_condition_periodic)2526###############################################################################27# ODE solvers, callbacks etc.2829# Create ODE problem with time span from 0.0 to 1.030ode = semidiscretize(semi, (0.0, 1.0))3132# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup33# and resets the timers34summary_callback = SummaryCallback()3536# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results37analysis_callback = AnalysisCallback(semi, interval = 100)3839# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step40stepsize_callback = StepsizeCallback(cfl = 0.9)4142# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver43callbacks = CallbackSet(summary_callback, analysis_callback, stepsize_callback)4445###############################################################################46# run the simulation4748# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks49sol = solve(ode, Euler();50dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback51ode_default_options()..., callback = callbacks);525354