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_isothermal_wave.jl
5586 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the polytropic Euler equations
6
7
gamma = 1.0 # With gamma = 1 the system is isothermal.
8
kappa = 1.0 # 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
periodicity = true)
43
44
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
45
boundary_conditions = boundary_conditions)
46
47
###############################################################################
48
# ODE solvers, callbacks etc.
49
50
tspan = (0.0, 1.0)
51
ode = semidiscretize(semi, tspan)
52
53
summary_callback = SummaryCallback()
54
55
analysis_interval = 200
56
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
57
58
alive_callback = AliveCallback(analysis_interval = analysis_interval)
59
60
save_solution = SaveSolutionCallback(interval = 50,
61
save_initial_solution = true,
62
save_final_solution = true,
63
solution_variables = cons2prim)
64
65
stepsize_callback = StepsizeCallback(cfl = 1.7)
66
67
callbacks = CallbackSet(summary_callback,
68
analysis_callback, alive_callback,
69
save_solution,
70
stepsize_callback)
71
72
stage_limiter! = PositivityPreservingLimiterZhangShu(thresholds = (1.0e-4, 1.0e-4),
73
variables = (Trixi.density, pressure))
74
75
###############################################################################
76
# run the simulation
77
78
sol = solve(ode, CarpenterKennedy2N54(stage_limiter!, williamson_condition = false);
79
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
80
ode_default_options()..., callback = callbacks);
81
82