Path: blob/main/src/equations/linearized_euler_1d.jl
2055 views
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).1# Since these FMAs can increase the performance of many numerical algorithms,2# we need to opt-in explicitly.3# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.4@muladd begin5#! format: noindent67@doc raw"""8LinearizedEulerEquations1D(v_mean_global, c_mean_global, rho_mean_global)910Linearized Euler equations in one space dimension. The equations are given by11```math12\partial_t13\begin{pmatrix}14\rho' \\ v_1' \\ p'15\end{pmatrix}16+17\partial_x18\begin{pmatrix}19\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'20\end{pmatrix}21=22\begin{pmatrix}230 \\ 0 \\ 024\end{pmatrix}25```26The bar ``\bar{(\cdot)}`` indicates uniform mean flow variables and ``c`` is the speed of sound.27The unknowns are the perturbation quantities of the acoustic velocity ``v_1'``, the pressure ``p'``28and the density ``\rho'``.29"""30struct LinearizedEulerEquations1D{RealT <: Real} <:31AbstractLinearizedEulerEquations{1, 3}32v_mean_global::RealT33c_mean_global::RealT34rho_mean_global::RealT35end3637function LinearizedEulerEquations1D(v_mean_global::Real,38c_mean_global::Real, rho_mean_global::Real)39if rho_mean_global < 040throw(ArgumentError("rho_mean_global must be non-negative"))41elseif c_mean_global < 042throw(ArgumentError("c_mean_global must be non-negative"))43end4445return LinearizedEulerEquations1D(v_mean_global, c_mean_global,46rho_mean_global)47end4849# Constructor with keywords50function LinearizedEulerEquations1D(; v_mean_global::Real,51c_mean_global::Real, rho_mean_global::Real)52return LinearizedEulerEquations1D(v_mean_global, c_mean_global,53rho_mean_global)54end5556function varnames(::typeof(cons2cons), ::LinearizedEulerEquations1D)57("rho_prime", "v1_prime", "p_prime")58end59function varnames(::typeof(cons2prim), ::LinearizedEulerEquations1D)60("rho_prime", "v1_prime", "p_prime")61end6263"""64initial_condition_convergence_test(x, t, equations::LinearizedEulerEquations1D)6566A smooth initial condition used for convergence tests.67"""68function initial_condition_convergence_test(x, t, equations::LinearizedEulerEquations1D)69rho_prime = -cospi(2 * t) * sinpi(2 * x[1])70v1_prime = sinpi(2 * t) * cospi(2 * x[1])71p_prime = rho_prime7273return SVector(rho_prime, v1_prime, p_prime)74end7576"""77boundary_condition_wall(u_inner, orientation, direction, x, t, surface_flux_function,78equations::LinearizedEulerEquations1D)7980Boundary conditions for a solid wall.81"""82function boundary_condition_wall(u_inner, orientation, direction, x, t,83surface_flux_function,84equations::LinearizedEulerEquations1D)85# Boundary state is equal to the inner state except for the velocity. For boundaries86# in the -x/+x direction, we multiply the velocity (in the x direction by) -1.87u_boundary = SVector(u_inner[1], -u_inner[2], u_inner[3])8889# Calculate boundary flux90if iseven(direction) # u_inner is "left" of boundary, u_boundary is "right" of boundary91flux = surface_flux_function(u_inner, u_boundary, orientation, equations)92else # u_boundary is "left" of boundary, u_inner is "right" of boundary93flux = surface_flux_function(u_boundary, u_inner, orientation, equations)94end9596return flux97end9899# Calculate 1D flux for a single point100@inline function flux(u, orientation::Integer, equations::LinearizedEulerEquations1D)101@unpack v_mean_global, c_mean_global, rho_mean_global = equations102rho_prime, v1_prime, p_prime = u103f1 = v_mean_global * rho_prime + rho_mean_global * v1_prime104f2 = v_mean_global * v1_prime + p_prime / rho_mean_global105f3 = v_mean_global * p_prime + c_mean_global^2 * rho_mean_global * v1_prime106107return SVector(f1, f2, f3)108end109110@inline have_constant_speed(::LinearizedEulerEquations1D) = True()111112@inline function max_abs_speeds(equations::LinearizedEulerEquations1D)113@unpack v_mean_global, c_mean_global = equations114return abs(v_mean_global) + c_mean_global115end116117@inline function max_abs_speed_naive(u_ll, u_rr, orientation::Integer,118equations::LinearizedEulerEquations1D)119@unpack v_mean_global, c_mean_global = equations120return abs(v_mean_global) + c_mean_global121end122123# Calculate estimate for minimum and maximum wave speeds for HLL-type fluxes124@inline function min_max_speed_naive(u_ll, u_rr, orientation::Integer,125equations::LinearizedEulerEquations1D)126min_max_speed_davis(u_ll, u_rr, orientation, equations)127end128129# More refined estimates for minimum and maximum wave speeds for HLL-type fluxes130@inline function min_max_speed_davis(u_ll, u_rr, orientation::Integer,131equations::LinearizedEulerEquations1D)132@unpack v_mean_global, c_mean_global = equations133134λ_min = v_mean_global - c_mean_global135λ_max = v_mean_global + c_mean_global136137return λ_min, λ_max138end139140# Convert conservative variables to primitive141@inline cons2prim(u, equations::LinearizedEulerEquations1D) = u142@inline cons2entropy(u, ::LinearizedEulerEquations1D) = u143end # muladd144145146