# opencr.core.rates

*module*

How the rate coefficient of a reaction is given.

A rate model describes the data, not how they are evaluated: the evaluation
(Maxwellian or any electron energy distribution, on any backend) is in
`opencr.kinetics.rates`. The rate of a reaction with reactants ``r_i``
is ``k prod n_i`` (a reactant that appears twice counts twice), so ``k`` is in
s^-1 for one reactant, m^3/s for two and m^6/s for three.

``depends_on`` names the temperature a model depends on: ``"electron"``
(``T_e``, or for a non-Maxwellian distribution the effective temperature
``2/3 <eps>``), ``"ion"``, ``"gas"`` or ``"none"``.

The masses (kg), energies and temperatures (eV) of a rate model take an
astropy Quantity or a string such as ``"11604 K"`` as well as a number (see
`plasmacoll.units`). The rate coefficients themselves (``Arrhenius.a``,
``Tabulated.values``, ``Constant.value``) are numbers in the SI unit of the
reaction's order, which the rate model does not know.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L1-L1)

## opencr.core.rates.TEMPERATURES

*attribute* · *module attribute*

```python
TEMPERATURES = ('electron', 'ion', 'gas', 'none')
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L45-L45)

## opencr.core.rates.Arrhenius

*class* · *dataclass*

```python
class Arrhenius(RateModel)
```

Bases: `opencr.core.rates.RateModel`

``k = a T^b exp(-c / T)`` with ``T`` in eV and ``k`` in SI.

**Attributes**

- `a` (`float`) — The prefactor in the SI unit of the reaction's order.
- `b` (`float`) — The temperature exponent.
- `c` (`float`) — The activation energy in eV.

**Numerics**

*arrhenius*

$$
k = a\,T^b\,e^{-c/T}
$$

Assumptions:

- $T$ in eV, $k$ in the SI unit of the reaction's order; $c$ is the threshold taken out before evaluation

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L207-L245)

### opencr.core.rates.Arrhenius.a

*attribute* · *class attribute* · *instance attribute*

```python
a: float = 0.0
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L227-L227)

### opencr.core.rates.Arrhenius.b

*attribute* · *class attribute* · *instance attribute*

```python
b: float = 0.0
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L228-L228)

### opencr.core.rates.Arrhenius.c

*attribute* · *class attribute* · *instance attribute*

```python
c: float = unit_field('eV', 0.0)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L229-L229)

### opencr.core.rates.Arrhenius.kind

*attribute* · *class attribute*

```python
kind: str = 'arrhenius'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L226-L226)

### opencr.core.rates.Arrhenius.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'electron'
```

Inherited from: `opencr.core.rates.RateModel`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L53-L53)

### opencr.core.rates.Arrhenius.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the three parameters.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L237-L245)

## opencr.core.rates.Constant

*class* · *dataclass*

```python
class Constant(RateModel)
```

Bases: `opencr.core.rates.RateModel`

A rate coefficient independent of temperature, e.g. an Einstein A in s^-1.

**Attributes**

- `value` (`float`) — ``k`` in the SI unit of the reaction's order.

**Numerics**

*constant*

$$
k = \mathrm{const}, \qquad \text{e.g. } k = g\,A_{ul} \text{ for a line with escape factor } g
$$

Assumptions:

- no temperature (`depends_on` is `none`): Einstein coefficients, wall losses, pumping

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L306-L334)

### opencr.core.rates.Constant.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'none'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L323-L323)

### opencr.core.rates.Constant.kind

*attribute* · *class attribute*

```python
kind: str = 'constant'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L322-L322)

### opencr.core.rates.Constant.value

*attribute* · *class attribute* · *instance attribute*

```python
value: float = 0.0
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L324-L324)

### opencr.core.rates.Constant.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the value.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L332-L334)

## opencr.core.rates.CrossSectionRate

*class* · *dataclass*

```python
class CrossSectionRate(RateModel)
```

