Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/equations/equation_of_state_ideal_gas.jl
5586 views
1
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
2
# Since these FMAs can increase the performance of many numerical algorithms,
3
# we need to opt-in explicitly.
4
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
5
@muladd begin
6
#! format: noindent
7
8
@doc raw"""
9
IdealGas{RealT <: Real} <: AbstractEquationOfState
10
11
This defines the polytropic ideal gas equation of state
12
given by the pressure and internal energy relations
13
```math
14
p = \rho R T, \quad e_{\text{internal}} = c_v T
15
```
16
with ``c_v = \frac{R}{\gamma - 1}``.
17
"""
18
struct IdealGas{RealT <: Real} <: AbstractEquationOfState
19
gamma::RealT
20
R::RealT
21
cv::RealT
22
end
23
24
"""
25
IdealGas(gamma = 1.4, R = 287)
26
27
If not specified, `R` is taken to be the gas constant for air. However, the
28
precise value does not matter since eliminating temperature yields non-dimensional
29
formulas in terms of only `gamma`.
30
"""
31
function IdealGas(gamma = 1.4, R = 287)
32
cv = R / (gamma - 1)
33
return IdealGas(promote(gamma, R, cv)...)
34
end
35
36
"""
37
pressure(V, T, eos::IdealGas)
38
39
Computes pressure for an ideal gas from primitive variables (see [`NonIdealCompressibleEulerEquations1D`](@ref))
40
specific volume `V` and temperature `T`.
41
"""
42
function pressure(V, T, eos::IdealGas)
43
(; R) = eos
44
rho = inv(V)
45
p = rho * R * T
46
return p
47
end
48
49
"""
50
energy_internal_specific(V, T, eos::IdealGas)
51
52
Computes internal energy for an ideal gas from specific volume `V` and temperature `T` as
53
``e_{\text{internal}} = c_v T``.
54
"""
55
function energy_internal_specific(V, T, eos::IdealGas)
56
(; cv) = eos
57
e_internal = cv * T
58
return e_internal
59
end
60
61
function entropy_specific(V, T, eos::IdealGas)
62
(; cv, R) = eos
63
s = cv * log(T) + R * log(V)
64
return s
65
end
66
67
function speed_of_sound(V, T, eos::IdealGas)
68
(; gamma) = eos
69
p = pressure(V, T, eos)
70
c2 = gamma * p * V
71
return sqrt(c2)
72
end
73
74
# This is not a required interface function, but specializing it
75
# if an explicit function is available can improve performance.
76
# For general EOS, this is calculated via a Newton solve.
77
function temperature(V, e_internal, eos::IdealGas)
78
(; cv) = eos
79
T = e_internal / cv
80
return T
81
end
82
end # @muladd
83
84