Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/equations/linearized_euler_1d.jl
2055 views
1
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
2
# Since these FMAs can increase the performance of many numerical algorithms,
3
# we need to opt-in explicitly.
4
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
5
@muladd begin
6
#! format: noindent
7
8
@doc raw"""
9
LinearizedEulerEquations1D(v_mean_global, c_mean_global, rho_mean_global)
10
11
Linearized Euler equations in one space dimension. The equations are given by
12
```math
13
\partial_t
14
\begin{pmatrix}
15
\rho' \\ v_1' \\ p'
16
\end{pmatrix}
17
+
18
\partial_x
19
\begin{pmatrix}
20
\bar{\rho} v_1' + \bar{v_1} \rho ' \\ \bar{v_1} v_1' + \frac{p'}{\bar{\rho}} \\ \bar{v_1} p' + c^2 \bar{\rho} v_1'
21
\end{pmatrix}
22
=
23
\begin{pmatrix}
24
0 \\ 0 \\ 0
25
\end{pmatrix}
26
```
27
The bar ``\bar{(\cdot)}`` indicates uniform mean flow variables and ``c`` is the speed of sound.
28
The unknowns are the perturbation quantities of the acoustic velocity ``v_1'``, the pressure ``p'``
29
and the density ``\rho'``.
30
"""
31
struct LinearizedEulerEquations1D{RealT <: Real} <:
32
AbstractLinearizedEulerEquations{1, 3}
33
v_mean_global::RealT
34
c_mean_global::RealT
35
rho_mean_global::RealT
36
end
37
38
function LinearizedEulerEquations1D(v_mean_global::Real,
39
c_mean_global::Real, rho_mean_global::Real)
40
if rho_mean_global < 0
41
throw(ArgumentError("rho_mean_global must be non-negative"))
42
elseif c_mean_global < 0
43
throw(ArgumentError("c_mean_global must be non-negative"))
44
end
45
46
return LinearizedEulerEquations1D(v_mean_global, c_mean_global,
47
rho_mean_global)
48
end
49
50
# Constructor with keywords
51
function LinearizedEulerEquations1D(; v_mean_global::Real,
52
c_mean_global::Real, rho_mean_global::Real)
53
return LinearizedEulerEquations1D(v_mean_global, c_mean_global,
54
rho_mean_global)
55
end
56
57
function varnames(::typeof(cons2cons), ::LinearizedEulerEquations1D)
58
("rho_prime", "v1_prime", "p_prime")
59
end
60
function varnames(::typeof(cons2prim), ::LinearizedEulerEquations1D)
61
("rho_prime", "v1_prime", "p_prime")
62
end
63
64
"""
65
initial_condition_convergence_test(x, t, equations::LinearizedEulerEquations1D)
66
67
A smooth initial condition used for convergence tests.
68
"""
69
function initial_condition_convergence_test(x, t, equations::LinearizedEulerEquations1D)
70
rho_prime = -cospi(2 * t) * sinpi(2 * x[1])
71
v1_prime = sinpi(2 * t) * cospi(2 * x[1])
72
p_prime = rho_prime
73
74
return SVector(rho_prime, v1_prime, p_prime)
75
end
76
77
"""
78
boundary_condition_wall(u_inner, orientation, direction, x, t, surface_flux_function,
79
equations::LinearizedEulerEquations1D)
80
81
Boundary conditions for a solid wall.
82
"""
83
function boundary_condition_wall(u_inner, orientation, direction, x, t,
84
surface_flux_function,
85
equations::LinearizedEulerEquations1D)
86
# Boundary state is equal to the inner state except for the velocity. For boundaries
87
# in the -x/+x direction, we multiply the velocity (in the x direction by) -1.
88
u_boundary = SVector(u_inner[1], -u_inner[2], u_inner[3])
89
90
# Calculate boundary flux
91
if iseven(direction) # u_inner is "left" of boundary, u_boundary is "right" of boundary
92
flux = surface_flux_function(u_inner, u_boundary, orientation, equations)
93
else # u_boundary is "left" of boundary, u_inner is "right" of boundary
94
flux = surface_flux_function(u_boundary, u_inner, orientation, equations)
95
end
96
97
return flux
98
end
99
100
# Calculate 1D flux for a single point
101
@inline function flux(u, orientation::Integer, equations::LinearizedEulerEquations1D)
102
@unpack v_mean_global, c_mean_global, rho_mean_global = equations
103
rho_prime, v1_prime, p_prime = u
104
f1 = v_mean_global * rho_prime + rho_mean_global * v1_prime
105
f2 = v_mean_global * v1_prime + p_prime / rho_mean_global
106
f3 = v_mean_global * p_prime + c_mean_global^2 * rho_mean_global * v1_prime
107
108
return SVector(f1, f2, f3)
109
end
110
111
@inline have_constant_speed(::LinearizedEulerEquations1D) = True()
112
113
@inline function max_abs_speeds(equations::LinearizedEulerEquations1D)
114
@unpack v_mean_global, c_mean_global = equations
115
return abs(v_mean_global) + c_mean_global
116
end
117
118
@inline function max_abs_speed_naive(u_ll, u_rr, orientation::Integer,
119
equations::LinearizedEulerEquations1D)
120
@unpack v_mean_global, c_mean_global = equations
121
return abs(v_mean_global) + c_mean_global
122
end
123
124
# Calculate estimate for minimum and maximum wave speeds for HLL-type fluxes
125
@inline function min_max_speed_naive(u_ll, u_rr, orientation::Integer,
126
equations::LinearizedEulerEquations1D)
127
min_max_speed_davis(u_ll, u_rr, orientation, equations)
128
end
129
130
# More refined estimates for minimum and maximum wave speeds for HLL-type fluxes
131
@inline function min_max_speed_davis(u_ll, u_rr, orientation::Integer,
132
equations::LinearizedEulerEquations1D)
133
@unpack v_mean_global, c_mean_global = equations
134
135
λ_min = v_mean_global - c_mean_global
136
λ_max = v_mean_global + c_mean_global
137
138
return λ_min, λ_max
139
end
140
141
# Convert conservative variables to primitive
142
@inline cons2prim(u, equations::LinearizedEulerEquations1D) = u
143
@inline cons2entropy(u, ::LinearizedEulerEquations1D) = u
144
end # muladd
145
146