Bases: `opencr.core.rates.RateModel`

A rate from a cross section averaged over a velocity distribution.

For electrons (``depends_on="electron"``) the average is over the electron
energy distribution of the conditions (Maxwellian by default); otherwise over
a Maxwellian of relative velocities at the ion or gas temperature.

**Attributes**

- `cross_section` (`CrossSection | None`) — The cross section (m^2) against energy (eV).
- `mass` (`float`) — The reduced mass in kg of the colliding pair.
- `incident_mass` (`float | None`) — For a table against the incident particle's energy with the target at rest (the lab frame), the incident mass in kg; the table is looked up at ``E incident_mass / mass``. ``None`` for a table in the centre-of-mass frame. For electrons both agree.

**Numerics**

*maxwellian*

$$
k(T) = \sqrt{\frac{8}{\pi\mu}}\,(kT)^{-3/2} \int_{E_{\mathrm{th}}}^\infty \sigma(E)\,E\,e^{-E/kT}\,dE
$$

*lab frame*

$$
E_{\mathrm{lab}} = E\,\frac{m_{\mathrm{inc}}}{\mu}
$$

*eedf*

$$
k = \sqrt{\frac{2e}{m_e}} \int_0^\infty \varepsilon\,\sigma(\varepsilon)\,F_0(\varepsilon)\,d\varepsilon
$$

Assumptions:

- $\sigma$ a plasmacoll `CrossSection`: linear between the table points, held at the last value above, zero below the threshold
- a Maxwellian of the reduced mass $\mu$ at $T_e$, $T_i$ or $T_{\mathrm{gas}}$ (`depends_on`); for electrons the conditions' EEDF when it is not Maxwellian
- a lab-frame table (target at rest) is read at $E_{\mathrm{lab}}$; a centre-of-mass table at $E$

References:

- [Hagelaar and Pitchford, Plasma Sources Sci. Technol. 14, 722 (2005)](https://doi.org/10.1088/0963-0252/14/4/011)

Built from:

- `opencr.kinetics.rates.MaxwellianIntegral`
- `opencr.kinetics.eedf.EEDF`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L127-L204)

### opencr.core.rates.CrossSectionRate.cross_section

*attribute* · *class attribute* · *instance attribute*

```python
cross_section: CrossSection | None = None
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L164-L164)

### opencr.core.rates.CrossSectionRate.incident_mass

*attribute* · *class attribute* · *instance attribute*

```python
incident_mass: float | None = unit_field('kg', None)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L166-L166)

### opencr.core.rates.CrossSectionRate.kind

*attribute* · *class attribute*

```python
kind: str = 'cross_section'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L163-L163)

### opencr.core.rates.CrossSectionRate.mass

*attribute* · *class attribute* · *instance attribute*

```python
mass: float = unit_field('kg', ELECTRON_MASS)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L165-L165)

