Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_3d_dgsem/elixir_euler_density_pulse.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the compressible Euler equations
6
7
equations = CompressibleEulerEquations3D(1.4)
8
9
"""
10
initial_condition_density_pulse(x, t, equations::CompressibleEulerEquations3D)
11
12
A Gaussian pulse in the density with constant velocity and pressure; reduces the
13
compressible Euler equations to the linear advection equations.
14
"""
15
function initial_condition_density_pulse(x, t, equations::CompressibleEulerEquations3D)
16
rho = 1 + exp(-(x[1]^2 + x[2]^2 + x[3]^2)) / 2
17
v1 = 1
18
v2 = 1
19
v3 = 1
20
rho_v1 = rho * v1
21
rho_v2 = rho * v2
22
rho_v3 = rho * v3
23
p = 1
24
rho_e = p / (equations.gamma - 1) + 1 / 2 * rho * (v1^2 + v2^2 + v3^2)
25
return SVector(rho, rho_v1, rho_v2, rho_v3, rho_e)
26
end
27
initial_condition = initial_condition_density_pulse
28
29
volume_flux = flux_ranocha
30
solver = DGSEM(polydeg = 3, surface_flux = flux_ranocha,
31
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
32
33
coordinates_min = (-2.0, -2.0, -2.0)
34
coordinates_max = (2.0, 2.0, 2.0)
35
mesh = TreeMesh(coordinates_min, coordinates_max,
36
initial_refinement_level = 3,
37
n_cells_max = 100_000)
38
39
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
40
41
###############################################################################
42
# ODE solvers, callbacks etc.
43
44
tspan = (0.0, 0.4)
45
ode = semidiscretize(semi, tspan)
46
47
summary_callback = SummaryCallback()
48
49
analysis_interval = 100
50
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
51
52
alive_callback = AliveCallback(analysis_interval = analysis_interval)
53
54
save_restart = SaveRestartCallback(interval = 100,
55
save_final_restart = true)
56
57
save_solution = SaveSolutionCallback(interval = 100,
58
save_initial_solution = true,
59
save_final_solution = true,
60
solution_variables = cons2prim)
61
62
stepsize_callback = StepsizeCallback(cfl = 1.1)
63
64
callbacks = CallbackSet(summary_callback,
65
analysis_callback, alive_callback,
66
save_restart, save_solution,
67
stepsize_callback)
68
69
###############################################################################
70
# run the simulation
71
72
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
73
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
74
ode_default_options()..., callback = callbacks);
75
76