# opencr.kinetics.effective

*module*

Elimination of quasi-static states: population coefficients and effective rates.

Split the states into the prescribed drivers ``P`` (the states with a density
in the conditions) and the rest ``Q``. With all reactions linear in the
states and ``n_e`` given, ``dn/dt = M n`` and the quasi-static ``Q`` follow
from ``M_QQ n_Q + M_QP n_P = 0``:

$$
\mathbf n_Q = C\,\mathbf n_P, \qquad C = -M_{QQ}^{-1} M_{QP},
$$

and the drivers then change at the effective rates

$$
\frac{d\mathbf n_P}{dt} = M^{\mathrm{eff}} \mathbf n_P, \qquad
M^{\mathrm{eff}} = M_{PP} + M_{PQ} C.
$$

``C / n_e`` are the population coefficients (m^3) and ``M_eff / n_e`` the
effective rate coefficients (m^3/s): for atomic hydrogen ``M_eff[H+, H(1)] / n_e``
is the collisional-radiative ionization coefficient and ``M_eff[H(1), H+] / n_e``
the recombination coefficient. The elementary reactions stay in the network;
the effective ones are a result, never mixed with them.

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

## opencr.kinetics.effective.QuasiStatic

*class* · *dataclass*

```python
class QuasiStatic
```

The quasi-static reduction of a network at fixed conditions.

**Attributes**

- `drivers` (`tuple[str, ...]`) — The names of the prescribed states ``P``.
- `excited` (`tuple[str, ...]`) — The names of the quasi-static states ``Q``.
- `coefficients` (`np.ndarray`) — ``C`` with shape ``(len(excited), len(drivers))``, dimensionless: ``n_Q = C n_P``.
- `effective` (`np.ndarray`) — ``M_eff`` with shape ``(len(drivers), len(drivers))`` in s^-1.
- `electron_density` (`float`) — ``n_e`` in m^-3.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/kinetics/effective.py#L46-L102)

### opencr.kinetics.effective.QuasiStatic.coefficients

*attribute* · *instance attribute*

```python
coefficients: np.ndarray
```

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

### opencr.kinetics.effective.QuasiStatic.drivers

*attribute* · *instance attribute*

```python
drivers: tuple[str, ...]
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/kinetics/effective.py#L59-L59)

### opencr.kinetics.effective.QuasiStatic.effective

*attribute* · *instance attribute*

```python
effective: np.ndarray
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/kinetics/effective.py#L62-L62)

### opencr.kinetics.effective.QuasiStatic.electron_density

*attribute* · *instance attribute*

```python
electron_density: float
```

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

### opencr.kinetics.effective.QuasiStatic.excited

*attribute* · *instance attribute*

