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_blob_amr.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the compressible Euler equations
6
gamma = 5 / 3
7
equations = CompressibleEulerEquations3D(gamma)
8
9
"""
10
initial_condition_blob(x, t, equations::CompressibleEulerEquations3D)
11
12
The blob test case taken from
13
- Agertz et al. (2006)
14
Fundamental differences between SPH and grid methods
15
[arXiv: astro-ph/0610051](https://arxiv.org/abs/astro-ph/0610051)
16
"""
17
function initial_condition_blob(x, t, equations::CompressibleEulerEquations3D)
18
# blob test case, see Agertz et al. https://arxiv.org/pdf/astro-ph/0610051.pdf
19
# other reference: https://doi.org/10.1111/j.1365-2966.2007.12183.x
20
# change discontinuity to tanh
21
# typical domain is rectangular, we change it to a square
22
# resolution 128^3, 256^3
23
# domain size is [-20.0,20.0]^3
24
# gamma = 5/3 for this test case
25
R = 1.0 # radius of the blob
26
# background density
27
rho = 1.0
28
Chi = 10.0 # density contrast
29
# reference time of characteristic growth of KH instability equal to 1.0
30
tau_kh = 1.0
31
tau_cr = tau_kh / 1.6 # crushing time
32
# determine background velocity
33
v1 = 2 * R * sqrt(Chi) / tau_cr
34
v2 = 0.0
35
v3 = 0.0
36
Ma0 = 2.7 # background flow Mach number Ma=v/c
37
c = v1 / Ma0 # sound speed
38
# use perfect gas assumption to compute background pressure via the sound speed c^2 = gamma * pressure/density
39
p = c * c * rho / equations.gamma
40
# initial center of the blob
41
inicenter = [-15, 0, 0]
42
x_rel = x - inicenter
43
r = sqrt(x_rel[1]^2 + x_rel[2]^2 + x_rel[3]^2)
44
# steepness of the tanh transition zone
45
slope = 2
46
# density blob
47
rho = rho +
48
(Chi - 1) * 0.5 * (1 + (tanh(slope * (r + R)) - (tanh(slope * (r - R)) + 1)))
49
# velocity blob is zero
50
v1 = v1 - v1 * 0.5 * (1 + (tanh(slope * (r + R)) - (tanh(slope * (r - R)) + 1)))
51
return prim2cons(SVector(rho, v1, v2, v3, p), equations)
52
end
53
initial_condition = initial_condition_blob
54
55
volume_flux = flux_ranocha
56
solver = DGSEM(polydeg = 3, surface_flux = flux_hllc,
57
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
58
59
coordinates_min = (-20.0, -20.0, -20.0)
60
coordinates_max = (20.0, 20.0, 20.0)
61
62
refinement_patches = ((type = "box", coordinates_min = (-20.0, -10.0, -10.0),
63
coordinates_max = (-10.0, 10.0, 10.0)),
64
(type = "box", coordinates_min = (-20.0, -5.0, -5.0),
65
coordinates_max = (-10.0, 5.0, 5.0)),
66
(type = "box", coordinates_min = (-17.0, -2.0, -2.0),
67
coordinates_max = (-13.0, 2.0, 2.0)),
68
(type = "box", coordinates_min = (-17.0, -2.0, -2.0),
69
coordinates_max = (-13.0, 2.0, 2.0)))
70
mesh = TreeMesh(coordinates_min, coordinates_max,
71
initial_refinement_level = 2,
72
refinement_patches = refinement_patches,
73
n_cells_max = 100_000)
74
75
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
76
77
###############################################################################
78
# ODE solvers, callbacks etc.
79
80
tspan = (0.0, 2.5)
81
ode = semidiscretize(semi, tspan)
82
83
summary_callback = SummaryCallback()
84
85
analysis_interval = 200
86
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
87
88
alive_callback = AliveCallback(analysis_interval = analysis_interval)
89
90
save_solution = SaveSolutionCallback(interval = 200,
91
save_initial_solution = true,
92
save_final_solution = true,
93
solution_variables = cons2prim)
94
95
amr_indicator = IndicatorLöhner(semi,
96
variable = Trixi.density)
97
amr_controller = ControllerThreeLevel(semi, amr_indicator,
98
base_level = 1,
99
med_level = 0, med_threshold = 0.1, # med_level = current level
100
max_level = 6, max_threshold = 0.3)
101
amr_callback = AMRCallback(semi, amr_controller,
102
interval = 3,
103
adapt_initial_condition = false,
104
adapt_initial_condition_only_refine = true)
105
106
stepsize_callback = StepsizeCallback(cfl = 1.7)
107
108
callbacks = CallbackSet(summary_callback,
109
analysis_callback, alive_callback,
110
save_solution,
111
amr_callback, stepsize_callback)
112
113
stage_limiter! = PositivityPreservingLimiterZhangShu(thresholds = (1.0e-4, 1.0e-4),
114
variables = (Trixi.density, pressure))
115
116
###############################################################################
117
# run the simulation
118
119
sol = solve(ode, CarpenterKennedy2N54(stage_limiter!, williamson_condition = false);
120
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
121
ode_default_options()..., callback = callbacks);
122
123