Path: blob/main/src/equations/equation_of_state_helmholtz_ideal_gas.jl
5586 views
1@doc raw"""2HelmholtzIdealGas{RealT <: Real} <: AbstractHelmholtzEOS34Ideal-gas specific Helmholtz energy from Klein et al., Appendix E, equation (E.1).5The specific Helmholtz energy is6```math7A = - R T \left(1 + \ln\left(T^{1/(\gamma-1)} V\right)\right),8```9with ``c_v = R / (\gamma - 1)``.1011Fields:12- `gamma`: ratio of specific heats13- `R`: specific gas constant14"""15struct HelmholtzIdealGas{RealT <: Real} <: AbstractHelmholtzEOS16gamma::RealT17R::RealT18end1920"""21HelmholtzIdealGas(gamma = 1.4, R = 287)2223Constructs a [`HelmholtzIdealGas`](@ref) with ratio of specific heats24`gamma` and specific gas constant `R`. If not specified, `R` defaults25to 287 J/(kg K), a value typical of air (see also [`IdealGas`](@ref)).26"""27function HelmholtzIdealGas(gamma = 1.4, R = 287)28return HelmholtzIdealGas(promote(gamma, R)...)29end3031@doc raw"""32helmholtz(V, T, eos::HelmholtzIdealGas)3334Returns the specific Helmholtz energy ``A(V, T)`` for an ideal gas, Klein et al.,35equation (E.1), with ``\alpha = 1/(\gamma - 1) = c_v/R``,36```math37A = - R T \left(1 + \ln\left(T^{\alpha} V\right)\right).38```39"""40function helmholtz(V, T, eos::HelmholtzIdealGas)41alpha = inv(eos.gamma - 1) # = c_v / R42return -eos.R * T * (1 + log((T^alpha) * V))43end4445@doc raw"""46temperature(V, e_internal, eos::HelmholtzIdealGas)4748This is not a required interface function, but specializing it if an explicit function is49available can improve performance. For general EOS, this is calculated via a Newton solve.5051For [`HelmholtzIdealGas`](@ref), ``e_{\text{internal}} = c_v T`` with52``c_v = R / (\gamma - 1)``, so ``T = e_{\text{internal}} / c_v``. The specific volume `V` is53unused.54"""55function temperature(V, e_internal, eos::HelmholtzIdealGas)56cv = eos.R / (eos.gamma - 1)57return e_internal / cv58end5960@doc raw"""61speed_of_sound(V, T, eos::HelmholtzIdealGas)6263Computes the speed of sound as ``\sqrt{\gamma p V}`` with ``p`` from [`pressure`](@ref) at64`(V, T, eos)`, matching [`IdealGas`](@ref) and equivalent to Klein et al., equation (C.8),65for this EOS. The general [`AbstractHelmholtzEOS`](@ref) implementation evaluates (C.8) from66derivatives of ``A(\rho, T)`` in natural variables ``(\rho, T)``.67"""68function speed_of_sound(V, T, eos::HelmholtzIdealGas)69(; gamma) = eos70p = pressure(V, T, eos)71return sqrt(gamma * p * V)72end737475