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_advection_shockcapturing.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the linear advection equation
6
7
advection_velocity = 1.0
8
9
"""
10
initial_condition_composite(x, t, equations::LinearScalarAdvectionEquation1D)
11
12
Wave form that is a combination of a Gaussian pulse, a square wave, a triangle wave,
13
and half an ellipse with periodic boundary conditions.
14
Slight simplification from
15
- Jiang, Shu (1996)
16
Efficient Implementation of Weighted ENO Schemes
17
[DOI: 10.1006/jcph.1996.0130](https://doi.org/10.1006/jcph.1996.0130)
18
"""
19
function initial_condition_composite(x, t, equations::LinearScalarAdvectionEquation1D)
20
xmin, xmax = -1.0, 1.0 # Only works if the domain is [-1.0,1.0]
21
x_trans = x[1] - t
22
L = xmax - xmin
23
if x_trans > xmax
24
x_ = x_trans - L * floor((x_trans + xmin) / L)
25
elseif x_trans < xmin
26
x_ = x_trans + L * floor((xmax - x_trans) / L)
27
else
28
x_ = x_trans
29
end
30
31
if x_ > -0.8 && x_ < -0.6
32
value = exp(-log(2.0) * (x_ + 0.7)^2 / 0.0009)
33
elseif x_ > -0.4 && x_ < -0.2
34
value = 1.0
35
elseif x_ > 0.0 && x_ < 0.2
36
value = 1.0 - abs(10.0 * (x_ - 0.1))
37
elseif x_ > 0.4 && x_ < 0.6
38
value = sqrt(1.0 - 100.0 * (x_ - 0.5)^2)
39
else
40
value = 0.0
41
end
42
43
return SVector(value)
44
end
45
46
initial_condition = initial_condition_composite
47
48
equations = LinearScalarAdvectionEquation1D(advection_velocity)
49
50
surface_flux = flux_lax_friedrichs
51
volume_flux = flux_central
52
polydeg = 3
53
basis = LobattoLegendreBasis(polydeg)
54
indicator_sc = IndicatorHennemannGassner(equations, basis,
55
alpha_max = 0.5,
56
alpha_min = 0.001,
57
alpha_smooth = true,
58
variable = Trixi.first)
59
volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;
60
volume_flux_dg = volume_flux,
61
volume_flux_fv = surface_flux)
62
solver = DGSEM(basis, surface_flux, volume_integral)
63
64
# Create curved mesh
65
cells_per_dimension = (120,)
66
coordinates_min = (-1.0,) # minimum coordinate
67
coordinates_max = (1.0,) # maximum coordinate
68
mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max,
69
periodicity = true)
70
71
# A semidiscretization collects data structures and functions for the spatial discretization
72
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
73
74
###############################################################################
75
# ODE solvers, callbacks etc.
76
77
# Create ODE problem with a given time span
78
tspan = (0.0, 4.0)
79
ode = semidiscretize(semi, tspan)
80
81
# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
82
# and resets the timers
83
summary_callback = SummaryCallback()
84
85
# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
86
analysis_callback = AnalysisCallback(semi, interval = 100)
87
88
# The SaveSolutionCallback allows to save the solution to a file in regular intervals
89
save_solution = SaveSolutionCallback(interval = 100, solution_variables = cons2prim)
90
91
# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
92
stepsize_callback = StepsizeCallback(cfl = 0.5)
93
94
# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
95
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
96
stepsize_callback)
97
98
###############################################################################
99
# run the simulation
100
101
# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
102
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
103
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
104
ode_default_options()..., callback = callbacks);
105
106