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,68 @@
|
|
|
1
|
+
"""NSCool ICON_CORE=2 lepton thermal conductivity, including proton pairing.
|
|
2
|
+
|
|
3
|
+
The Shternin–Yakovlev 2007 prescription used by NSCool (2009 routine).
|
|
4
|
+
NSCool deliberately excludes its computed baryon conductivity from this
|
|
5
|
+
return value. This is a reference prescription, not a modern total-core model;
|
|
6
|
+
its superconducting transverse screening uses the Pippard-limit fit.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import jax.numpy as jnp
|
|
11
|
+
|
|
12
|
+
from .superfluid import below, f32, u_1s0
|
|
13
|
+
|
|
14
|
+
__all__ = ["lambda_core"]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def lambda_core(T, kfe, kfm, kfp, mstp, tcp):
|
|
18
|
+
"""Thermal conductivity [erg cm^-1 s^-1 K^-1] of core electrons and muons.
|
|
19
|
+
|
|
20
|
+
Mirrors NSCool ``con_core_lep`` and the lepton-only ``con_core`` sum.
|
|
21
|
+
T is local [K], kF [fm^-1], mstp the proton Landau/bare mass ratio,
|
|
22
|
+
tcp [K]. Inputs broadcast; T > 0, kF >= 0, mstp > 0 where protons exist.
|
|
23
|
+
Absent leptons contribute zero. Derivatives are intended away from
|
|
24
|
+
species onsets and the pairing transition (the shared gap helper clips Tc).
|
|
25
|
+
Hyperon scattering, baryon conduction and magnetic anisotropy are excluded.
|
|
26
|
+
"""
|
|
27
|
+
T, kfe, kfm, kfp, mstp, tcp = map(jnp.asarray, (T, kfe, kfm, kfp, mstp, tcp))
|
|
28
|
+
e = jnp.where(kfe > 0, kfe, 1.0)
|
|
29
|
+
has_mu = kfm > 0
|
|
30
|
+
m = kfm/e
|
|
31
|
+
ms = jnp.where(has_mu, m, 1.0)
|
|
32
|
+
p = kfp/e
|
|
33
|
+
mp = jnp.where(kfp > 0, mstp, 0.0)
|
|
34
|
+
r0, t8 = 1.68/e, T/1e8
|
|
35
|
+
ql3 = (0.00929*(1 + m + 2.83*mp*r0*p))**-1.5
|
|
36
|
+
qt2 = 1/(0.00929*(1 + m**2 + p**2))
|
|
37
|
+
ee_par = 1.43e11*r0*ql3*t8**2
|
|
38
|
+
ep_par = 1.15e12*mp**2*r0**2*ql3*t8**2
|
|
39
|
+
ee_per = 6.49e14*qt2*t8
|
|
40
|
+
ee_pri = 4.38e12*r0**f32(2/3)*qt2**f32(1/3)*ql3**f32(2/3)*t8**f32(5/3)
|
|
41
|
+
|
|
42
|
+
paired, tau = below(T, tcp, strict=False)
|
|
43
|
+
paired = paired & (kfp > 0)
|
|
44
|
+
y = u_1s0(jnp.where(paired, tau, 0.5))
|
|
45
|
+
# Preserve the reference value exactly at Tc without evaluating sqrt(0)
|
|
46
|
+
# in an AD-active branch. Transition derivatives are outside the contract.
|
|
47
|
+
y = jnp.where(T == tcp, 0.0, y)
|
|
48
|
+
sqrt_y = jnp.where(y > 0, jnp.sqrt(jnp.where(y > 0, y, 1.0)), 0.0)
|
|
49
|
+
ps = jnp.where(kfp > 0, kfp, e)
|
|
50
|
+
r = (e**2+kfm**2)/ps**2
|
|
51
|
+
rl = (r+1)**f32(1/3)/((r+1)**2-0.757*y+(0.50651*y)**2)**f32(1/6)
|
|
52
|
+
p1 = 0.48-0.17*r
|
|
53
|
+
p3 = ((1-p1)*54/4/3.1415926535**2/r)**2
|
|
54
|
+
rt = p1*jnp.exp(-0.14*y**2)+(1-p1)/jnp.sqrt(1+p3*y**2)
|
|
55
|
+
rp = (0.998+(2.04+0.68*sqrt_y+5.7*y**2+1.71*y**4)*jnp.exp(-1.04*y))*jnp.exp(-jnp.sqrt(1.23+y**2))
|
|
56
|
+
rl, rt, rp = (jnp.where(paired, x, 1.0) for x in (rl, rt, rp))
|
|
57
|
+
|
|
58
|
+
nu_e = (ee_par*(1+has_mu)+ep_par*rp
|
|
59
|
+
+ ee_per*(1+m**2+p**2)*rt + ee_pri*rl)
|
|
60
|
+
nu_m = jnp.where(has_mu,
|
|
61
|
+
(2*ee_par+ep_par*rp)/ms + ee_per*(m**3+m+m*p**2)*rt + ee_pri*m**3*rl, 0.0)
|
|
62
|
+
em = jnp.where(has_mu, ee_pri*m**2*rl, 0.0)
|
|
63
|
+
me = jnp.where(has_mu, ee_pri/ms*rl, 0.0)
|
|
64
|
+
denominator = jnp.where(has_mu, nu_e*nu_m-em*me, 1.0)
|
|
65
|
+
tau_e = jnp.where(has_mu, (nu_m-em)/denominator, 1/nu_e)
|
|
66
|
+
tau_m = jnp.where(has_mu, (nu_e-me)/denominator, 0.0)
|
|
67
|
+
lam = 1.70e24*t8*1e15*(tau_e*(e/1.68)**2+tau_m*(kfm/1.68)**2)
|
|
68
|
+
return jnp.where(kfe > 0, lam, 0.0)
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"""Core neutrino emissivities (erg cm^-3 s^-1), as NSCool's ``neutrino_core.f``.
|
|
2
|
+
|
|
3
|
+
All functions are elementwise over zones. T is the local temperature (K),
|
|
4
|
+
k_F in fm^-1, m* the Landau effective mass over the bare mass, nb in fm^-3.
|
|
5
|
+
``i`` is the zone index (0 = centre) and ``isf`` NSCool's last n3P2 zone;
|
|
6
|
+
NSCool treats neutron pairing as 3P2 for i < isf in the Urca and
|
|
7
|
+
bremsstrahlung routines and for i <= isf in pair breaking (zone isf
|
|
8
|
+
itself differs between them; we keep both).
|
|
9
|
+
|
|
10
|
+
| Function | NSCool routine | Source cited there |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| ``murca`` | numurca_nucl | Yakovlev & Levenfish 1995 |
|
|
13
|
+
| ``brem`` | nubrem_nucl | same |
|
|
14
|
+
| ``durca`` | nudurca_h (n-p channel) | Levenfish & Yakovlev 1994; Lattimer+1991 |
|
|
15
|
+
| ``pbf_1s0``, ``pbf_n3p2`` | nu_1s0_pbf, nu_n3p2_B_pbf | Yakovlev+1999; Kaminker+1999; Leinson 2010 |
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import functools
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
import jax.numpy as jnp
|
|
23
|
+
import numpy as np
|
|
24
|
+
|
|
25
|
+
from ._spline import natural_y2_matrix, spline_y2, splint2
|
|
26
|
+
from .superfluid import below, f32, fexp, u_1s0, u_3p2b
|
|
27
|
+
|
|
28
|
+
__all__ = ["murca", "brem", "durca", "durca_unpaired_channel", "durca_flag", "r_durca", "pbf_1s0",
|
|
29
|
+
"pbf_n3p2", "pbf_neutron", "sf_suppression_table"]
|
|
30
|
+
|
|
31
|
+
_PI = 3.14159265
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _sq(a, b):
|
|
35
|
+
return jnp.sqrt(a ** 2 + b ** 2)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# ---- modified Urca --------------------------------------------------------
|
|
39
|
+
def _r_mu_a(u): # rmurca_n_p1s0 = rmurca_p_n1s0
|
|
40
|
+
return (fexp(3.4370 - _sq(3.4370, u)) * 0.5
|
|
41
|
+
* ((0.1477 + _sq(0.8523, 0.1175 * u)) ** 7.5
|
|
42
|
+
+ (0.1477 + _sq(0.8523, 0.1297 * u)) ** 5.5))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _r_mu_b(u): # rmurca_n_n1s0 = rmurca_p_p1s0
|
|
46
|
+
return fexp(5.3390 - _sq(5.3390, 2.0 * u)) * (0.2414 + _sq(0.7586, 0.1318 * u)) ** 7.0
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _r_mu_p_3p2(u):
|
|
50
|
+
return (fexp(2.3980 - _sq(2.3980, u)) * 0.5
|
|
51
|
+
* ((0.1612 + _sq(0.8388, 0.1117 * u)) ** 7
|
|
52
|
+
+ (0.1612 + _sq(0.8388, 0.1274 * u)) ** 5))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def murca(T, kfe, kfm, kfn, kfp, mstn, mstp, tcn, tcp, i, isf):
|
|
56
|
+
"""Modified Urca, neutron plus proton branch (numurca_nucl)."""
|
|
57
|
+
t9 = T / 1e9
|
|
58
|
+
on = kfn * kfp != 0.0
|
|
59
|
+
kfn_ = jnp.where(on, kfn, 1.0)
|
|
60
|
+
kfp_ = jnp.where(on, kfp, 1.0)
|
|
61
|
+
kfe_ = jnp.where(kfe != 0.0, kfe, 1.0)
|
|
62
|
+
ab = (1.76 - 0.63 * (1.68 / kfn_) ** 2) * 0.68
|
|
63
|
+
qn = 8.55e21 * mstn ** 3 * mstp * (kfe / 1.68 + kfm / 1.68) * ab * t9 ** 8
|
|
64
|
+
qp = (8.55e21 * mstn * mstp ** 3 * (kfe / 1.68)
|
|
65
|
+
* (kfe + 3.0 * kfp_ - kfn_) ** 2 / (8.0 * kfe_ * kfp_) * ab * t9 ** 8)
|
|
66
|
+
# neutron pairing: 1S0 for i >= isf, 3P2 below
|
|
67
|
+
mn, tn = below(T, tcn)
|
|
68
|
+
trip = i < isf
|
|
69
|
+
u1, u3 = u_1s0(tn), u_3p2b(tn)
|
|
70
|
+
r_nn = jnp.where(trip, 39.1 * tn * fexp(-1.188 / tn) * _r_mu_p_3p2(u3), _r_mu_b(u1))
|
|
71
|
+
r_pn = jnp.where(trip, _r_mu_p_3p2(u3), _r_mu_a(u1))
|
|
72
|
+
r_nn, r_pn = jnp.where(mn, r_nn, 1.0), jnp.where(mn, r_pn, 1.0)
|
|
73
|
+
mp, tp = below(T, tcp)
|
|
74
|
+
up = u_1s0(tp)
|
|
75
|
+
r_np = jnp.where(mp, _r_mu_a(up), 1.0)
|
|
76
|
+
r_pp = jnp.where(mp, _r_mu_b(up), 1.0)
|
|
77
|
+
q = jnp.minimum(r_np, r_nn) * qn + jnp.minimum(r_pp, r_pn) * qp
|
|
78
|
+
return jnp.where(on, q, 0.0)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# ---- nucleon-nucleon bremsstrahlung -------------------------------------
|
|
82
|
+
def _r_nn(u): # rbrem_nn_n1s0 (also pp for p1S0, nn for n3P2)
|
|
83
|
+
return ((0.1747 + _sq(0.8253, 0.07933 * u)) ** 2 * fexp(4.228 - _sq(4.228, 4.0 * u)) / 2.0
|
|
84
|
+
+ (0.7333 + _sq(0.2667, 0.1678 * u)) ** 7.5 * fexp(7.762 - _sq(7.762, 9.0 * u)) / 2.0)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _r_np(u): # rbrem_np_p1s0 = rbrem_np_n1s0 = rbrem_np_n3p2B
|
|
88
|
+
return ((0.9982 + _sq(0.0018, 0.3815 * u)) * fexp(1.306 - _sq(1.306, u)) / 2.732
|
|
89
|
+
+ (0.3949 + _sq(0.6051, 0.2666 * u)) ** 7 * fexp(3.303 - _sq(3.303, 4.0 * u)) / 1.577)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def brem(T, kfn, kfp, mstn, mstp, tcn, tcp, i, isf):
|
|
93
|
+
"""nn + np + pp bremsstrahlung in the core (nubrem_nucl), three flavours."""
|
|
94
|
+
c = 3.0 * (T / 1e9) ** 8
|
|
95
|
+
qnn = c * 7.4e19 * mstn ** 4 * (kfn / 1.68) * 0.59 * 0.56
|
|
96
|
+
qnp = c * 1.5e20 * mstn ** 2 * mstp ** 2 * (kfp / 1.68) * 1.06 * 0.66
|
|
97
|
+
qpp = c * 7.4e19 * mstp ** 4 * (kfp / 1.68) * 0.11 * 0.7
|
|
98
|
+
mn, tn = below(T, tcn)
|
|
99
|
+
u = jnp.where(i < isf, u_3p2b(tn), u_1s0(tn))
|
|
100
|
+
rnn_n = jnp.where(mn, _r_nn(u), 1.0)
|
|
101
|
+
rnp_n = jnp.where(mn, _r_np(u), 1.0)
|
|
102
|
+
mp, tp = below(T, tcp)
|
|
103
|
+
up = u_1s0(tp)
|
|
104
|
+
rnp_p = jnp.where(mp, _r_np(up), 1.0)
|
|
105
|
+
rpp_p = jnp.where(mp, _r_nn(up), 1.0)
|
|
106
|
+
return rnn_n * qnn + jnp.minimum(rnp_p, rnp_n) * qnp + rpp_p * qpp
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# ---- direct Urca ---------------------------------------------------------
|
|
110
|
+
def durca_flag(kfe, kfm, kfn, kfp):
|
|
111
|
+
"""NSCool idurca_np: 0 closed, 1 electron triangle, 2 electron and muon."""
|
|
112
|
+
kfe, kfm, kfn, kfp = (jnp.asarray(x) for x in (kfe, kfm, kfn, kfp))
|
|
113
|
+
tri = lambda a, b, c: (a < b + c) & (b < a + c) & (c < a + b)
|
|
114
|
+
e = tri(kfp, kfn, kfe)
|
|
115
|
+
mu = e & tri(kfp, kfn, kfm)
|
|
116
|
+
return e.astype(int) + mu.astype(int)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _r1(u):
|
|
120
|
+
return (0.2312 + _sq(0.7688, 0.1438 * u)) ** 5.5 * fexp(3.427 - _sq(3.427, u))
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _r3(u):
|
|
124
|
+
return (0.2546 + _sq(0.7454, 0.1284 * u)) ** 5 * fexp(2.701 - _sq(2.701, u))
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _r_1s0_1s0(v1, v2):
|
|
128
|
+
"""func_r_1s0_1s0 (Levenfish & Yakovlev 1994, both 1S0)."""
|
|
129
|
+
gamma = 5040.0 / 457.0 / _PI ** 6
|
|
130
|
+
u = v1 ** 2 + v2 ** 2
|
|
131
|
+
w = v1 ** 2 - v2 ** 2
|
|
132
|
+
u1 = 1.8091 + jnp.sqrt(v1 ** 2 + 2.2476 ** 2)
|
|
133
|
+
u2 = 1.8091 + jnp.sqrt(v2 ** 2 + 2.2476 ** 2)
|
|
134
|
+
root = jnp.sqrt(w ** 2 + 16.350 * u + 45.171)
|
|
135
|
+
p = (u + 12.421 + root) / 2.0
|
|
136
|
+
q = (u + 12.421 - root) / 2.0
|
|
137
|
+
ps = (u + jnp.sqrt(w ** 2 + 5524.8 * u + 6.7737)) / 2.0
|
|
138
|
+
pe = (u + 0.43847 + jnp.sqrt(w ** 2 + 8.3680 * u + 491.32)) / 2.0
|
|
139
|
+
d = ((u1 * u2) ** 1.5 / (2.0 * 4.0567 ** 5) * (u1 ** 2 + u2 ** 2)
|
|
140
|
+
* jnp.exp(-u1 - u2 + 8.1134))
|
|
141
|
+
lg = jnp.log((jnp.sqrt(p) + jnp.sqrt(p - q)) / jnp.sqrt(q))
|
|
142
|
+
k0 = (jnp.sqrt(p - q) / 120.0 * (6.0 * p ** 2 + 83.0 * p * q + 16.0 * q ** 2)
|
|
143
|
+
- jnp.sqrt(p) * q / 8.0 * (4.0 * p + 3.0 * q) * lg)
|
|
144
|
+
k1 = (_PI ** 2 * jnp.sqrt(p - q) / 6.0 * (p + 2.0 * q)
|
|
145
|
+
- _PI ** 2 / 2.0 * q * jnp.sqrt(p) * lg)
|
|
146
|
+
k2 = 7.0 * _PI ** 4 / 60.0 * jnp.sqrt(p - q)
|
|
147
|
+
s = (gamma * (k0 + k1 + 0.42232 * k2) * jnp.sqrt(_PI / 2.0) * ps ** 0.25
|
|
148
|
+
* jnp.exp(-jnp.sqrt(pe)))
|
|
149
|
+
return u / (u + 0.9163) * s + d
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@functools.lru_cache(maxsize=None)
|
|
153
|
+
def sf_suppression_table(path=None):
|
|
154
|
+
"""NSCool's Code/Data_Files/SF_suppression.dat as spline arrays.
|
|
155
|
+
|
|
156
|
+
log10 R(log10 tau_p, log10 tau_n) for dUrca with p1S0 and n3P2 pairing.
|
|
157
|
+
NSCool has no licence, so the table is read from the NSCool build
|
|
158
|
+
(``build_nscool.sh``), not shipped with nmbackend. ``durca`` needs it
|
|
159
|
+
even for stars without dUrca; the default path is fixed at first use.
|
|
160
|
+
"""
|
|
161
|
+
if path is None:
|
|
162
|
+
from ..runner import default_home
|
|
163
|
+
path = default_home() / "Code" / "Data_Files" / "SF_suppression.dat"
|
|
164
|
+
v = np.array(Path(path).read_text().split(), float)
|
|
165
|
+
if v.size != 35 + 35 + 35 * 35:
|
|
166
|
+
raise ValueError(f"{path}: expected 35 + 35 + 35x35 numbers")
|
|
167
|
+
x1, x2 = v[:35][::-1], v[35:70][::-1] # read backwards
|
|
168
|
+
lgr = v[70:].reshape(35, 35)[::-1, ::-1]
|
|
169
|
+
y2 = np.stack([spline_y2(x2, row) for row in lgr])
|
|
170
|
+
return x1, x2, lgr, y2, natural_y2_matrix(x1)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _r_1s0_3p2b(t1, t2, table):
|
|
174
|
+
"""func_r_1s0_3P2B: spline in (log10 T/Tcp, log10 T/Tcn); beyond radius 3
|
|
175
|
+
NSCool evaluates on the unit circle and multiplies by exp(-r/3)."""
|
|
176
|
+
l1, l2 = jnp.log10(t1), jnp.log10(t2)
|
|
177
|
+
lt = jnp.sqrt(l1 ** 2 + l2 ** 2)
|
|
178
|
+
far = lt > 3.0
|
|
179
|
+
s = jnp.where(far, lt, 1.0)
|
|
180
|
+
ev = jnp.vectorize(lambda a, b: splint2(*table[:4], table[4], a, b))
|
|
181
|
+
return 10.0 ** ev(l1 / s, l2 / s) * jnp.where(far, jnp.exp(-lt / 3.0), 1.0)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def r_durca(T, tcn, tcp, i, isf, table=None):
|
|
185
|
+
"""Pairing suppression of n-p dUrca (nudurca_h)."""
|
|
186
|
+
table = sf_suppression_table() if table is None else table
|
|
187
|
+
sn = T <= tcn
|
|
188
|
+
sp = T <= tcp
|
|
189
|
+
_, tn = below(T, tcn, strict=False)
|
|
190
|
+
_, tp = below(T, tcp, strict=False)
|
|
191
|
+
trip = i < isf
|
|
192
|
+
vp, vn1, vn3 = u_1s0(tp), u_1s0(tn), u_3p2b(tn)
|
|
193
|
+
r_p = _r1(vp)
|
|
194
|
+
r_n = jnp.where(trip, _r3(vn3), _r1(vn1))
|
|
195
|
+
r_both = jnp.where(trip, _r_1s0_3p2b(tp, tn, table), _r_1s0_1s0(vp, vn1))
|
|
196
|
+
return jnp.where(sn & sp, r_both, jnp.where(sn, r_n, jnp.where(sp, r_p, 1.0)))
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def durca_unpaired_channel(T, mstn, mstp, nb, Yl):
|
|
200
|
+
"""Unpaired n-p direct-Urca amplitude for one lepton, without a threshold.
|
|
201
|
+
|
|
202
|
+
Mirrors ``nudurca_h``'s n-p channel; the caller supplies its active domain.
|
|
203
|
+
"""
|
|
204
|
+
present = jnp.abs(Yl) > 0
|
|
205
|
+
density = jnp.where(present, jnp.abs(Yl) * nb / 0.16, 1.)
|
|
206
|
+
return 4.24e27 * mstn * mstp * (T / 1e9)**6 * jnp.where(present, density**(1./3.), 0.)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def durca(T, kfe, kfm, kfn, kfp, mstn, mstp, nb, Ye, Ymu, tcn, tcp, i, isf, table=None):
|
|
210
|
+
"""n-p direct Urca with electrons, plus muons where their triangle closes."""
|
|
211
|
+
flag = durca_flag(kfe, kfm, kfn, kfp)
|
|
212
|
+
mu = flag == 2
|
|
213
|
+
q = durca_unpaired_channel(T, mstn, mstp, nb, Ye)
|
|
214
|
+
q += jnp.where(mu, durca_unpaired_channel(T, mstn, mstp, nb, Ymu), 0.)
|
|
215
|
+
return jnp.where(flag > 0, q * r_durca(T, tcn, tcp, i, isf, table), 0.0)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
# ---- pair breaking and formation --------------------------------------------
|
|
219
|
+
_C011 = f32(0.01130)
|
|
220
|
+
_C3P2 = (f32(0.3191), f32(0.3511), f32(0.7591))
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _ctrl_1s0(v):
|
|
224
|
+
x = 0.602 * v ** 2 + 0.5942 * v ** 4 + 0.288 * v ** 6
|
|
225
|
+
y = jnp.sqrt(0.5547 + jnp.sqrt(0.4453 ** 2 + _C011 * v ** 2))
|
|
226
|
+
return x * y * jnp.exp(-jnp.sqrt(4.0 * v ** 2 + 2.245 ** 2) + 2.245)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _ctrl_3p2b(v):
|
|
230
|
+
a, b, c = _C3P2
|
|
231
|
+
x = (1.204 * v ** 2 + 3.733 * v ** 4 + a * v ** 6) / (1.0 + b * v ** 2)
|
|
232
|
+
y = (c + jnp.sqrt(0.2409 ** 2 + 0.3145 * v ** 2)) ** 2
|
|
233
|
+
return x * y * jnp.exp(-jnp.sqrt(4.0 * v ** 2 + 0.4616 ** 2) + 0.4616)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _pbf(T, kf, mst, a, ctrl, m, v):
|
|
237
|
+
vf = kf * 197.0 / mst / 940.0
|
|
238
|
+
q = 1.170e21 * mst ** 2 * vf * (T / 1e9) ** 7 * 3.0 * a * ctrl(v)
|
|
239
|
+
return jnp.where(m, q, 0.0)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def pbf_1s0(T, tc, mst, kf):
|
|
243
|
+
"""Singlet pair breaking, axial part only (nu_1s0_pbf)."""
|
|
244
|
+
m, tau = below(T, tc, strict=False)
|
|
245
|
+
m, mst = m & (mst > 0), jnp.where(mst > 0, mst, 1.0) # no neutrons: m* = 0
|
|
246
|
+
vf = kf * 197.0 / mst / 940.0
|
|
247
|
+
a = 1.60 * vf ** 2 * (mst ** 2 + 11.0 / 42.0)
|
|
248
|
+
return _pbf(T, kf, mst, a, _ctrl_1s0, m, u_1s0(tau))
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def pbf_n3p2(T, tc, mst, kf, ca=0.5):
|
|
252
|
+
"""n3P2 (m=0) pair breaking with a_A = c_A g_A^2 (nu_n3p2_B_pbf, nmbackend patch).
|
|
253
|
+
|
|
254
|
+
NSCool's gap here is sqrt(1-tau)(0.7893 + 1.764/tau); the Urca routines
|
|
255
|
+
use 1.188/tau (Yakovlev+1999 Table 1) for the same gap.
|
|
256
|
+
"""
|
|
257
|
+
m, tau = below(T, tc, strict=False)
|
|
258
|
+
m, mst = m & (mst > 0), jnp.where(mst > 0, mst, 1.0)
|
|
259
|
+
v = jnp.sqrt(1.0 - tau) * (0.7893 + 1.764 / tau)
|
|
260
|
+
return _pbf(T, kf, mst, ca * 1.26 ** 2, _ctrl_3p2b, m, v)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def pbf_neutron(T, tcn, mstn, kfn, i, isf, ca=0.5):
|
|
264
|
+
"""Neutron pair breaking as neutrino.f dispatches it: (n1S0 for i > isf,
|
|
265
|
+
n3P2 for i <= isf). Applies in the crust as well as the core."""
|
|
266
|
+
q1 = jnp.where(i > isf, pbf_1s0(T, tcn, mstn, kfn), 0.0)
|
|
267
|
+
q3 = jnp.where(i <= isf, pbf_n3p2(T, tcn, mstn, kfn, ca), 0.0)
|
|
268
|
+
return q1, q3
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Tabulated NSCool crust thermal chemistry, distinct from the native EOS density."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import NamedTuple
|
|
6
|
+
|
|
7
|
+
import jax.numpy as jnp
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CrustTable(NamedTuple):
|
|
12
|
+
"""Ascending density nodes; rho in g/cm^3 and chemical n in fm^-3."""
|
|
13
|
+
rho: jnp.ndarray
|
|
14
|
+
n: jnp.ndarray
|
|
15
|
+
A_cell: jnp.ndarray
|
|
16
|
+
A_ion: jnp.ndarray
|
|
17
|
+
Z: jnp.ndarray
|
|
18
|
+
|
|
19
|
+
@classmethod
|
|
20
|
+
def read(cls, path):
|
|
21
|
+
"""Read and validate an NSCool six-column crust file outside JIT."""
|
|
22
|
+
lines = Path(path).read_text().splitlines()
|
|
23
|
+
n_text, n_rows = map(int, lines[0].split()[:2])
|
|
24
|
+
records = [line for line in lines[1+n_text:] if line.strip()][:n_rows]
|
|
25
|
+
# Fortran reads six quantities; trailing phase-transition annotations are ignored.
|
|
26
|
+
data = np.asarray([[float(v) for v in line.split()[:6]] for line in records])
|
|
27
|
+
if data.shape != (n_rows, 6) or n_rows < 2 or not np.all(np.isfinite(data)):
|
|
28
|
+
raise ValueError('Crust file must contain finite six-column rows')
|
|
29
|
+
data = data[np.argsort(data[:, 0])]
|
|
30
|
+
rho, pressure, n, cell, ion, z = data.T
|
|
31
|
+
if (np.any(rho <= 0) or np.any(pressure <= 0) or np.any(n <= 0)
|
|
32
|
+
or np.any(np.diff(rho) <= 0) or np.any(np.diff(n) <= 0)
|
|
33
|
+
or np.any(z <= 0) or np.any(ion < z) or np.any(cell < ion)):
|
|
34
|
+
raise ValueError('Invalid crust density or nuclear composition')
|
|
35
|
+
return cls(*(jnp.asarray(v) for v in (rho, n, cell, ion, z)))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class CrustChemistry(NamedTuple):
|
|
39
|
+
"""Reference chemical n, fractions and nuclei; n does not overwrite EOS n."""
|
|
40
|
+
n: jnp.ndarray
|
|
41
|
+
Ye: jnp.ndarray
|
|
42
|
+
Yn: jnp.ndarray
|
|
43
|
+
A_cell: jnp.ndarray
|
|
44
|
+
A_ion: jnp.ndarray
|
|
45
|
+
Z: jnp.ndarray
|
|
46
|
+
v_ion: jnp.ndarray
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def crust_chemistry(table: CrustTable, rho, *, core_rho, core_n, core_Ye):
|
|
50
|
+
"""Thermal chemistry with a moving core-matched upper node; invalid inputs give NaN.
|
|
51
|
+
|
|
52
|
+
Mirrors ``get_crust_chemistry`` in NSCool ``precool.f``. Intervals are
|
|
53
|
+
lower < rho <= upper. Derivatives are conditional between species/join
|
|
54
|
+
contacts. Queries must exceed the lowest node and not exceed core_rho.
|
|
55
|
+
The supplied core electron fraction sets the virtual top's A_cell.
|
|
56
|
+
"""
|
|
57
|
+
last = jnp.clip(jnp.searchsorted(table.rho, core_rho, side='left')-1,
|
|
58
|
+
0, table.rho.size-1)
|
|
59
|
+
upper = jnp.clip(jnp.searchsorted(table.rho, rho, side='left'), 1, last+1)
|
|
60
|
+
lower = upper-1
|
|
61
|
+
index = jnp.minimum(upper, table.rho.size-1)
|
|
62
|
+
virtual = upper == last+1
|
|
63
|
+
safe_ye = jnp.where(core_Ye > 0, core_Ye, 1.)
|
|
64
|
+
top_cell = table.Z[last]/safe_ye
|
|
65
|
+
hi_rho = jnp.where(virtual, core_rho, table.rho[index])
|
|
66
|
+
hi_n = jnp.where(virtual, core_n, table.n[index])
|
|
67
|
+
hi_cell = jnp.where(virtual, top_cell, table.A_cell[index])
|
|
68
|
+
hi_ion = jnp.where(virtual, table.A_ion[last], table.A_ion[index])
|
|
69
|
+
hi_z = jnp.where(virtual, table.Z[last], table.Z[index])
|
|
70
|
+
width = hi_rho-table.rho[lower]
|
|
71
|
+
weight = (rho-table.rho[lower])/jnp.where(width > 0, width, 1.)
|
|
72
|
+
cell = jnp.where(hi_cell == hi_ion, hi_cell,
|
|
73
|
+
table.A_cell[lower]+weight*(hi_cell-table.A_cell[lower]))
|
|
74
|
+
n = table.n[lower]+weight*(hi_n-table.n[lower])
|
|
75
|
+
safe_cell = jnp.where(cell > 0, cell, 1.)
|
|
76
|
+
ye, yn = hi_z/safe_cell, (cell-hi_ion)/safe_cell
|
|
77
|
+
# The nuclear mass cancels in NSCool's n_ion * v_nucleus prescription.
|
|
78
|
+
volume = jnp.minimum(1., rho*(4./3.*3.14159*1.1**3*1e-39)/(1.66e-24))
|
|
79
|
+
values = CrustChemistry(n, ye, yn, cell, hi_ion, hi_z, volume)
|
|
80
|
+
valid = (jnp.isfinite(rho) & jnp.isfinite(core_rho) & jnp.isfinite(core_n)
|
|
81
|
+
& jnp.isfinite(core_Ye) & (core_rho > table.rho[0]) & (core_n > 0)
|
|
82
|
+
& (core_Ye > 0) & (core_Ye <= 1)
|
|
83
|
+
& jnp.isfinite(top_cell) & jnp.isfinite(cell) & jnp.isfinite(n)
|
|
84
|
+
& (top_cell >= table.A_ion[last]) & (core_n >= table.n[last])
|
|
85
|
+
& (rho > table.rho[0])
|
|
86
|
+
& (rho <= core_rho) & (width > 0) & (n > 0)
|
|
87
|
+
& (hi_z > 0) & (hi_ion >= hi_z) & (cell >= hi_ion))
|
|
88
|
+
return CrustChemistry(*(jnp.where(valid, value, jnp.nan) for value in values))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _unpaired_crust_terms(T_local, rho, chemistry, *, rho_drip):
|
|
92
|
+
"""Local unpaired crust cv and neutrino emissivity, without GR weights.
|
|
93
|
+
|
|
94
|
+
Mirrors NSCool's EMNCR=5 neutron mass prescription and unpaired thermal
|
|
95
|
+
calls. Chemical density is distinct from EOS energy density. The caller
|
|
96
|
+
owns density coverage and moving species, drip and ionic phase contacts.
|
|
97
|
+
The unsupported ionic source-table overrun branch must be excluded.
|
|
98
|
+
"""
|
|
99
|
+
from . import crust_nu, heat
|
|
100
|
+
from .native import _kf
|
|
101
|
+
|
|
102
|
+
ke = _kf(chemistry.n, chemistry.Ye)
|
|
103
|
+
kn = _kf(chemistry.n, chemistry.Yn)
|
|
104
|
+
mn = jnp.minimum(1., 1.09-.11*kn)
|
|
105
|
+
inner = rho >= rho_drip
|
|
106
|
+
cv = (heat.lepton_cv_coeff(ke, .511)*T_local
|
|
107
|
+
+ heat.cv_ion(T_local, rho, chemistry.A_cell, chemistry.Z)
|
|
108
|
+
+ jnp.where(inner, heat.cv_coeff(kn, 939.56*mn)*T_local, 0.))
|
|
109
|
+
q = (crust_nu.eebrem(T_local, ke) + crust_nu.npb(T_local, rho)
|
|
110
|
+
+ crust_nu.plasma(T_local, rho, chemistry.A_cell, chemistry.Z)
|
|
111
|
+
+ jnp.where(inner, crust_nu.brem_nn_crust(
|
|
112
|
+
T_local, kn, mn, 0., chemistry.v_ion, 0, -1), 0.))
|
|
113
|
+
return cv, q
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Crust neutrino emissivities (erg cm^-3 s^-1), as NSCool's ``neutrino_crust.f``.
|
|
2
|
+
|
|
3
|
+
| Function | NSCool routine | Source cited there |
|
|
4
|
+
|---|---|---|
|
|
5
|
+
| ``eebrem`` | neebrem | Jaikumar, Gale & Page 2005 (table Nalpha.dat) |
|
|
6
|
+
| ``npb`` | npb_new | Kaminker+1999, Eq. 40 |
|
|
7
|
+
| ``plasma`` | nplasma | Haft, Raffelt & Weiss 1994; Itoh+1996 |
|
|
8
|
+
| ``brem_nn_crust`` | nubrem_crust_nn | Yakovlev & Levenfish 1995 |
|
|
9
|
+
|
|
10
|
+
NSCool calls them only at rho < rhocore (nn bremsstrahlung only above
|
|
11
|
+
neutron drip). Pair, photo and synchrotron emission are off in our runs
|
|
12
|
+
(I_Neutrino_1.dat).
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import functools
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
import jax.numpy as jnp
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
from ._spline import spline_y2, splint
|
|
23
|
+
from .core_nu import _r_nn
|
|
24
|
+
from .superfluid import below, f32, fexp, u_1s0, u_3p2b
|
|
25
|
+
|
|
26
|
+
__all__ = ["eebrem", "npb", "plasma", "brem_nn_crust", "nalpha_table"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@functools.lru_cache(maxsize=None)
|
|
30
|
+
def nalpha_table(path=None):
|
|
31
|
+
"""NSCool's Code/Data_Files/Nalpha.dat, read from the NSCool build
|
|
32
|
+
(not shipped: NSCool has no licence). x = log10 T9 + 9."""
|
|
33
|
+
if path is None:
|
|
34
|
+
from ..runner import default_home
|
|
35
|
+
path = default_home() / "Code" / "Data_Files" / "Nalpha.dat"
|
|
36
|
+
v = np.array(Path(path).read_text().split(), float).reshape(-1, 2)
|
|
37
|
+
x = np.log10(v[:, 0]) + 9.0
|
|
38
|
+
return x, v[:, 1], spline_y2(x, v[:, 1])
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def eebrem(T, kfe, table=None):
|
|
42
|
+
"""Electron-electron pair bremsstrahlung (neebrem).
|
|
43
|
+
|
|
44
|
+
NSCool evaluates the table at log10(T / (mu_e / 10 MeV)), with T in K.
|
|
45
|
+
"""
|
|
46
|
+
x, y, y2 = nalpha_table() if table is None else table
|
|
47
|
+
ok = kfe > 0
|
|
48
|
+
mu = jnp.where(ok, kfe, 1.0) * 197.0
|
|
49
|
+
naa = splint(x, y, y2, jnp.log10(T / (mu / 10.0)))
|
|
50
|
+
return jnp.where(ok, 2.16e14 * (T / 1e9) ** 7 * (mu / 10.0) ** 2 * naa, 0.0)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
_NPB = [f32(c) for c in (11.204, 7.304, 0.2976, 0.370, 0.188, 0.103, 0.0547, 6.77, 0.228)]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def npb(T, rho):
|
|
57
|
+
"""Electron-nucleus pair bremsstrahlung, Kaminker+1999 fit (npb_new)."""
|
|
58
|
+
c0, c1, c2, c3, c4, c5, c6, c7, c8 = _NPB
|
|
59
|
+
tau = jnp.log10(T / 1e8)
|
|
60
|
+
r = jnp.log10(rho / 1e12)
|
|
61
|
+
lgq = (c0 + c1 * tau + c2 * r - c3 * tau ** 2 + c4 * tau * r - c5 * r ** 2
|
|
62
|
+
+ c6 * tau ** 2 * r - c7 * jnp.log10(1.0 + c8 * rho / 2.8e14))
|
|
63
|
+
return 10.0 ** lgq
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def plasma(T, rho, A, Z):
|
|
67
|
+
"""Plasmon decay (nplasma); A is NSCool's a_cell, Z the nuclear charge."""
|
|
68
|
+
ok = (Z != 0.0) & (A > 0)
|
|
69
|
+
zs = jnp.where(ok, Z, 1.0)
|
|
70
|
+
rza = rho * zs / jnp.where(ok, A, 1.0)
|
|
71
|
+
l = T / 5.9302e9
|
|
72
|
+
den = 1.0 + (1.019e-6 * rza) ** (2.0 / 3.0)
|
|
73
|
+
g2 = 1.1095e11 * rza / T ** 2 / den ** 0.5
|
|
74
|
+
g = jnp.sqrt(g2)
|
|
75
|
+
f_t = 2.4 + 0.6 * g ** 0.5 + 0.51 * g + 1.25 * g ** 1.5
|
|
76
|
+
f_l = (8.6 * g2 + 1.35 * g ** 3.5) / (225.0 - 17.0 * g + g2)
|
|
77
|
+
x = (17.5 + jnp.log10(2.0 * rza) - 3.0 * jnp.log10(T)) / 6.0
|
|
78
|
+
y = (-24.5 + jnp.log10(2.0 * rza) + 3.0 * jnp.log10(T)) / 6.0
|
|
79
|
+
first = (0.39 - 1.25 * x - 0.35 * jnp.sin(4.5 * x)
|
|
80
|
+
- 0.3 * fexp(-(4.5 * x + 0.9) ** 2))
|
|
81
|
+
second = jnp.minimum(0.0, y - 1.6 + 1.25 * x) / (0.57 - 0.25 * x)
|
|
82
|
+
f_xy = jnp.where((jnp.abs(x) > 0.7) | (y < 0.0), 1.0, 1.05 + first * fexp(-second ** 2))
|
|
83
|
+
q = 3.00e21 * l ** 9 * g ** 6 * fexp(-g) * (f_l + f_t) * f_xy
|
|
84
|
+
return jnp.where(ok, q, 0.0)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def brem_nn_crust(T, kfn, mstn, tcn, v_ion, i, isf):
|
|
88
|
+
"""nn bremsstrahlung of the dripped neutrons (nubrem_crust_nn), reduced by
|
|
89
|
+
the volume fraction of nuclei v_ion."""
|
|
90
|
+
q = 3.0 * 7.4e19 * mstn ** 4 * (kfn / 1.68) * 0.59 * 0.56 * (T / 1e9) ** 8
|
|
91
|
+
m, tau = below(T, tcn)
|
|
92
|
+
u = jnp.where(i < isf, u_3p2b(tau), u_1s0(tau))
|
|
93
|
+
return jnp.where(m, _r_nn(u), 1.0) * q * (1.0 - v_ion)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Isothermal cooling curve from the JAX sums (``nmbackend.cooling.isothermal``
|
|
2
|
+
with jnp, so it is differentiable).
|
|
3
|
+
|
|
4
|
+
t(T) = int C / (L_nu + L_gamma) dT, trapezoid in ln T on a decreasing grid
|
|
5
|
+
of T_b, with the crust blanket: the interior at T_in(T_b) has C(T_in) and
|
|
6
|
+
L_nu(T_in), interpolated log-log on the grid as the C1 driver does.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import jax
|
|
11
|
+
import jax.numpy as jnp
|
|
12
|
+
|
|
13
|
+
from ..isothermal import YEAR_S, IsothermalCurve
|
|
14
|
+
from .star import isothermal_sums
|
|
15
|
+
|
|
16
|
+
__all__ = ["isothermal_curve"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def isothermal_curve(T_grid, star, tc, eta=0.0, rho_b=0.0, ca_n3p2=0.5,
|
|
20
|
+
blanket=None) -> IsothermalCurve:
|
|
21
|
+
"""Curve on ``T_grid`` (redshifted T_b, any order; returned decreasing).
|
|
22
|
+
|
|
23
|
+
``blanket`` defaults to rho_b > 0; pass it when rho_b is traced.
|
|
24
|
+
Heating is off (L_heat = 0).
|
|
25
|
+
"""
|
|
26
|
+
if blanket is None:
|
|
27
|
+
if not isinstance(rho_b, (int, float)):
|
|
28
|
+
raise TypeError("pass blanket= when rho_b is a JAX value")
|
|
29
|
+
blanket = rho_b > 0
|
|
30
|
+
T = jnp.sort(jnp.asarray(T_grid, float))[::-1]
|
|
31
|
+
s = jax.vmap(lambda t: isothermal_sums(t, star, tc, eta, rho_b, ca_n3p2))(T)
|
|
32
|
+
lnT = jnp.log(T)
|
|
33
|
+
C, L_nu = s.C, s.L_nu
|
|
34
|
+
if blanket:
|
|
35
|
+
lnTi = jnp.log(s.T_in)
|
|
36
|
+
li = lambda y: jnp.exp(jnp.interp(-lnTi, -lnT, jnp.log(jnp.maximum(y, 1e-300))))
|
|
37
|
+
C, L_nu = li(C), li(L_nu)
|
|
38
|
+
lnT = lnTi
|
|
39
|
+
f = C / (L_nu + s.L_gamma) * jnp.exp(lnT)
|
|
40
|
+
t = jnp.cumsum(0.5 * (f[1:] + f[:-1]) * -jnp.diff(lnT))
|
|
41
|
+
return IsothermalCurve(t / YEAR_S, jnp.exp(lnT[1:]), s.Teff_inf[1:],
|
|
42
|
+
s.L_gamma[1:], L_nu[1:])
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Envelope T_b -> T_s: Potekhin, Chabrier & Yakovlev 1997 (PCY97), Eqs. A7-A10.
|
|
2
|
+
|
|
3
|
+
As NSCool's ``fteff_acc``. ``eta`` here is PCY97's eta = g_s14^2 Delta M / M.
|
|
4
|
+
NSCool divides its input ETA by 0.443 before this formula
|
|
5
|
+
(see physics/README.md, envelope normalization), so NSCool ETA = 0.443 eta.
|
|
6
|
+
Steiner interprets the fixed factor as a reference-gravity normalization;
|
|
7
|
+
it is not recomputed from the current star's gs14.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import jax.numpy as jnp
|
|
12
|
+
|
|
13
|
+
from .superfluid import f32
|
|
14
|
+
|
|
15
|
+
__all__ = ["teff_local", "gs14"]
|
|
16
|
+
|
|
17
|
+
_G, _MSUN, _C = 6.67e-8, 1.989e33, 2.99792e10
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def gs14(mass_msun, radius_cm):
|
|
21
|
+
"""Surface gravity / 1e14 cm s^-2, as NSCool.f (with its constants)."""
|
|
22
|
+
root = jnp.sqrt(1.0 - 2.0 * _G * _MSUN * mass_msun / radius_cm / _C ** 2)
|
|
23
|
+
return _G * _MSUN * mass_msun / radius_cm ** 2 / root / 1e14
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def teff_local(Tb, eta, g14):
|
|
27
|
+
"""Local effective temperature (K) for local T_b (K) at rho_b = 1e10 g/cm^3."""
|
|
28
|
+
tb9 = Tb / 1e9
|
|
29
|
+
ts = jnp.sqrt(7.0 * tb9 * jnp.sqrt(g14))
|
|
30
|
+
z = tb9 - ts / 1e3
|
|
31
|
+
t4_iron = g14 * ((7.0 * z) ** 2.25 + (z / 3.0) ** 1.25)
|
|
32
|
+
t4_wacc = g14 * (18.1 * tb9) ** f32(2.42)
|
|
33
|
+
acc = eta > 1e-30
|
|
34
|
+
es = jnp.where(acc, eta, 1.0)
|
|
35
|
+
a = (1.2 + (5.3e-6 / es) ** f32(0.38)) * tb9 ** f32(5.0 / 3.0)
|
|
36
|
+
t4 = jnp.where(acc, (a * t4_iron + t4_wacc) / (a + 1.0), t4_iron)
|
|
37
|
+
return t4 ** 0.25 * 1e6
|