rizer.kin.fit_druyvesteyn#

Classes#

Functions#

druyvesteyn_rate(→ T)

Return the modified Druyvesteyn expression for the rate constant \(k\).

k_fit_druyvesteyn_lstsq(→ tuple[float, float, float, ...)

Fit the rate constant k(T) with an modified Druyvesteyn expression using a least square fit.

druyvesteyn_rate_fit_from_cross_section(→ DruyvesteynRate)

Fit a DruyvesteynRate for a given cross section.

group_and_sort_druyvesteyn_rate_by_equation(...)

Sort Druyvesteyn rate from various sources by equation.

Module Contents#

rizer.kin.fit_druyvesteyn.druyvesteyn_rate[T: float | numpy.ndarray](A: float, b: float, Ea: float, temperature: T) T#

Return the modified Druyvesteyn expression for the rate constant \(k\).

The modified Druyvesteyn takes the form:

\[k(T) = A T^b exp(-\frac{E_a^2}{T^2})\]
Parameters:
  • A (float) – Pre-exponential factor. Units could used one of (cm3, mol, s, K) / (m3, kmol, s, K) / …

  • b (float) – Temperature exponent [-].

  • Ea (float) – Activation energy [K].

  • temperature (float or numpy.ndarray) – Temperature [K].

Returns:

rate constant. - For first order reaction, it is in [s^-1]. - For second order reaction, it is in [cm3/(mol*s)] / [m^3/(kmol*s)] / … - For third order reaction, it is in [cm6/(mol^2*s)] / [m^6/(kmol^2*s)] / …

Return type:

float or numpy.ndarray

rizer.kin.fit_druyvesteyn.k_fit_druyvesteyn_lstsq(k: numpy.ndarray, temperatures: numpy.ndarray) tuple[float, float, float, float]#

Fit the rate constant k(T) with an modified Druyvesteyn expression using a least square fit.

The modified Druyvesteyn takes the form:

with:

  • \(k(T)\): rate constant [Could be (cm3, mol, s) / (m3, kmol, s) / …],

  • \(A\): pre-exponential factor [Same units as \(\frac{k(T)}{T^b}\)],

  • \(b\): temperature exponent [-],

  • \(E_a\): activation energy [K],

  • \(T\): temperature [K].

Parameters:
  • k (numpy.ndarray) – Rate constant to be fitted. Units should be the same as the rate constant in the reaction.

  • temperatures (numpy.ndarray) – Temperatures at which the rate constant is computed, in Kelvin.

Returns:

Fitted parameters A, b and Ea, and the cost function.

  • A has the same units as the rate constant in the reaction.

  • b is dimensionless.

  • Ea is in K.

  • Cost function has no unit, as it is the sum of the square of the residuals, divided by 2.

Return type:

tuple of float, float, float, float

Raises:

ValueError – If the least square optimization failed.

Notes

The function fits the rate constant k(T) with an modified Druyvesteyn expression using a least square fit.

For more accuracy, the logarithm of the rate constant is used:

\[log(k(T)) = log(A) + b \cdot log(T) - \frac{E_a^2}{T^2}\]

For further clarification, this function calls [scipy.optimize.lsq_linear](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.lsq_linear.html) to perform a linear least squares fit with bounds on the parameters.

The system to solve is:

\[minimize 0.5 * ||A x - b||**2 subject to lb <= x <= ub\]

The matrix A is defined as:

\[\begin{split}A = \begin{bmatrix} 1 & log(T_1) & -\frac{1}{T_1^2} \\ 1 & log(T_2) & -\frac{1}{T_2^2} \\ \vdots & \vdots & \vdots \\ 1 & log(T_n) & -\frac{1}{T_n^2} \end{bmatrix}\end{split}\]

The vector b is defined as:

\[\begin{split}b = \begin{bmatrix} log(k_1) \\ log(k_2) \\ \vdots \\ log(k_n) \end{bmatrix}\end{split}\]

The vector of fitted parameters x is defined as:

\[\begin{split}x = \begin{bmatrix} log(A) \\ b \\ E_a^2 \end{bmatrix}\end{split}\]

The bounds on the parameters are defined as:

\[\begin{split}\begin{align*} -\infty &\leq log(A) \leq \infty \\ -\infty &\leq b \leq \infty \\ 0 &\leq E_a \leq \infty \end{align*}\end{split}\]

Once solved, the fitted parameters (log(A), b, E_a^2) are extracted and converted to A, b and Ea.

The function returns these parameters, i.e. A, b and Ea.

If return_cost is True, the cost function value is also returned. The cost function is defined as the sum of the square of the residuals, divided by 2. The residuals are the difference between the fitted rate constant and the training data.

\[cost = 0.5 * ||A x_lsq - b||**2\]

where x_lsq are the fitted parameters and b is the training data.

class rizer.kin.fit_druyvesteyn.DruyvesteynRate#
A_m3_per_s: float#
b: float#
Ea_K: float#
fit_cost: float#
electron_temperature: numpy.ndarray#
k_raw: numpy.ndarray#
equation: str#
source: str#
equation_alias: str#
note: str#
A_cm3_per_mol_per_s: float#
Ea_kJ_per_mol: float#
as_cantera_string(unit_A: str = 'cm3/mol/s', unit_Ea: str = 'K', commented: bool = False) str#
rizer.kin.fit_druyvesteyn.druyvesteyn_rate_fit_from_cross_section(cross_section_data: rizer.kin.load_cross_sections.CrossSectionData, electron_temperatures: numpy.ndarray) DruyvesteynRate#

Fit a DruyvesteynRate for a given cross section.

Druyvesteyn distribution is assumed for electron.

Parameters:
Returns:

DruyvesteynRate object, containing the Druyvesteyn rate parameters.

Return type:

DruyvesteynRate

rizer.kin.fit_druyvesteyn.group_and_sort_druyvesteyn_rate_by_equation(druyvesteyn_rates: list[DruyvesteynRate], janev_cross_section_first: bool = False) dict[str, list[DruyvesteynRate]]#

Sort Druyvesteyn rate from various sources by equation.

Druyvesteyn rates are first grouped together, then sorted by fit cost. If janev_cross_section_first is True, it is moved to the first position.

Parameters:
  • druyvesteyn_rates (list of DruyvesteynRate) – List containing DruyvesteynRate. Typically generated by druyvesteyn_rate_fit_from_cross_section.

  • janev_cross_section_first (bool, optional) – If True, move Janev cross section (if it exists) to the first position, by default False. Useful for choosing with database used for a mechanism.

Returns:

Dictionnary where equation are mapped to corresponding list of DruyvesteynRate.

Return type:

dict of str to list of DruyvesteynRate