opencr.backends.batched
The quasi-static reduction of many conditions at once, on cunumpy.
For a network that is linear in its states (one heavy reactant per reaction) the rate matrix of one set of conditions is
with N the net stoichiometry (states x reactions), S the selector of
each reaction’s heavy reactant (reactions x states) and a_e the number
of electrons among the reactants. For a batch of B electron temperatures
and densities the matrices are a dense (B, n, n) array assembled in one
einsum, and the quasi-static reduction of opencr.kinetics.effective
is a batched dense solve, C = -M_QQ^-1 M_QP, M_eff = M_PP + M_PQ C.
Every point is independent, so the batch is the natural unit of work for a
GPU (cunumpy.set_backend("cupy")); the result comes back to the host and
is checked against the per-point sparse reference solves in the tests.
The drivers are the states with a density in the conditions, or the model’s drivers when the conditions give none; the driver densities do not enter the coefficients (the system is linear).
Classes
| Name | Description |
|---|---|
BatchedQuasiStatic | The batched quasi-static reduction of a model. |
BatchedReduction | The quasi-static reduction at a batch of conditions (NumPy arrays). |
Functions
| Name | Description |
|---|---|
batched_scan | Return the effective rates and PECs on a grid of T_e and n_e. |
BatchedQuasiStaticclass#
class BatchedQuasiStatic(model: Model)The batched quasi-static reduction of a model.
Parameters
| Name | Type | Description |
|---|---|---|
model | Model | The model; its network must be linear in the states. |
Raises
ValueError- A reaction has two heavy reactants.
assemblemethod#
def assemble(te: np.ndarray, ne: np.ndarray, drivers: tuple[str, ...], excited: tuple[str, ...], coefficients: np.ndarray, effective: np.ndarray, rates: np.ndarray) -> BatchedReductionReturn the BatchedReduction of host arrays, with the PECs from coefficients.
drivers_ofmethod#
def drivers_of(conditions: Conditions) -> tuple[str, ...]Return the drivers: the prescribed states of conditions, else the model’s.
matricesmethod#
def matrices(conditions: Conditions, electron_temperatures: Any, electron_densities: Any) -> tuple[Any, Any]Return k of shape (B, n_reactions) and M of shape (B, n, n) on xp.
Numerics
matrix
Assumptions:
- the net stoichiometry (states reactions), the selector of each reaction’s one heavy reactant (reactions states), the electrons among the reactants
- one dense
einsumon cunumpy’sxp(NumPy or CuPy for the whole process) - Maxwellian electrons: the cross-section integrals of all reactions stacked and evaluated 32 temperatures per chunk; a non-Maxwellian EEDF is refused
partitionmethod#
def partition(conditions: Conditions) -> tuple[tuple[str, ...], tuple[str, ...], list[int], list[int]]Return the drivers, the excited states and their indices in the state order.
runmethod#
def run(conditions: Conditions, electron_temperatures: Any, electron_densities: Any) -> BatchedReductionReturn the reduction at every pair of electron_temperatures and electron_densities.
The two are broadcast against each other and flattened; the result’s arrays follow that flat order.
Numerics
reduction
pec
Assumptions:
- one heavy reactant per reaction and a given ; the driver densities do not enter (the system is linear)
- one batched dense
xp.linalg.solvefor all points; the reference is the per-point sparsequasi_static
Built from:
opencr.backends.batched.BatchedQuasiStatic.matricesopencr.kinetics.effective.quasi_static
BatchedReductionclassdataclass#
class BatchedReduction(electron_temperatures: np.ndarray, electron_densities: np.ndarray, drivers: tuple[str, ...], excited: tuple[str, ...], coefficients: np.ndarray, effective: np.ndarray, rates: np.ndarray, lines: tuple[str, ...], pec: np.ndarray)The quasi-static reduction at a batch of conditions (NumPy arrays).
Attributes
| Name | Type | Description |
|---|---|---|
electron_temperatures | np.ndarray | T_e in eV, shape (B,). |
electron_densities | np.ndarray | n_e in m^-3, shape (B,). |
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 (B, len(excited), len(drivers)). |
effective | np.ndarray | M_eff with shape (B, len(drivers), len(drivers)) in s^-1. |
rates | np.ndarray | k_r in SI with shape (B, n_reactions). |
lines | tuple[str, ...] | The names of the spontaneous emissions. |
pec | np.ndarray | The photon emissivity coefficients (B, len(lines), len(drivers))
in m^3/s. |
coefficientsattributeinstance attribute#
coefficients: np.ndarraydriversattributeinstance attribute#
drivers: tuple[str, ...]effectiveattributeinstance attribute#
effective: np.ndarrayelectron_densitiesattributeinstance attribute#
electron_densities: np.ndarrayelectron_temperaturesattributeinstance attribute#
electron_temperatures: np.ndarrayexcitedattributeinstance attribute#
excited: tuple[str, ...]linesattributeinstance attribute#
lines: tuple[str, ...]pecattributeinstance attribute#
pec: np.ndarrayratesattributeinstance attribute#
rates: np.ndarrayeffective_ratemethod#
def effective_rate(source: str, target: str) -> np.ndarrayReturn M_eff[target, source] / n_e in m^3/s for every point.
population_coefficientmethod#
def population_coefficient(state: str, driver: str) -> np.ndarrayReturn n_state / (n_e n_driver) in m^3 for every point.
to_datasetmethod#
def to_dataset() -> xr.DatasetReturn the effective rates, population coefficients and PECs over point.
batched_scanfunction#
def batched_scan(model: Model, conditions: Conditions, electron_temperature: Sequence[float], electron_density: Sequence[float]) -> xr.DatasetReturn the effective rates and PECs on a grid of T_e and n_e.
The batched counterpart of opencr.scan for quasi-static solves of
Maxwellian plasmas: the same variables (effective_rate over
(electron_temperature, electron_density, target, source),
pec over (..., line, driver) and population_coefficient over
(..., state, driver)), computed in one batch on cunumpy’s xp.
The temperatures are in eV and the densities in m^-3, or quantities.