Path: blob/main/examples/tree_1d_dgsem/elixir_advection_finite_volume.jl
2055 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) # 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)2425###############################################################################26# ODE solvers, callbacks etc.2728# Create ODE problem with time span from 0.0 to 1.029ode = semidiscretize(semi, (0.0, 1.0))3031# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup32# and resets the timers33summary_callback = SummaryCallback()3435# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results36analysis_callback = AnalysisCallback(semi, interval = 100)3738# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step39stepsize_callback = StepsizeCallback(cfl = 0.9)4041# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver42callbacks = CallbackSet(summary_callback, analysis_callback, stepsize_callback)4344###############################################################################45# run the simulation4647# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks48sol = solve(ode, Euler();49dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback50ode_default_options()..., callback = callbacks);515253