Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/p4est_2d_dgsem/elixir_navierstokes_convergence_nonperiodic.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the ideal compressible Navier-Stokes equations
6
7
prandtl_number() = 0.72
8
mu() = 0.01
9
10
equations = CompressibleEulerEquations2D(1.4)
11
equations_parabolic = CompressibleNavierStokesDiffusion2D(equations, mu = mu(),
12
Prandtl = prandtl_number(),
13
gradient_variables = GradientVariablesPrimitive())
14
15
# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
16
17
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
18
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
19
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
20
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
21
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
22
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
23
# `StepsizeCallback` (CFL-Condition) and less diffusion.
24
solver = DGSEM(polydeg = 3, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive),
25
volume_integral = VolumeIntegralWeakForm())
26
27
coordinates_min = (-1.0, -1.0) # minimum coordinates (min(x), min(y))
28
coordinates_max = (1.0, 1.0) # maximum coordinates (max(x), max(y))
29
30
trees_per_dimension = (4, 4)
31
mesh = P4estMesh(trees_per_dimension,
32
polydeg = 3, initial_refinement_level = 2,
33
coordinates_min = coordinates_min, coordinates_max = coordinates_max,
34
periodicity = (false, false))
35
36
# Note: the initial condition cannot be specialized to `CompressibleNavierStokesDiffusion2D`
37
# since it is called by both the parabolic solver (which passes in `CompressibleNavierStokesDiffusion2D`)
38
# and by the initial condition (which passes in `CompressibleEulerEquations2D`).
39
# This convergence test setup was originally derived by Andrew Winters (@andrewwinters5000)
40
function initial_condition_navier_stokes_convergence_test(x, t, equations)
41
# Amplitude and shift
42
A = 0.5
43
c = 2.0
44
45
# convenience values for trig. functions
46
pi_x = pi * x[1]
47
pi_y = pi * x[2]
48
pi_t = pi * t
49
50
rho = c + A * sin(pi_x) * cos(pi_y) * cos(pi_t)
51
v1 = sin(pi_x) * log(x[2] + 2.0) * (1.0 - exp(-A * (x[2] - 1.0))) * cos(pi_t)
52
v2 = v1
53
p = rho^2
54
55
return prim2cons(SVector(rho, v1, v2, p), equations)
56
end
57
58
@inline function source_terms_navier_stokes_convergence_test(u, x, t, equations)
59
y = x[2]
60
61
# TODO: parabolic
62
# we currently need to hardcode these parameters until we fix the "combined equation" issue
63
# see also https://github.com/trixi-framework/Trixi.jl/pull/1160
64
inv_gamma_minus_one = inv(equations.gamma - 1)
65
Pr = prandtl_number()
66
mu_ = mu()
67
68
# Same settings as in `initial_condition`
69
# Amplitude and shift
70
A = 0.5
71
c = 2.0
72
73
# convenience values for trig. functions
74
pi_x = pi * x[1]
75
pi_y = pi * x[2]
76
pi_t = pi * t
77
78
# compute the manufactured solution and all necessary derivatives
79
rho = c + A * sin(pi_x) * cos(pi_y) * cos(pi_t)
80
rho_t = -pi * A * sin(pi_x) * cos(pi_y) * sin(pi_t)
81
rho_x = pi * A * cos(pi_x) * cos(pi_y) * cos(pi_t)
82
rho_y = -pi * A * sin(pi_x) * sin(pi_y) * cos(pi_t)
83
rho_xx = -pi * pi * A * sin(pi_x) * cos(pi_y) * cos(pi_t)
84
rho_yy = -pi * pi * A * sin(pi_x) * cos(pi_y) * cos(pi_t)
85
86
v1 = sin(pi_x) * log(y + 2.0) * (1.0 - exp(-A * (y - 1.0))) * cos(pi_t)
87
v1_t = -pi * sin(pi_x) * log(y + 2.0) * (1.0 - exp(-A * (y - 1.0))) * sin(pi_t)
88
v1_x = pi * cos(pi_x) * log(y + 2.0) * (1.0 - exp(-A * (y - 1.0))) * cos(pi_t)
89
v1_y = sin(pi_x) *
90
(A * log(y + 2.0) * exp(-A * (y - 1.0)) +
91
(1.0 - exp(-A * (y - 1.0))) / (y + 2.0)) * cos(pi_t)
92
v1_xx = -pi * pi * sin(pi_x) * log(y + 2.0) * (1.0 - exp(-A * (y - 1.0))) * cos(pi_t)
93
v1_xy = pi * cos(pi_x) *
94
(A * log(y + 2.0) * exp(-A * (y - 1.0)) +
95
(1.0 - exp(-A * (y - 1.0))) / (y + 2.0)) * cos(pi_t)
96
v1_yy = (sin(pi_x) *
97
(2.0 * A * exp(-A * (y - 1.0)) / (y + 2.0) -
98
A * A * log(y + 2.0) * exp(-A * (y - 1.0)) -
99
(1.0 - exp(-A * (y - 1.0))) / ((y + 2.0) * (y + 2.0))) * cos(pi_t))
100
v2 = v1
101
v2_t = v1_t
102
v2_x = v1_x
103
v2_y = v1_y
104
v2_xx = v1_xx
105
v2_xy = v1_xy
106
v2_yy = v1_yy
107
108
p = rho * rho
109
p_t = 2.0 * rho * rho_t
110
p_x = 2.0 * rho * rho_x
111
p_y = 2.0 * rho * rho_y
112
p_xx = 2.0 * rho * rho_xx + 2.0 * rho_x * rho_x
113
p_yy = 2.0 * rho * rho_yy + 2.0 * rho_y * rho_y
114
115
# Note this simplifies slightly because the ansatz assumes that v1 = v2
116
E = p * inv_gamma_minus_one + 0.5 * rho * (v1^2 + v2^2)
117
E_t = p_t * inv_gamma_minus_one + rho_t * v1^2 + 2.0 * rho * v1 * v1_t
118
E_x = p_x * inv_gamma_minus_one + rho_x * v1^2 + 2.0 * rho * v1 * v1_x
119
E_y = p_y * inv_gamma_minus_one + rho_y * v1^2 + 2.0 * rho * v1 * v1_y
120
121
# Some convenience constants
122
T_const = equations.gamma * inv_gamma_minus_one / Pr
123
inv_rho_cubed = 1.0 / (rho^3)
124
125
# compute the source terms
126
# density equation
127
du1 = rho_t + rho_x * v1 + rho * v1_x + rho_y * v2 + rho * v2_y
128
129
# x-momentum equation
130
du2 = (rho_t * v1 + rho * v1_t + p_x + rho_x * v1^2
131
+ 2.0 * rho * v1 * v1_x
132
+ rho_y * v1 * v2
133
+ rho * v1_y * v2
134
+ rho * v1 * v2_y -
135
# stress tensor from x-direction
136
4.0 / 3.0 * v1_xx * mu_ +
137
2.0 / 3.0 * v2_xy * mu_ -
138
v1_yy * mu_ -
139
v2_xy * mu_)
140
# y-momentum equation
141
du3 = (rho_t * v2 + rho * v2_t + p_y + rho_x * v1 * v2
142
+ rho * v1_x * v2
143
+ rho * v1 * v2_x
144
+ rho_y * v2^2
145
+ 2.0 * rho * v2 * v2_y -
146
# stress tensor from y-direction
147
v1_xy * mu_ -
148
v2_xx * mu_ -
149
4.0 / 3.0 * v2_yy * mu_ +
150
2.0 / 3.0 * v1_xy * mu_)
151
# total energy equation
152
du4 = (E_t + v1_x * (E + p) + v1 * (E_x + p_x)
153
+ v2_y * (E + p) + v2 * (E_y + p_y) -
154
# stress tensor and temperature gradient terms from x-direction
155
4.0 / 3.0 * v1_xx * v1 * mu_ +
156
2.0 / 3.0 * v2_xy * v1 * mu_ -
157
4.0 / 3.0 * v1_x * v1_x * mu_ +
158
2.0 / 3.0 * v2_y * v1_x * mu_ -
159
v1_xy * v2 * mu_ -
160
v2_xx * v2 * mu_ -
161
v1_y * v2_x * mu_ -
162
v2_x * v2_x * mu_ -
163
T_const * inv_rho_cubed *
164
(p_xx * rho * rho -
165
2.0 * p_x * rho * rho_x +
166
2.0 * p * rho_x * rho_x -
167
p * rho * rho_xx) * mu_ -
168
# stress tensor and temperature gradient terms from y-direction
169
v1_yy * v1 * mu_ -
170
v2_xy * v1 * mu_ -
171
v1_y * v1_y * mu_ -
172
v2_x * v1_y * mu_ -
173
4.0 / 3.0 * v2_yy * v2 * mu_ +
174
2.0 / 3.0 * v1_xy * v2 * mu_ -
175
4.0 / 3.0 * v2_y * v2_y * mu_ +
176
2.0 / 3.0 * v1_x * v2_y * mu_ -
177
T_const * inv_rho_cubed *
178
(p_yy * rho * rho -
179
2.0 * p_y * rho * rho_y +
180
2.0 * p * rho_y * rho_y -
181
p * rho * rho_yy) * mu_)
182
183
return SVector(du1, du2, du3, du4)
184
end
185
186
initial_condition = initial_condition_navier_stokes_convergence_test
187
188
# BC types
189
velocity_bc_top_bottom = NoSlip() do x, t, equations_parabolic
190
u_cons = initial_condition_navier_stokes_convergence_test(x, t, equations_parabolic)
191
return SVector(u_cons[2] / u_cons[1], u_cons[3] / u_cons[1])
192
end
193
194
heat_bc_top_bottom = Adiabatic((x, t, equations_parabolic) -> 0.0)
195
boundary_condition_top_bottom = BoundaryConditionNavierStokesWall(velocity_bc_top_bottom,
196
heat_bc_top_bottom)
197
198
boundary_condition_left_right = BoundaryConditionDirichlet(initial_condition_navier_stokes_convergence_test)
199
200
# define inviscid boundary conditions
201
boundary_conditions = Dict(:x_neg => boundary_condition_left_right,
202
:x_pos => boundary_condition_left_right,
203
:y_neg => boundary_condition_slip_wall,
204
:y_pos => boundary_condition_slip_wall)
205
206
# define viscous boundary conditions
207
boundary_conditions_parabolic = Dict(:x_neg => boundary_condition_left_right,
208
:x_pos => boundary_condition_left_right,
209
:y_neg => boundary_condition_top_bottom,
210
:y_pos => boundary_condition_top_bottom)
211
212
semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),
213
initial_condition, solver;
214
boundary_conditions = (boundary_conditions,
215
boundary_conditions_parabolic),
216
source_terms = source_terms_navier_stokes_convergence_test)
217
218
# ###############################################################################
219
# # ODE solvers, callbacks etc.
220
221
# Create ODE problem with time span `tspan`
222
tspan = (0.0, 0.5)
223
ode = semidiscretize(semi, tspan)
224
225
summary_callback = SummaryCallback()
226
alive_callback = AliveCallback(alive_interval = 10)
227
analysis_interval = 100
228
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
229
callbacks = CallbackSet(summary_callback, alive_callback, analysis_callback)
230
231
###############################################################################
232
# run the simulation
233
234
time_int_tol = 1e-8
235
sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol, dt = 1e-5,
236
ode_default_options()..., callback = callbacks)
237
238