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_burgers_rarefaction.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the (inviscid) Burgers' equation
6
7
equations = InviscidBurgersEquation1D()
8
9
basis = LobattoLegendreBasis(3)
10
# Use shock capturing techniques to suppress oscillations at discontinuities
11
indicator_sc = IndicatorHennemannGassner(equations, basis,
12
alpha_max = 1.0,
13
alpha_min = 0.001,
14
alpha_smooth = true,
15
variable = first)
16
17
volume_flux = flux_ec
18
surface_flux = flux_lax_friedrichs
19
20
volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;
21
volume_flux_dg = volume_flux,
22
volume_flux_fv = surface_flux)
23
24
solver = DGSEM(basis, surface_flux, volume_integral)
25
26
coordinate_min = 0.0
27
coordinate_max = 1.0
28
29
# Make sure to turn periodicity explicitly off as special boundary conditions are specified
30
mesh = TreeMesh(coordinate_min, coordinate_max,
31
initial_refinement_level = 6,
32
n_cells_max = 10_000,
33
periodicity = false)
34
35
# Discontinuous initial condition (Riemann Problem) leading to a rarefaction fan.
36
function initial_condition_rarefaction(x, t, equation::InviscidBurgersEquation1D)
37
RealT = eltype(x)
38
scalar = x[1] < 0.5f0 ? convert(RealT, 0.5f0) : convert(RealT, 1.5f0)
39
40
return SVector(scalar)
41
end
42
43
###############################################################################
44
# Specify non-periodic boundary conditions
45
46
boundary_condition_inflow = BoundaryConditionDirichlet(initial_condition_rarefaction)
47
48
function boundary_condition_outflow(u_inner, orientation, direction, x, t,
49
surface_flux_function,
50
equations::InviscidBurgersEquation1D)
51
# Calculate the boundary flux entirely from the internal solution state
52
return flux(u_inner, orientation, equations)
53
end
54
55
boundary_conditions = (x_neg = boundary_condition_inflow,
56
x_pos = boundary_condition_outflow)
57
58
initial_condition = initial_condition_rarefaction
59
60
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
61
boundary_conditions = boundary_conditions)
62
63
###############################################################################
64
# ODE solvers, callbacks etc.
65
66
tspan = (0.0, 0.2)
67
ode = semidiscretize(semi, tspan)
68
69
summary_callback = SummaryCallback()
70
71
analysis_interval = 100
72
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
73
74
alive_callback = AliveCallback(analysis_interval = analysis_interval)
75
76
stepsize_callback = StepsizeCallback(cfl = 0.9)
77
78
callbacks = CallbackSet(summary_callback,
79
analysis_callback, alive_callback,
80
stepsize_callback)
81
82
###############################################################################
83
# run the simulation
84
85
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
86
dt = 42, # solve needs some value here but it will be overwritten by the stepsize_callback
87
ode_default_options()..., callback = callbacks);
88
89