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,225 @@
|
|
|
1
|
+
"""NSCool's physics summed over a star with uniform redshifted temperature.
|
|
2
|
+
|
|
3
|
+
``Star`` holds the zone arrays of an NSCool star (``Star.from_dump``; C3
|
|
4
|
+
builds them from nmbackend TOV and composition). ``zone_terms`` gives
|
|
5
|
+
every emissivity and heat-capacity term per temperature zone, as
|
|
6
|
+
NSCool's ``neutrino`` and ``specheat``; ``isothermal_sums`` gives C,
|
|
7
|
+
L_nu, L_gamma and T_in as ``NSCool_iso.out`` does (C1 driver).
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import dataclasses
|
|
12
|
+
from typing import NamedTuple
|
|
13
|
+
|
|
14
|
+
import jax
|
|
15
|
+
import jax.numpy as jnp
|
|
16
|
+
import numpy as np
|
|
17
|
+
|
|
18
|
+
from . import conduct, core_conduct, core_nu, crust_nu, envelope, heat
|
|
19
|
+
from .gaps import StarTc, star_tc
|
|
20
|
+
|
|
21
|
+
__all__ = ["Star", "zone_terms", "IsoSums", "isothermal_sums"]
|
|
22
|
+
|
|
23
|
+
_LSOL = 3.826e33
|
|
24
|
+
_SIGMA = 5.67e-5
|
|
25
|
+
_PI = 3.1415926535
|
|
26
|
+
|
|
27
|
+
_ARRAYS = ("rad", "rho", "nb", "debar", "dvol", "ephi", "a2ephin", "Ye", "Ymu",
|
|
28
|
+
"kfe", "kfm", "kfn", "kfp", "mstn", "mstp", "A_cell", "A_ion", "Z_ion",
|
|
29
|
+
"v_ion")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@jax.tree_util.register_dataclass
|
|
33
|
+
@dataclasses.dataclass(frozen=True)
|
|
34
|
+
class Star:
|
|
35
|
+
"""Zone arrays i = 0..imax+1 (centre first), NSCool units (cm, g/cm^3,
|
|
36
|
+
fm^-3, fm^-1); temperatures live on odd zones."""
|
|
37
|
+
rad: jnp.ndarray
|
|
38
|
+
rho: jnp.ndarray
|
|
39
|
+
nb: jnp.ndarray
|
|
40
|
+
debar: jnp.ndarray
|
|
41
|
+
dvol: jnp.ndarray
|
|
42
|
+
ephi: jnp.ndarray
|
|
43
|
+
a2ephin: jnp.ndarray
|
|
44
|
+
Ye: jnp.ndarray
|
|
45
|
+
Ymu: jnp.ndarray
|
|
46
|
+
kfe: jnp.ndarray
|
|
47
|
+
kfm: jnp.ndarray
|
|
48
|
+
kfn: jnp.ndarray
|
|
49
|
+
kfp: jnp.ndarray
|
|
50
|
+
mstn: jnp.ndarray
|
|
51
|
+
mstp: jnp.ndarray
|
|
52
|
+
A_cell: jnp.ndarray
|
|
53
|
+
A_ion: jnp.ndarray
|
|
54
|
+
Z_ion: jnp.ndarray
|
|
55
|
+
v_ion: jnp.ndarray
|
|
56
|
+
gs14: jnp.ndarray
|
|
57
|
+
imax: int = dataclasses.field(metadata=dict(static=True))
|
|
58
|
+
icore: int = dataclasses.field(metadata=dict(static=True))
|
|
59
|
+
idrip: int = dataclasses.field(metadata=dict(static=True))
|
|
60
|
+
rhocore: float = dataclasses.field(metadata=dict(static=True))
|
|
61
|
+
rhodrip: float = dataclasses.field(metadata=dict(static=True))
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
def from_dump(cls, d) -> "Star":
|
|
65
|
+
"""From ``NSCool.zone_dump``."""
|
|
66
|
+
a = {k: jnp.asarray(d.star[k], float) for k in _ARRAYS}
|
|
67
|
+
return cls(**a, gs14=jnp.asarray(d.gs14), imax=d.imax, icore=d.icore,
|
|
68
|
+
idrip=d.idrip, rhocore=d.rhocore, rhodrip=d.rhodrip)
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def zones(self) -> np.ndarray:
|
|
72
|
+
return np.arange(1, self.imax + 1, 2)
|
|
73
|
+
|
|
74
|
+
def tc(self, gaps, **kw) -> StarTc:
|
|
75
|
+
"""Gap Tc per zone (``gaps.star_tc``)."""
|
|
76
|
+
return star_tc(gaps, self.kfn, self.kfp, self.nb, self.icore, self.idrip, **kw)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def zone_terms(T, s: Star, tc: StarTc, ca_n3p2=0.5, qimp=1e-10) -> dict:
|
|
80
|
+
"""Per-zone terms at redshifted T on the temperature zones (``Star.zones``).
|
|
81
|
+
|
|
82
|
+
Keys follow ``NSCool.zone_dump``: q* (erg cm^-3 s^-1), cv* (erg cm^-3 K^-1),
|
|
83
|
+
lam (crust ICON_CRUST=3; core lepton-only ICON_CORE=2).
|
|
84
|
+
"""
|
|
85
|
+
i = jnp.asarray(s.zones)
|
|
86
|
+
g = lambda a: a[i]
|
|
87
|
+
t = T / g(s.ephi)
|
|
88
|
+
rho = g(s.rho)
|
|
89
|
+
core = i <= s.icore # rho >= rhocore
|
|
90
|
+
crust = ~core
|
|
91
|
+
inner = crust & (rho >= s.rhodrip)
|
|
92
|
+
tcn, tcp, isf = g(tc.tcn), g(tc.tcp), tc.isf
|
|
93
|
+
kfe, kfm, kfn, kfp = g(s.kfe), g(s.kfm), g(s.kfn), g(s.kfp)
|
|
94
|
+
mstn, mstp = g(s.mstn), g(s.mstp)
|
|
95
|
+
A = jnp.where(crust, g(s.A_cell), 1.0)
|
|
96
|
+
Z = jnp.where(crust, g(s.Z_ion), 1.0)
|
|
97
|
+
kfe_c = jnp.where(crust, kfe, 1.0)
|
|
98
|
+
z0 = jnp.zeros_like(t)
|
|
99
|
+
q = {
|
|
100
|
+
"qeebrem": jnp.where(crust, crust_nu.eebrem(t, kfe_c), 0.0),
|
|
101
|
+
"qnpb": jnp.where(crust, crust_nu.npb(t, rho), 0.0),
|
|
102
|
+
"qplasma": jnp.where(crust, crust_nu.plasma(t, rho, A, Z), 0.0),
|
|
103
|
+
"qbrem_nn": jnp.where(inner, crust_nu.brem_nn_crust(
|
|
104
|
+
t, kfn, mstn, tcn, g(s.v_ion), i, isf), 0.0),
|
|
105
|
+
"qmurca_nucl": jnp.where(core, core_nu.murca(
|
|
106
|
+
t, kfe, kfm, kfn, kfp, mstn, mstp, tcn, tcp, i, isf), 0.0),
|
|
107
|
+
"qbrem_nucl": jnp.where(core, core_nu.brem(
|
|
108
|
+
t, kfn, kfp, mstn, mstp, tcn, tcp, i, isf), 0.0),
|
|
109
|
+
"qdurca_np": jnp.where(core, core_nu.durca(
|
|
110
|
+
t, kfe, kfm, kfn, kfp, mstn, mstp, g(s.nb), g(s.Ye), g(s.Ymu),
|
|
111
|
+
tcn, tcp, i, isf), 0.0),
|
|
112
|
+
**dict(zip(("qpbf_n1s0", "qpbf_n3p2"),
|
|
113
|
+
core_nu.pbf_neutron(t, tcn, mstn, kfn, i, isf, ca_n3p2))),
|
|
114
|
+
"qpbf_p1s0": core_nu.pbf_1s0(t, tcp, jnp.where(core, mstp, 1.0), kfp),
|
|
115
|
+
}
|
|
116
|
+
q["qnu"] = sum(q.values()) + z0
|
|
117
|
+
cn = heat.cv_coeff(kfn, 939.56 * mstn)
|
|
118
|
+
cp = heat.cv_coeff(kfp, 938.27 * mstp)
|
|
119
|
+
c = {
|
|
120
|
+
"cv_n": jnp.where(rho >= s.rhodrip, heat.cv_neutron(t, cn, tcn, i, isf), 0.0),
|
|
121
|
+
"cv_p": jnp.where(core, heat.cv_proton(t, cp, tcp), 0.0),
|
|
122
|
+
"cv_e": heat.lepton_cv_coeff(kfe, 0.511) * t,
|
|
123
|
+
"cv_m": heat.lepton_cv_coeff(kfm, 105.0) * t,
|
|
124
|
+
"cv_ion": jnp.where(crust, heat.cv_ion(t, rho, A, Z), 0.0),
|
|
125
|
+
}
|
|
126
|
+
c["cv"] = sum(c.values())
|
|
127
|
+
rho_c = jnp.where(crust, rho, s.rhodrip)
|
|
128
|
+
lam_core = core_conduct.lambda_core(t, kfe, kfm, kfp, mstp, tcp)
|
|
129
|
+
lam = jnp.where(crust, conduct.lambda_crust(t, rho_c, A, Z, kfe_c, qimp, s.rhodrip), lam_core)
|
|
130
|
+
return {**q, **c, "T": t, "lam": lam}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class IsoSums(NamedTuple):
|
|
134
|
+
C: jnp.ndarray # erg/K
|
|
135
|
+
L_nu: jnp.ndarray # erg/s at infinity
|
|
136
|
+
L_gamma: jnp.ndarray # erg/s at infinity
|
|
137
|
+
Teff_inf: jnp.ndarray
|
|
138
|
+
T_in: jnp.ndarray # redshifted T at the march's inner end
|
|
139
|
+
C_core: jnp.ndarray
|
|
140
|
+
L_durca: jnp.ndarray
|
|
141
|
+
L_nu_crust: jnp.ndarray
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _l_gamma(T, s: Star, eta):
|
|
145
|
+
"""Photon luminosity at infinity and Teff_inf, as the C1 driver."""
|
|
146
|
+
im = s.imax
|
|
147
|
+
radius = s.rad[im]
|
|
148
|
+
teff = envelope.teff_local(T / s.ephi[im], eta, s.gs14)
|
|
149
|
+
lg = 4.0 * _PI * radius ** 2 * _SIGMA * teff ** 4 * s.ephi[im] ** 2
|
|
150
|
+
te_inf = ((lg / s.ephi[im - 1] ** 2 / (4.0 * _PI * radius ** 2 * _SIGMA)) ** 0.25
|
|
151
|
+
* s.ephi[im - 1])
|
|
152
|
+
return lg, te_inf
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _fp(s: Star, tc: StarTc, i, ttil, qimp):
|
|
156
|
+
"""NSCool flux-equation coefficient lam bar / L_sun at zone i.
|
|
157
|
+
|
|
158
|
+
The crust march reaches at most the core boundary zone icore. Deeper
|
|
159
|
+
unused zones are clamped there to keep their values and AD finite.
|
|
160
|
+
"""
|
|
161
|
+
i = jnp.maximum(i, s.icore)
|
|
162
|
+
j = jnp.maximum(i, s.icore + 2)
|
|
163
|
+
t = ttil / s.ephi[i]
|
|
164
|
+
crust_lam = conduct.lambda_crust(t, s.rho[i], s.A_cell[j], s.Z_ion[j],
|
|
165
|
+
s.kfe[i], qimp, s.rhodrip)
|
|
166
|
+
core_lam = core_conduct.lambda_core(t, s.kfe[i], s.kfm[i], s.kfp[i],
|
|
167
|
+
s.mstp[i], tc.tcp[i])
|
|
168
|
+
lam = jnp.where(i <= s.icore, core_lam, crust_lam)
|
|
169
|
+
return lam * s.nb[i] / _LSOL
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def crust_march(T, s: Star, lg, rho_b, qimp=1e-10, n_iter=20, *, tc):
|
|
173
|
+
"""T_in: march the steady flux equation from T_b = T at zone imax inward
|
|
174
|
+
to the first zone with rho >= rho_b, at L = lg (C1 driver).
|
|
175
|
+
|
|
176
|
+
NSCool's last step reaches zone icore when rho_b = rhocore, where
|
|
177
|
+
the lepton core conductivity uses the same proton gap as the star.
|
|
178
|
+
Supply tc (StarTc) so the core boundary uses the star's actual pairing.
|
|
179
|
+
rho_b > rhocore would march deeper through the core, outside this
|
|
180
|
+
crust-blanket approximation, and is refused for Python numbers;
|
|
181
|
+
a traced rho_b must respect the same bound.
|
|
182
|
+
"""
|
|
183
|
+
if isinstance(rho_b, (int, float)) and rho_b > s.rhocore:
|
|
184
|
+
raise ValueError(f"rho_b = {rho_b:g} > rhocore: deeper-core marching is "
|
|
185
|
+
"outside the crust-blanket approximation")
|
|
186
|
+
xl = lg / _LSOL
|
|
187
|
+
|
|
188
|
+
def step(carry, j1):
|
|
189
|
+
tcur, fpout = carry
|
|
190
|
+
j0, ie = j1 - 2, j1 - 1
|
|
191
|
+
num = xl * (s.debar[ie] + s.debar[ie + 1])
|
|
192
|
+
|
|
193
|
+
def picard(c, _):
|
|
194
|
+
x0, done = c
|
|
195
|
+
x1 = tcur + num / (0.5 * (_fp(s, tc, j0, x0, qimp) + fpout) * s.a2ephin[ie])
|
|
196
|
+
new_done = done | (jnp.abs(x1 - x0) < 1e-10 * x1)
|
|
197
|
+
return (jnp.where(done, x0, x1), new_done), None
|
|
198
|
+
|
|
199
|
+
(x, _), _ = jax.lax.scan(picard, (tcur, jnp.asarray(False)), None, length=n_iter)
|
|
200
|
+
on = s.rho[j1] < rho_b # rho grows inwards, so steps stop once
|
|
201
|
+
return (jnp.where(on, x, tcur), jnp.where(on, _fp(s, tc, j0, x, qimp), fpout)), None
|
|
202
|
+
|
|
203
|
+
(tin, _), _ = jax.lax.scan(step, (T, _fp(s, tc, s.imax, T, qimp)),
|
|
204
|
+
jnp.arange(s.imax, 1, -2))
|
|
205
|
+
return tin
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def isothermal_sums(T, s: Star, tc: StarTc, eta=0.0, rho_b=0.0, ca_n3p2=0.5,
|
|
209
|
+
qimp=1e-10) -> IsoSums:
|
|
210
|
+
"""C, L_nu, L_gamma at uniform redshifted T (scalar), as NSCool_iso.out.
|
|
211
|
+
|
|
212
|
+
``eta`` is PCY97's eta (NSCool's ETA / 0.443). ``rho_b`` > rhosurf
|
|
213
|
+
marches the crust (``crust_march``); otherwise T_in = T.
|
|
214
|
+
"""
|
|
215
|
+
z = jnp.asarray(s.zones)
|
|
216
|
+
terms = zone_terms(T, s, tc, ca_n3p2, qimp)
|
|
217
|
+
dv = s.dvol[z] + s.dvol[z + 1]
|
|
218
|
+
w = s.ephi[z] ** 2 * dv
|
|
219
|
+
core = z <= s.icore
|
|
220
|
+
lg, te = _l_gamma(T, s, eta)
|
|
221
|
+
tin = crust_march(T, s, lg, rho_b, qimp, tc=tc)
|
|
222
|
+
return IsoSums(jnp.sum(terms["cv"] * dv), jnp.sum(terms["qnu"] * w), lg, te, tin,
|
|
223
|
+
jnp.sum(jnp.where(core, terms["cv"] * dv, 0.0)),
|
|
224
|
+
jnp.sum(terms["qdurca_np"] * w),
|
|
225
|
+
jnp.sum(jnp.where(core, 0.0, terms["qnu"] * w)))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Superfluid gap and reduction-factor fits used by NSCool.
|
|
2
|
+
|
|
3
|
+
u(tau) is the dimensionless gap v = Delta / T at tau = T / Tc
|
|
4
|
+
(Levenfish & Yakovlev 1994). ``below`` returns tau = 0.5 outside the
|
|
5
|
+
paired region and tau <= 1 - 1e-12 inside it, so that the derivative of
|
|
6
|
+
sqrt(1 - tau), and of every branch a ``jnp.where`` discards, stays finite.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import jax.numpy as jnp
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
__all__ = ["below", "u_1s0", "u_3p2b", "fexp"]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def fexp(x):
|
|
17
|
+
"""NSCool's fexp: exp(max(x, -700))."""
|
|
18
|
+
return jnp.exp(jnp.maximum(x, -700.0))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def below(t, tc, strict=True):
|
|
22
|
+
"""(mask, tau): mask = T < Tc (or <=); tau = T/Tc there (at most
|
|
23
|
+
1 - 1e-12), else 0.5. Tc <= 0 counts as unpaired."""
|
|
24
|
+
m = ((t < tc) if strict else (t <= tc)) & (tc > 0)
|
|
25
|
+
tcs = jnp.where(m, tc, 1.0)
|
|
26
|
+
return m, jnp.where(m, jnp.minimum(t / tcs, 1.0 - 1e-12), 0.5)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def u_1s0(tau):
|
|
30
|
+
"""Singlet gap v(tau) (NSCool u_1s0)."""
|
|
31
|
+
return jnp.sqrt(1.0 - tau) * (1.456 - 0.157 / jnp.sqrt(tau) + 1.764 / tau)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def u_3p2b(tau):
|
|
35
|
+
"""Triplet m=0 gap v(tau) (NSCool u_3p2B in the Urca and brem routines)."""
|
|
36
|
+
return jnp.sqrt(1.0 - tau) * (0.7893 + 1.188 / tau)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def f32(x):
|
|
40
|
+
"""A single-precision Fortran literal (no d0), widened as gfortran does."""
|
|
41
|
+
return float(np.float32(x))
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""Internal forward-only unpaired core/crust sums on a native spherical profile.
|
|
2
|
+
|
|
3
|
+
The operational density cut and tabulated crust prescription are explicit.
|
|
4
|
+
Integrated derivatives remain unqualified until ionic moving contacts are
|
|
5
|
+
included; this module is not a cooling curve or transport solver.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import NamedTuple
|
|
10
|
+
import jax
|
|
11
|
+
import jax.numpy as jnp
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
from ...constants import MEVFM3_TO_GEOM
|
|
15
|
+
from ...eos.crust import _G_CM3_TO_MEVFM3
|
|
16
|
+
from . import heat
|
|
17
|
+
from .crust import crust_chemistry, _unpaired_crust_terms
|
|
18
|
+
from .geometry import enthalpy_at_energy, volume_at_h, volume_quadrature
|
|
19
|
+
from .native import (InnerCoreSums, density_at_h, onset_density, _margin,
|
|
20
|
+
_unpaired_core_terms, _composition_at)
|
|
21
|
+
from .superfluid import f32
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CrustSums(NamedTuple):
|
|
25
|
+
"""Crust budget with ionic capacity separated for phase-fit qualification."""
|
|
26
|
+
C: jax.Array
|
|
27
|
+
L_nu: jax.Array
|
|
28
|
+
C_ion: jax.Array
|
|
29
|
+
volume_cm3: jax.Array
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class WholeStarSums(NamedTuple):
|
|
33
|
+
"""Separate core/crust budgets; capacities in erg/K, luminosities in erg/s."""
|
|
34
|
+
core: InnerCoreSums
|
|
35
|
+
crust: CrustSums
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def C(self):
|
|
39
|
+
return self.core.C+self.crust.C
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def L_nu(self):
|
|
43
|
+
return self.core.L_nu+self.crust.L_nu
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def L_durca(self):
|
|
47
|
+
return self.core.L_durca
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def volume_cm3(self):
|
|
51
|
+
return self.core.volume_cm3+self.crust.volume_cm3
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _unpaired_sums(table, profile, h_c, comp, crust, T_inf, *,
|
|
55
|
+
rho_core=1.6e14, rho_base=1e10, rho_drip=4e11, order=16):
|
|
56
|
+
"""Instantaneous forward sums down to rho_base, excluding the outer blanket.
|
|
57
|
+
|
|
58
|
+
Requires matched profile/h_c, composition coverage, a supported chemistry
|
|
59
|
+
join and at most one simple opening per Urca channel. Density boundaries
|
|
60
|
+
are static prescription choices. EOS/profile, chemistry and Urca contacts
|
|
61
|
+
split quadrature; ionic phase jumps require forward order refinement and
|
|
62
|
+
their moving-boundary derivatives are NOT qualified by this interface.
|
|
63
|
+
Callers must qualify absence of the ionic source-table overrun region
|
|
64
|
+
between sampled nodes; the local guard alone is not a coverage proof.
|
|
65
|
+
Homogeneous core composition is continued down to the operational core
|
|
66
|
+
cut, including any EOS joining segment. This is a declared ansatz.
|
|
67
|
+
No gradients are stopped. Invalid stellar/composition support gives NaN.
|
|
68
|
+
"""
|
|
69
|
+
if not 0 < rho_base < rho_drip < rho_core:
|
|
70
|
+
raise ValueError('Require 0 < rho_base < rho_drip < rho_core')
|
|
71
|
+
conversion = _G_CM3_TO_MEVFM3*MEVFM3_TO_GEOM
|
|
72
|
+
# Static prescription nodes; EOS-dependent contact positions are evaluated
|
|
73
|
+
# below in JAX. Keep repeated clipped edges as finite zero-weight padding.
|
|
74
|
+
densities = jnp.sort(jnp.concatenate((jnp.asarray([
|
|
75
|
+
rho_base, rho_drip, np.clip(f32(4.3e11), rho_base, rho_core), rho_core]),
|
|
76
|
+
jnp.clip(crust.rho, rho_base, rho_core))))
|
|
77
|
+
hs = jax.vmap(lambda rho: enthalpy_at_energy(table, rho*conversion))(densities)
|
|
78
|
+
hbase, hcore = hs[0], hs[-1]
|
|
79
|
+
ncore, nc = density_at_h(table, hcore), density_at_h(table, h_c)
|
|
80
|
+
yecore = jnp.interp(ncore, comp.n, comp.x_e)
|
|
81
|
+
onsets, topology = [], jnp.asarray(True)
|
|
82
|
+
for channel in ('electron', 'muon'):
|
|
83
|
+
opened = _margin(comp, jnp.clip(comp.n, ncore, nc), channel) > 0
|
|
84
|
+
topology &= ~jnp.any(opened[:-1] & ~opened[1:])
|
|
85
|
+
onsets.append(onset_density(comp, ncore, nc, lepton=channel))
|
|
86
|
+
hdu = jnp.interp(jnp.log(jnp.asarray(onsets)), jnp.log(table.n), table.h)
|
|
87
|
+
hcomp = jnp.interp(jnp.log(jnp.clip(comp.n, ncore, nc)), jnp.log(table.n), table.h)
|
|
88
|
+
core_h = jnp.sort(jnp.clip(jnp.concatenate((jnp.asarray([h_c, hcore]),
|
|
89
|
+
table.h, profile.h, hcomp, hdu)), hcore, h_c))[::-1]
|
|
90
|
+
crust_h = jnp.sort(jnp.clip(jnp.concatenate((hs, table.h, profile.h)), hbase, hcore))[::-1]
|
|
91
|
+
core_edges = volume_at_h(profile, h_c, core_h)
|
|
92
|
+
crust_edges = volume_at_h(profile, h_c, crust_h)
|
|
93
|
+
g, w = volume_quadrature(profile, h_c, core_edges, order=order)
|
|
94
|
+
n = density_at_h(table, g.h)
|
|
95
|
+
cv, slow, qe, qm = _unpaired_core_terms(T_inf/g.ephi, n, comp)
|
|
96
|
+
resolved = jnp.asarray(True)
|
|
97
|
+
for channel in ('electron', 'muon'):
|
|
98
|
+
opened = _margin(comp, n, channel) > 0
|
|
99
|
+
resolved &= ~jnp.any((w[:, 0] > 0) & jnp.any(opened[:, 1:] != opened[:, :-1], axis=1))
|
|
100
|
+
fast = jnp.where(_margin(comp, n, 'electron') > 0, qe, 0.)
|
|
101
|
+
fast += jnp.where(_margin(comp, n, 'muon') > 0, qm, 0.)
|
|
102
|
+
xp, xe, xm, mn, mp = _composition_at(comp, n)
|
|
103
|
+
physical = (jnp.all(jnp.isfinite(jnp.stack((xp, xe, xm, mn, mp))))
|
|
104
|
+
& jnp.all((xp >= 0) & (xp <= 1) & (xe >= 0) & (xm >= 0))
|
|
105
|
+
& jnp.all(jnp.abs(xp-xe-xm) <= 1e-12)
|
|
106
|
+
& jnp.all((mn > 0) & (mp > 0)))
|
|
107
|
+
core = InnerCoreSums(jnp.sum(w*cv), jnp.sum(w*g.ephi**2*(slow+fast)),
|
|
108
|
+
jnp.sum(w*g.ephi**2*fast), jnp.sum(w))
|
|
109
|
+
gc, wc = volume_quadrature(profile, h_c, crust_edges, order=order)
|
|
110
|
+
rho = table.at_h(gc.h)[0]/conversion
|
|
111
|
+
# Padded cells can sit exactly on a rounded chemistry endpoint. Evaluate
|
|
112
|
+
# their unused rates in a covered interior state; their weights remain zero.
|
|
113
|
+
rho = jnp.where(wc > 0, rho, np.sqrt(rho_base*rho_core))
|
|
114
|
+
chemistry = crust_chemistry(crust, rho, core_rho=rho_core,
|
|
115
|
+
core_n=ncore, core_Ye=yecore)
|
|
116
|
+
cvc, qc = _unpaired_crust_terms(T_inf/gc.ephi, rho, chemistry, rho_drip=rho_drip)
|
|
117
|
+
gamma = heat._G*chemistry.Z**2*(rho/chemistry.A_cell)**heat._THIRD/(T_inf/gc.ephi)
|
|
118
|
+
a1 = jnp.where(rho >= f32(4.3e11), 3*chemistry.Z, chemistry.A_cell)
|
|
119
|
+
delta = heat._NA*chemistry.Z*jnp.sqrt(rho/(a1*chemistry.A_cell))/(T_inf/gc.ephi)
|
|
120
|
+
source_supported = ~jnp.any((wc > 0) & (gamma > 178) & (gamma <= 210)
|
|
121
|
+
& (delta > f32(7e20)))
|
|
122
|
+
ion = heat.cv_ion(T_inf/gc.ephi, rho, chemistry.A_cell, chemistry.Z)
|
|
123
|
+
shell = CrustSums(jnp.sum(wc*cvc), jnp.sum(wc*gc.ephi**2*qc),
|
|
124
|
+
jnp.sum(wc*ion), jnp.sum(wc))
|
|
125
|
+
valid = (jnp.isfinite(T_inf) & (T_inf > 0) & topology & resolved & physical & source_supported
|
|
126
|
+
& jnp.all(jnp.isfinite(comp.n)) & jnp.all(comp.n > 0)
|
|
127
|
+
& jnp.all(jnp.diff(comp.n) > 0)
|
|
128
|
+
& jnp.all(jnp.stack([jnp.all(jnp.isfinite(x) & (x >= 0))
|
|
129
|
+
for x in (w, cv, slow, qe, qm, wc, cvc, qc, ion)]))
|
|
130
|
+
& (hbase < hcore) & (hcore < h_c)
|
|
131
|
+
& (ncore >= comp.n[0]) & (nc <= comp.n[-1])
|
|
132
|
+
& jnp.all(jnp.isfinite(hs))
|
|
133
|
+
& jnp.all(jnp.isfinite(jnp.asarray(core)))
|
|
134
|
+
& jnp.all(jnp.isfinite(jnp.asarray(shell))))
|
|
135
|
+
return WholeStarSums(*(type(sums)(*(jnp.where(valid, x, jnp.nan) for x in sums))
|
|
136
|
+
for sums in (core, shell)))
|