Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_2d_dgsem/elixir_advection_basic.jl
2802 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the linear advection equation
6
7
advection_velocity = (0.2, -0.7)
8
equations = LinearScalarAdvectionEquation2D(advection_velocity)
9
10
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
11
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
12
13
coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))
14
coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))
15
16
# Create a uniformly refined mesh with periodic boundaries
17
mesh = TreeMesh(coordinates_min, coordinates_max,
18
initial_refinement_level = 4,
19
n_cells_max = 30_000, periodicity = true) # set maximum capacity of tree data structure
20
21
# A semidiscretization collects data structures and functions for the spatial discretization
22
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
23
solver;
24
boundary_conditions = boundary_condition_periodic)
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 SaveSolutionCallback allows to save the solution to a file in regular intervals
40
save_solution = SaveSolutionCallback(interval = 100,
41
solution_variables = cons2prim)
42
43
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
44
stepsize_callback = StepsizeCallback(cfl = 1.6)
45
46
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
47
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
48
stepsize_callback)
49
50
###############################################################################
51
# run the simulation
52
53
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
54
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
55
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
56
ode_default_options()..., callback = callbacks);
57
58