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
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
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
periodicity = true)
27
28
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
29
source_terms = source_terms_convergence_test,
30
boundary_conditions = boundary_condition_periodic)
31
32
###############################################################################
33
# ODE solvers, callbacks etc.
34
35
tspan = (0.0, 2.0)
36
ode = semidiscretize(semi, tspan)
37
38
summary_callback = SummaryCallback()
39
40
analysis_interval = 200
41
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
42
43
alive_callback = AliveCallback(analysis_interval = analysis_interval)
44
45
save_solution = SaveSolutionCallback(dt = 0.1,
46
save_initial_solution = true,
47
save_final_solution = true,
48
solution_variables = cons2prim)
49
50
# Construct third order paired explicit Runge-Kutta method with 8 stages for given simulation setup.
51
# Pass `tspan` to calculate maximum time step allowed for the bisection algorithm used
52
# in calculating the polynomial coefficients in the ODE algorithm.
53
ode_algorithm = Trixi.PairedExplicitRK3(8, tspan, semi)
54
55
cfl_number = Trixi.calculate_cfl(ode_algorithm, ode)
56
# For non-linear problems, the CFL number should be reduced by a safety factor
57
# as the spectrum changes (in general) over the course of a simulation
58
stepsize_callback = StepsizeCallback(cfl = 0.85 * cfl_number)
59
60
callbacks = CallbackSet(summary_callback,
61
analysis_callback, alive_callback, save_solution,
62
stepsize_callback)
63
64
###############################################################################
65
# run the simulation
66
sol = Trixi.solve(ode, ode_algorithm;
67
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
68
ode_default_options()..., callback = callbacks);
69
70