Path: blob/main/src/equations/equations_of_state_helmholtz.jl
5586 views
@doc raw"""1AbstractHelmholtzEOS23Abstract base type for a thermodynamic description based on the specific Helmholtz energy4``A(V, T)`` as a function of specific volume ``V`` and temperature ``T``.56Subtypes specialize [`helmholtz`](@ref) for arguments `(V, T, eos)`.78Derived quantities follow Klein et al., Appendix C: (C.3)--(C.5) for entropy, pressure, and9internal energy; (C.6) for specific Gibbs energy; (C.8) for speed of sound. All use specific10volume `V`, temperature `T`, and `eos` as arguments.1112Expressions and notation follow:1314- R. Klein, B. Sanderse, P. Costa, R. Pecnik, R. Henkes (2026)15Generalized Tadmor Conditions and Structure-Preserving Numerical Fluxes for the16Compressible Flow of Real Gases17[arXiv:2603.15112](https://arxiv.org/abs/2603.15112)18"""19abstract type AbstractHelmholtzEOS <: AbstractEquationOfState end2021@doc raw"""22pressure(V, T, eos::AbstractHelmholtzEOS)2324Computes pressure from specific volume `V` and temperature `T` using the Helmholtz identity25```math26p = -\frac{\partial A}{\partial V}27```28(Klein et al., equation (C.4)), where ``A`` is given by [`helmholtz`](@ref) at29`(V, T, eos)`.30"""31function pressure(V, T, eos::AbstractHelmholtzEOS)32return -ForwardDiff.derivative(V_ -> helmholtz(V_, T, eos), V)33end3435@doc raw"""36entropy_specific(V, T, eos::AbstractHelmholtzEOS)3738Computes specific entropy from specific volume `V` and temperature `T` using39```math40s = -\frac{\partial A}{\partial T}41```42(Klein et al., equation (C.3)), where ``A`` is given by [`helmholtz`](@ref) at43`(V, T, eos)`.4445This uses the same name and `(V, T, eos)` argument order as [`entropy_specific`](@ref) on46[`AbstractEquationOfState`](@ref).47"""48function entropy_specific(V, T, eos::AbstractHelmholtzEOS)49return -ForwardDiff.derivative(T_ -> helmholtz(V, T_, eos), T)50end5152@doc raw"""53energy_internal_specific(V, T, eos::AbstractHelmholtzEOS)5455Computes specific internal energy from specific volume `V` and temperature `T` using56```math57e = A - T \frac{\partial A}{\partial T}58```59(Klein et al., equation (C.5)), where ``A`` is given by [`helmholtz`](@ref) at60`(V, T, eos)`.61"""62function energy_internal_specific(V, T, eos::AbstractHelmholtzEOS)63A = helmholtz(V, T, eos)64dAdT = ForwardDiff.derivative(T_ -> helmholtz(V, T_, eos), T)65return A - T * dAdT66end6768@doc raw"""69gibbs_free_energy(V, T, eos::AbstractHelmholtzEOS)7071Computes the specific Gibbs energy using Klein et al., equation (C.6), expressed in mass72density ``\rho = 1/V`` as ``g = A + \rho \, \partial A / \partial\rho``, which is73equivalent to ``g = A + p V`` when ``A`` is the specific Helmholtz energy as a function of74`(V, T)` with ``p = -\partial A / \partial V``.75"""76function gibbs_free_energy(V, T, eos::AbstractHelmholtzEOS)77A = helmholtz(V, T, eos)78p = pressure(V, T, eos)79return A + p * V80end8182@doc raw"""83speed_of_sound(V, T, eos::AbstractHelmholtzEOS)8485Computes the speed of sound using Klein et al., equation (C.8), with ``A`` expressed in the86natural variables ``(\rho, T)`` and ``\rho = 1/V``:87```math88c^2 = 2\rho \frac{\partial A}{\partial \rho}89+ \rho^2 \frac{\partial^2 A}{\partial \rho^2}90- \frac{\left(\rho \, \partial^2 A / \partial\rho\,\partial T\right)^2}91{\partial^2 A / \partial T^2}.92```93"""94function speed_of_sound(V, T, eos::AbstractHelmholtzEOS)95rho = inv(V)96A_of_rho(r) = helmholtz(inv(r), T, eos)97Ar = ForwardDiff.derivative(A_of_rho, rho)98Arr = ForwardDiff.derivative(r -> ForwardDiff.derivative(A_of_rho, r), rho)99Att = ForwardDiff.derivative(t_ -> ForwardDiff.derivative(t__ -> helmholtz(inv(rho),100t__,101eos), t_), T)102Art = ForwardDiff.derivative(t_ -> begin103A_r(r) = helmholtz(inv(r), t_, eos)104return ForwardDiff.derivative(A_r, rho)105end, T)106c2 = 2 * rho * Ar + rho^2 * Arr - (rho * Art)^2 / Att107return sqrt(c2)108end109110111