Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/dgmulti_1d/elixir_navierstokes_convergence_periodic.jl
5586 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
dg = DGMulti(polydeg = 3, element_type = Line(), approximation_type = GaussSBP(),
5
surface_integral = SurfaceIntegralWeakForm(flux_hllc))
6
7
prandtl_number() = 0.72
8
mu() = 6.25e-4 # equivalent to Re = 1600
9
10
equations = CompressibleEulerEquations1D(1.4)
11
equations_parabolic = CompressibleNavierStokesDiffusion1D(equations, mu = mu(),
12
Prandtl = prandtl_number(),
13
gradient_variables = GradientVariablesPrimitive())
14
15
function initial_condition_navier_stokes_convergence_test(x, t, equations)
16
# Amplitude and shift
17
RealT = eltype(x)
18
A = 0.5f0
19
c = 2
20
21
# convenience values for trig. functions
22
pi_x = convert(RealT, pi) * x[1]
23
pi_t = convert(RealT, pi) * t
24
25
rho = c + A * sin(pi_x) * cos(pi_t)
26
v1 = sin(pi_x) * cos(pi_t)
27
p = rho^2
28
29
return prim2cons(SVector(rho, v1, p), equations)
30
end
31
initial_condition = initial_condition_navier_stokes_convergence_test
32
33
@inline function source_terms_navier_stokes_convergence_test(u, x, t, equations)
34
# we currently need to hardcode these parameters until we fix the "combined equation" issue
35
# see also https://github.com/trixi-framework/Trixi.jl/pull/1160
36
RealT = eltype(x)
37
38
@unpack gamma, inv_gamma_minus_one = equations
39
Pr = prandtl_number()
40
mu_ = mu()
41
42
# Same settings as in `initial_condition`
43
# Amplitude and shift
44
A = 0.5f0
45
c = 2
46
47
# convenience values for trig. functions
48
pi_x = convert(RealT, pi) * x[1]
49
pi_t = convert(RealT, pi) * t
50
51
# compute the manufactured solution and all necessary derivatives
52
rho = c + A * sin(pi_x) * cos(pi_t)
53
rho_t = -convert(RealT, pi) * A * sin(pi_x) * sin(pi_t)
54
rho_x = convert(RealT, pi) * A * cos(pi_x) * cos(pi_t)
55
rho_xx = -convert(RealT, pi) * convert(RealT, pi) * A * sin(pi_x) * cos(pi_t)
56
57
v1 = sin(pi_x) * cos(pi_t)
58
v1_t = -convert(RealT, pi) * sin(pi_x) * sin(pi_t)
59
v1_x = convert(RealT, pi) * cos(pi_x) * cos(pi_t)
60
v1_xx = -convert(RealT, pi) * convert(RealT, pi) * sin(pi_x) * cos(pi_t)
61
62
p = rho * rho
63
p_t = 2 * rho * rho_t
64
p_x = 2 * rho * rho_x
65
p_xx = 2 * rho * rho_xx + 2 * rho_x * rho_x
66
67
E = p * inv_gamma_minus_one + 0.5f0 * rho * v1^2
68
E_t = p_t * inv_gamma_minus_one + 0.5f0 * rho_t * v1^2 + rho * v1 * v1_t
69
E_x = p_x * inv_gamma_minus_one + 0.5f0 * rho_x * v1^2 + rho * v1 * v1_x
70
71
# Some convenience constants
72
T_const = gamma * inv_gamma_minus_one / Pr
73
inv_rho_cubed = 1 / (rho^3)
74
75
# compute the source terms
76
# density equation
77
du1 = rho_t + rho_x * v1 + rho * v1_x
78
79
# x-momentum equation
80
du2 = (rho_t * v1 + rho * v1_t
81
+ p_x + rho_x * v1^2 + 2 * rho * v1 * v1_x -
82
# stress tensor from x-direction
83
v1_xx * mu_)
84
85
# total energy equation
86
du3 = (E_t + v1_x * (E + p) + v1 * (E_x + p_x) -
87
# stress tensor and temperature gradient terms from x-direction
88
v1_xx * v1 * mu_ -
89
v1_x * v1_x * mu_ -
90
T_const * inv_rho_cubed *
91
(p_xx * rho * rho -
92
2 * p_x * rho * rho_x +
93
2 * p * rho_x * rho_x -
94
p * rho * rho_xx) * mu_)
95
96
return SVector(du1, du2, du3)
97
end
98
99
cells_per_dimension = (12,)
100
mesh = DGMultiMesh(dg, cells_per_dimension,
101
coordinates_min = (-1.0,), coordinates_max = (1.0,),
102
periodicity = true)
103
104
# define periodic boundary conditions everywhere
105
boundary_conditions = boundary_condition_periodic
106
boundary_conditions_parabolic = boundary_condition_periodic
107
108
semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),
109
initial_condition, dg;
110
boundary_conditions = (boundary_conditions,
111
boundary_conditions_parabolic),
112
source_terms = source_terms_navier_stokes_convergence_test)
113
114
tspan = (0.0, 1.0)
115
ode = semidiscretize(semi, tspan)
116
117
summary_callback = SummaryCallback()
118
119
alive_callback = AliveCallback(alive_interval = 10)
120
121
analysis_interval = 100
122
analysis_callback = AnalysisCallback(semi, interval = analysis_interval, uEltype = real(dg))
123
124
callbacks = CallbackSet(summary_callback, alive_callback,
125
analysis_callback)
126
127
###############################################################################
128
# run the simulation
129
time_int_tol = 1e-6
130
sol = solve(ode, RDPK3SpFSAL49(); adaptive = true, dt = 1e-3,
131
abstol = time_int_tol, reltol = time_int_tol,
132
ode_default_options()..., callback = callbacks)
133
134