Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/equations/equations_of_state_helmholtz.jl
5586 views
1
@doc raw"""
2
AbstractHelmholtzEOS
3
4
Abstract base type for a thermodynamic description based on the specific Helmholtz energy
5
``A(V, T)`` as a function of specific volume ``V`` and temperature ``T``.
6
7
Subtypes specialize [`helmholtz`](@ref) for arguments `(V, T, eos)`.
8
9
Derived quantities follow Klein et al., Appendix C: (C.3)--(C.5) for entropy, pressure, and
10
internal energy; (C.6) for specific Gibbs energy; (C.8) for speed of sound. All use specific
11
volume `V`, temperature `T`, and `eos` as arguments.
12
13
Expressions and notation follow:
14
15
- R. Klein, B. Sanderse, P. Costa, R. Pecnik, R. Henkes (2026)
16
Generalized Tadmor Conditions and Structure-Preserving Numerical Fluxes for the
17
Compressible Flow of Real Gases
18
[arXiv:2603.15112](https://arxiv.org/abs/2603.15112)
19
"""
20
abstract type AbstractHelmholtzEOS <: AbstractEquationOfState end
21
22
@doc raw"""
23
pressure(V, T, eos::AbstractHelmholtzEOS)
24
25
Computes pressure from specific volume `V` and temperature `T` using the Helmholtz identity
26
```math
27
p = -\frac{\partial A}{\partial V}
28
```
29
(Klein et al., equation (C.4)), where ``A`` is given by [`helmholtz`](@ref) at
30
`(V, T, eos)`.
31
"""
32
function pressure(V, T, eos::AbstractHelmholtzEOS)
33
return -ForwardDiff.derivative(V_ -> helmholtz(V_, T, eos), V)
34
end
35
36
@doc raw"""
37
entropy_specific(V, T, eos::AbstractHelmholtzEOS)
38
39
Computes specific entropy from specific volume `V` and temperature `T` using
40
```math
41
s = -\frac{\partial A}{\partial T}
42
```
43
(Klein et al., equation (C.3)), where ``A`` is given by [`helmholtz`](@ref) at
44
`(V, T, eos)`.
45
46
This uses the same name and `(V, T, eos)` argument order as [`entropy_specific`](@ref) on
47
[`AbstractEquationOfState`](@ref).
48
"""
49
function entropy_specific(V, T, eos::AbstractHelmholtzEOS)
50
return -ForwardDiff.derivative(T_ -> helmholtz(V, T_, eos), T)
51
end
52
53
@doc raw"""
54
energy_internal_specific(V, T, eos::AbstractHelmholtzEOS)
55
56
Computes specific internal energy from specific volume `V` and temperature `T` using
57
```math
58
e = A - T \frac{\partial A}{\partial T}
59
```
60
(Klein et al., equation (C.5)), where ``A`` is given by [`helmholtz`](@ref) at
61
`(V, T, eos)`.
62
"""
63
function energy_internal_specific(V, T, eos::AbstractHelmholtzEOS)
64
A = helmholtz(V, T, eos)
65
dAdT = ForwardDiff.derivative(T_ -> helmholtz(V, T_, eos), T)
66
return A - T * dAdT
67
end
68
69
@doc raw"""
70
gibbs_free_energy(V, T, eos::AbstractHelmholtzEOS)
71
72
Computes the specific Gibbs energy using Klein et al., equation (C.6), expressed in mass
73
density ``\rho = 1/V`` as ``g = A + \rho \, \partial A / \partial\rho``, which is
74
equivalent to ``g = A + p V`` when ``A`` is the specific Helmholtz energy as a function of
75
`(V, T)` with ``p = -\partial A / \partial V``.
76
"""
77
function gibbs_free_energy(V, T, eos::AbstractHelmholtzEOS)
78
A = helmholtz(V, T, eos)
79
p = pressure(V, T, eos)
80
return A + p * V
81
end
82
83
@doc raw"""
84
speed_of_sound(V, T, eos::AbstractHelmholtzEOS)
85
86
Computes the speed of sound using Klein et al., equation (C.8), with ``A`` expressed in the
87
natural variables ``(\rho, T)`` and ``\rho = 1/V``:
88
```math
89
c^2 = 2\rho \frac{\partial A}{\partial \rho}
90
+ \rho^2 \frac{\partial^2 A}{\partial \rho^2}
91
- \frac{\left(\rho \, \partial^2 A / \partial\rho\,\partial T\right)^2}
92
{\partial^2 A / \partial T^2}.
93
```
94
"""
95
function speed_of_sound(V, T, eos::AbstractHelmholtzEOS)
96
rho = inv(V)
97
A_of_rho(r) = helmholtz(inv(r), T, eos)
98
Ar = ForwardDiff.derivative(A_of_rho, rho)
99
Arr = ForwardDiff.derivative(r -> ForwardDiff.derivative(A_of_rho, r), rho)
100
Att = ForwardDiff.derivative(t_ -> ForwardDiff.derivative(t__ -> helmholtz(inv(rho),
101
t__,
102
eos), t_), T)
103
Art = ForwardDiff.derivative(t_ -> begin
104
A_r(r) = helmholtz(inv(r), t_, eos)
105
return ForwardDiff.derivative(A_r, rho)
106
end, T)
107
c2 = 2 * rho * Ar + rho^2 * Arr - (rho * Art)^2 / Att
108
return sqrt(c2)
109
end
110
111