Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/structured_1d_dgsem/elixir_burgers_perk3.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
5
# NLsolve is imported to solve the system of nonlinear equations to find the coefficients
6
# in the Butcher tableau in the third order PERK time integrator.
7
using NLsolve
8
9
using Trixi
10
11
###############################################################################
12
# semidiscretization of the (inviscid) Burgers equation
13
14
equations = InviscidBurgersEquation1D()
15
16
initial_condition = initial_condition_convergence_test
17
18
# Create DG solver with polynomial degree = 4 and (local) Lax-Friedrichs/Rusanov flux as surface flux
19
solver = DGSEM(polydeg = 4, surface_flux = flux_lax_friedrichs)
20
21
coordinates_min = (0.0,) # minimum coordinate
22
coordinates_max = (1.0,) # maximum coordinate
23
cells_per_dimension = (64,)
24
25
mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max)
26
27
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
28
source_terms = source_terms_convergence_test)
29
30
###############################################################################
31
# ODE solvers, callbacks etc.
32
33
tspan = (0.0, 2.0)
34
ode = semidiscretize(semi, tspan)
35
36
summary_callback = SummaryCallback()
37
38
analysis_interval = 200
39
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
40
41
alive_callback = AliveCallback(analysis_interval = analysis_interval)
42
43
save_solution = SaveSolutionCallback(dt = 0.1,
44
save_initial_solution = true,
45
save_final_solution = true,
46
solution_variables = cons2prim)
47
48
# Construct third order paired explicit Runge-Kutta method with 8 stages for given simulation setup.
49
# Pass `tspan` to calculate maximum time step allowed for the bisection algorithm used
50
# in calculating the polynomial coefficients in the ODE algorithm.
51
ode_algorithm = Trixi.PairedExplicitRK3(8, tspan, semi)
52
53
cfl_number = Trixi.calculate_cfl(ode_algorithm, ode)
54
# For non-linear problems, the CFL number should be reduced by a safety factor
55
# as the spectrum changes (in general) over the course of a simulation
56
stepsize_callback = StepsizeCallback(cfl = 0.85 * cfl_number)
57
58
callbacks = CallbackSet(summary_callback,
59
analysis_callback, alive_callback, save_solution,
60
stepsize_callback)
61
62
###############################################################################
63
# run the simulation
64
sol = Trixi.solve(ode, ode_algorithm;
65
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
66
ode_default_options()..., callback = callbacks);
67
68