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
20#include "shambackends/sycl.hpp"
23
24namespace shamphys {
25
31 template<class T>
33
34 static constexpr T pressure(T cs, T rho) { return cs * cs * rho; }
35 };
36
44 template<class T>
46
47 static constexpr T pressure(T gamma, T rho, T u) { return (gamma - 1) * rho * u; }
48
49 static constexpr T soundspeed(T gamma, T rho, T u) {
50 return sycl::sqrt(gamma * eos_adiabatic(gamma, rho, u) / rho);
51 }
52
53 static constexpr T cs_from_p(T gamma, T rho, T P) { return sycl::sqrt(gamma * P / rho); }
54 };
55
65 template<class T>
67
68 static constexpr T pressure(T gamma, T K, T rho) { return K * sycl::pow(rho, gamma); }
69
70 static constexpr T soundspeed(T gamma, T K, T rho) {
71 return sycl::sqrt(gamma * pressure(gamma, K, rho) / rho);
72 }
73
74 static constexpr T polytropic_index(T n) { return 1. + 1. / n; }
75 };
76
86 template<class T>
88
89 static constexpr T soundspeed_sq(T cs0sq, T Rsq, T mq) {
90 return cs0sq * sycl::pow(Rsq, mq);
91 }
92
93 static constexpr T pressure(T cs0sq, T Rsq, T mq, T rho) {
94 return soundspeed_sq(cs0sq, Rsq, mq) * rho;
95 }
96
97 static constexpr T pressure_from_cs(T cs0sq, T rho) { return cs0sq * rho; }
98 };
99
132 template<class T>
134
135 static constexpr T soundspeed(T P, T rho, T rho_c1, T rho_c2, T rho_c3) {
136 const T gamma = (rho < rho_c1) ? T(1.0)
137 : (rho < rho_c2) ? T(7.0 / 5.0)
138 : (rho < rho_c3) ? T(1.1)
139 : T(5.0 / 3.0);
140 return sycl::sqrt(gamma * P / rho);
141 }
142
143 static constexpr T temperature(T P, T rho, T mu, T mh, T kb) {
144 return mu * mh * P / (rho * kb);
145 }
146
147 static constexpr T pressure(T cs, T rho, T rho_c1, T rho_c2, T rho_c3) {
148 if (rho < rho_c1) {
149 return cs * cs * rho;
150 } else if (rho < rho_c2) {
151 return cs * cs * rho_c1 * sycl::pow(rho / rho_c1, 7. / 5.);
152 } else if (rho < rho_c3) {
153 return cs * cs * rho_c1 * sycl::pow(rho_c2 / rho_c1, 7. / 5.)
154 * sycl::pow(rho / rho_c2, 1.1);
155 } else {
156 return cs * cs * rho_c1 * sycl::pow(rho_c2 / rho_c1, 7. / 5.)
157 * sycl::pow(rho_c3 / rho_c2, 1.1) * sycl::pow(rho / rho_c3, 5. / 3.);
158 }
159 };
160 };
161
167 template<class T>
172
195 template<class T>
196 struct EOS_Fermi {
197
205 static constexpr PressureAndCs<T> pressure_and_soundspeed(T mu_e, T rho) {
206
207 constexpr T ALPHA
208 = 0.10064082802851738e-2; // = (3/(8pi))**(1./3) * h / (mp^(1/3) m_e c) (SI)
209 constexpr T BETA = 6002.332181706928e18; // = (pi/3) * m_e^4c^5/h^3 (SI)
210
211 //\tilde p_F is the Fermi momentum divided by m_e*c
212 const T mu13 = sycl::rootn(mu_e, 3);
213 T tpf = ALPHA * sycl::rootn(rho, 3) / mu13;
214 T tpf2 = tpf * tpf;
215
216 T P = BETA * (tpf * sycl::sqrt(tpf2 + 1) * (2 * tpf2 - 3) + 3 * sycl::asinh(tpf));
217 T cs2 = 8 * ALPHA * BETA * tpf2 * tpf2
218 / (3 * mu13 * sycl::powr(rho, 2. / 3.) * sycl::sqrt(1 + tpf2));
219 return {P, sycl::sqrt(cs2)};
220 }
221 };
222
223} // namespace shamphys
Adiabatic equation of state.
Definition eos.hpp:45
Fermi Gas EoS.
Definition eos.hpp:196
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:205
Isothermal equation of state.
Definition eos.hpp:32
Locally isothermal equation of state with radial dependence.
Definition eos.hpp:87
Piecewise polytropic EOS from Machida et al. (2006)
Definition eos.hpp:133
Polytropic equation of state.
Definition eos.hpp:66
PressureAndCs.
Definition eos.hpp:168
T soundspeed
sound speed value
Definition eos.hpp:170
T pressure
pressure pressure value
Definition eos.hpp:169