pynucastro.rates.reaclib_rate module#

class pynucastro.rates.reaclib_rate.ReacLibRate(rfile=None, chapter=None, original_source=None, reactants=None, products=None, sets=None, labelprops=None, Q=None)[source]#

Bases: Rate

A single reaction rate from the ReacLib library, which can be composed of multiple sets.

Parameters:
  • rfile (str, pathlib.Path, io.StringIO) – the data file or string containing the rate in ReacLib format.

  • chapter (int) – the ReacLib chapter describing the number of reactants and products

  • original_source (str) – the original source. This is usually set automatically when reading rfile, but can be manually provided when adding rates together.

  • reactants (list(str), list(Nucleus)) – the reactants for the reaction

  • products (list(str), list(Nucleus)) – the products for the reaction

  • sets (list(SingleSet)) – the sets that make up the rate

  • labelprops (str) – a collection of flags that classify a ReacLib rate

  • Q (float) – the energy release (in MeV)

Raises:
eval(T, *, rho=None, comp=None)[source]#

Evaluate the reaction rate for temperature T

Parameters:
  • T (float) – the temperature to evaluate the rate at

  • rho (float) – the density to evaluate the rate at (not needed for ReacLib rates).

  • comp (float) – the composition (of type Composition) to evaluate the rate with (not needed for ReacLib rates).

Return type:

float

eval_deriv(T, *, rho=None, comp=None)[source]#

Evaluate the derivative of reaction rate with respect to T

Parameters:
  • T (float) – the temperature to evaluate the rate at

  • rho (float) – the density to evaluate the rate at (not needed for ReacLib rates).

  • comp (float) – the composition (of type Composition) to evaluate the rate with (not needed for ReacLib rates).

Return type:

float

function_string_cxx(dtype='double', specifiers='inline', leave_open=False, extra_args=None)[source]#

Return a string containing the C++ function that computes the rate

Parameters:
  • dtype (str) – The C++ datatype to use for all declarations

  • specifiers (str) – C++ specifiers to add before each function declaration (i.e. “inline”)

  • leave_open (bool) – If true, then we leave the function unclosed (no “}” at the end). This can allow additional functions to add to this output.

  • extra_args (list, tuple) – A list of strings representing additional arguments that should be appended to the argument list when defining the function interface.

Return type:

str

function_string_py()[source]#

Return a string containing the python function that computes the rate.

Return type:

str

get_rate_exponent(T0)[source]#

For a rate written as a power law, r = r_0 (T/T0)**nu, return nu corresponding to T0

Parameters:

T0 (float) – the temperature to base the power law from

Return type:

float

get_rate_id()[source]#

Get an identifying string for this rate. Don’t include resonance state since we combine resonant and non-resonant versions of reactions.

Return type:

str

plot(Tmin=100000000.0, Tmax=1600000000.0, rhoYmin=390000000.0, rhoYmax=2000000000.0, figsize=(10, 10))[source]#

Plot the rate’s temperature sensitivity vs temperature

Parameters:
  • Tmin (float) – minimum temperature for the plot

  • Tmax (float) – maximum temperature for the plot

  • rhoYmin (float) – unused for ReacLib rates

  • rhoYmax (float) – unused for ReacLib rates

  • figsize (tuple) – the horizontal, vertical size (in inches) for the plot

Return type:

matplotlib.figure.Figure

write_to_file(f)[source]#

Given a file object, write rate data to the file.

Parameters:

f (io.TextIOWrapper, io.StringIO)

class pynucastro.rates.reaclib_rate.SingleSet(a, labelprops)[source]#

Bases: object

A single ReacLib set for a reaction in the form:

λ = exp[ a_0 + sum_{i=1}^5 a_i T_9**(2i-5)/3 + a_6 log T_9]

A single rate in Reaclib can be composed of multiple sets.

Parameters:
  • a (list, numpy.ndarray) – the coefficients of the exponential fit

  • labelprops (str) – a collection of flags that classify a ReacLib rate

dfdT()[source]#

Return a function for the temperature derivative of the set, dratedT(tf), where tf is a Tfactors object

dln_set_string_dT9_cxx(*, prefix='dset_dT', plus_equal=False)[source]#

Generate the C++ code to evaluate d/dT9 ln(set).

Parameters:
  • prefix (str) – variable name used to store the set

  • plus_equal (bool) – do we add to the existing set? or create a new variable and initialize it to this set?

Return type:

str

f()[source]#

Return a function for rate(tf) where tf is a Tfactors object

Return type:

Callable

set_string_cxx(*, prefix='set', plus_equal=False, with_exp=True)[source]#

Generate the C++ code needed to evaluate the set.

Parameters:
  • prefix (str) – variable name used to store the set

  • plus_equal (bool) – do we add to the existing set? or create a new variable and initialize it to this set?

  • with_exp (bool) – do we compute the set (True) or the log of the set (False)? The later is useful if we also are computing the derivative.

Return type:

str

set_string_py(*, prefix='set', plus_equal=False)[source]#

Generate the python code needed to evaluate the set.

Parameters:
  • prefix (str) – variable name used to store the set

  • plus_equal (bool) – do we add to the existing set? or create a new variable and initialize it to this set?

Return type:

str