Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/structured_2d_dgsem/elixir_eulerpolytropic_wave.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the polytropic Euler equations
6
7
gamma() = 2.0 # Adiabatic monatomic gas in 2d.
8
kappa() = 0.5 # Scaling factor for the pressure.
9
equations = PolytropicEulerEquations2D(gamma(), kappa())
10
11
# Linear pressure wave in the negative x-direction.
12
function initial_condition_wave(x, t, equations::PolytropicEulerEquations2D)
13
rho = 1.0
14
v1 = 0.0
15
if x[1] > 0.0
16
rho = ((1.0 + 0.01 * sin(x[1] * 2 * pi)) / equations.kappa)^(1 / equations.gamma)
17
v1 = ((0.01 * sin((x[1] - 1 / 2) * 2 * pi)) / equations.kappa)
18
end
19
v2 = 0.0
20
21
return prim2cons(SVector(rho, v1, v2), equations)
22
end
23
initial_condition = initial_condition_wave
24
25
volume_flux = flux_winters_etal
26
solver = DGSEM(polydeg = 2, surface_flux = flux_hll,
27
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
28
29
coordinates_min = (-2.0, -1.0)
30
coordinates_max = (2.0, 1.0)
31
32
cells_per_dimension = (64, 32)
33
34
boundary_conditions = (x_neg = boundary_condition_periodic,
35
x_pos = boundary_condition_periodic,
36
y_neg = boundary_condition_periodic,
37
y_pos = boundary_condition_periodic)
38
39
mesh = StructuredMesh(cells_per_dimension,
40
coordinates_min,
41
coordinates_max)
42
43
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
44
boundary_conditions = boundary_conditions)
45
46
###############################################################################
47
# ODE solvers, callbacks etc.
48
49
tspan = (0.0, 1.0)
50
ode = semidiscretize(semi, tspan)
51
52
summary_callback = SummaryCallback()
53
54
analysis_interval = 200
55
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
56
57
alive_callback = AliveCallback(analysis_interval = analysis_interval)
58
59
save_solution = SaveSolutionCallback(interval = 50,
60
save_initial_solution = true,
61
save_final_solution = true,
62
solution_variables = cons2prim)
63
64
stepsize_callback = StepsizeCallback(cfl = 1.7)
65
66
callbacks = CallbackSet(summary_callback,
67
analysis_callback, alive_callback,
68
save_solution,
69
stepsize_callback)
70
71
###############################################################################
72
# run the simulation
73
74
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
75
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
76
ode_default_options()..., callback = callbacks);
77
78