Path: blob/main/src/equations/equation_of_state_ideal_gas.jl
5586 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"""8IdealGas{RealT <: Real} <: AbstractEquationOfState910This defines the polytropic ideal gas equation of state11given by the pressure and internal energy relations12```math13p = \rho R T, \quad e_{\text{internal}} = c_v T14```15with ``c_v = \frac{R}{\gamma - 1}``.16"""17struct IdealGas{RealT <: Real} <: AbstractEquationOfState18gamma::RealT19R::RealT20cv::RealT21end2223"""24IdealGas(gamma = 1.4, R = 287)2526If not specified, `R` is taken to be the gas constant for air. However, the27precise value does not matter since eliminating temperature yields non-dimensional28formulas in terms of only `gamma`.29"""30function IdealGas(gamma = 1.4, R = 287)31cv = R / (gamma - 1)32return IdealGas(promote(gamma, R, cv)...)33end3435"""36pressure(V, T, eos::IdealGas)3738Computes pressure for an ideal gas from primitive variables (see [`NonIdealCompressibleEulerEquations1D`](@ref))39specific volume `V` and temperature `T`.40"""41function pressure(V, T, eos::IdealGas)42(; R) = eos43rho = inv(V)44p = rho * R * T45return p46end4748"""49energy_internal_specific(V, T, eos::IdealGas)5051Computes internal energy for an ideal gas from specific volume `V` and temperature `T` as52``e_{\text{internal}} = c_v T``.53"""54function energy_internal_specific(V, T, eos::IdealGas)55(; cv) = eos56e_internal = cv * T57return e_internal58end5960function entropy_specific(V, T, eos::IdealGas)61(; cv, R) = eos62s = cv * log(T) + R * log(V)63return s64end6566function speed_of_sound(V, T, eos::IdealGas)67(; gamma) = eos68p = pressure(V, T, eos)69c2 = gamma * p * V70return sqrt(c2)71end7273# This is not a required interface function, but specializing it74# if an explicit function is available can improve performance.75# For general EOS, this is calculated via a Newton solve.76function temperature(V, e_internal, eos::IdealGas)77(; cv) = eos78T = e_internal / cv79return T80end81end # @muladd828384