### opencr.core.rates.CrossSectionRate.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'electron'
```

Inherited from: `opencr.core.rates.RateModel`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L53-L53)

### opencr.core.rates.CrossSectionRate.table

*property*

```python
table: CrossSection
```

The cross section (never ``None`` after construction).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L181-L184)

### opencr.core.rates.CrossSectionRate.threshold

*property*

```python
threshold: float
```

The threshold of the cross section in eV (in its own frame).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L187-L189)

### opencr.core.rates.CrossSectionRate.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the table, threshold and masses.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L191-L204)

## opencr.core.rates.DetailedBalance

*class* · *dataclass*

```python
class DetailedBalance(RateModel)
```

Bases: `opencr.core.rates.RateModel`

The inverse of another reaction of the network, by detailed balance.

De-excitation from excitation, three-body recombination from ionization,
and any other inverse whose forward reaction has the products as
reactants and an electron on both sides or one more on the forward
product side. The evaluation (`opencr.kinetics.rates`) uses the
state energies and weights: the Klein-Rosseland inverse cross section for
an electron-impact excitation (valid for any energy distribution), and
the Maxwellian relation (Boltzmann, Saha) otherwise.

**Attributes**

- `forward` (`str`) — The name of the forward reaction.

**Numerics**

*inverse*

$$
k_{\mathrm{inv}}(T) = k_{\mathrm{fwd}}(T)\,\frac{g_{\mathrm{in}}}{g_{\mathrm{out}}}\, e^{\Delta E/T}\,\big(\Lambda^3\big)^{\Delta e}, \qquad \Lambda^3 = \left(\frac{h^2}{2\pi m_e kT}\right)^{3/2}
$$

*klein rosseland*

$$
\sigma_{ul}(\varepsilon) = \frac{g_l}{g_u}\,\frac{\varepsilon + \Delta E}{\varepsilon}\,\sigma_{lu}(\varepsilon + \Delta E)
$$

Assumptions:

- $g_{\mathrm{in}}, g_{\mathrm{out}}$ the products of the weights of the forward reactants and products ($g_e = 2$), $\Delta E$ the forward energy change from the state energies
- the same number of heavy particles on both sides of the forward reaction and $\Delta e \ge 0$ extra electrons among its products: Boltzmann ($\Delta e = 0$) or Saha ($\Delta e = 1$)
- with a non-Maxwellian EEDF an electron-impact excitation is inverted by its Klein-Rosseland cross section; a Saha inverse uses the Maxwellian forward rate at $T_{\mathrm{eff}}$

References:

- [Klein and Rosseland, Z. Phys. 4, 46 (1921)](https://doi.org/10.1007/BF01328041)

Built from:

- `opencr.kinetics.rates.RateEvaluator.coefficients`
- `opencr.kinetics.rates.inverse_cross_section`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L394-L443)

### opencr.core.rates.DetailedBalance.forward

*attribute* · *class attribute* · *instance attribute*

```python
forward: str = ''
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L429-L429)

### opencr.core.rates.DetailedBalance.kind

*attribute* · *class attribute*

```python
kind: str = 'detailed_balance'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L428-L428)

### opencr.core.rates.DetailedBalance.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'electron'
```

Inherited from: `opencr.core.rates.RateModel`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L53-L53)

### opencr.core.rates.DetailedBalance.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the forward reaction's name.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L437-L443)

## opencr.core.rates.Function

*class* · *dataclass*

```python
class Function(RateModel)
```

Bases: `opencr.core.rates.RateModel`

``k(T)`` from a Python function of the temperature in eV (array in, array out).

Written to files as a table on `file_temperatures`.

**Attributes**

- `function` (`Callable[[np.ndarray], np.ndarray] | None`) — ``k`` in SI as a function of ``T`` in eV.
- `label` (`str`) — What the function is, e.g. ``"Kramers radiative recombination"``.
- `threshold` (`float`) — As for `Tabulated`, used when the function is tabulated.
- `file_temperatures` (`tuple[float, ...]`) — The temperatures (eV) of the table written to files.

**Numerics**

*function*

$$
k = f(T)
$$

*tabulation*

$$
T_i = 10^{-2 + 6 i / 240}\ \mathrm{eV}, \quad i = 0, \dots, 240, \qquad \text{then as } \texttt{Tabulated}
$$

Assumptions:

- $f$ is host Python code; files and the JAX backend use its table
- $k$ itself is returned, so the threshold scaling does not protect it: $k$ underflows to zero once $E_{\mathrm{th}}/T \gtrsim 708$, and so does an inverse of it

Built from:

- `opencr.core.rates.Tabulated`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L337-L391)

### opencr.core.rates.Function.file_temperatures

*attribute* · *class attribute* · *instance attribute*

```python
file_temperatures: tuple[float, ...] = unit_field('eV', default_factory=lambda : tuple(np.geomspace(0.01, 10000.0, 241).tolist()))
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L365-L367)

### opencr.core.rates.Function.function

*attribute* · *class attribute* · *instance attribute*

```python
function: Callable[[np.ndarray], np.ndarray] | None = None
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L362-L362)

