pynucastro.networks.python_network module#
Support modules to write a pure python reaction network ODE source.
- class pynucastro.networks.python_network.NetworkSolution(sol, rhs, jac, network, rho, T=None, self_heating=False, thermal_neutrinos=False, screen_func=None)[source]#
Bases:
objectA class to hold the solution from integrating PythonNetwork. The member functions provide common visualization and analysis routines.
- Parameters:
sol (object) – Solution object returned by
scipy.integrate.solve_ivp(). The array sol.y is assumed to contain the molar abundances, Y_i, ordered consistently with unique_nucleirhs (Callable) – Function that computes the RHS of the PythonNetwork
jac (Callable) – Function that computes the Jacobian of the PythonNetwork
network (PythonNetwork) – PythonNetwork used for integration
rho (float) – density used to integrate the network
T (float) – temperature used to integrate the network. Only needed if this is not a self-heating burn
self_heating (bool) – is temperature integrated together with composition?
thermal_neutrinos (bool) – whether to include thermal neutrino cooling in the energy balance?
screen_func (Callable) – screening function used to evaluate rates when integrating the network
- T_at(t)[source]#
Evaluate the temperature for a given time.
- Parameters:
t (float or list or numpy.ndarray) – time or time array used to evaluate the molar abundances
- Return type:
- property Temp#
Return the array of temperature for all times.
- Return type:
- property X#
Return the 2D array of mass fractions abundances for all times.
- Return type:
- X_at(t)[source]#
Evaluate the mass fractions for a given time.
- Parameters:
t (float or list or numpy.ndarray) – time or time array used to evaluate the mass fractions. If a time array is given, the output is an array of shape (nuc, times)
- Return type:
- property Y#
Return the 2D array of molar abundances for all times.
- Return type:
- Y_at(t)[source]#
Evaluate the molar abundances for a given time.
- Parameters:
t (float or list or numpy.ndarray) – time or time array used to evaluate the molar abundances
- Return type:
- energy_release(dY)[source]#
Evaluate the energy release in erg/g (/s if dY is actually dY/dt)
- Parameters:
dY (numpy.ndarray) – Finite change or the rate of instataneous change in molar fractions
- Return type:
- jac(t, Y)[source]#
Evaluate the Jacobian of the network with the same thermodynamic condition and screening routine used to integrate the network.
- Parameters:
t (float) – time used to evaluate the RHS
Y (numpy.ndarray) – molar abundances of the species
- Return type:
- jac_at(t)[source]#
Evaluate the Jacobian of the network for a given time.
- Parameters:
t (float) – time used to evaluate the Jacobian
- Return type:
- plot_energy_generation(tmin=None, tmax=None, ymin=None, ymax=None, include_neutrino_loss=None, size=(800, 600), dpi=100, label_size=14, legend_size=10, outfile=None)[source]#
Plot the nuclear energy generation rate, and optionally the thermal neutrino cooling rate.
- Parameters:
tmin (float) –
- Minimum time shown on the x-axis. If None, the first value of
self.t is used.
tmax (float) – Maximum time shown on the x-axis. If None, the last value of self.t is used.
ymin (float) – Minimum rate shown on the y-axis.
ymax (float) – Maximum rate shown on the y-axis.
include_neutrino_loss (bool) – Whether to also plot the thermal neutrino cooling rate. If None, use self.thermal_neutrinos.
dpi (int) – dots per inch used with size to set output image size.
size ((tuple, list)) – (width, height) of the plot in pixels.
label_size (int) – Font size for axis labels.
legend_size (int) – Font size for the legend.
outfile (str) – output name of the plot (extension determines the type).
- Return type:
- plot_evolution(tmin=None, tmax=None, ymin=None, ymax=None, size=(800, 600), dpi=100, X_cutoff_value=None, label_size=14, legend_size=10, three_level_style=False, outfile=None)[source]#
Plot the time evolution of nuclei mass fractions using the solution returned by SciPy’s solve_ivp().
- Parameters:
tmin (float) – Minimum time shown on the x-axis. If None, the first value of self.t is used.
tmax (float) – Maximum time shown on the x-axis. If None, the last value of self.t is used.
ymin (float) – Minimum mass fraction shown on the y-axis. If None, use the Matplotlib autoscaled value.
ymax (float) – Maximum mass fraction shown on the y-axis. If None, use the Matplotlib autoscaled value. The autoscaled value is capped at 1.2
dpi (int) – dots per inch used with size to set output image size
size ((tuple, list)) – (width, height) of the plot in pixels
X_cutoff_value (float) – Minimum peak mass fraction required for a nucleus to be plotted.
label_size (int) – Font size for axis labels.
legend_size (int) – Font size for the legend.
three_level_style (bool) – If True, use three-level linestyle and linewidth based on the peak mass fraction to help distinguish different curves. If False, all curves use the same line style and linewidth.
outfile (str) – output name of the plot (extension determines the type)
- Return type:
- plot_temperature(tmin=None, tmax=None, size=(800, 600), dpi=100, label_size=14, outfile=None)[source]#
Plot the time evolution of temperature for self-heating burns.
- Parameters:
tmin (float) – Minimum time shown on the x-axis. If None, the first value of self.t is used.
tmax (float) – Maximum time shown on the x-axis. If None, the last value of self.t is used.
dpi (int) – dots per inch used with size to set output image size
size ((tuple, list)) – (width, height) of the plot in pixels
label_size (int) – Font size for axis labels.
outfile (str) – output name of the plot (extension determines the type)
- Return type:
- rhs(t, Y, T=None)[source]#
Evaluate the RHS of the network with the same thermodynamic condition and screening routine used to integrate the network.
- Parameters:
t (float) – time used to evaluate the RHS
Y (numpy.ndarray) – molar abundances of the species
T (float) – temperature (required for self-heating)
- Return type:
- rhs_at(t)[source]#
Evaluate the RHS of the network for a given time. Note: for a self-heating burn, this gives only dY/dt.
- Parameters:
t (float) – time used to evaluate the RHS
- Return type:
- property t#
Return the time array for integration
- Return type:
- property unique_nuclei#
Return a list of nuclei explicitly carried in the network, ordered consistent with molar fraction solution, Y.
- Return type:
List(Nucleus)
- ye(Y)[source]#
Evaluate the electron fraction with a given set of molar fractions
- Parameters:
Y (numpy.ndarray) – Molar fraction array
- Return type:
- class pynucastro.networks.python_network.PythonNetwork(rate_files=None, libraries=None, rates=None, inert_nuclei=None, do_screening=True, verbose=False)[source]#
Bases:
RateCollectionA pure python reaction network. This can create a python module as a file that contains everything needed to evaluate the reaction rates and construct the righthand side and Jacobian functions.
- full_jacobian_element_string(ydot_i_nucleus, y_j_nucleus, indent='')[source]#
Construct a string containing the python code for a single element of the Jacobian, dYdot(ydot_i_nucleus)/dY(y_j_nucleus)
- Parameters:
ydot_i_nucleus (Nucleus) – The nucleus representing the dY/dt term we are differentiating. This is the row of the Jacobian.
ydot_j_nucleus (Nucleus) – The nucleus we are differentiating with respect to. This is the column of the Jacobian.
indent (str) – A string that will be prepended to each line of the output, typically consisting of just spaces representing the amount of indent desired.
- Return type:
- full_ydot_string(nucleus, indent='')[source]#
Construct a string containing the python code for dY(nucleus)/dt by considering every reaction that involves nucleus, adding terms that result in its creation and subtracting terms representing its destruction.
- integrate_network(tmax, rho, T, molar_composition=None, screen_method=None, self_heating=False, thermal_neutrinos=False, initial_comp='uniform', rtol=1e-08, atol=1e-08)[source]#
Integrate the network to tmax given (rho, T, Y0) using SciPy’s solve_ivp() with BDF method. Optionally, we can integrate temperature together in a self-heating mode.
- Parameters:
tmax (float) – final integration time.
rho (float) – density used to integrate the network
T (float) – temperature used to integrate the network
molar_composition (numpy.ndarray or Composition) – initial molar abundance of the nuclei. This can be either a NumPy array of molar fractions or a Composition object. If not provided, the initial composition is initialized according to initial_comp
screen_method (str) – name of the screening function used to evaluate rates when integrating the network. Valid choices are: screen5, chugunov_2007, chugunov_2009, potekhin_1998, and debye_huckel. If None, no screening is applied.
self_heating (bool) – do we evolve temperature (as dT/dt = ε / c_v) together with the EOS?
thermal_neutrinos (bool) – whether to include thermal neutrino cooling in the energy balance?
initial_comp (str) – different modes to use to set up the initial composition if molar_composition is None. Valid choices are: uniform, random, and solar.
rtol (float) – relative tolerance for SciPy’s solve_ivp()
atol (float) – absolute tolerance for SciPy’s solve_ivp()
- Returns:
sol – Solution returned by
scipy.integrate.solve_ivp().- Return type:
- rates_string(indent='')[source]#
Create the python code that calls the evaluation function for each rate. Typically this is of the form
name(rate_eval, ...), whererate_evalis a container class in the output network that stores the rate values. This also callsscreening_string()after the main rates are evaluated but before the approximate rates are constructed.