Creating an NSE table

We can tabulate the NSE state on a grid \((\rho, T, Y_e)\), giving:

  • \(\bar{A}\) : the mean molecular weight

  • \(\langle B/A \rangle\) : the average binding energy per nucleon of the NSE state [MeV]

  • \(dY_e/dt\) : the time-evolution of \(Y_e\) due to weak reactions [1/s]

  • \(d\bar{A}/dt\) : the time-evolution of \(\bar{A}\) due to weak reactions [1/s]

  • \(d\langle B/A\rangle/dt\) : the time-evolution of the binding energy per nucleon due to weak reactions [MeV/s]

  • \(\epsilon_\nu\) : the energy loss due to neutrinos [erg / g / s]

[1]:
import pynucastro as pyna
from pynucastro import Nucleus

First we’ll create a simple NSE network with a few nuclei. We’ll include tabulated weak rates so we can compute the change in the state due to electron/positron captures and decays.

[2]:
nucs = [Nucleus("p"), Nucleus("n"), Nucleus("he4"),
        Nucleus("fe52"), Nucleus("fe53"), Nucleus("fe54"),
        Nucleus("fe55"), Nucleus("fe56"),
        Nucleus("co54"), Nucleus("co55"), Nucleus("co56"),
        Nucleus("ni56"), Nucleus("ni57")]
[3]:
tl = pyna.TabularLibrary().linking_nuclei(nucs)
rl = pyna.ReacLibLibrary().linking_nuclei(nucs)
all_lib = tl + rl
warning: He4 was not able to be linked
warning: Fe53 was not able to be linked
warning: Fe52 was not able to be linked
warning: Ni57 was not able to be linked
[4]:
dupes = all_lib.find_duplicate_links()
rates_to_remove = []
for d in dupes:
    rates_to_remove += [r for r in d if isinstance(r, pyna.rates.ReacLibRate)]

for r in rates_to_remove:
    all_lib.remove_rate(r)
[5]:
nse = pyna.NSENetwork(libraries=[all_lib])

Now we’ll create a grid of temperature, density, and \(Y_e\) where we want to compute the NSE state

[6]:
import numpy as np
[7]:
Ts = np.logspace(9.6, 10.4, 3)
rhos = np.logspace(7, 10, 4)
yes = np.linspace(0.43, 0.5, 3)

Finally we can generate the table. This will compute the NSE state at each combination of \((\rho, T, Y_e)\). To help accelerate the convergence, it will start at the highest temperature and loop over \(\rho\) and \(Y_e\) and cache the values of the proton and neutron chemical potentials for the next temperature.

[8]:
nse.generate_table(rho_values=rhos,
                   T_values=Ts,
                   Ye_values=yes)

The table is stored as nse.tbl

