Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_1d_dgsem/elixir_advection_finite_volume.jl
2055 views
1
using OrdinaryDiffEqLowOrderRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the linear advection equation
6
7
advection_velocity = 1.0
8
equations = LinearScalarAdvectionEquation1D(advection_velocity)
9
10
# Create DG solver with polynomial degree = 0, i.e., a first order finite volume solver,
11
# with (local) Lax-Friedrichs/Rusanov flux as surface flux
12
solver = DGSEM(polydeg = 0, surface_flux = flux_lax_friedrichs)
13
14
coordinates_min = -1.0 # minimum coordinate
15
coordinates_max = 1.0 # maximum coordinate
16
17
# Create a uniformly refined mesh with periodic boundaries
18
mesh = TreeMesh(coordinates_min, coordinates_max,
19
initial_refinement_level = 5,
20
n_cells_max = 30_000) # set maximum capacity of tree data structure
21
22
# A semidiscretization collects data structures and functions for the spatial discretization
23
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
24
solver)
25
26
###############################################################################
27
# ODE solvers, callbacks etc.
28
29
# Create ODE problem with time span from 0.0 to 1.0
30
ode = semidiscretize(semi, (0.0, 1.0))
31
32
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
33
# and resets the timers
34
summary_callback = SummaryCallback()
35
36
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
37
analysis_callback = AnalysisCallback(semi, interval = 100)
38
39
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
40
stepsize_callback = StepsizeCallback(cfl = 0.9)
41
42
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
43
callbacks = CallbackSet(summary_callback, analysis_callback, stepsize_callback)
44
45
###############################################################################
46
# run the simulation
47
48
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
49
sol = solve(ode, Euler();
50
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
51
ode_default_options()..., callback = callbacks);
52
53