Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_2d_dgsem/elixir_euler_colliding_flow.jl
5586 views
1
using OrdinaryDiffEqSSPRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the compressible Euler equations
6
gamma = 1.001 # almost isothermal when gamma reaches 1
7
equations = CompressibleEulerEquations2D(gamma)
8
9
# This is a hand made colliding flow setup without reference. Features Mach=70 inflow from both
10
# sides, with relative low temperature, such that pressure keeps relatively small
11
# Computed with gamma close to 1, to simulate isothermal gas
12
function initial_condition_colliding_flow_astro(x, t,
13
equations::CompressibleEulerEquations2D)
14
# change discontinuity to tanh
15
# resolution 128^2 elements (refined close to the interface) and polydeg=3 (total of 512^2 DOF)
16
# domain size is [-64,+64]^2
17
RealT = eltype(x)
18
@unpack gamma = equations
19
# the quantities are chosen such, that they are as close as possible to the astro examples
20
# keep in mind, that in the astro example, the physical units are weird (parsec, mega years, ...)
21
rho = convert(RealT, 0.0247)
22
c = convert(RealT, 0.2)
23
p = c^2 / gamma * rho
24
vel = convert(RealT, 13.907432274789372)
25
slope = 1
26
v1 = -vel * tanh(slope * x[1])
27
# add small initial disturbance to the field, but only close to the interface
28
if abs(x[1]) < 10
29
v1 = v1 * (1 + RealT(0.01) * sinpi(x[2]))
30
end
31
v2 = 0
32
return prim2cons(SVector(rho, v1, v2, p), equations)
33
end
34
initial_condition = initial_condition_colliding_flow_astro
35
36
boundary_conditions = (;
37
x_neg = BoundaryConditionDirichlet(initial_condition_colliding_flow_astro),
38
x_pos = BoundaryConditionDirichlet(initial_condition_colliding_flow_astro),
39
y_neg = boundary_condition_periodic,
40
y_pos = boundary_condition_periodic)
41
42
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
43
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
44
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
45
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
46
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
47
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
48
# `StepsizeCallback` (CFL-Condition) and less diffusion.
49
surface_flux = FluxLaxFriedrichs(max_abs_speed_naive) # HLLC needs more shock capturing (alpha_max)
50
volume_flux = flux_ranocha # works with Chandrashekar flux as well
51
polydeg = 3
52
basis = LobattoLegendreBasis(polydeg)
53
54
# shock capturing necessary for this tough example, however alpha_max = 0.5 is fine
55
indicator_sc = IndicatorHennemannGassner(equations, basis,
56
alpha_max = 0.5,
57
alpha_min = 0.0001,
58
alpha_smooth = true,
59
variable = density_pressure)
60
volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;
61
volume_flux_dg = volume_flux,
62
volume_flux_fv = surface_flux)
63
solver = DGSEM(basis, surface_flux, volume_integral)
64
65
coordinates_min = (-64.0, -64.0)
66
coordinates_max = (64.0, 64.0)
67
68
# only refinement in a patch. Needs x=-17/+17 to trigger refinement due to coarse base mesh
69
refinement_patches = ((type = "box", coordinates_min = (-17, -64),
70
coordinates_max = (17, 64)),
71
(type = "box", coordinates_min = (-17, -64),
72
coordinates_max = (17, 64)),
73
(type = "box", coordinates_min = (-17, -64),
74
coordinates_max = (17, 64)),
75
(type = "box", coordinates_min = (-17, -64),
76
coordinates_max = (17, 64))
77
#(type="box", coordinates_min=(-17, -64), coordinates_max=(17, 64)), # very high resolution, takes about 1000s on 2 cores
78
)
79
mesh = TreeMesh(coordinates_min, coordinates_max,
80
initial_refinement_level = 3,
81
refinement_patches = refinement_patches,
82
periodicity = (false, true),
83
n_cells_max = 100_000)
84
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
85
boundary_conditions = boundary_conditions)
86
87
###############################################################################
88
# ODE solvers, callbacks etc.
89
90
tspan = (0.0, 25.0)
91
ode = semidiscretize(semi, tspan)
92
93
summary_callback = SummaryCallback()
94
95
analysis_interval = 1000
96
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
97
98
alive_callback = AliveCallback(analysis_interval = analysis_interval)
99
100
save_solution = SaveSolutionCallback(interval = 1000,
101
save_initial_solution = true,
102
save_final_solution = true,
103
solution_variables = cons2prim)
104
105
callbacks = CallbackSet(summary_callback,
106
analysis_callback, alive_callback,
107
save_solution)
108
109
# positivity limiter necessary for this tough example
110
stage_limiter! = PositivityPreservingLimiterZhangShu(thresholds = (5.0e-6, 5.0e-6),
111
variables = (Trixi.density, pressure))
112
113
###############################################################################
114
# run the simulation
115
# use adaptive time stepping based on error estimates, time step roughly dt = 5e-3
116
sol = solve(ode, SSPRK43(stage_limiter!);
117
ode_default_options()..., callback = callbacks);
118
119