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,164 @@
|
|
|
1
|
+
"""Pairing critical temperatures Tc(k_F), as NSCool's ``get_Tc`` builds them.
|
|
2
|
+
|
|
3
|
+
Fits (NSCool ``tc.f``; k_F in fm^-1, Tc in K):
|
|
4
|
+
|
|
5
|
+
| NSCool code | channel | source | form |
|
|
6
|
+
|---|---|---|---|
|
|
7
|
+
| SFN1S0 = 1 | n1S0 | SFB, Schwenk, Friman & Brown 2003 | spline of Delta(k_F), Tc = Delta / 1.76 |
|
|
8
|
+
| SFN1S0 = 2 | n1S0 | CCDK, Chen et al. 1993 | same |
|
|
9
|
+
| SFN3P2 = 101, 102, 103 | n3P2 | gaps "a", "b", "c" of Page et al. 2004 | Gaussian in k_F |
|
|
10
|
+
| SFP1S0 = 3 | p1S0 | T73, Takatsuka 1973 | spline of Tc(k_F), NSCool's y'' |
|
|
11
|
+
| SFP1S0 = 7 | p1S0 | CCDK | spline of Delta(k_F) |
|
|
12
|
+
|
|
13
|
+
Zhou+2026 Eq. 10 scalings, Delta(n) = s_y Delta_0(n / s_x), act as in the
|
|
14
|
+
nmbackend NSCool patch: s_y multiplies Tc (FN3P2, FP1S0); s_x evaluates the
|
|
15
|
+
gap at the k_F the star has at baryon density n / s_x (core zones only).
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from typing import NamedTuple
|
|
20
|
+
|
|
21
|
+
import jax.numpy as jnp
|
|
22
|
+
import numpy as np
|
|
23
|
+
|
|
24
|
+
from ._spline import spline_y2, splint
|
|
25
|
+
|
|
26
|
+
__all__ = ["tc_n1s0", "tc_p1s0", "tc_n3p2_gauss", "N3P2_GAUSS", "kf_scaled",
|
|
27
|
+
"StarTc", "star_tc"]
|
|
28
|
+
|
|
29
|
+
_MEV_K = 1.1604e10 / 1.76 # Delta [MeV] -> Tc [K], as in tc.f
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _f32(v):
|
|
33
|
+
"""Single-precision literals of NSCool DATA statements, widened."""
|
|
34
|
+
return np.asarray(v, np.float32).astype(float)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class _Table(NamedTuple):
|
|
38
|
+
k: np.ndarray
|
|
39
|
+
t: np.ndarray
|
|
40
|
+
y2: np.ndarray
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# n1S0 SFB (tcn1_sfb): the spline is of Delta in MeV, scaled after.
|
|
44
|
+
_K = np.array([0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1.0, 1.1, 1.175, 1.25, 1.3,
|
|
45
|
+
1.35, 1.4, 1.45])
|
|
46
|
+
_D = np.array([0, 0, .09, .21, .35, .49, .61, .72, .79, .78, .70, .57, .44, .28,
|
|
47
|
+
.19, .10, .03, 0])
|
|
48
|
+
_SFB = _Table(_K, _D, spline_y2(_K, _D, 0.0, 0.0))
|
|
49
|
+
# n1S0 CCDK (tcn1_ccdk): spline of Tc
|
|
50
|
+
_K = np.round(np.arange(1, 12) * 0.1, 2)
|
|
51
|
+
_D = np.array([0, .02, .14, .36, .60, .83, .86, .67, .35, .07, 0]) * _MEV_K
|
|
52
|
+
_CCDK_N = _Table(_K, _D, spline_y2(_K, _D, 0.0, 0.0))
|
|
53
|
+
# p1S0 CCDK (tcp1_ccdk)
|
|
54
|
+
_K = np.round(np.arange(0, 14) * 0.1, 2)
|
|
55
|
+
_D = np.array([0, .05, .19, .41, .66, .84, .97, 1.0, .90, .72, .49, .22, .07, 0]) * _MEV_K
|
|
56
|
+
_CCDK_P = _Table(_K, _D, spline_y2(_K, _D, 0.0, 0.0))
|
|
57
|
+
# p1S0 T73 (tcp1_t73): Tc and its y'' are tabulated (single precision)
|
|
58
|
+
_T73 = _Table(_f32([0.00, 0.30, 0.41, 0.48, 0.53, 0.58, 0.63, 0.67, 0.72, 0.76, 0.80, 0.84]),
|
|
59
|
+
_f32([0.00e0, 7.58e8, 2.27e9, 3.03e9, 3.29e9, 3.00e9, 2.55e9, 2.11e9,
|
|
60
|
+
1.50e9, 8.45e8, 3.29e7, 0.00e0]),
|
|
61
|
+
_f32([-2.49e+10, +1.00e+11, -6.79e+10, -5.58e+10, -3.16e+11, -1.03e+09,
|
|
62
|
+
-6.41e+10, -1.04e+10, -5.55e+10, -3.64e+11, +9.21e+11, -3.99e+11]))
|
|
63
|
+
del _K, _D
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _table_tc(tab: _Table, kf, scale=1.0):
|
|
67
|
+
"""Tc from a table; 0 at or outside its k_F range (as tc.f)."""
|
|
68
|
+
inside = (kf > tab.k[0]) & (kf < tab.k[-1])
|
|
69
|
+
k = jnp.clip(kf, tab.k[0], tab.k[-1])
|
|
70
|
+
return jnp.where(inside, scale * splint(tab.k, tab.t, tab.y2, k), 0.0)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def tc_n1s0(code, kf):
|
|
74
|
+
"""Neutron 1S0 Tc (K) for NSCool code SFN1S0 (1 SFB, 2 CCDK), before the floor at 1 K."""
|
|
75
|
+
if code == 1:
|
|
76
|
+
return _table_tc(_SFB, kf, _MEV_K)
|
|
77
|
+
if code == 2:
|
|
78
|
+
return _table_tc(_CCDK_N, kf)
|
|
79
|
+
raise NotImplementedError(f"SFN1S0 = {code}")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def tc_p1s0(code, kf):
|
|
83
|
+
"""Proton 1S0 Tc (K) for NSCool code SFP1S0 (3 T73, 7 CCDK), before the floor."""
|
|
84
|
+
if code == 3:
|
|
85
|
+
return _table_tc(_T73, kf)
|
|
86
|
+
if code == 7:
|
|
87
|
+
return _table_tc(_CCDK_P, kf)
|
|
88
|
+
raise NotImplementedError(f"SFP1S0 = {code}")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
#: SFN3P2 code -> (k_F of the maximum [fm^-1], width [fm^-1], Tc max [K])
|
|
92
|
+
N3P2_GAUSS = {101: (1.8, 0.5, 1.0e9), 102: (2.0, 0.5, 3.0e9), 103: (2.5, 0.7, 1.0e10)}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def tc_n3p2_gauss(kf, kf_max, dkf, tc_max):
|
|
96
|
+
"""Neutron 3P2 Tc of the minimal-cooling gaps (Page et al. 2004)."""
|
|
97
|
+
return tc_max * jnp.exp(-(kf - kf_max) ** 2 / dkf ** 2)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def kf_scaled(sx, kf, nb, icore: int):
|
|
101
|
+
"""k_F at baryon density n / s_x in the core (NSCool patch, get_kf_scaled).
|
|
102
|
+
|
|
103
|
+
Linear in n between core zones; k_F ~ n^(1/3) beyond the centre or the
|
|
104
|
+
core boundary; crust zones (i > icore) unchanged. ``nb`` decreases
|
|
105
|
+
outwards from the centre (zone 0).
|
|
106
|
+
"""
|
|
107
|
+
kf, nb = jnp.asarray(kf), jnp.asarray(nb)
|
|
108
|
+
b = nb[:icore + 1] / sx
|
|
109
|
+
xs, ys = nb[icore::-1], kf[icore::-1] # ascending n
|
|
110
|
+
mid = jnp.interp(b, xs, ys)
|
|
111
|
+
hi = kf[0] * (b / nb[0]) ** (1.0 / 3.0)
|
|
112
|
+
lo = kf[icore] * (b / nb[icore]) ** (1.0 / 3.0)
|
|
113
|
+
core = jnp.where(b >= nb[0], hi, jnp.where(b <= nb[icore], lo, mid))
|
|
114
|
+
return jnp.concatenate([core, kf[icore + 1:]])
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class StarTc(NamedTuple):
|
|
118
|
+
tcn: jnp.ndarray # neutron Tc per zone (K); 1 K means unpaired
|
|
119
|
+
tcp: jnp.ndarray # proton Tc per zone (K)
|
|
120
|
+
isf: jnp.ndarray # end of the run of n3P2 zones from the centre (NSCool isf; -1 if none)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def star_tc(gaps, kfn, kfp, nb, icore: int, idrip: int, *, sy_n3p2=None,
|
|
124
|
+
sx_n3p2=None, sy_p1s0=None, sx_p1s0=None, n3p2_params=None) -> StarTc:
|
|
125
|
+
"""NSCool ``get_Tc`` on a star's zones (index 0 = centre).
|
|
126
|
+
|
|
127
|
+
``gaps`` is a ``GapModel`` (only its integer codes are used here unless
|
|
128
|
+
the keyword overrides are None). The scalings and the 3P2 Gaussian
|
|
129
|
+
parameters can be passed as JAX values to differentiate through them.
|
|
130
|
+
``isf`` follows get_Tc for codes 101-103: the run of zones from the
|
|
131
|
+
centre in which the 3P2 Tc is at least the 1S0 Tc.
|
|
132
|
+
"""
|
|
133
|
+
for c in (gaps.n1s0, gaps.n3p2, gaps.p1s0):
|
|
134
|
+
if c != int(c):
|
|
135
|
+
raise ValueError(f"gap code {c} is not an integer (NSCool matches none)")
|
|
136
|
+
sy_n3p2 = gaps.sy_n3p2 if sy_n3p2 is None else sy_n3p2
|
|
137
|
+
sx_n3p2 = gaps.sx_n3p2 if sx_n3p2 is None else sx_n3p2
|
|
138
|
+
sy_p1s0 = gaps.sy_p1s0 if sy_p1s0 is None else sy_p1s0
|
|
139
|
+
sx_p1s0 = gaps.sx_p1s0 if sx_p1s0 is None else sx_p1s0
|
|
140
|
+
kfn, kfp, nb = jnp.asarray(kfn), jnp.asarray(kfp), jnp.asarray(nb)
|
|
141
|
+
i = jnp.arange(kfn.shape[0])
|
|
142
|
+
one = jnp.ones_like(kfn)
|
|
143
|
+
# n1S0 (FN1S0 = 1 in GapModel)
|
|
144
|
+
tcn = one
|
|
145
|
+
if gaps.n1s0 != 0:
|
|
146
|
+
tcn = jnp.where(i <= idrip, jnp.maximum(1.0, tc_n1s0(int(gaps.n1s0), kfn)), 1.0)
|
|
147
|
+
# n3P2
|
|
148
|
+
isf = jnp.asarray(-1)
|
|
149
|
+
if gaps.n3p2 != 0:
|
|
150
|
+
code = int(gaps.n3p2)
|
|
151
|
+
if code not in N3P2_GAUSS:
|
|
152
|
+
raise NotImplementedError(f"SFN3P2 = {code}")
|
|
153
|
+
par = N3P2_GAUSS[code] if n3p2_params is None else n3p2_params
|
|
154
|
+
t3 = tc_n3p2_gauss(kf_scaled(sx_n3p2, kfn, nb, icore), *par) * sy_n3p2
|
|
155
|
+
win = (t3 >= tcn) & (i <= idrip)
|
|
156
|
+
tcn = jnp.where(win, t3, tcn)
|
|
157
|
+
isf = jnp.sum(jnp.cumprod(win.astype(int))) - 1
|
|
158
|
+
# p1S0
|
|
159
|
+
tcp = one
|
|
160
|
+
if gaps.p1s0 != 0:
|
|
161
|
+
kps = kf_scaled(sx_p1s0, kfp, nb, icore)
|
|
162
|
+
tcp = jnp.where(i <= icore,
|
|
163
|
+
jnp.maximum(1.0, tc_p1s0(int(gaps.p1s0), kps)) * sy_p1s0, 1.0)
|
|
164
|
+
return StarTc(jnp.abs(tcn), jnp.abs(tcp), isf)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Moving density contacts and proper-volume quadrature on native TOV profiles."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
from typing import NamedTuple
|
|
4
|
+
|
|
5
|
+
import jax
|
|
6
|
+
import jax.numpy as jnp
|
|
7
|
+
from numpy.polynomial.legendre import leggauss
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def enthalpy_at_energy(table, energy):
|
|
11
|
+
"""Invert actual Hermite eps(h) for a scalar energy in km^-2; unsupported roots give NaN.
|
|
12
|
+
|
|
13
|
+
Requires strictly ordered finite nodes and a non-tangent monotone selected
|
|
14
|
+
interval. Derivatives include EOS nodes and target energy, conditional on
|
|
15
|
+
this interval. At an EOS knot the lower interval supplies the derivative.
|
|
16
|
+
"""
|
|
17
|
+
if table.h.size < 2:
|
|
18
|
+
raise ValueError('EOS needs at least two nodes')
|
|
19
|
+
i = jnp.clip(jnp.searchsorted(table.eps, energy, side='left'), 1, table.h.size-1)
|
|
20
|
+
lo, hi = table.h[i-1], table.h[i]
|
|
21
|
+
dh = hi-lo
|
|
22
|
+
safe_dh = jnp.where(dh > 0, dh, 1.)
|
|
23
|
+
p0, p1 = table.p[i-1], table.p[i]
|
|
24
|
+
s0, s1 = table.eps[i-1]+p0, table.eps[i]+p1
|
|
25
|
+
c1 = safe_dh*s0
|
|
26
|
+
c2 = 3*(p1-p0)-safe_dh*(2*s0+s1)
|
|
27
|
+
c3 = 2*(p0-p1)+safe_dh*(s0+s1)
|
|
28
|
+
# eps = p_t/dh-p is cubic in t; its h derivative is quadratic.
|
|
29
|
+
e1, e2, e3 = 2*c2/safe_dh-c1, 3*c3/safe_dh-c2, -c3
|
|
30
|
+
vertex = jnp.clip(-e2/jnp.where(e3 != 0, 3*e3, 1.), 0., 1.)
|
|
31
|
+
derivative = lambda t: (e1+2*e2*t+3*e3*t*t)/safe_dh
|
|
32
|
+
minimum = jnp.minimum(derivative(0.), jnp.minimum(derivative(1.), derivative(vertex)))
|
|
33
|
+
scale = jnp.maximum(jnp.maximum(jnp.abs(table.eps[i-1]), jnp.abs(table.eps[i])), 1e-300)
|
|
34
|
+
tolerance = 64*jnp.finfo(table.h.dtype).eps*scale
|
|
35
|
+
f = lambda h: table.at_h(h)[0]-energy
|
|
36
|
+
nodes_valid = (jnp.all(jnp.isfinite(table.h)) & jnp.all(jnp.isfinite(table.eps))
|
|
37
|
+
& jnp.all(jnp.isfinite(table.p)) & jnp.all(jnp.diff(table.h) > 0)
|
|
38
|
+
& jnp.all(jnp.diff(table.eps) > 0) & jnp.all(table.eps > 0)
|
|
39
|
+
& jnp.all(table.p > 0))
|
|
40
|
+
valid = (nodes_valid & jnp.isfinite(energy) & (energy > 0)
|
|
41
|
+
& (energy >= table.eps[0]) & (energy <= table.eps[-1])
|
|
42
|
+
& (f(lo) <= tolerance) & (f(hi) >= -tolerance) & jnp.isfinite(minimum)
|
|
43
|
+
& (minimum > 1e-12*scale/safe_dh))
|
|
44
|
+
|
|
45
|
+
def root(_):
|
|
46
|
+
def solve(fun, initial):
|
|
47
|
+
def step(_, bracket):
|
|
48
|
+
a, b = bracket
|
|
49
|
+
mid = .5*(a+b)
|
|
50
|
+
above = fun(mid) > 0
|
|
51
|
+
return jnp.where(above, a, mid), jnp.where(above, mid, b)
|
|
52
|
+
a, b = jax.lax.fori_loop(0, 48, step, (lo, hi))
|
|
53
|
+
mid = .5*(a+b)
|
|
54
|
+
candidates = jnp.stack((a, mid, b))
|
|
55
|
+
residuals = jax.vmap(fun)(candidates)
|
|
56
|
+
return candidates[jnp.argmin(jnp.abs(residuals))]
|
|
57
|
+
h = jax.lax.custom_root(f, .5*(lo+hi), solve, lambda g, y: y/g(jnp.ones_like(y)))
|
|
58
|
+
supported = jnp.isfinite(h) & (jnp.abs(f(h)) <= tolerance)
|
|
59
|
+
return jnp.where(supported, h, jnp.nan)
|
|
60
|
+
|
|
61
|
+
return jax.lax.cond(valid, root, lambda _: jnp.asarray(jnp.nan), None)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _profile_nodes(profile, h_c):
|
|
65
|
+
drop = h_c-profile.h
|
|
66
|
+
u = jnp.concatenate((jnp.zeros(1), jnp.sqrt(jnp.where(drop > 0, drop, 1.))))
|
|
67
|
+
r = jnp.concatenate((jnp.zeros(1), profile.r_km))
|
|
68
|
+
m = jnp.concatenate((jnp.zeros(1), profile.m_km))
|
|
69
|
+
valid = (jnp.isfinite(h_c) & jnp.all(jnp.isfinite(profile.h))
|
|
70
|
+
& jnp.all(jnp.isfinite(profile.r_km)) & jnp.all(jnp.isfinite(profile.m_km))
|
|
71
|
+
& jnp.all(jnp.isfinite(profile.ephi)) & jnp.all(jnp.isfinite(drop)) & jnp.all(drop > 0)
|
|
72
|
+
& jnp.all(jnp.diff(profile.h) < 0) & jnp.all(jnp.diff(r) > 0)
|
|
73
|
+
& jnp.all(jnp.diff(m) >= 0) & jnp.all(profile.m_km >= 0)
|
|
74
|
+
& jnp.all(profile.ephi > 0) & jnp.all(2*profile.m_km < profile.r_km))
|
|
75
|
+
return u, r, m, valid
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def volume_at_h(profile, h_c, h):
|
|
79
|
+
"""r^3 in km^3 at a supported h; h_c must match the profile-generating solve."""
|
|
80
|
+
u, r, _, valid = _profile_nodes(profile, h_c)
|
|
81
|
+
drop = h_c-h
|
|
82
|
+
target = jnp.where(drop > 0, jnp.sqrt(jnp.where(drop > 0, drop, 1.)), 0.)
|
|
83
|
+
volume = jnp.interp(target, u, r)**3
|
|
84
|
+
valid &= jnp.isfinite(h) & (h >= profile.h[-1]) & (h <= h_c)
|
|
85
|
+
return jnp.where(valid, volume, jnp.nan)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class VolumeGeometry(NamedTuple):
|
|
89
|
+
h: jax.Array
|
|
90
|
+
r_km: jax.Array
|
|
91
|
+
m_km: jax.Array
|
|
92
|
+
ephi: jax.Array
|
|
93
|
+
proper_factor: jax.Array # dV_proper / d(r^3), cm^3 / km^3
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def geometry_at_volume(profile, h_c, volume):
|
|
97
|
+
"""Geometry at r^3; centre uses m~r^3 and lapse uses the exact first integral."""
|
|
98
|
+
u, r, m, valid = _profile_nodes(profile, h_c)
|
|
99
|
+
radius = jnp.where(volume > 0, jnp.where(volume > 0, volume, 1.)**(1./3.), 0.)
|
|
100
|
+
h = h_c-jnp.interp(radius, r, u)**2
|
|
101
|
+
mass = jnp.interp(volume, r**3, m)
|
|
102
|
+
ephi = profile.ephi[-1]*jnp.exp(profile.h[-1]-h)
|
|
103
|
+
compactness = 2*mass/jnp.where(radius > 0, radius, 1.)
|
|
104
|
+
factor = 4*jnp.pi/3*1e15/jnp.sqrt(jnp.where(compactness < 1, 1-compactness, 1.))
|
|
105
|
+
valid &= (jnp.isfinite(volume) & (volume >= 0) & (volume <= r[-1]**3)
|
|
106
|
+
& jnp.isfinite(factor) & jnp.isfinite(h) & jnp.isfinite(radius)
|
|
107
|
+
& jnp.isfinite(mass) & jnp.isfinite(ephi) & (compactness < 1))
|
|
108
|
+
return VolumeGeometry(*(jnp.where(valid, x, jnp.nan) for x in (h, radius, mass, ephi, factor)))
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def volume_quadrature(profile, h_c, edges, *, order=8):
|
|
112
|
+
"""Gauss geometry and proper-volume weights for ascending contact r^3 edges.
|
|
113
|
+
|
|
114
|
+
Equal adjacent edges give finite nodes and zero weights. Endpoint motion
|
|
115
|
+
remains differentiable; contact ordering and stellar support must be fixed.
|
|
116
|
+
h_c must match the profile-generating solve. Invalid edges give NaN weights.
|
|
117
|
+
No thermal redshift weights are included: callers supply their rate's factor.
|
|
118
|
+
Refine order and saved-profile resolution together for each thermal problem.
|
|
119
|
+
"""
|
|
120
|
+
if edges.size < 2:
|
|
121
|
+
raise ValueError('quadrature needs at least two edges')
|
|
122
|
+
if order < 1:
|
|
123
|
+
raise ValueError('order must be positive')
|
|
124
|
+
nodes, weights = (jnp.asarray(x) for x in leggauss(order))
|
|
125
|
+
width = jnp.diff(edges)
|
|
126
|
+
volume = edges[:-1, None]+.5*width[:, None]*(nodes+1)
|
|
127
|
+
geometry = geometry_at_volume(profile, h_c, volume)
|
|
128
|
+
valid = (jnp.all(jnp.isfinite(edges)) & jnp.all(width >= 0)
|
|
129
|
+
& jnp.all(edges >= 0) & jnp.all(edges <= profile.r_km[-1]**3))
|
|
130
|
+
proper = .5*width[:, None]*weights*geometry.proper_factor
|
|
131
|
+
return geometry, jnp.where(valid, proper, jnp.nan)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""Heat capacity per volume (erg cm^-3 K^-1), as NSCool's ``spec_heat.f``.
|
|
2
|
+
|
|
3
|
+
Degenerate fermions: C = (pi^2/3) N(0) k_B^2 T with N(0) = m* p_F / pi^2
|
|
4
|
+
(``cvt_deg``; leptons use m* = sqrt(m^2 + p_F^2)). Superfluid reduction
|
|
5
|
+
of Levenfish & Yakovlev 1994 (``r_1s0``, ``r_3p2``). Ions: NSCool's
|
|
6
|
+
``cvion`` (liquid fit, then a Debye-table solid). Most of spec_heat.f's
|
|
7
|
+
literals are single precision; they are kept so.
|
|
8
|
+
|
|
9
|
+
NSCool departures kept here: the proton C is not the BCS jump at Tc; it
|
|
10
|
+
falls linearly from the reduced value just below Tc to the normal value
|
|
11
|
+
at 1.1 Tc. Neutrons have no such ramp.
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import jax.numpy as jnp
|
|
16
|
+
import numpy as np
|
|
17
|
+
|
|
18
|
+
from .superfluid import f32, fexp
|
|
19
|
+
|
|
20
|
+
__all__ = ["cv_coeff", "cv_neutron", "cv_proton", "cv_ion", "R_1S0", "R_3P2"]
|
|
21
|
+
|
|
22
|
+
_PI = 3.14159265
|
|
23
|
+
_KB, _MEV = 1.38e-16, 1.602e-6
|
|
24
|
+
_PI4 = f32(3.14159265) # spec_heat.f: parameter (pi = 3.14159265)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def cv_coeff(kf, m):
|
|
28
|
+
"""cvt_deg: C/T (erg cm^-3 K^-2) for k_F in fm^-1 and m in MeV."""
|
|
29
|
+
pf = kf * 197.0
|
|
30
|
+
n0 = 2.0 * m * pf / 2.0 / _PI ** 2
|
|
31
|
+
return jnp.where(pf == 0.0, 0.0, _PI ** 2 / 3.0 * n0) * _KB ** 2 / _MEV / 197.0 ** 3 * 1e39
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def lepton_cv_coeff(kf, m0):
|
|
35
|
+
"""C/T for electrons (m0 = 0.511 MeV) or muons (105 MeV)."""
|
|
36
|
+
pf = kf * 197.0
|
|
37
|
+
return cv_coeff(kf, jnp.sqrt(m0 ** 2 + pf ** 2))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
_A = [f32(c) for c in (1.456, 0.157, 1.764, 0.4186, 1.007, 0.5010,
|
|
41
|
+
5.596, 8.424, 0.6893, 0.790, 0.03983, 1.934)]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _u1(t):
|
|
45
|
+
return jnp.sqrt(1.0 - t) * (_A[0] - _A[1] / jnp.sqrt(t) + _A[2] / t)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def R_1S0(u):
|
|
49
|
+
return (_A[3] + jnp.sqrt(_A[4] ** 2 + (_A[5] * u) ** 2)) ** 2.5 * fexp(_A[0] - jnp.sqrt(_A[0] ** 2 + u ** 2))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _u3(t):
|
|
53
|
+
return jnp.sqrt(1.0 - t) * (_A[6] + _A[7] / t)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def R_3P2(u):
|
|
57
|
+
return ((_A[8] + jnp.sqrt(_A[9] ** 2 + (_A[10] * u) ** 2)) ** 2
|
|
58
|
+
* fexp(_A[11] - jnp.sqrt(_A[11] ** 2 + u ** 2 / (16.0 * _PI4))))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
_T0MAX = 0.999999999999
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def cv_neutron(T, cvn, tcn, i, isf):
|
|
65
|
+
"""Neutron C (3P2 reduction for i <= isf, 1S0 above); NSCool applies it
|
|
66
|
+
only at rho >= rhodrip, which the caller masks."""
|
|
67
|
+
m = (T < tcn) & (tcn > 0)
|
|
68
|
+
t0 = jnp.where(m, jnp.minimum(_T0MAX, T / jnp.where(m, tcn, 1.0)), 0.5)
|
|
69
|
+
r = jnp.where(i <= isf, R_3P2(_u3(t0)), R_1S0(_u1(t0)))
|
|
70
|
+
return cvn * T * jnp.where(m, r, 1.0)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def cv_proton(T, cvp, tcp, raise_=1.1):
|
|
74
|
+
"""Proton C with NSCool's ramp from Tc to 1.1 Tc."""
|
|
75
|
+
m = (T < raise_ * tcp) & (tcp > 0)
|
|
76
|
+
tcs = jnp.where(m, tcp, 1.0)
|
|
77
|
+
t0 = jnp.where(m, jnp.minimum(_T0MAX, T / tcs), 0.5)
|
|
78
|
+
r = R_1S0(_u1(t0))
|
|
79
|
+
w1 = (raise_ * tcs - T) / ((raise_ - 1.0) * tcs)
|
|
80
|
+
r = jnp.where(T > tcp, w1 * r + (1.0 - w1), r)
|
|
81
|
+
return cvp * T * jnp.where(m, r, 1.0)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
_BCV, _CCV, _DCV, _HCV, _CTE = (f32(c) for c in (.95043, .18956, -.81487, 3225.0, 1.417e2))
|
|
85
|
+
_CV0 = np.asarray([0.0, 2.956, 2.829, 2.633, 2.389, 2.118, 1.840, 1.572,
|
|
86
|
+
1.323, 1.102, 0.909, 0.745, 0.609, 0.496, 0.404], np.float32).astype(float)
|
|
87
|
+
_G, _NA, _KBS, _THIRD = f32(2.273e5), f32(6.022e23), f32(1.38e-16), f32(1.0 / 3.0)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def cv_ion(T, rho, A, Z):
|
|
91
|
+
"""cvion: ions per cm^3 with A = a_cell (nucleons per cell), Z per nucleus.
|
|
92
|
+
|
|
93
|
+
Zones without nuclei (A or Z = 0, as in the core) give 0 with finite
|
|
94
|
+
gradients. In the 178 < Gamma < 210 blend NSCool reads past its Debye
|
|
95
|
+
table when delta > 7e20 (low Z only, not reached by our crusts); here
|
|
96
|
+
the table is clamped at its last entry.
|
|
97
|
+
"""
|
|
98
|
+
ok = (A > 0) & (Z > 0)
|
|
99
|
+
A, Z = jnp.where(ok, A, 1.0), jnp.where(ok, Z, 1.0)
|
|
100
|
+
return jnp.where(ok, _cv_ion(T, rho, A, Z), 0.0)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _cv_ion(T, rho, A, Z):
|
|
104
|
+
gamma = _G * Z ** 2 * (rho / A) ** _THIRD / T
|
|
105
|
+
a1 = jnp.where(rho >= f32(4.3e11), 3.0 * Z, A) # cvion's own drip density
|
|
106
|
+
nk = _KBS * _NA * rho / A
|
|
107
|
+
delta = 1.0 / T * Z * jnp.sqrt(rho / (a1 * A)) * _NA
|
|
108
|
+
g = jnp.maximum(gamma, 1e-30)
|
|
109
|
+
liquid = nk * (.75 * _BCV * g ** .25 + 1.25 * _CCV / g ** .25 + _DCV + 1.5)
|
|
110
|
+
gas = 1.5 * nk
|
|
111
|
+
solid0 = 1.5 + 3.0 * _HCV / g ** 2 + 1.5 # cv0(0), set at each call
|
|
112
|
+
x = jnp.minimum(delta * f32(2e-20), 14.0)
|
|
113
|
+
i1 = jnp.clip(jnp.floor(x).astype(int), 0, 13)
|
|
114
|
+
cv0 = lambda j: jnp.where(j == 0, solid0, jnp.asarray(_CV0)[j])
|
|
115
|
+
table = nk * (cv0(i1) + (x - i1) * (cv0(i1 + 1) - cv0(i1)))
|
|
116
|
+
harm = nk * solid0
|
|
117
|
+
debye = nk * _CTE / (delta * f32(1e-20)) ** 3
|
|
118
|
+
blend = (gamma - 178.0) / 32.0 * table + (210.0 - gamma) / 32.0 * harm
|
|
119
|
+
p1, p2 = f32(.1), f32(.2)
|
|
120
|
+
return jnp.select(
|
|
121
|
+
[gamma <= p1, gamma <= p2, gamma <= 178.0,
|
|
122
|
+
(gamma <= 210.0) & (delta >= f32(1e19)), delta <= f32(1e19),
|
|
123
|
+
delta < f32(7e20)],
|
|
124
|
+
[gas, (gamma - p1) / p1 * liquid + (p2 - gamma) / p1 * gas, liquid,
|
|
125
|
+
blend, harm, table], debye)
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Unpaired inner-core thermal integrals on a native spherical TOV profile.
|
|
2
|
+
|
|
3
|
+
The caller chooses a density cut inside homogeneous matter. Native log-density
|
|
4
|
+
interpolation is used throughout; crust and pairing are outside this interface.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import NamedTuple
|
|
9
|
+
import jax
|
|
10
|
+
import jax.numpy as jnp
|
|
11
|
+
from . import core_nu, heat
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class InnerCoreSums(NamedTuple):
|
|
15
|
+
C: jax.Array # erg/K, d E_infinity / d T_infinity
|
|
16
|
+
L_nu: jax.Array # erg/s at infinity
|
|
17
|
+
L_durca: jax.Array # electron + muon direct Urca at infinity
|
|
18
|
+
volume_cm3: jax.Array # proper volume of the selected inner core
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def density_at_h(table, h):
|
|
22
|
+
"""Native EOS density (fm^-3), log-linear in pseudo-enthalpy."""
|
|
23
|
+
return jnp.exp(jnp.interp(h, table.h, jnp.log(table.n)))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _composition_at(comp, n):
|
|
27
|
+
return tuple(jnp.interp(n, comp.n, field) for field in
|
|
28
|
+
(comp.x_p, comp.x_e, comp.x_mu, comp.mst_n, comp.mst_p))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _kf(n, fraction):
|
|
32
|
+
present = fraction > 0
|
|
33
|
+
return jnp.where(present, (3.*jnp.pi**2*n*jnp.where(present, fraction, 1.))**(1./3.), 0.)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _unpaired_core_terms(T_local, n, comp):
|
|
37
|
+
"""Local cv (erg cm^-3 K^-1), slow and e/mu Urca rates (erg cm^-3 s^-1).
|
|
38
|
+
|
|
39
|
+
Direct-Urca amplitudes are unmasked; callers own their active domains.
|
|
40
|
+
Requires positive local T/density and covered physical npeμ composition.
|
|
41
|
+
"""
|
|
42
|
+
xp, xe, xm, mn, mp = _composition_at(comp, n)
|
|
43
|
+
kn, kp, ke, km = (_kf(n, x) for x in (1.-xp, xp, xe, xm))
|
|
44
|
+
cv = (heat.cv_coeff(kn,939.56*mn) + heat.cv_coeff(kp,938.27*mp)
|
|
45
|
+
+ heat.lepton_cv_coeff(ke,.511) + heat.lepton_cv_coeff(km,105.))*T_local
|
|
46
|
+
slow = (core_nu.murca(T_local,ke,km,kn,kp,mn,mp,0.,0.,0,-1)
|
|
47
|
+
+ core_nu.brem(T_local,kn,kp,mn,mp,0.,0.,0,-1))
|
|
48
|
+
return (cv, slow,
|
|
49
|
+
core_nu.durca_unpaired_channel(T_local,mn,mp,n,xe),
|
|
50
|
+
core_nu.durca_unpaired_channel(T_local,mn,mp,n,xm))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _margin(comp, n, lepton):
|
|
54
|
+
xp, xe, xm, _, _ = _composition_at(comp, n)
|
|
55
|
+
return _kf(n, xp) + _kf(n, xe if lepton == 'electron' else xm) - _kf(n, 1.-xp)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def onset_density(comp, n_min, n_max, *, lepton='electron'):
|
|
59
|
+
"""First opening for one monotone Urca channel; n_max if still closed.
|
|
60
|
+
|
|
61
|
+
Uses the interpolated composition actually supplied to the rate. The scalar
|
|
62
|
+
root has an implicit derivative, including composition-node sensitivities.
|
|
63
|
+
Re-closing/tangent roots are outside this first inner-core interface.
|
|
64
|
+
"""
|
|
65
|
+
if lepton not in ('electron', 'muon'):
|
|
66
|
+
raise ValueError("lepton must be electron or muon")
|
|
67
|
+
grid = jnp.clip(comp.n, n_min, n_max)
|
|
68
|
+
margin = _margin(comp, grid, lepton)
|
|
69
|
+
opened = margin > 0
|
|
70
|
+
k = jnp.maximum(jnp.argmax(opened), 1)
|
|
71
|
+
a, b = grid[k-1], grid[k]
|
|
72
|
+
f = lambda n: _margin(comp, n, lepton)
|
|
73
|
+
|
|
74
|
+
def root(_):
|
|
75
|
+
def solve(fun, initial):
|
|
76
|
+
def step(i, bracket):
|
|
77
|
+
lo, hi = bracket
|
|
78
|
+
mid = .5*(lo+hi)
|
|
79
|
+
positive = fun(mid) > 0
|
|
80
|
+
return jnp.where(positive, lo, mid), jnp.where(positive, mid, hi)
|
|
81
|
+
lo, hi = jax.lax.fori_loop(0, 48, step, (a, b))
|
|
82
|
+
return .5*(lo+hi)
|
|
83
|
+
return jax.lax.custom_root(f, .5*(a+b), solve, lambda g, y: y/g(jnp.ones_like(y)))
|
|
84
|
+
|
|
85
|
+
return jax.lax.cond(f(n_min)>0, lambda _: n_min,
|
|
86
|
+
lambda _: jax.lax.cond(jnp.any(opened), root, lambda _: n_max, None), None)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _shell_integral(r, integrand, volume_limit):
|
|
90
|
+
"""Partial-cell integral in r^3, so a moving cutoff retains its derivative."""
|
|
91
|
+
v = r**3
|
|
92
|
+
left, right = v[:-1], jnp.minimum(v[1:], volume_limit)
|
|
93
|
+
width = jnp.maximum(right-left, 0.)
|
|
94
|
+
fraction = width/jnp.diff(v)
|
|
95
|
+
end = integrand[:-1] + fraction*jnp.diff(integrand)
|
|
96
|
+
return 4.*jnp.pi/3.*jnp.sum(.5*(integrand[:-1]+end)*width)*1e15
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def inner_core_sums(table, profile, h_c, comp, T_inf, *, n_cut):
|
|
100
|
+
"""C and L_nu of unpaired npeμ matter above n_cut, from a native profile.
|
|
101
|
+
|
|
102
|
+
Requires a smooth EOS, supplied central h matching the profile, composition
|
|
103
|
+
coverage, and at most one non-tangent opening per Urca channel inside the
|
|
104
|
+
star. Saved-profile and shell-quadrature convergence must be checked.
|
|
105
|
+
n_cut must lie above the model's crust remapping region; this is NOT a
|
|
106
|
+
whole-star cooling curve. Density is the native-grid ansatz, not inferred
|
|
107
|
+
from a renormalized surface chemical potential.
|
|
108
|
+
"""
|
|
109
|
+
h = jnp.concatenate((jnp.atleast_1d(h_c), profile.h))
|
|
110
|
+
r = jnp.concatenate((jnp.zeros(1), profile.r_km))
|
|
111
|
+
m = jnp.concatenate((jnp.zeros(1), profile.m_km))
|
|
112
|
+
ephi = profile.ephi[-1]*jnp.exp(profile.h[-1]-h)
|
|
113
|
+
n = density_at_h(table, h)
|
|
114
|
+
t = T_inf/ephi
|
|
115
|
+
metric = jnp.sqrt(1.-2.*m/jnp.where(r>0,r,1.))
|
|
116
|
+
# Interpolate in sqrt(enthalpy drop); the central-series segment then
|
|
117
|
+
# retains r ~ sqrt(h_c-h), including an Urca ball smaller than r_start.
|
|
118
|
+
u = jnp.concatenate((jnp.zeros(1), jnp.sqrt(h_c-profile.h)))
|
|
119
|
+
def volume_limit(density):
|
|
120
|
+
target_h = jnp.interp(jnp.log(density), jnp.log(table.n), table.h)
|
|
121
|
+
drop = h_c-target_h
|
|
122
|
+
target_u = jnp.where(drop>0,jnp.sqrt(jnp.where(drop>0,drop,1.)),0.)
|
|
123
|
+
return jnp.interp(target_u, u, r)**3
|
|
124
|
+
limit = volume_limit(n_cut)
|
|
125
|
+
integrate = lambda value, v=limit: _shell_integral(r, value/metric, v)
|
|
126
|
+
cv, qslow, q_e, q_mu = _unpaired_core_terms(t,n,comp)
|
|
127
|
+
fast = jnp.asarray(0.)
|
|
128
|
+
single_onset = jnp.asarray(True)
|
|
129
|
+
for lepton, q in [('electron',q_e), ('muon',q_mu)]:
|
|
130
|
+
opened = _margin(comp,jnp.clip(comp.n,n_cut,n[0]),lepton)>0
|
|
131
|
+
single_onset &= ~jnp.any(opened[:-1] & ~opened[1:])
|
|
132
|
+
threshold = onset_density(comp,n_cut,n[0],lepton=lepton)
|
|
133
|
+
active = _margin(comp,n[0],lepton)>0
|
|
134
|
+
v = jax.lax.cond(active, lambda _: volume_limit(threshold), lambda _: jnp.asarray(0.), None)
|
|
135
|
+
fast += integrate(ephi**2*q,v)
|
|
136
|
+
valid = (n[0]>n_cut) & (n_cut>=comp.n[0]) & (n[0]<=comp.n[-1]) & single_onset & (T_inf>0)
|
|
137
|
+
values = InnerCoreSums(integrate(cv),integrate(ephi**2*qslow)+fast,fast,integrate(jnp.ones_like(n)))
|
|
138
|
+
return InnerCoreSums(*(jnp.where(valid,value,jnp.nan) for value in values))
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""NSCool reference cases for the C2 physics tests and analysis.
|
|
2
|
+
|
|
3
|
+
``dump(mass, gaps, eta)`` caches ``NSCool.zone_dump`` on the test
|
|
4
|
+
temperatures; ``gate_error`` is the C2 comparison: the worst relative
|
|
5
|
+
error where a term is at least 1e-6 of the total, and elsewhere the worst
|
|
6
|
+
absolute error over the total.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import functools
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
from ..runner import GapModel, NSCool
|
|
15
|
+
|
|
16
|
+
__all__ = ["GAPS", "T_TEST", "dump", "gate_error"]
|
|
17
|
+
|
|
18
|
+
#: gap sets of C1 (nmb-papers analyses/c1_isothermal/run_case.py), plus one
|
|
19
|
+
#: that keeps protons paired in the dUrca core of APR 2.0 (two-gap suppression)
|
|
20
|
+
GAPS = {
|
|
21
|
+
"none": GapModel(n1s0=0, n3p2=0, p1s0=0),
|
|
22
|
+
"default": GapModel(),
|
|
23
|
+
"zhou": GapModel(sx_p1s0=0.8, sy_p1s0=0.4),
|
|
24
|
+
"zhou_no3p2": GapModel(n3p2=0, sx_p1s0=0.8, sy_p1s0=0.4),
|
|
25
|
+
"c_ccdk": GapModel(n3p2=103, p1s0=7, sx_p1s0=2.0),
|
|
26
|
+
# neutron pairing alone, so zone isf's neutron factor is not hidden by min(R_n, R_p)
|
|
27
|
+
"n_only": GapModel(p1s0=0),
|
|
28
|
+
# p1S0 alone, kept open in the dUrca core: the proton-only dUrca branch
|
|
29
|
+
"p_ccdk": GapModel(n1s0=0, n3p2=0, p1s0=7, sx_p1s0=2.0),
|
|
30
|
+
# the remaining supported codes, with both scalings on n3P2
|
|
31
|
+
"ccdk_n": GapModel(n1s0=2, n3p2=102, p1s0=7, sx_n3p2=1.3, sy_n3p2=0.7, sx_p1s0=1.5),
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#: redshifted temperatures of the gates, 1e7 to 1e10 K
|
|
35
|
+
T_TEST = tuple(np.logspace(7, 10, 13))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@functools.lru_cache(maxsize=None)
|
|
39
|
+
def dump(mass, gaps="default", eta=0.0, eos_table=None, T=T_TEST, rho_b=1.6e14):
|
|
40
|
+
"""Zone dump with the scan on the same T grid (so ``iso`` rows line up)."""
|
|
41
|
+
return NSCool().zone_dump(list(T), mass=mass, gaps=GAPS[gaps], eta=eta,
|
|
42
|
+
eos_table=eos_table, rho_b=rho_b,
|
|
43
|
+
T_grid=(T[0], T[-1], len(T)))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def gate_error(val, ref, total, floor=1e-6):
|
|
47
|
+
"""(worst relative error where |ref| >= floor * total, worst |val - ref| / total elsewhere)."""
|
|
48
|
+
val, ref, total = (np.asarray(x, float) for x in (val, ref, total))
|
|
49
|
+
big = (np.abs(ref) >= floor * total) & (total > 0)
|
|
50
|
+
rel = np.max(np.abs(val[big] / ref[big] - 1.0), initial=0.0)
|
|
51
|
+
tot = np.where(total > 0, total, 1.0)
|
|
52
|
+
small = np.max((np.abs(val - ref) / tot)[~big], initial=0.0)
|
|
53
|
+
return rel, small
|