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
nmbackend/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""NuclearMatter-Backend (nmbackend).
|
|
2
|
+
|
|
3
|
+
A differentiable (JAX) neutron-star EOS + TOV toolkit for EOS inference, designed
|
|
4
|
+
to interface with RIFT (per-EOS evidence / hyperpipeline) and gwkokab (population
|
|
5
|
+
inference). See README.md and docs/architecture.md.
|
|
6
|
+
"""
|
|
7
|
+
from . import constants
|
|
8
|
+
from . import ejecta
|
|
9
|
+
from . import ipad
|
|
10
|
+
from . import postmerger
|
|
11
|
+
# lab_likelihood, priors, inference, rift, adapters are add-ons imported
|
|
12
|
+
# explicitly (from nmbackend import lab_likelihood), not eagerly here.
|
|
13
|
+
from .eos import MetaModelEOS, PolytropeEOS, EOSModel, EOSTable
|
|
14
|
+
from .tov import solve_structure, build_family, m_max
|
|
15
|
+
|
|
16
|
+
__version__ = "0.4.0"
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"constants", "ejecta",
|
|
20
|
+
"MetaModelEOS", "PolytropeEOS", "EOSModel", "EOSTable",
|
|
21
|
+
"solve_structure", "build_family", "m_max",
|
|
22
|
+
]
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""RIFT ``EOSConcrete``-compatible adapter.
|
|
2
|
+
|
|
3
|
+
RIFT's ``EOSManager.EOSConcrete`` objects are consumed downstream mainly through
|
|
4
|
+
|
|
5
|
+
* ``lambda_from_m(m)`` -> tidal deformability at gravitational mass m
|
|
6
|
+
* ``lambda_from_m_vector(marr)``
|
|
7
|
+
* ``pressure_density_on_grid(logrho_grid, ...)`` -> log10 p(SI) vs log10 rho(SI)
|
|
8
|
+
* ``mMaxMsun`` -> maximum mass (prior bound)
|
|
9
|
+
* ``name`` -> identifier
|
|
10
|
+
|
|
11
|
+
``EOSConcreteNMB`` provides exactly this surface, backed by the differentiable
|
|
12
|
+
JAX TOV family, so a NuclearMatter-Backend EOS drops into "normal" RIFT (per-EOS
|
|
13
|
+
evidence) and hence the tabular hyperpipeline. It does **not** import lalsuite;
|
|
14
|
+
``self.eos``/``self.eos_fam`` are exposed (table / ``None``) for duck-typing.
|
|
15
|
+
|
|
16
|
+
Accepts mass either in solar masses (~1.4) or SI kg (>1e10), matching RIFT.
|
|
17
|
+
"""
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
from ..constants import MSUN_SI, MEVFM3_TO_PA, NUCLEON_KG, FM3_TO_M3
|
|
23
|
+
from ..eos.base import EOSModel
|
|
24
|
+
from ..tov.family import build_family, default_hc_grid
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _to_msun(m):
|
|
28
|
+
m = np.asarray(m, dtype=float)
|
|
29
|
+
return np.where(m > 1e10, m / MSUN_SI, m)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class EOSConcreteNMB:
|
|
33
|
+
"""Duck-typed RIFT EOSConcrete backed by nmbackend's JAX TOV family."""
|
|
34
|
+
|
|
35
|
+
def __init__(self, model: EOSModel, params: dict = None, name: str = None,
|
|
36
|
+
n_models: int = 120, n_steps: int = 800):
|
|
37
|
+
self.name = name or getattr(model, "name", "nmbackend-EOS")
|
|
38
|
+
self.model = model
|
|
39
|
+
self.params = dict(params or {})
|
|
40
|
+
|
|
41
|
+
table = model.eos_table(self.params)
|
|
42
|
+
self.eos = table # RIFT duck-typing: the EOS object
|
|
43
|
+
self.eos_fam = None # no lalsuite family; sequence cached below
|
|
44
|
+
|
|
45
|
+
fam = build_family(table, default_hc_grid(table, n_models=n_models),
|
|
46
|
+
n_steps=n_steps)
|
|
47
|
+
|
|
48
|
+
# cache stable rising branch (numpy) for fast lookup
|
|
49
|
+
M = np.asarray(fam.M_msun)
|
|
50
|
+
R = np.asarray(fam.R_km)
|
|
51
|
+
L = np.asarray(fam.Lambda)
|
|
52
|
+
stable = np.asarray(fam.stable)
|
|
53
|
+
idx_max = int(np.argmax(np.where(stable, M, -np.inf)))
|
|
54
|
+
sl = slice(int(np.argmax(stable)), idx_max + 1) # minimum mass to M_max
|
|
55
|
+
self._M = M[sl]
|
|
56
|
+
self._R = R[sl]
|
|
57
|
+
self._L = L[sl]
|
|
58
|
+
self.mMaxMsun = float(M[idx_max])
|
|
59
|
+
|
|
60
|
+
# EOS table in SI for pressure_density_on_grid
|
|
61
|
+
n = np.asarray(table.n) # fm^-3
|
|
62
|
+
self._rho_si = n * NUCLEON_KG / FM3_TO_M3 # kg/m^3 (rest-mass density)
|
|
63
|
+
self._p_si = np.asarray(table.p_mevfm3) * MEVFM3_TO_PA # Pa
|
|
64
|
+
|
|
65
|
+
# ---- RIFT EOSConcrete surface ----
|
|
66
|
+
def lambda_from_m(self, m):
|
|
67
|
+
m_msun = float(_to_msun(np.atleast_1d(m))[0])
|
|
68
|
+
if m_msun >= self.mMaxMsun:
|
|
69
|
+
return 0.0
|
|
70
|
+
return float(np.interp(m_msun, self._M, self._L))
|
|
71
|
+
|
|
72
|
+
def lambda_from_m_vector(self, m):
|
|
73
|
+
m_msun = _to_msun(m)
|
|
74
|
+
out = np.interp(m_msun, self._M, self._L,
|
|
75
|
+
left=self._L[0], right=0.0)
|
|
76
|
+
out = np.where(m_msun >= self.mMaxMsun, 0.0, out)
|
|
77
|
+
return out
|
|
78
|
+
|
|
79
|
+
def radius_from_m(self, m):
|
|
80
|
+
m_msun = float(_to_msun(np.atleast_1d(m))[0])
|
|
81
|
+
return float(np.interp(m_msun, self._M, self._R))
|
|
82
|
+
|
|
83
|
+
def pressure_density_on_grid(self, logrho_grid, enforce_causal=False):
|
|
84
|
+
"""log10 p[SI, Pa] on a grid of log10 rho[SI, kg/m^3] (rest-mass density)."""
|
|
85
|
+
logrho_tab = np.log10(self._rho_si)
|
|
86
|
+
logp_tab = np.log10(self._p_si)
|
|
87
|
+
return np.interp(np.asarray(logrho_grid), logrho_tab, logp_tab)
|
|
88
|
+
|
|
89
|
+
def mass_radius_lambda(self):
|
|
90
|
+
"""Return cached stable-branch (M[Msun], R[km], Lambda) arrays."""
|
|
91
|
+
return self._M.copy(), self._R.copy(), self._L.copy()
|
|
92
|
+
|
|
93
|
+
def __repr__(self):
|
|
94
|
+
return (f"<EOSConcreteNMB {self.name} "
|
|
95
|
+
f"mMax={self.mMaxMsun:.3f} Msun, params={self.params}>")
|
nmbackend/constants.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Physical constants and unit conversions for NuclearMatter-Backend.
|
|
2
|
+
|
|
3
|
+
Internal TOV units are *geometric* (G = c = 1) with **length in km**. In these
|
|
4
|
+
units energy density and pressure have dimension km^-2, mass has dimension km,
|
|
5
|
+
and the pseudo-enthalpy h = integral dp/(eps+p) is dimensionless. Masses are
|
|
6
|
+
reported in solar masses by dividing the geometric mass (km) by GMsun/c^2.
|
|
7
|
+
|
|
8
|
+
Nuclear inputs are in MeV and fm^-3; the conversion ``MEVFM3_TO_GEOM`` maps an
|
|
9
|
+
energy density in MeV/fm^3 to geometric km^-2.
|
|
10
|
+
|
|
11
|
+
Motivated by unit handling in RIFT ``EOSManager`` and ``jester`` (MIT); see
|
|
12
|
+
ATTRIBUTION.md.
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# --- fundamental constants (CODATA-ish, SI) ---
|
|
17
|
+
G_SI = 6.67430e-11 # m^3 kg^-1 s^-2
|
|
18
|
+
C_SI = 2.99792458e8 # m / s
|
|
19
|
+
# Solar mass parameter: the IAU 2015 Resolution B3 nominal (GM)_sun (exact by
|
|
20
|
+
# definition), as current LALSuite (LAL_GMSUN_SI in lal 7.7.0 LALConstants.h)
|
|
21
|
+
# and the Q2C oracle use. Until 2026-10-14 this module had MSUN_SI = 1.98892e30
|
|
22
|
+
# kg (old LAL's solar mass, meant for CODATA-1986 G); paired with CODATA-2018 G,
|
|
23
|
+
# GMSUN_KM came out 1.4770039 km, 2.566e-4 above the 1.476625 km its comment
|
|
24
|
+
# claimed (docs/devlog/2026-10-14-gmsun-iau.md). MSUN_SI is derived, so
|
|
25
|
+
# G_SI * MSUN_SI == GM_SUN_SI.
|
|
26
|
+
GM_SUN_SI = 1.3271244e20 # m^3 s^-2
|
|
27
|
+
MSUN_SI = GM_SUN_SI / G_SI # kg, 1.98840987069805e30 (= lal 7.7 LAL_MSUN_SI)
|
|
28
|
+
|
|
29
|
+
# --- nuclear constants ---
|
|
30
|
+
HBARC = 197.3269804 # MeV fm
|
|
31
|
+
M_N = 939.565421 # neutron mass, MeV
|
|
32
|
+
M_P = 938.272088 # proton mass, MeV
|
|
33
|
+
M_E = 0.510998950 # electron mass, MeV
|
|
34
|
+
M_MU = 105.6583755 # muon mass, MeV
|
|
35
|
+
M_BARYON = 939.0 # representative baryon (rest-mass density) mass, MeV
|
|
36
|
+
MEV_TO_FM_INV = 1.0 / HBARC # 1 MeV = (1/hbarc) fm^-1
|
|
37
|
+
|
|
38
|
+
# --- geometric length scale: GMsun/c^2 in km ---
|
|
39
|
+
# 1.476625 km (IAU nominal). Geometric mass [km] / GMSUN_KM -> mass [Msun].
|
|
40
|
+
GMSUN_KM = GM_SUN_SI / C_SI**2 / 1.0e3 # 1.4766250 km
|
|
41
|
+
|
|
42
|
+
# --- energy-density / pressure conversion: MeV/fm^3 -> geometric km^-2 ---
|
|
43
|
+
# eps_geom[m^-2] = (G/c^4) * eps_SI[Pa]; 1 MeV/fm^3 = 1.602176634e32 Pa.
|
|
44
|
+
_MEVFM3_TO_PA = 1.602176634e32
|
|
45
|
+
_G_OVER_C4 = G_SI / C_SI**4 # m^-1 kg^-1 s^2
|
|
46
|
+
MEVFM3_TO_GEOM = _G_OVER_C4 * _MEVFM3_TO_PA * 1.0e6 # km^-2 per (MeV/fm^3)
|
|
47
|
+
|
|
48
|
+
# --- SI helpers for the RIFT adapter (pressure in Pa, density in kg/m^3) ---
|
|
49
|
+
GEOM_KM2_TO_PA = 1.0 / (_G_OVER_C4 * 1.0e6) # km^-2 -> Pa
|
|
50
|
+
MEVFM3_TO_PA = _MEVFM3_TO_PA # MeV/fm^3 -> Pa
|
|
51
|
+
FM3_TO_M3 = 1.0e-45 # fm^3 -> m^3
|
|
52
|
+
NUCLEON_KG = M_BARYON * 1.602176634e-13 / C_SI**2 # kg per baryon (rest mass)
|
|
53
|
+
|
|
54
|
+
# default nuclear saturation density (fm^-3)
|
|
55
|
+
N_SAT_DEFAULT = 0.16
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# nmbackend.cooling: NSCool driver
|
|
2
|
+
|
|
3
|
+
This package runs D. Page's NSCool on one star and returns its cooling curve.
|
|
4
|
+
It does not contain NSCool. The build script downloads and builds it.
|
|
5
|
+
|
|
6
|
+
## Source
|
|
7
|
+
|
|
8
|
+
| Item | Value |
|
|
9
|
+
|---|---|
|
|
10
|
+
| Code | NSCool, D. Page (UNAM), Fortran 77 |
|
|
11
|
+
| URL | https://www.astroscu.unam.mx/neutrones/NSCool/NSCool.tar.gz |
|
|
12
|
+
| Version | unversioned tarball, files dated to 2010-02-01 |
|
|
13
|
+
| sha256 | `c671fb959c732af595834152416cb60336009aa0e218b65ead55cae32f6af35a` (fetched 2026-09-29) |
|
|
14
|
+
| Licence | none stated in the tarball or on the web page |
|
|
15
|
+
| Guides | same URL: `NSCool_Guide_1.1_*.pdf`, `NSCool_Guide_0.0_Control.pdf`, `TOV_Guide.pdf` |
|
|
16
|
+
|
|
17
|
+
With no licence we do not redistribute NSCool. `build_nscool.sh` fetches it,
|
|
18
|
+
checks the sha256, applies `nscool_nmbackend.patch` and compiles.
|
|
19
|
+
|
|
20
|
+
## Build
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
src/nmbackend/cooling/build_nscool.sh # installs into ~/.local/share/nmbackend/nscool
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Set `NSCOOL_HOME` to change the prefix (the driver reads the same variable).
|
|
27
|
+
Set `NSCOOL_TARBALL` to build from a local tarball. The CIT build of 2026-09-29
|
|
28
|
+
used gfortran 8.5.0 with `-O3 -fno-automatic -std=legacy -w` on ldas-pcdev13.
|
|
29
|
+
`NSCool/BUILD_INFO.txt` records each build.
|
|
30
|
+
|
|
31
|
+
The patch changes five files:
|
|
32
|
+
|
|
33
|
+
| File | Change |
|
|
34
|
+
|---|---|
|
|
35
|
+
| `Code/pairing.inc.f`, `Code/NSCool_READ.inc.f` | optional trailing lines `SXP1S0`, `SXN3P2` (default 1) and `CA3P2` (default 0.5) in the pairing file; NSCool prints the values it read, and the driver checks them |
|
|
36
|
+
| `Code/neutrino_core.f` (`nu_n3p2_B_pbf`) | n3P2 pair-breaking axial coefficient a_A = c_A g_A^2 with c_A = `CA3P2`. The release has c_A = 2. We use 0.5, Leinson's correction for the anomalous axial contribution, as in A. W. Steiner's fork (github awsteiner/nscool). This cuts n3P2 pair-breaking emission by 4. |
|
|
37
|
+
| `Code/precool.f` (`get_Tc`) | in core zones, p1S0 and n3P2 gaps are evaluated at the Fermi momentum the star has at baryon density n/s_x; outside the core density range k_F scales as n^(1/3) from the nearest core zone; crust zones are not rescaled |
|
|
38
|
+
| `TOV/TOV.f` | drop the hard-coded `/Users/dany/...` EOS prefix; call `gread` as the function it is (gfortran rejects `CALL`) |
|
|
39
|
+
|
|
40
|
+
With s_x = 1 and `GapModel(ca_n3p2=2.0)` the patched binary reproduces the
|
|
41
|
+
bundled Model_1 output to the printed digits. Default runs differ from it,
|
|
42
|
+
because the default c_A is 0.5. A build without `CA3P2` fails the driver's
|
|
43
|
+
echo check; rerun `build_nscool.sh`.
|
|
44
|
+
|
|
45
|
+
## Use
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from nmbackend.cooling import NSCool, GapModel
|
|
49
|
+
ns = NSCool()
|
|
50
|
+
c = ns.run(mass=1.4, gaps=GapModel(p1s0=3, sx_p1s0=0.8, sy_p1s0=0.4), eta=1e-9)
|
|
51
|
+
c.t_yr, c.Teff_inf, c.L_gamma_inf # NSCool output, redshifted to infinity
|
|
52
|
+
c.Ts, c.L_gamma # local surface values
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- `mass`: the driver builds the star with NSCool's TOV solver from `eos_table`.
|
|
56
|
+
It raises `NSCoolError` if the star is on the unstable branch.
|
|
57
|
+
Or pass `profile=` for a ready profile.
|
|
58
|
+
- `eos_table`, `crust_table`: default the bundled APR table and the HZD-NV crust.
|
|
59
|
+
- `GapModel`: NSCool gap codes (`SFP1S0`, `SFN3P2`, `SFN1S0`; see `get_Tc` in
|
|
60
|
+
`precool.f`) and the scalings of Zhou+2026 (arXiv:2609.34338) Eq. 10,
|
|
61
|
+
Delta(n) = s_y Delta_0(n/s_x). The code applies s_y through NSCool's own
|
|
62
|
+
`FP1S0`/`FN3P2` factors and s_x through the patch.
|
|
63
|
+
- `eta`: written to NSCool's `ETA`. NSCool divides it by 0.443 before the
|
|
64
|
+
envelope formula (see Notes).
|
|
65
|
+
- `star=True` also returns the core-zone profile (n_b, k_F, T_c).
|
|
66
|
+
|
|
67
|
+
Pass `workroot=` to put the per-run directories on a node-local disk.
|
|
68
|
+
|
|
69
|
+
## Isothermal star
|
|
70
|
+
|
|
71
|
+
`NSCool.isothermal()` takes the arguments of `run()` and returns NSCool's
|
|
72
|
+
heat capacity C, L_nu and L_gamma for a star at uniform redshifted T, on a
|
|
73
|
+
log grid of T. `Code/NSCool_iso.out` is the setup part of `NSCool.f` plus
|
|
74
|
+
`nscool_isothermal_tail.f`, which calls `neutrino`, `heating`, `specheat`
|
|
75
|
+
and `fteff` as the time loop does: C = sum cv dV, L_nu = sum e^(2 phi) q_nu dV.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from nmbackend.cooling import NSCool, isothermal_curve
|
|
79
|
+
s = NSCool().isothermal(mass=1.4, eta=1e-9, rho_b=1.6e14)
|
|
80
|
+
c = isothermal_curve(s, blanket=True) # t(T) = int C dT / (L_nu + L_gamma)
|
|
81
|
+
c.t_yr, c.Teff_inf
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
With `rho_b` set, the driver marches NSCool's steady flux equation from
|
|
85
|
+
T_b = T at 1e10 g/cm3 in to rho_b at L = L_gamma(T_b). `blanket=True` then
|
|
86
|
+
makes only the star below rho_b isothermal. A 961-point scan takes 1 s.
|
|
87
|
+
Other approximations: envelope densities stay at NSCool's initial ones; the
|
|
88
|
+
crust layer's C and L_nu use T_in; `C_core` sums zones i <= icore.
|
|
89
|
+
Accuracy against full NSCool: nmb-papers
|
|
90
|
+
`paper7_cooling_population/notes/RESULTS-C1-isothermal.md`.
|
|
91
|
+
|
|
92
|
+
## Zone dump
|
|
93
|
+
|
|
94
|
+
`NSCool.zone_dump(T, ...)` gives each term NSCool sums, per zone, at uniform
|
|
95
|
+
redshifted T. The JAX physics tests compare with it.
|
|
96
|
+
|
|
97
|
+
## EOS table format (interface with W2, `nscool_io`)
|
|
98
|
+
|
|
99
|
+
NSCool reads one core+crust table, as in the bundled `EOS/APR_EOS_Cat.dat`.
|
|
100
|
+
The TOV solver reads the same file.
|
|
101
|
+
|
|
102
|
+
1. Seven header lines. Line 1 is `6 Imax Icore` (integers). The first number must
|
|
103
|
+
be 6: `TOV.f` skips six lines, and NSCool skips `Itext` lines after line 1.
|
|
104
|
+
So line 7 must be blank: TOV reads it as data and fails on text.
|
|
105
|
+
2. `Icore` core rows, densest first, 17 columns:
|
|
106
|
+
`rho[g/cm3] P[dyn/cm2] nbar[fm^-3] Ye Ymu Yn Yp Yla Ysm Ys0 Ysp mstp mstn mstla mstsm msts0 mstsp`.
|
|
107
|
+
`rho` is the total energy density over c^2 (TOV uses it as such), not the
|
|
108
|
+
rest-mass density. Y is the number per baryon. `mst*` is the Landau effective mass over the bare
|
|
109
|
+
mass. NSCool uses these m* in the core (version `'NEW'`).
|
|
110
|
+
3. Crust rows below, densest first: `rho P n A_cell A_ion Z`. TOV uses rho, P and n.
|
|
111
|
+
The cooling code takes crust composition from the separate crust file.
|
|
112
|
+
|
|
113
|
+
Limits in the Fortran:
|
|
114
|
+
|
|
115
|
+
| Limit | Source |
|
|
116
|
+
|---|---|
|
|
117
|
+
| Icore <= 500 | `get_core_chemistry` arrays |
|
|
118
|
+
| all rows <= 1000 | `TOV.f` `limit` |
|
|
119
|
+
| path <= 60 characters | TOV `title`; the driver symlinks the table to `eos.dat` |
|
|
120
|
+
| sum of baryon Y within 1e-2 of 1, and net charge per baryon below 1e-2 | `get_core_chemistry`, on the interpolated core zones; else Fortran `PAUSE` |
|
|
121
|
+
|
|
122
|
+
The core-crust boundary of the cooling grid is `rhocore` (default 1.6e14 g/cm3).
|
|
123
|
+
It is a `run()` argument. The table does not set it.
|
|
124
|
+
|
|
125
|
+
## Validation and cost
|
|
126
|
+
|
|
127
|
+
`tests/test_cooling_nscool.py` checks the driver against NSCool's bundled
|
|
128
|
+
`Model_1/Teff_Try_KEEP.dat` (APR, 1.4 Msun, SFB / gap "a" / T73, iron
|
|
129
|
+
envelope). All 246 time steps agree to the printed four digits. This holds for
|
|
130
|
+
the bundled profile and for a profile built by the driver's TOV call. The
|
|
131
|
+
figure is `docs/cooling/nscool_validation.png`
|
|
132
|
+
(`python -m nmbackend.cooling.validate --fig ...`).
|
|
133
|
+
|
|
134
|
+
One curve takes 3.1 s on one core of ldas-pcdev11 (Xeon E5-2630 v4).
|
|
135
|
+
TOV adds 0.01 s.
|
|
136
|
+
|
|
137
|
+
## Notes for users
|
|
138
|
+
|
|
139
|
+
- NSCool divides the input `ETA` by 0.443 (`NSCool_READ.inc.f`, line 78) and
|
|
140
|
+
passes the result to `fteff_acc`. That function is Eqs. (A7)-(A10) of
|
|
141
|
+
Potekhin, Chabrier and Yakovlev (1997), where eta = g_s14^2 Delta M / M
|
|
142
|
+
(their Eq. A5). So the envelope formula sees eta = ETA / 0.443 = 2.26 ETA.
|
|
143
|
+
`run(eta=x)` therefore means PCY97 eta = x / 0.443.
|
|
144
|
+
`IsothermalStar.eta_nscool` reports the value used. See
|
|
145
|
+
[envelope normalization and provenance](physics/README.md#envelope-normalization-and-provenance)
|
|
146
|
+
for the reference-gravity interpretation and its limits.
|
|
147
|
+
- NSCool's default time step (`Code/Data_Files/NUM_PARAM.dat`: DT0 = TVAR = 1.2)
|
|
148
|
+
is not converged at late times. The error in log10 T_eff^inf is about
|
|
149
|
+
0.25 (DT0 - 1) at 1 Myr for a GM1 1.6 Msun star, and larger in the
|
|
150
|
+
photon-cooling drop. For reference curves, copy the tree and lower DT0
|
|
151
|
+
and TVAR together. Some stars with pairing then stall (for example APR
|
|
152
|
+
1.1 Msun at DT0 = 1.02 ran for over 25 min); give `run()` a timeout.
|
|
153
|
+
- The T73 and CCDK proton gaps close below n = 0.6 fm^-3. For APR the dUrca core of a
|
|
154
|
+
2.1 Msun star lies above that. So s_x <= 1, the range of Zhou+2026, cannot
|
|
155
|
+
quench dUrca there. With CCDK, s_x = 2 can.
|
|
156
|
+
- s_x < 1 moves the density where a gap closes down into the core. With CCDK at
|
|
157
|
+
1.4 Msun, s_x = 0.5 leaves 52 of 112 core zones unpaired.
|
|
158
|
+
- NSCool Ioffe proton gaps (`SFP1S0` = 201-203) are called with the neutron k_F
|
|
159
|
+
in `get_Tc`, and s_x does not act on them.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Neutron-star cooling: a driver for D. Page's NSCool (built separately).
|
|
2
|
+
|
|
3
|
+
See README.md in this directory for the build and the input formats.
|
|
4
|
+
"""
|
|
5
|
+
from .isothermal import IsothermalCurve, isothermal_curve
|
|
6
|
+
from .runner import (CoolingCurve, GapModel, IsothermalStar, NSCool, NSCoolError,
|
|
7
|
+
ZoneDump, default_home, parse_isothermal, parse_star_file,
|
|
8
|
+
parse_teff_file, parse_zone_dump)
|
|
9
|
+
|
|
10
|
+
__all__ = ["CoolingCurve", "GapModel", "IsothermalCurve", "IsothermalStar",
|
|
11
|
+
"NSCool", "NSCoolError", "ZoneDump", "default_home", "isothermal_curve",
|
|
12
|
+
"parse_isothermal", "parse_star_file", "parse_teff_file",
|
|
13
|
+
"parse_zone_dump"]
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Fetch, verify, patch and build NSCool (D. Page) outside the repository.
|
|
3
|
+
# NSCool ships without a licence, so nmbackend does not vendor it.
|
|
4
|
+
# NSCOOL_HOME install prefix (default ~/.local/share/nmbackend/nscool)
|
|
5
|
+
# NSCOOL_TARBALL use a local copy of NSCool.tar.gz instead of downloading
|
|
6
|
+
# FC Fortran compiler (default gfortran)
|
|
7
|
+
set -euo pipefail
|
|
8
|
+
URL=https://www.astroscu.unam.mx/neutrones/NSCool/NSCool.tar.gz
|
|
9
|
+
SHA256=c671fb959c732af595834152416cb60336009aa0e218b65ead55cae32f6af35a
|
|
10
|
+
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
11
|
+
PREFIX=${NSCOOL_HOME:-$HOME/.local/share/nmbackend/nscool}
|
|
12
|
+
FC=${FC:-gfortran}
|
|
13
|
+
FFLAGS="-O3 -fno-automatic -std=legacy -w"
|
|
14
|
+
|
|
15
|
+
mkdir -p "$PREFIX"
|
|
16
|
+
cd "$PREFIX"
|
|
17
|
+
if [[ -n "${NSCOOL_TARBALL:-}" ]]; then
|
|
18
|
+
cp "$NSCOOL_TARBALL" NSCool.tar.gz
|
|
19
|
+
elif [[ ! -f NSCool.tar.gz ]]; then
|
|
20
|
+
curl -fsSL --max-time 300 -o NSCool.tar.gz.part "$URL"
|
|
21
|
+
mv NSCool.tar.gz.part NSCool.tar.gz
|
|
22
|
+
fi
|
|
23
|
+
echo "$SHA256 NSCool.tar.gz" | sha256sum -c -
|
|
24
|
+
|
|
25
|
+
rm -rf NSCool
|
|
26
|
+
tar xzf NSCool.tar.gz
|
|
27
|
+
find NSCool \( -name '.DS_Store' -o -name '.#*' \) -delete
|
|
28
|
+
rm -f NSCool/NSCool.out NSCool/Code/NSCool.out NSCool/Plot/Plot_Teff NSCool/Model_1/Plot_Teff NSCool/TOV/TOV
|
|
29
|
+
(cd NSCool && patch -p1 -s < "$HERE/nscool_nmbackend.patch")
|
|
30
|
+
|
|
31
|
+
(cd NSCool/Code && make -s COMPILER="$FC" OPTIONS="$FFLAGS" NSCool.out >/dev/null)
|
|
32
|
+
(cd NSCool/TOV && "$FC" $FFLAGS -o TOV TOV.f)
|
|
33
|
+
# Isothermal-star scan: NSCool.f up to its output files, then our tail.
|
|
34
|
+
(cd NSCool/Code \
|
|
35
|
+
&& grep -q "INCLUDE 'NSCool_OPEN.inc.f'" NSCool.f \
|
|
36
|
+
&& sed "/INCLUDE 'NSCool_OPEN.inc.f'/,\$d" NSCool.f > NSCool_iso.f \
|
|
37
|
+
&& cat "$HERE/nscool_isothermal_tail.f" >> NSCool_iso.f \
|
|
38
|
+
&& "$FC" $FFLAGS -o NSCool_iso.out NSCool_iso.f \
|
|
39
|
+
$(sed -n '/^DEPENDS/,/^#/p' makefile | tr -d '\\' | sed 's/DEPENDS *=//;/^#/d'))
|
|
40
|
+
|
|
41
|
+
{
|
|
42
|
+
echo "source: $URL"
|
|
43
|
+
echo "sha256: $SHA256"
|
|
44
|
+
echo "patch: nscool_nmbackend.patch sha256 $(sha256sum "$HERE/nscool_nmbackend.patch" | cut -d' ' -f1)"
|
|
45
|
+
echo "iso: nscool_isothermal_tail.f sha256 $(sha256sum "$HERE/nscool_isothermal_tail.f" | cut -d' ' -f1)"
|
|
46
|
+
echo "fc: $("$FC" --version | head -1)"
|
|
47
|
+
echo "flags: $FFLAGS"
|
|
48
|
+
echo "host: $(hostname)"
|
|
49
|
+
echo "date: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
50
|
+
} > NSCool/BUILD_INFO.txt
|
|
51
|
+
echo "NSCool built in $PREFIX/NSCool"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Isothermal-interior cooling curve from an ``IsothermalStar`` table.
|
|
2
|
+
|
|
3
|
+
With a uniform redshifted interior temperature T, NSCool's energy
|
|
4
|
+
equation summed over zones is C(T) dT/dt = -[L_nu(T) - L_heat(T) + L_gamma(T)],
|
|
5
|
+
so the age at temperature T is
|
|
6
|
+
|
|
7
|
+
t(T) = integral_T^T0 C / (L_nu - L_heat + L_gamma) dT'.
|
|
8
|
+
|
|
9
|
+
With ``blanket=True`` the star is isothermal only below density rho_b:
|
|
10
|
+
the layer from NSCool's outer boundary to rho_b carries L_gamma by
|
|
11
|
+
conduction (``IsothermalStar.T_in``), so the interior at T_in(T_b) has
|
|
12
|
+
C(T_in) and L_nu(T_in) while the surface radiates L_gamma(T_b).
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import NamedTuple
|
|
17
|
+
|
|
18
|
+
import numpy as np
|
|
19
|
+
|
|
20
|
+
from .runner import IsothermalStar
|
|
21
|
+
|
|
22
|
+
__all__ = ["IsothermalCurve", "isothermal_curve"]
|
|
23
|
+
|
|
24
|
+
YEAR_S = 3.15576e7
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class IsothermalCurve(NamedTuple):
|
|
28
|
+
t_yr: np.ndarray # age, increasing
|
|
29
|
+
T: np.ndarray # redshifted interior temperature
|
|
30
|
+
Teff_inf: np.ndarray
|
|
31
|
+
L_gamma_inf: np.ndarray
|
|
32
|
+
L_nu_inf: np.ndarray
|
|
33
|
+
|
|
34
|
+
def at(self, t_yr, quantity: str = "Teff_inf") -> np.ndarray:
|
|
35
|
+
"""Log-log interpolation at finite positive ages within curve support.
|
|
36
|
+
|
|
37
|
+
Raises ValueError rather than returning an unsupported endpoint value.
|
|
38
|
+
"""
|
|
39
|
+
ages = np.asarray(self.t_yr, float)
|
|
40
|
+
query = np.asarray(t_yr, float)
|
|
41
|
+
if (ages.ndim != 1 or ages.size == 0 or not np.all(np.isfinite(ages))
|
|
42
|
+
or np.any(ages <= 0) or np.any(np.diff(ages) <= 0)):
|
|
43
|
+
raise ValueError("curve ages must be finite, positive and increasing")
|
|
44
|
+
if not np.all(np.isfinite(query)) or np.any(query <= 0):
|
|
45
|
+
raise ValueError("queried ages must be finite and positive")
|
|
46
|
+
if np.any(query < ages[0]) or np.any(query > ages[-1]):
|
|
47
|
+
raise ValueError(f"queried age outside curve support [{ages[0]:g}, {ages[-1]:g}] yr")
|
|
48
|
+
y = getattr(self, quantity)
|
|
49
|
+
return np.exp(np.interp(np.log(query), np.log(ages), np.log(y)))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def isothermal_curve(star: IsothermalStar, blanket: bool = False) -> IsothermalCurve:
|
|
53
|
+
"""Integrate t down the grid, with t = 0 at the top of the grid.
|
|
54
|
+
|
|
55
|
+
``T`` of the result is the interior temperature (T_in with
|
|
56
|
+
``blanket``). The integrand C T / L is integrated in ln T by the
|
|
57
|
+
trapezoid rule on NSCool's grid; refine the grid
|
|
58
|
+
(``NSCool.isothermal(T_grid=...)``) to check convergence.
|
|
59
|
+
"""
|
|
60
|
+
o = np.argsort(star.T)[::-1] # decreasing T (= T_b)
|
|
61
|
+
lnT = np.log(star.T[o])
|
|
62
|
+
C, L_nu, L_heat = star.C[o], star.L_nu[o], star.L_heat[o]
|
|
63
|
+
if blanket:
|
|
64
|
+
lnTi = np.log(star.T_in[o])
|
|
65
|
+
if np.any(np.diff(lnTi) >= 0):
|
|
66
|
+
raise ValueError("T_in is not monotonic in T_b")
|
|
67
|
+
C, L_nu, L_heat = (np.exp(np.interp(-lnTi, -lnT, np.log(np.maximum(y, 1e-300))))
|
|
68
|
+
for y in (C, L_nu, L_heat))
|
|
69
|
+
lnT = lnTi
|
|
70
|
+
L = L_nu - L_heat + star.L_gamma[o]
|
|
71
|
+
if np.any(L <= 0):
|
|
72
|
+
raise ValueError("net luminosity is not positive on the grid")
|
|
73
|
+
f = C / L * np.exp(lnT)
|
|
74
|
+
t = np.cumsum(0.5 * (f[1:] + f[:-1]) * -np.diff(lnT))
|
|
75
|
+
return IsothermalCurve(t / YEAR_S, np.exp(lnT[1:]), star.Teff_inf[o][1:],
|
|
76
|
+
star.L_gamma[o][1:], L_nu[1:])
|