rizer.kin.fit_arrhenius#
Classes#
Functions#
|
Return the modified Arrhenius expression for the rate constant \(k\). |
|
Fit the rate constant k(T) with an modified Arrhenius expression using a least square fit. |
|
Fit an ArrheniusRate,for a given cross section. |
|
Sort Arrhenius rate from various sources by equation. |
Module Contents#
- rizer.kin.fit_arrhenius.arrhenius_rate[T: float | numpy.ndarray](A: float, b: float, Ea: float, temperature: T) T#
Return the modified Arrhenius expression for the rate constant \(k\).
The modified Arrhenius takes the form:
\[k(T) = A T^b exp(-\frac{E_a}{T})\]- 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 (
floatornumpy.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:
- rizer.kin.fit_arrhenius.k_fit_arrhenius_lstsq(k: numpy.ndarray, temperatures: numpy.ndarray, only_positive_activation_energy: bool = True) tuple[float, float, float, float]#
Fit the rate constant k(T) with an modified Arrhenius expression using a least square fit.
The modified Arrhenius 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.only_positive_activation_energy (
bool, optional) – False if the activation energy can be negative, by default True.
- 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:
- Raises:
ValueError – If the least square optimization failed.
Notes
The function fits the rate constant k(T) with an modified Arrhenius 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}{T}\]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} \\ 1 & log(T_2) & -\frac{1}{T_2} \\ \vdots & \vdots & \vdots \\ 1 & log(T_n) & -\frac{1}{T_n} \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 \end{bmatrix}\end{split}\]The bounds on the parameters are defined as:
If only_positive_activation_energy is True:
\[\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}\]If only_positive_activation_energy is False:
\[\begin{split}\begin{align*} -\infty &\leq log(A) \leq \infty \\ -\infty &\leq b \leq \infty \\ -\infty &\leq E_a \leq \infty \end{align*}\end{split}\]Once solved, the fitted parameters (log(A), b, E_a) 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_arrhenius.ArrheniusRate#
-
- electron_temperature: numpy.ndarray#
- k_raw: numpy.ndarray#
- rizer.kin.fit_arrhenius.arrhenius_rate_fit_from_cross_section(cross_section_data: rizer.kin.load_cross_sections.CrossSectionData, electron_temperatures: numpy.ndarray, nb_points_integrand: int = 100000) ArrheniusRate#
Fit an ArrheniusRate,for a given cross section.
Maxwellian distribution is assumed for electron.
- Parameters:
cross_section_data (
rizer.kin.load_cross_sections.CrossSectionData) – CrossSectionData object.electron_temperatures (
numpy.ndarray) – Range of electron temperatures to use for the fit.nb_points_integrand (
int, optional) – Number of points used in the computation of the reaction rate, by default 100_000.
- Returns:
ArrheniusRate object, containing the Arrhenius rate parameters.
- Return type:
- rizer.kin.fit_arrhenius.group_and_sort_arrhenius_rate_by_equation(arrhenius_rate: list[ArrheniusRate], janev_cross_section_first: bool = False) dict[str, list[ArrheniusRate]]#
Sort Arrhenius rate from various sources by equation.
Arrhenius 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:
arrhenius_rate (
listofArrheniusRate) – List containing ArrheniusRate. Typically generated by arrhenius_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 ArrheniusRate.
- Return type:
dictofstrtolistofArrheniusRate