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
2055 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 = (x_neg = BoundaryConditionDirichlet(initial_condition_colliding_flow_astro),
37
x_pos = BoundaryConditionDirichlet(initial_condition_colliding_flow_astro),
38
y_neg = boundary_condition_periodic,
39
y_pos = boundary_condition_periodic)
40
41
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
42
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
43
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
44
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
45
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
46
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
47
# `StepsizeCallback` (CFL-Condition) and less diffusion.
48
surface_flux = FluxLaxFriedrichs(max_abs_speed_naive) # HLLC needs more shock capturing (alpha_max)
49
volume_flux = flux_ranocha # works with Chandrashekar flux as well
50
polydeg = 3
51
basis = LobattoLegendreBasis(polydeg)
52
53
# shock capturing necessary for this tough example, however alpha_max = 0.5 is fine
54
indicator_sc = IndicatorHennemannGassner(equations, basis,
55
alpha_max = 0.5,
56
alpha_min = 0.0001,
57
alpha_smooth = true,
58
variable = density_pressure)
59
volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;
60
volume_flux_dg = volume_flux,
61
volume_flux_fv = surface_flux)
62
solver = DGSEM(basis, surface_flux, volume_integral)
63
64
coordinates_min = (-64.0, -64.0)
65
coordinates_max = (64.0, 64.0)
66
67
# only refinement in a patch. Needs x=-17/+17 to trigger refinement due to coarse base mesh
68
refinement_patches = ((type = "box", coordinates_min = (-17, -64),
69
coordinates_max = (17, 64)),
70
(type = "box", coordinates_min = (-17, -64),
71
coordinates_max = (17, 64)),
72
(type = "box", coordinates_min = (-17, -64),
73
coordinates_max = (17, 64)),
74
(type = "box", coordinates_min = (-17, -64),
75
coordinates_max = (17, 64))
76
#(type="box", coordinates_min=(-17, -64), coordinates_max=(17, 64)), # very high resolution, takes about 1000s on 2 cores
77
)
78
mesh = TreeMesh(coordinates_min, coordinates_max,
79
initial_refinement_level = 3,
80
refinement_patches = refinement_patches,
81
periodicity = (false, true),
82
n_cells_max = 100_000)
83
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
84
boundary_conditions = boundary_conditions)
85
86
###############################################################################
87
# ODE solvers, callbacks etc.
88
89
tspan = (0.0, 25.0)
90
ode = semidiscretize(semi, tspan)
91
92
summary_callback = SummaryCallback()
93
94
analysis_interval = 1000
95
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
96
97
alive_callback = AliveCallback(analysis_interval = analysis_interval)
98
99
save_solution = SaveSolutionCallback(interval = 1000,
100
save_initial_solution = true,
101
save_final_solution = true,
102
solution_variables = cons2prim)
103
104
callbacks = CallbackSet(summary_callback,
105
analysis_callback, alive_callback,
106
save_solution)
107
108
# positivity limiter necessary for this tough example
109
stage_limiter! = PositivityPreservingLimiterZhangShu(thresholds = (5.0e-6, 5.0e-6),
110
variables = (Trixi.density, pressure))
111
112
###############################################################################
113
# run the simulation
114
# use adaptive time stepping based on error estimates, time step roughly dt = 5e-3
115
sol = solve(ode, SSPRK43(stage_limiter!);
116
ode_default_options()..., callback = callbacks);
117
118