nmbackend 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nmbackend/__init__.py +22 -0
- nmbackend/adapters/__init__.py +4 -0
- nmbackend/adapters/rift.py +95 -0
- nmbackend/constants.py +55 -0
- nmbackend/cooling/README.md +159 -0
- nmbackend/cooling/__init__.py +13 -0
- nmbackend/cooling/build_nscool.sh +51 -0
- nmbackend/cooling/isothermal.py +76 -0
- nmbackend/cooling/nscool_nmbackend.patch +310 -0
- nmbackend/cooling/physics/__init__.py +18 -0
- nmbackend/cooling/physics/_spline.py +71 -0
- nmbackend/cooling/physics/blanket.py +66 -0
- nmbackend/cooling/physics/conduct.py +196 -0
- nmbackend/cooling/physics/core_conduct.py +68 -0
- nmbackend/cooling/physics/core_nu.py +268 -0
- nmbackend/cooling/physics/crust.py +113 -0
- nmbackend/cooling/physics/crust_nu.py +93 -0
- nmbackend/cooling/physics/curve.py +42 -0
- nmbackend/cooling/physics/envelope.py +37 -0
- nmbackend/cooling/physics/gaps.py +164 -0
- nmbackend/cooling/physics/geometry.py +131 -0
- nmbackend/cooling/physics/heat.py +125 -0
- nmbackend/cooling/physics/native.py +138 -0
- nmbackend/cooling/physics/reference.py +53 -0
- nmbackend/cooling/physics/star.py +225 -0
- nmbackend/cooling/physics/superfluid.py +41 -0
- nmbackend/cooling/physics/whole.py +136 -0
- nmbackend/cooling/runner.py +583 -0
- nmbackend/cooling/validate.py +120 -0
- nmbackend/data/crust_sly_dh2001.dat +81 -0
- nmbackend/data/frib_scenario_ladder.yaml +100 -0
- nmbackend/durca.py +111 -0
- nmbackend/ejecta.py +614 -0
- nmbackend/eos/__init__.py +19 -0
- nmbackend/eos/base.py +523 -0
- nmbackend/eos/compose.py +251 -0
- nmbackend/eos/coolcomp.py +67 -0
- nmbackend/eos/crust.py +318 -0
- nmbackend/eos/ddrmf.py +388 -0
- nmbackend/eos/hybrid.py +173 -0
- nmbackend/eos/leptons.py +74 -0
- nmbackend/eos/metamodel.py +303 -0
- nmbackend/eos/polytrope.py +33 -0
- nmbackend/eos/rmft.py +450 -0
- nmbackend/eos/skyrme.py +352 -0
- nmbackend/inference/__init__.py +13 -0
- nmbackend/inference/fisher.py +174 -0
- nmbackend/inference/synthetic.py +83 -0
- nmbackend/ipad.py +102 -0
- nmbackend/lab_likelihood.py +587 -0
- nmbackend/nscool_io.py +112 -0
- nmbackend/postmerger.py +264 -0
- nmbackend/priors/__init__.py +16 -0
- nmbackend/priors/bridge.py +437 -0
- nmbackend/priors/bridge_jax.py +435 -0
- nmbackend/priors/gp_pca.py +325 -0
- nmbackend/reference/__init__.py +11 -0
- nmbackend/reference/reprimand.py +108 -0
- nmbackend/reference/scipy_tov.py +289 -0
- nmbackend/rift/__init__.py +26 -0
- nmbackend/rift/compressed.py +194 -0
- nmbackend/rift/evidence.py +276 -0
- nmbackend/rift/sequence.py +428 -0
- nmbackend/rotating/__init__.py +7 -0
- nmbackend/rotating/rns.py +197 -0
- nmbackend/rotating/tabulated.py +249 -0
- nmbackend/thermal/__init__.py +1 -0
- nmbackend/thermal/diffusion.py +86 -0
- nmbackend/tov/__init__.py +15 -0
- nmbackend/tov/central.py +72 -0
- nmbackend/tov/family.py +155 -0
- nmbackend/tov/phase_transition.py +93 -0
- nmbackend/tov/solver.py +475 -0
- nmbackend/validation/__init__.py +5 -0
- nmbackend/validation/model_diagnostic.py +67 -0
- nmbackend/validation/reference_matrix.py +216 -0
- nmbackend-0.4.0.dist-info/METADATA +168 -0
- nmbackend-0.4.0.dist-info/RECORD +81 -0
- nmbackend-0.4.0.dist-info/WHEEL +5 -0
- nmbackend-0.4.0.dist-info/licenses/LICENSE +21 -0
- nmbackend-0.4.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"""Nuclear empirical-parameter "metamodel" EOS (physical, parameter-based).
|
|
2
|
+
|
|
3
|
+
A cold, charge-neutral, beta-equilibrium EOS of nucleons + leptons built from the
|
|
4
|
+
standard nuclear empirical parameters (NEPs). The isoscalar and isovector energy
|
|
5
|
+
per nucleon are Taylor-expanded around saturation:
|
|
6
|
+
|
|
7
|
+
x(n) = (n - n_sat) / (3 n_sat)
|
|
8
|
+
e_sat = E_sat + 1/2 K_sat x^2 + 1/6 Q_sat x^3
|
|
9
|
+
S(n) = E_sym + L_sym x + 1/2 K_sym x^2 + 1/6 Q_sym x^3
|
|
10
|
+
e_nuc = e_sat(n) + S(n) * delta^2, delta = 1 - 2 x_p (parabolic approx)
|
|
11
|
+
|
|
12
|
+
Leptons are relativistic Fermi gases with charge neutrality x_p = x_e + x_mu.
|
|
13
|
+
beta-equilibrium fixes the proton fraction x_p(n) via mu_e = (M_N - M_P) + 4 S delta.
|
|
14
|
+
By default only electrons are included (``MetaModelEOS(muons=False)``, the
|
|
15
|
+
historical behaviour, kept so existing tables are unchanged). Pass
|
|
16
|
+
``muons=True`` whenever the composition matters: muons lower the direct-Urca
|
|
17
|
+
threshold proton fraction below the npe value 1/9 and change x_p above
|
|
18
|
+
mu_e ~ m_mu (n ~ n_sat).
|
|
19
|
+
Pressure follows from the *envelope theorem*: because total energy density is
|
|
20
|
+
stationary in x_p at equilibrium, p = n d(eps)/dn - eps can be taken at fixed x_p.
|
|
21
|
+
|
|
22
|
+
A bare Taylor expansion is only trustworthy near saturation and softens
|
|
23
|
+
unphysically when extrapolated to several n_sat. Following the standard practice
|
|
24
|
+
(MetaModel+CSE in ``jester``; constant-speed-of-sound extensions), above a matching
|
|
25
|
+
density ``n_match`` (default 2 n_sat) we append a **constant-sound-speed (CSS)**
|
|
26
|
+
causal segment with dp/deps = cs2_tail. ``cs2_tail`` thus becomes a physical
|
|
27
|
+
stiffness parameter controlling the maximum mass -- a natural inference knob.
|
|
28
|
+
|
|
29
|
+
Effective masses (:func:`landau_masses`, used only for the cooling composition).
|
|
30
|
+
The Taylor energy has no kinetic/potential split, so the metamodel carries no
|
|
31
|
+
effective mass of its own. We take the form of Margueron, Hoffmann Casali &
|
|
32
|
+
Gulminelli (2018), Eqs. 15-16:
|
|
33
|
+
|
|
34
|
+
m / m*_q = 1 + (kappa_sat + tau_q kappa_sym delta) n / n_sat, tau_n = +1
|
|
35
|
+
|
|
36
|
+
with kappa_sat = m/m*_sat - 1 and kappa_sym fixed by the neutron-proton
|
|
37
|
+
splitting m*_n/m - m*_p/m = dmstar_sat in neutron matter at n_sat. Defaults
|
|
38
|
+
are their central values (Sec. II A), m*_sat/m = 0.75 and Delta m*_sat/m = 0.10
|
|
39
|
+
(``MSTAR_DEFAULTS``; override through ``params``). The same form is used
|
|
40
|
+
above n_match, like the Taylor x_p there. The EOS itself does not depend on
|
|
41
|
+
these two parameters.
|
|
42
|
+
|
|
43
|
+
This is the empirical-parameter ("physical") nuclear-matter model emphasized in the
|
|
44
|
+
project notes. Below n_t the table uses the SLy crust (``eos.crust``); the
|
|
45
|
+
legacy polytrope surface continuation is ``crust="polytrope"``.
|
|
46
|
+
|
|
47
|
+
Motivated by: Margueron, Hoffmann Casali & Gulminelli PRC 97 (2018) 025805; the
|
|
48
|
+
``jester`` MetaModel (MIT); the RMF parameterization in Z. Zhu's ``fisher_eos``
|
|
49
|
+
(motivated-by only -- see ATTRIBUTION.md).
|
|
50
|
+
"""
|
|
51
|
+
from __future__ import annotations
|
|
52
|
+
|
|
53
|
+
import math
|
|
54
|
+
import jax
|
|
55
|
+
import jax.numpy as jnp
|
|
56
|
+
|
|
57
|
+
from ..constants import HBARC, M_N, M_P, M_E, N_SAT_DEFAULT
|
|
58
|
+
from .base import EOSModel, Composition, compiled_method, compiled_table
|
|
59
|
+
from .leptons import lepton_sector
|
|
60
|
+
from .crust import (N_T_DEFAULT, check_crust, finish_table_flags, join_density,
|
|
61
|
+
monotone_core)
|
|
62
|
+
|
|
63
|
+
jax.config.update("jax_enable_x64", True)
|
|
64
|
+
|
|
65
|
+
#: Default NEPs (MeV; n_sat in fm^-3) plus high-density extension controls.
|
|
66
|
+
DEFAULT_PARAMS = dict(
|
|
67
|
+
n_sat=N_SAT_DEFAULT,
|
|
68
|
+
E_sat=-16.0, K_sat=230.0, Q_sat=-300.0,
|
|
69
|
+
E_sym=32.0, L_sym=60.0, K_sym=-100.0, Q_sym=0.0,
|
|
70
|
+
cs2_tail=0.4, # constant sound speed^2 of the causal high-density segment
|
|
71
|
+
n_match_fac=2.0, # matching density in units of n_sat
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
#: Effective-mass prescription (Margueron+2018 central values); composition only.
|
|
75
|
+
MSTAR_DEFAULTS = dict(mstar_sat=0.75, dmstar_sat=0.10)
|
|
76
|
+
|
|
77
|
+
_PI = math.pi
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _eps_electron(n_e):
|
|
81
|
+
"""Relativistic electron-gas energy density, MeV/fm^3 (n_e in fm^-3)."""
|
|
82
|
+
n_e = jnp.maximum(n_e, 1e-30)
|
|
83
|
+
kF = HBARC * (3.0 * _PI**2 * n_e) ** (1.0 / 3.0) # MeV
|
|
84
|
+
m = M_E
|
|
85
|
+
EF = jnp.sqrt(kF**2 + m**2)
|
|
86
|
+
term = kF * EF * (2.0 * kF**2 + m**2) - m**4 * jnp.log((kF + EF) / m)
|
|
87
|
+
return term / (8.0 * _PI**2 * HBARC**3)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _mu_electron(n_e):
|
|
91
|
+
"""Electron chemical potential mu_e = E_F, MeV."""
|
|
92
|
+
n_e = jnp.maximum(n_e, 1e-30)
|
|
93
|
+
kF = HBARC * (3.0 * _PI**2 * n_e) ** (1.0 / 3.0)
|
|
94
|
+
return jnp.sqrt(kF**2 + M_E**2)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _esat_S(n, p):
|
|
98
|
+
"""Isoscalar e_sat(n) and symmetry energy S(n), MeV."""
|
|
99
|
+
x = (n - p["n_sat"]) / (3.0 * p["n_sat"])
|
|
100
|
+
e_sat = p["E_sat"] + 0.5 * p["K_sat"] * x**2 + (1.0 / 6.0) * p["Q_sat"] * x**3
|
|
101
|
+
S = (p["E_sym"] + p["L_sym"] * x + 0.5 * p["K_sym"] * x**2
|
|
102
|
+
+ (1.0 / 6.0) * p["Q_sym"] * x**3)
|
|
103
|
+
return e_sat, S
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _eps_total(n, x_p, p, muons=False):
|
|
107
|
+
"""Total energy density (nucleons + leptons), MeV/fm^3, incl. rest mass."""
|
|
108
|
+
e_sat, S = _esat_S(n, p)
|
|
109
|
+
delta = 1.0 - 2.0 * x_p
|
|
110
|
+
e_per_baryon = (x_p * M_P + (1.0 - x_p) * M_N + e_sat + S * delta**2)
|
|
111
|
+
eps_b = n * e_per_baryon
|
|
112
|
+
if muons:
|
|
113
|
+
eps_l = lepton_sector(x_p * n, muons=True)[3] * HBARC
|
|
114
|
+
else:
|
|
115
|
+
eps_l = _eps_electron(x_p * n)
|
|
116
|
+
return eps_b + eps_l
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _solve_xp(n, p, n_iter=70, muons=False, S=None):
|
|
120
|
+
"""beta-equilibrium proton fraction x_p(n), differentiable w.r.t. params.
|
|
121
|
+
|
|
122
|
+
The forward solve is a robust vectorized bisection (non-differentiable); we
|
|
123
|
+
then take a single Newton step at the converged root so that AD recovers the
|
|
124
|
+
correct implicit derivative dx_p/dparam = -(dg/dparam)/(dg/dx_p).
|
|
125
|
+
``S`` overrides the Taylor symmetry energy on ``n`` if given.
|
|
126
|
+
"""
|
|
127
|
+
if S is None:
|
|
128
|
+
_, S = _esat_S(n, p)
|
|
129
|
+
|
|
130
|
+
def g(x_p):
|
|
131
|
+
delta = 1.0 - 2.0 * x_p
|
|
132
|
+
if muons: # charge neutrality n_p = n_e + n_mu, mu_mu = mu_e
|
|
133
|
+
mu_e = lepton_sector(x_p * n, muons=True)[0] * HBARC
|
|
134
|
+
else:
|
|
135
|
+
mu_e = _mu_electron(x_p * n)
|
|
136
|
+
return mu_e - ((M_N - M_P) + 4.0 * S * delta)
|
|
137
|
+
|
|
138
|
+
lo = jnp.full_like(n, 1e-6)
|
|
139
|
+
hi = jnp.full_like(n, 0.5 - 1e-9)
|
|
140
|
+
|
|
141
|
+
def body(_, carry):
|
|
142
|
+
lo, hi = carry
|
|
143
|
+
mid = 0.5 * (lo + hi)
|
|
144
|
+
gm = g(mid) # g increasing in x_p
|
|
145
|
+
lo = jnp.where(gm < 0.0, mid, lo)
|
|
146
|
+
hi = jnp.where(gm < 0.0, hi, mid)
|
|
147
|
+
return lo, hi
|
|
148
|
+
|
|
149
|
+
lo, hi = jax.lax.fori_loop(0, n_iter, body, (lo, hi))
|
|
150
|
+
x0 = jax.lax.stop_gradient(0.5 * (lo + hi))
|
|
151
|
+
|
|
152
|
+
# one differentiable Newton step (implicit differentiation)
|
|
153
|
+
gx = g(x0)
|
|
154
|
+
dg = jax.grad(lambda xp: jnp.sum(g(xp)))(x0)
|
|
155
|
+
return x0 - gx / dg
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def landau_masses(params, n, x_p):
|
|
159
|
+
"""(m*_n/m, m*_p/m) of the Margueron+2018 prescription (module docstring)."""
|
|
160
|
+
p = dict(DEFAULT_PARAMS, **MSTAR_DEFAULTS)
|
|
161
|
+
p.update(params or {})
|
|
162
|
+
n = jnp.asarray(n, float)
|
|
163
|
+
delta = 1.0 - 2.0 * jnp.asarray(x_p, float)
|
|
164
|
+
a = 1.0 / p["mstar_sat"] # 1 + kappa_sat
|
|
165
|
+
d = p["dmstar_sat"]
|
|
166
|
+
# 1/(a + k) - 1/(a - k) = d, the root with |k| < a
|
|
167
|
+
k_sym = -d * a**2 / (1.0 + jnp.sqrt(1.0 + (d * a) ** 2))
|
|
168
|
+
u = n / p["n_sat"]
|
|
169
|
+
inv = lambda tau: 1.0 + (a - 1.0 + tau * k_sym * delta) * u
|
|
170
|
+
return 1.0 / inv(1.0), 1.0 / inv(-1.0)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class MetaModelEOS(EOSModel):
|
|
174
|
+
"""Empirical-parameter nuclear-matter EOS (NEP metamodel) + CSS tail."""
|
|
175
|
+
|
|
176
|
+
name = "MetaModelEOS"
|
|
177
|
+
|
|
178
|
+
def __init__(self, n_min=3e-4, n_points_low=240, n_points_tail=160,
|
|
179
|
+
eps_max_fac=14.0, n_surface=1e-7, gamma_crust=1.3,
|
|
180
|
+
muons=False, s_high="taylor", crust="sly", n_t=N_T_DEFAULT,
|
|
181
|
+
allow_unstable_core=False):
|
|
182
|
+
if s_high not in ("taylor", "power", "power_matched"):
|
|
183
|
+
raise ValueError(f"unknown s_high={s_high!r}")
|
|
184
|
+
self.muons = muons
|
|
185
|
+
self.s_high = s_high
|
|
186
|
+
self.n_min = n_min
|
|
187
|
+
self.n_points_low = n_points_low
|
|
188
|
+
self.n_points_tail = n_points_tail
|
|
189
|
+
self.eps_max_fac = eps_max_fac
|
|
190
|
+
# low-density completion (eos.crust.finish_table): the SLy crust below
|
|
191
|
+
# n_t, or with crust="polytrope" the legacy surface continuation
|
|
192
|
+
# (n_surface, gamma_crust). n_surface=None disables both and recovers
|
|
193
|
+
# the old truncated-at-n_min behaviour.
|
|
194
|
+
self.n_surface = n_surface
|
|
195
|
+
self.gamma_crust = gamma_crust
|
|
196
|
+
self.crust = check_crust(crust, n_surface)
|
|
197
|
+
self.n_t = n_t
|
|
198
|
+
# True keeps cores whose raw pressure falls with density (plateau
|
|
199
|
+
# tables; see eos.crust.monotone_core) instead of rejecting them
|
|
200
|
+
self.allow_unstable_core = allow_unstable_core
|
|
201
|
+
|
|
202
|
+
def _low_density(self, p, n_min=None, onset=False):
|
|
203
|
+
"""Taylor metamodel part on n in [n_min, n_match]; MeV/fm^3, fm^-3.
|
|
204
|
+
``onset=True`` also returns ln n_u of :func:`eos.crust.monotone_core`."""
|
|
205
|
+
n_match = p["n_match_fac"] * p["n_sat"]
|
|
206
|
+
n_min = self.n_min if n_min is None else n_min
|
|
207
|
+
n = jnp.exp(jnp.linspace(math.log(n_min), jnp.log(n_match),
|
|
208
|
+
self.n_points_low))
|
|
209
|
+
# x_p is differentiable w.r.t. params; the inner pressure derivative below
|
|
210
|
+
# differentiates only w.r.t. n, so x_p is correctly held fixed there.
|
|
211
|
+
mu = self.muons
|
|
212
|
+
x_p = _solve_xp(n, p, muons=mu)
|
|
213
|
+
eps = jax.vmap(lambda ni, xi: _eps_total(ni, xi, p, mu))(n, x_p)
|
|
214
|
+
deps_dn = jax.vmap(
|
|
215
|
+
lambda ni, xi: jax.grad(lambda nn: _eps_total(nn, xi, p, mu))(ni)
|
|
216
|
+
)(n, x_p)
|
|
217
|
+
pres, ln_nu = monotone_core(n, n * deps_dn - eps, self.n_t)
|
|
218
|
+
return (n, eps, pres, ln_nu) if onset else (n, eps, pres)
|
|
219
|
+
|
|
220
|
+
def _css_tail(self, n_m, eps_m, p_m, p):
|
|
221
|
+
"""Constant-sound-speed causal extension above the match point.
|
|
222
|
+
|
|
223
|
+
dp/deps = cs2_tail => p = p_m + cs2 (eps - eps_m). The baryon density
|
|
224
|
+
follows from dln n = deps/(eps+p), which integrates in closed form.
|
|
225
|
+
"""
|
|
226
|
+
cs2 = p["cs2_tail"]
|
|
227
|
+
eps = jnp.exp(jnp.linspace(jnp.log(eps_m * (1.0 + 1e-3)),
|
|
228
|
+
jnp.log(eps_m * self.eps_max_fac),
|
|
229
|
+
self.n_points_tail))
|
|
230
|
+
pres = p_m + cs2 * (eps - eps_m)
|
|
231
|
+
c0 = p_m - cs2 * eps_m
|
|
232
|
+
lin = (1.0 + cs2) * eps + c0
|
|
233
|
+
lin_m = (1.0 + cs2) * eps_m + c0
|
|
234
|
+
n = n_m * (lin / lin_m) ** (1.0 / (1.0 + cs2))
|
|
235
|
+
return n, eps, pres
|
|
236
|
+
|
|
237
|
+
def composition(self, params: dict = None) -> Composition:
|
|
238
|
+
"""beta-equilibrium (x_p, x_e, x_mu) on the table's density grid.
|
|
239
|
+
|
|
240
|
+
Below n_match this is the composition of the EOS itself. Above n_match
|
|
241
|
+
the pressure comes from the CSS tail, which carries no composition; there
|
|
242
|
+
x_p is the beta-equilibrium solution of the Taylor S(n) extrapolated past
|
|
243
|
+
n_match. That is a modelling choice (as in MetaModel+CSE dUrca studies),
|
|
244
|
+
not a property of the tail. Leptons follow ``self.muons``.
|
|
245
|
+
|
|
246
|
+
``s_high`` (constructor) replaces the Taylor S(n) above n_match by a
|
|
247
|
+
bounded power law S(n_match) (n/n_match)^g. For "power",
|
|
248
|
+
g = params["gamma_S"] (default 0.5); for "power_matched", g is the
|
|
249
|
+
slope-matched n S'/S at n_match, clipped to [0, 1]. The pressure is
|
|
250
|
+
unchanged (it comes from the tail).
|
|
251
|
+
"""
|
|
252
|
+
p = dict(DEFAULT_PARAMS)
|
|
253
|
+
if params:
|
|
254
|
+
p.update(params)
|
|
255
|
+
return compiled_method(self, "_composition", p)
|
|
256
|
+
|
|
257
|
+
def _composition(self, p):
|
|
258
|
+
n_lo, eps_lo, p_lo = self._low_density(p)
|
|
259
|
+
n_t, _, _ = self._css_tail(n_lo[-1], eps_lo[-1], p_lo[-1], p)
|
|
260
|
+
n = jnp.concatenate([n_lo, n_t])
|
|
261
|
+
S = None
|
|
262
|
+
if self.s_high != "taylor":
|
|
263
|
+
n_m = n_lo[-1]
|
|
264
|
+
_, S = _esat_S(n, p)
|
|
265
|
+
S_m = _esat_S(n_m, p)[1]
|
|
266
|
+
if self.s_high == "power":
|
|
267
|
+
g = p.get("gamma_S", 0.5)
|
|
268
|
+
else:
|
|
269
|
+
dS = jax.grad(lambda x: _esat_S(x, p)[1])(n_m)
|
|
270
|
+
g = jnp.clip(n_m * dS / S_m, 0.0, 1.0)
|
|
271
|
+
S = jnp.where(n <= n_m, S, S_m * (n / n_m) ** g)
|
|
272
|
+
x_p = jnp.clip(_solve_xp(n, p, muons=self.muons, S=S), 0.0, 0.5)
|
|
273
|
+
if self.muons:
|
|
274
|
+
_, n_e, n_mu, _ = lepton_sector(x_p * n, muons=True)
|
|
275
|
+
x_e, x_mu = n_e / n, n_mu / n
|
|
276
|
+
else:
|
|
277
|
+
x_e, x_mu = x_p, jnp.zeros_like(x_p)
|
|
278
|
+
return Composition(n=n, x_p=x_p, x_e=x_e, x_mu=x_mu)
|
|
279
|
+
|
|
280
|
+
def landau_masses(self, params, comp):
|
|
281
|
+
"""(m*_n/m, m*_p/m) on ``comp`` (see :func:`landau_masses`)."""
|
|
282
|
+
return landau_masses(params, comp.n, comp.x_p)
|
|
283
|
+
|
|
284
|
+
def eos_table(self, params: dict = None):
|
|
285
|
+
p = dict(DEFAULT_PARAMS)
|
|
286
|
+
if params:
|
|
287
|
+
p.update(params)
|
|
288
|
+
return compiled_table(self, p)
|
|
289
|
+
|
|
290
|
+
def _table_flags(self, p):
|
|
291
|
+
sly = self.crust == "sly" and self.n_surface is not None
|
|
292
|
+
n_lo, eps_lo, p_lo, ln_nu = self._low_density(
|
|
293
|
+
p, n_min=join_density(self.n_t) if sly else None, onset=True)
|
|
294
|
+
n_t, eps_t, p_t = self._css_tail(n_lo[-1], eps_lo[-1], p_lo[-1], p)
|
|
295
|
+
|
|
296
|
+
n = jnp.concatenate([n_lo, n_t])
|
|
297
|
+
eps = jnp.concatenate([eps_lo, eps_t])
|
|
298
|
+
pres = jnp.concatenate([p_lo, p_t])
|
|
299
|
+
pres = jax.lax.cummax(jnp.maximum(pres, 1e-9))
|
|
300
|
+
|
|
301
|
+
return finish_table_flags(n, eps, pres, self.crust, self.n_t,
|
|
302
|
+
self.n_surface, self.gamma_crust, ln_nu,
|
|
303
|
+
self.allow_unstable_core)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Single relativistic polytrope -- a clean, analytic EOS for solver validation.
|
|
2
|
+
|
|
3
|
+
p = K n^Gamma (MeV/fm^3), eps = n m_b + p/(Gamma-1). Not meant as a physical
|
|
4
|
+
NS EOS; it gives an independent, well-behaved barotrope to exercise and validate
|
|
5
|
+
the TOV solver and the AD machinery.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import math
|
|
10
|
+
import jax.numpy as jnp
|
|
11
|
+
|
|
12
|
+
from ..constants import M_BARYON
|
|
13
|
+
from .base import EOSModel, build_h_and_cs2
|
|
14
|
+
|
|
15
|
+
DEFAULT_PARAMS = dict(K=120.0, Gamma=2.0)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class PolytropeEOS(EOSModel):
|
|
19
|
+
name = "PolytropeEOS"
|
|
20
|
+
|
|
21
|
+
def __init__(self, n_min=1e-4, n_max=2.5, n_points=400):
|
|
22
|
+
self.n_grid = jnp.exp(
|
|
23
|
+
jnp.linspace(math.log(n_min), math.log(n_max), n_points)
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
def eos_table(self, params: dict = None):
|
|
27
|
+
p = dict(DEFAULT_PARAMS)
|
|
28
|
+
if params:
|
|
29
|
+
p.update(params)
|
|
30
|
+
n = self.n_grid
|
|
31
|
+
pres = p["K"] * n ** p["Gamma"] # MeV/fm^3
|
|
32
|
+
eps = n * M_BARYON + pres / (p["Gamma"] - 1.0) # MeV/fm^3
|
|
33
|
+
return build_h_and_cs2(n, eps, pres)
|