[9]:
%cat nse.tbl
# NSE table generated by pynucastro 2.2.0.post23+gddbc6ae8
# original NSENetwork had 13 nuclei
#
#   log10(rho)       log10(T)           Ye             Abar            <B/A>          dYe/dt         dAbar/dt        d<B/A>/dt         e_nu
   7.0000000000    9.6000000000    0.5000000000   50.2057480859    8.6280577146  -4.3803693e-05   1.7080366e-17   2.3287883e-06   7.4773253e+13
   7.0000000000    9.6000000000    0.4650000000   55.7461136880    8.7870609269  -5.5255921e-09  -1.8576389e-21   3.9319171e-10     1.39808e+10
   7.0000000000    9.6000000000    0.4300000000   11.0637644849    8.1412160175   0.00017699678  -2.9553491e-26  -1.8453762e-12   2.7707299e+14
   7.0000000000   10.0000000000    0.5000000000    1.2148718034    1.6681978229     0.084056626  -4.1382279e-56   5.7341747e-41   7.8635859e+17
   7.0000000000   10.0000000000    0.4650000000    1.2129151675    1.6556736890      0.10066497  -2.9530597e-56    3.521478e-41   8.3544486e+17
   7.0000000000   10.0000000000    0.4300000000    1.2071212811    1.6183497719      0.11786424  -1.1606804e-56   5.9185559e-42   8.8944373e+17
   7.0000000000   10.4000000000    0.5000000000    1.0000000000    0.0000000002       5.7463273  2.7835262e-218  6.7437141e-203   2.3050257e+20
   7.0000000000   10.4000000000    0.4650000000    1.0000000000    0.0000000002       7.2542055 -3.8299905e-219  5.8186031e-203    2.360043e+20
   7.0000000000   10.4000000000    0.4300000000    1.0000000000    0.0000000002       8.7650901  2.0886837e-218  3.8274857e-203   2.4155562e+20
   8.0000000000    9.6000000000    0.5000000000   54.3195129673    8.6383992184  -0.00084875851              -0   4.3700394e-05   1.4743336e+15
   8.0000000000    9.6000000000    0.4650000000   55.8970081563    8.7873915908  -4.9040515e-08  -6.1382007e-21   4.1959348e-09   1.2982252e+11
   8.0000000000    9.6000000000    0.4300000000   11.0638264093    8.1412199515   9.2047376e-06  -3.3885784e-29  -5.6069156e-13   1.1254068e+13
   8.0000000000   10.0000000000    0.5000000000    2.5712542408    5.7636820538    -0.019589298  -1.8701585e-33   1.7211947e-19      1.6311e+17
   8.0000000000   10.0000000000    0.4650000000    2.5124362034    5.6778066014   -0.0041256975   5.0812947e-34   2.1065809e-19   1.5065038e+17
   8.0000000000   10.0000000000    0.4300000000    2.3664067080    5.4461446407    0.0093041487  -6.5089027e-34   1.1442051e-19   1.6169818e+17
   8.0000000000   10.4000000000    0.5000000000    1.0000000214    0.0000002024        1.213841  7.2035365e-165  9.8460077e-150   2.1894106e+20
   8.0000000000   10.4000000000    0.4650000000    1.0000000212    0.0000002004       2.8346072  1.8145634e-165  8.4158915e-150   2.2127881e+20
   8.0000000000   10.4000000000    0.4300000000    1.0000000206    0.0000001945       4.4726034  2.4538451e-165   5.481869e-150   2.2397331e+20
   9.0000000000    9.6000000000    0.5000000000   55.5136288840    8.6413421175    -0.060154436              -0    0.0031211006   1.5552556e+17
   9.0000000000    9.6000000000    0.4650000000   55.9133553598    8.7874247178  -3.9839589e-06   7.6546118e-19   3.6046977e-07   1.0369536e+13
   9.0000000000    9.6000000000    0.4300000000   11.0638296395    8.1412201568   1.0225013e-08  -9.8142004e-34  -5.2463937e-15   1.1664591e+10
   9.0000000000   10.0000000000    0.5000000000    4.3121615772    7.1515898299     -0.10742116  -7.8751776e-19   2.9757777e-05   4.7264232e+17
   9.0000000000   10.0000000000    0.4650000000    5.1247240232    7.3995844381    -0.019430675   -5.218123e-20   3.3567416e-06   8.7381876e+16
   9.0000000000   10.0000000000    0.4300000000    4.4162729378    7.0777579412   -0.0059568824   1.4777727e-20   5.1854108e-07   3.2607638e+16
   9.0000000000   10.4000000000    0.5000000000    1.0000214391    0.0002025494      -17.715252  1.5106478e-112   3.7266649e-96   2.7735801e+20
   9.0000000000   10.4000000000    0.4650000000    1.0000212298    0.0002005604      -15.005795 -5.5593438e-112   3.0826278e-96   2.5962747e+20
   9.0000000000   10.4000000000    0.4300000000    1.0000206076    0.0001946699      -12.327315 -6.3674509e-112   1.9400005e-96   2.4324142e+20
  10.0000000000    9.6000000000    0.5000000000   55.8692197296    8.6423237057      -5.2276094              -0       0.2720124   2.9376254e+19
  10.0000000000    9.6000000000    0.4650000000   55.9152992729    8.7874226105  -0.00092940692   -2.648266e-16   8.5387004e-05   4.3026908e+15
  10.0000000000    9.6000000000    0.4300000000   11.0638297827    8.1412201659   5.0971987e-15  -9.3107493e-42  -6.8646484e-21       5801.4456
  10.0000000000   10.0000000000    0.5000000000   13.9370868136    8.2743459363      -5.5785841   1.0782619e-14      0.10961074   3.9381535e+19
  10.0000000000   10.0000000000    0.4650000000   28.2438967467    8.6492551831    -0.075078082   2.0321472e-16   0.00050736054   5.2201774e+17
  10.0000000000   10.0000000000    0.4300000000   10.2419420841    8.0844779277   -0.0025107223  -1.1694167e-19   1.1073417e-06   1.7236419e+16
  10.0000000000   10.4000000000    0.5000000000    1.0197762456    0.1829100336       -196.6445   -4.638832e-57     3.90578e-42   2.3555844e+21
  10.0000000000   10.4000000000    0.4650000000    1.0195858994    0.1811833443      -167.54221   3.2294093e-57   3.0442073e-42   1.9968628e+21
  10.0000000000   10.4000000000    0.4300000000    1.0190251146    0.1760925439      -140.99607  -1.1373217e-57   1.8183284e-42   1.6720803e+21

There are other options to the NSE table writing, including storing the mass fractions or a reduced composition constructed by binning the nuclei into the closest nuclei in a smaller set.