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
5586 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, periodicity = true) # 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
boundary_conditions = boundary_condition_periodic)
27
28
###############################################################################
29
# ODE solvers, callbacks etc.
30
31
# Create ODE problem with time span from 0.0 to 20.0
32
tspan = (0.0, 20.0)
33
ode = semidiscretize(semi, tspan)
34
35
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
36
# and resets the timers
37
summary_callback = SummaryCallback()
38
39
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
40
analysis_interval = 100
41
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
42
43
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
44
stepsize_callback = StepsizeCallback(cfl = 2.5)
45
46
alive_callback = AliveCallback(alive_interval = analysis_interval)
47
48
save_solution = SaveSolutionCallback(dt = 0.1,
49
save_initial_solution = true,
50
save_final_solution = true,
51
solution_variables = cons2prim)
52
53
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
54
callbacks = CallbackSet(summary_callback,
55
alive_callback,
56
save_solution,
57
analysis_callback,
58
stepsize_callback)
59
60
###############################################################################
61
# run the simulation
62
63
# Construct second order paired explicit Runge-Kutta method with 6 stages for given simulation setup.
64
# Pass `tspan` to calculate maximum time step allowed for the bisection algorithm used
65
# in calculating the polynomial coefficients in the ODE algorithm.
66
ode_algorithm = Trixi.PairedExplicitRK2(6, tspan, semi)
67
68
sol = Trixi.solve(ode, ode_algorithm;
69
dt = 1.0, # Manual time step value, will be overwritten by the stepsize_callback when it is specified.
70
ode_default_options()..., callback = callbacks);
71
72