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
5586 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_total = 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_total)
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, periodicity = true)
38
39
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
40
boundary_conditions = boundary_condition_periodic)
41
42
###############################################################################
43
# ODE solvers, callbacks etc.
44
45
tspan = (0.0, 0.4)
46
ode = semidiscretize(semi, tspan)
47
48
summary_callback = SummaryCallback()
49
50
analysis_interval = 100
51
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
52
53
alive_callback = AliveCallback(analysis_interval = analysis_interval)
54
55
save_restart = SaveRestartCallback(interval = 100,
56
save_final_restart = true)
57
58
save_solution = SaveSolutionCallback(interval = 100,
59
save_initial_solution = true,
60
save_final_solution = true,
61
solution_variables = cons2prim)
62
63
stepsize_callback = StepsizeCallback(cfl = 1.1)
64
65
callbacks = CallbackSet(summary_callback,
66
analysis_callback, alive_callback,
67
save_restart, save_solution,
68
stepsize_callback)
69
70
###############################################################################
71
# run the simulation
72
73
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
74
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
75
ode_default_options()..., callback = callbacks);
76
77