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_perk2.jl
2055 views
1
# Convex and ECOS are imported because they are used for finding the optimal time step and optimal
2
# monomial coefficients in the stability polynomial of PERK time integrators.
3
using Convex, ECOS
4
using Trixi
5
6
###############################################################################
7
# semidiscretization of the linear advection equation
8
9
advection_velocity = 1.0
10
equations = LinearScalarAdvectionEquation1D(advection_velocity)
11
12
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
13
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
14
15
coordinates_min = -1.0 # minimum coordinate
16
coordinates_max = 1.0 # maximum coordinate
17
18
# Create a uniformly refined mesh with periodic boundaries
19
mesh = TreeMesh(coordinates_min, coordinates_max,
20
initial_refinement_level = 4,
21
n_cells_max = 30_000) # set maximum capacity of tree data structure
22
23
# A semidiscretization collects data structures and functions for the spatial discretization
24
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test,
25
solver)
26
27
###############################################################################
28
# ODE solvers, callbacks etc.
29
30
# Create ODE problem with time span from 0.0 to 20.0
31
tspan = (0.0, 20.0)
32
ode = semidiscretize(semi, tspan)
33
34
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
35
# and resets the timers
36
summary_callback = SummaryCallback()
37
38
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
39
analysis_interval = 100
40
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
41
42
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
43
stepsize_callback = StepsizeCallback(cfl = 2.5)
44
45
alive_callback = AliveCallback(alive_interval = analysis_interval)
46
47
save_solution = SaveSolutionCallback(dt = 0.1,
48
save_initial_solution = true,
49
save_final_solution = true,
50
solution_variables = cons2prim)
51
52
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
53
callbacks = CallbackSet(summary_callback,
54
alive_callback,
55
save_solution,
56
analysis_callback,
57
stepsize_callback)
58
59
###############################################################################
60
# run the simulation
61
62
# Construct second order paired explicit Runge-Kutta method with 6 stages for given simulation setup.
63
# Pass `tspan` to calculate maximum time step allowed for the bisection algorithm used
64
# in calculating the polynomial coefficients in the ODE algorithm.
65
ode_algorithm = Trixi.PairedExplicitRK2(6, tspan, semi)
66
67
sol = Trixi.solve(ode, ode_algorithm;
68
dt = 1.0, # Manual time step value, will be overwritten by the stepsize_callback when it is specified.
69
ode_default_options()..., callback = callbacks);
70
71