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
2055 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) # 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
25
###############################################################################
26
# ODE solvers, callbacks etc.
27
28
# Create ODE problem with time span from 0.0 to 1.0
29
ode = semidiscretize(semi, (0.0, 1.0))
30
31
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
32
# and resets the timers
33
summary_callback = SummaryCallback()
34
35
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
36
analysis_callback = AnalysisCallback(semi, interval = 100)
37
38
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
39
save_solution = SaveSolutionCallback(interval = 100,
40
solution_variables = cons2prim)
41
42
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
43
stepsize_callback = StepsizeCallback(cfl = 1.6)
44
45
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
46
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
47
stepsize_callback)
48
49
###############################################################################
50
# run the simulation
51
52
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
53
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
54
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
55
ode_default_options()..., callback = callbacks);
56
57