Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
eos.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
19
20#include "shambackends/sycl.hpp"
21
22namespace shamphys {
23
29 template<class T>
31
32 static constexpr T pressure(T cs, T rho) { return cs * cs * rho; }
33 };
34
42 template<class T>
44
45 static constexpr T pressure(T gamma, T rho, T u) { return (gamma - 1) * rho * u; }
46
47 static constexpr T soundspeed(T gamma, T rho, T u) {
48 return sycl::sqrt(gamma * eos_adiabatic(gamma, rho, u) / rho);
49 }
50
51 static constexpr T cs_from_p(T gamma, T rho, T P) { return sycl::sqrt(gamma * P / rho); }
52 };
53
63 template<class T>
65
66 static constexpr T pressure(T gamma, T K, T rho) { return K * sycl::pow(rho, gamma); }
67
68 static constexpr T soundspeed(T gamma, T K, T rho) {
69 return sycl::sqrt(gamma * pressure(gamma, K, rho) / rho);
70 }
71
72 static constexpr T polytropic_index(T n) { return 1. + 1. / n; }
73 };
74
88 template<class T>
90
92 static constexpr T adiab_ratio(T rho, T rho0, T gamma0) {
93 return sycl::pow(rho / rho0, gamma0 - 1);
94 }
95
96 static constexpr T pressure(T cs0, T rho0, T gamma0, T rho) {
97 return cs0 * cs0 * rho * (1 + adiab_ratio(rho, rho0, gamma0));
98 }
99
100 static constexpr T soundspeed(T cs0, T rho0, T gamma0, T rho) {
101 return cs0 * sycl::sqrt(1 + gamma0 * adiab_ratio(rho, rho0, gamma0));
102 }
103 };
104
114 template<class T>
116
117 static constexpr T soundspeed_sq(T cs0sq, T Rsq, T mq) {
118 return cs0sq * sycl::pow(Rsq, mq);
119 }
120
121 static constexpr T pressure(T cs0sq, T Rsq, T mq, T rho) {
122 return soundspeed_sq(cs0sq, Rsq, mq) * rho;
123 }
124
125 static constexpr T pressure_from_cs(T cs0sq, T rho) { return cs0sq * rho; }
126 };
127
160 template<class T>
162
163 static constexpr T soundspeed(T P, T rho, T rho_c1, T rho_c2, T rho_c3) {
164 const T gamma = (rho < rho_c1) ? T(1.0)
165 : (rho < rho_c2) ? T(7.0 / 5.0)
166 : (rho < rho_c3) ? T(1.1)
167 : T(5.0 / 3.0);
168 return sycl::sqrt(gamma * P / rho);
169 }
170
171 static constexpr T temperature(T P, T rho, T mu, T mh, T kb) {
172 return mu * mh * P / (rho * kb);
173 }
174
175 static constexpr T pressure(T cs, T rho, T rho_c1, T rho_c2, T rho_c3) {
176 if (rho < rho_c1) {
177 return cs * cs * rho;
178 } else if (rho < rho_c2) {
179 return cs * cs * rho_c1 * sycl::pow(rho / rho_c1, 7. / 5.);
180 } else if (rho < rho_c3) {
181 return cs * cs * rho_c1 * sycl::pow(rho_c2 / rho_c1, 7. / 5.)
182 * sycl::pow(rho / rho_c2, 1.1);
183 } else {
184 return cs * cs * rho_c1 * sycl::pow(rho_c2 / rho_c1, 7. / 5.)
185 * sycl::pow(rho_c3 / rho_c2, 1.1) * sycl::pow(rho / rho_c3, 5. / 3.);
186 }
187 };
188 };
189
195 template<class T>
200
223 template<class T>
224 struct EOS_Fermi {
225
233 static constexpr PressureAndCs<T> pressure_and_soundspeed(T mu_e, T rho) {
234
235 constexpr T ALPHA
236 = 0.10064082802851738e-2; // = (3/(8pi))**(1./3) * h / (mp^(1/3) m_e c) (SI)
237 constexpr T BETA = 6002.332181706928e18; // = (pi/3) * m_e^4c^5/h^3 (SI)
238
239 //\tilde p_F is the Fermi momentum divided by m_e*c
240 const T mu13 = sycl::rootn(mu_e, 3);
241 T tpf = ALPHA * sycl::rootn(rho, 3) / mu13;
242 T tpf2 = tpf * tpf;
243
244 T P = BETA * (tpf * sycl::sqrt(tpf2 + 1) * (2 * tpf2 - 3) + 3 * sycl::asinh(tpf));
245 T cs2 = 8 * ALPHA * BETA * tpf2 * tpf2
246 / (3 * mu13 * sycl::powr(rho, 2. / 3.) * sycl::sqrt(1 + tpf2));
247 return {P, sycl::sqrt(cs2)};
248 }
249 };
250
251} // namespace shamphys
Adiabatic equation of state.
Definition eos.hpp:43
Barotropic equation of state, isothermal at low density and adiabatic at high density (e....
Definition eos.hpp:89
static constexpr T adiab_ratio(T rho, T rho0, T gamma0)
, ratio of the adiabatic to isothermal pressure
Definition eos.hpp:92
Fermi Gas EoS.
Definition eos.hpp:224
static constexpr PressureAndCs< T > pressure_and_soundspeed(T mu_e, T rho)
EOS_Fermi::pressure_and_soundspeed Returns pressure and sound speed from the given value of density i...
Definition eos.hpp:233
Isothermal equation of state.
Definition eos.hpp:30
Locally isothermal equation of state with radial dependence.
Definition eos.hpp:115
Piecewise polytropic EOS from Machida et al. (2006).
Definition eos.hpp:161
Polytropic equation of state.
Definition eos.hpp:64
PressureAndCs.
Definition eos.hpp:196
T soundspeed
sound speed value
Definition eos.hpp:198
T pressure
pressure pressure value
Definition eos.hpp:197