```python
excited: tuple[str, ...]
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/kinetics/effective.py#L60-L60)

### opencr.kinetics.effective.QuasiStatic.effective_rate

*method*

```python
def effective_rate(source: str, target: str) -> float
```

Return the effective rate coefficient from ``source`` to ``target`` in m^3/s.

``M_eff[target, source] / n_e``: the rate at which ``target`` is created
per electron and per particle of ``source`` (``source != target``), or
for ``source == target`` minus the total loss rate coefficient.

**Numerics**

*effective rate*

$$
K_{\mathrm{source}\to\mathrm{target}} = \frac{M^{\mathrm{eff}}_{\mathrm{target},\mathrm{source}}}{n_e} \quad [\mathrm{m^3/s}]
$$

*hydrogen*

$$
S_{\mathrm{CR}} = \frac{M^{\mathrm{eff}}_{\mathrm{H^+},\mathrm{H}(1)}}{n_e}, \qquad \alpha_{\mathrm{CR}} = \frac{M^{\mathrm{eff}}_{\mathrm{H}(1),\mathrm{H^+}}}{n_e}
$$

Assumptions:

- the diagonal ($\mathrm{source} = \mathrm{target}$) is minus the driver's total effective loss coefficient
- three-body recombination enters $M_{\cdot,\mathrm{H^+}}$ with $k\,n_e^2$, so $\alpha_{\mathrm{CR}}$ depends on $n_e$
- effective rates are results, never reactions of a network

References:

- [Summers et al., Plasma Phys. Control. Fusion 48, 263 (2006)](https://doi.org/10.1088/0741-3335/48/2/007)

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/kinetics/effective.py#L75-L97)

### opencr.kinetics.effective.QuasiStatic.population_coefficient

*method*

```python
def population_coefficient(state: str, driver: str) -> float
```

Return ``n_state / (n_e n_driver)`` in m^3.

**Numerics**

*coefficient*

$$
\frac{n_q}{n_e\, n_d} = \frac{C_{qd}}{n_e} \quad [\mathrm{m^3}]
$$

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/kinetics/effective.py#L65-L73)

### opencr.kinetics.effective.QuasiStatic.populations

*method*

```python
def populations(densities: dict[str, float]) -> np.ndarray
```

Return ``n_Q`` for the driver densities ``densities``.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/kinetics/effective.py#L99-L102)

## opencr.kinetics.effective.SingularSystemError

*class*

```python
class SingularSystemError(ValueError)
```

Bases: `ValueError`

The quasi-static system has no unique solution; the message says which states.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/kinetics/effective.py#L42-L43)

## opencr.kinetics.effective.quasi_static

*function*

```python
def quasi_static(network: ReactionNetwork, rates: np.ndarray, conditions: Conditions) -> QuasiStatic
```

Return the quasi-static reduction with the drivers ``conditions.densities``.

**Raises**

- `ValueError` — If ``n_e`` is not given or a reaction has two quasi-static
reactants (reactions with driver partners are linear in the rest).
- `SingularSystemError` — If ``M_QQ`` is singular (a state without losses, or a
group of states without a path out).

**Numerics**

*matrix*

$$
M_{ij} = \sum_{r:\ j \text{ is the quasi-static reactant of } r} \nu_{ir}\, k_r\, n_e^{a_{re}} \prod_{p \in P,\, p \ne j} n_p^{a_{rp}}
$$

*reduction*

$$
\frac{d\mathbf n_Q}{dt} = M_{QQ}\mathbf n_Q + M_{QP}\mathbf n_P = 0 \quad\Rightarrow\quad \mathbf n_Q = C\,\mathbf n_P, \qquad C = -M_{QQ}^{-1} M_{QP}
$$

*effective*

$$
\frac{d\mathbf n_P}{dt} = M^{\mathrm{eff}} \mathbf n_P, \qquad M^{\mathrm{eff}} = M_{PP} + M_{PQ} C
$$

*solve*

$$
M_{QQ} = LU, \qquad X_0 = U^{-1}L^{-1} M_{QP}, \qquad X = X_0 + U^{-1}L^{-1}\left(M_{QP} - M_{QQ} X_0\right)
$$

Assumptions:

- drivers $P$: the states with a density in the conditions; $Q$ the rest
- every reaction linear in its one quasi-static reactant (two are refused); a reaction among drivers only goes on the column of its first heavy reactant
- a given $n_e$ (a quasi-neutral one is refused)
- sparse LU (`splu`) with one step of iterative refinement; a zero diagonal of $M_{QQ}$ (a state without losses) or a singular factorisation raises `SingularSystemError`

References:

- [Summers et al., Plasma Phys. Control. Fusion 48, 263 (2006)](https://doi.org/10.1088/0741-3335/48/2/007)
- [Virtanen et al., Nat. Methods 17, 261 (2020)](https://doi.org/10.1038/s41592-019-0686-2) (`splu`)

Built from:

- `opencr.kinetics.effective.QuasiStatic.population_coefficient`
- `opencr.kinetics.effective.QuasiStatic.effective_rate`

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