### opencr.core.rates.Function.kind

*attribute* · *class attribute*

```python
kind: str = 'function'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L361-L361)

### opencr.core.rates.Function.label

*attribute* · *class attribute* · *instance attribute*

```python
label: str = ''
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L363-L363)

### opencr.core.rates.Function.threshold

*attribute* · *class attribute* · *instance attribute*

```python
threshold: float = unit_field('eV', 0.0)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L364-L364)

### opencr.core.rates.Function.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'electron'
```

Inherited from: `opencr.core.rates.RateModel`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L53-L53)

### opencr.core.rates.Function.tabulate

*method*

```python
def tabulate() -> Tabulated
```

Return the function as a `Tabulated` model on `file_temperatures`.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L375-L385)

### opencr.core.rates.Function.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the function tabulated (see `tabulate`).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L387-L391)

## opencr.core.rates.RateModel

*class* · *dataclass*

```python
class RateModel
```

Base class of the rate models; ``kind`` names the model in files.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L48-L63)

### opencr.core.rates.RateModel.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'electron'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L53-L53)

### opencr.core.rates.RateModel.kind

*attribute* · *class attribute*

```python
kind: str = ''
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L52-L52)

### opencr.core.rates.RateModel.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the model as plain data (see `opencr.data.native`).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L61-L63)

## opencr.core.rates.Tabulated

*class* · *dataclass*

```python
class Tabulated(RateModel)
```

Bases: `opencr.core.rates.RateModel`

``k(T)`` from a table, interpolated linearly in ``log k`` against ``log T``.

A ``threshold`` (eV) removes the Boltzmann factor before interpolating,
``log(k exp(threshold / T))``, which keeps the interpolation accurate at
temperatures far below a threshold. Outside the table this scaled
quantity holds its end value, so ``k = k_end exp(threshold / T_end -
threshold / T)`` there.

**Attributes**

- `temperatures` (`tuple[float, ...]`) — The table temperatures in eV, increasing.
- `values` (`tuple[float, ...]`) — ``k`` in SI at ``temperatures``, non-negative.
- `threshold` (`float`) — The energy in eV of the Boltzmann factor to remove.

**Numerics**

*interpolation*

$$
\ln\!\big(k\, e^{E_{\mathrm{th}}/T}\big) \text{ linear in } \ln T \text{ between the table points}
$$

*extrapolation*

$$
k(T) = k_{\mathrm{end}}\, e^{E_{\mathrm{th}}/T_{\mathrm{end}} - E_{\mathrm{th}}/T} \quad \text{outside the table } (\ln T \text{ clipped})
$$

Order of accuracy: 2.

Assumptions:

- the order is in the table spacing in $\ln T$, for a smooth $\ln(k\,e^{E_{\mathrm{th}}/T})$
- outside the table the scaled quantity $k\,e^{E_{\mathrm{th}}/T}$ holds its end value, not $k$ itself

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L248-L303)

### opencr.core.rates.Tabulated.kind

*attribute* · *class attribute*

```python
kind: str = 'tabulated'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L276-L276)

### opencr.core.rates.Tabulated.temperatures

*attribute* · *class attribute* · *instance attribute*

```python
temperatures: tuple[float, ...] = unit_field('eV', ())
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L277-L277)

### opencr.core.rates.Tabulated.threshold

*attribute* · *class attribute* · *instance attribute*

```python
threshold: float = unit_field('eV', 0.0)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L279-L279)

### opencr.core.rates.Tabulated.values

*attribute* · *class attribute* · *instance attribute*

```python
values: tuple[float, ...] = ()
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L278-L278)

### opencr.core.rates.Tabulated.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'electron'
```

Inherited from: `opencr.core.rates.RateModel`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L53-L53)

### opencr.core.rates.Tabulated.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the table.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L295-L303)
