Skip to content
Projects

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

M=N diag(k neae) S,M = N\,\mathrm{diag}\big(k\, n_e^{a_e}\big)\, S,

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

NameDescription
BatchedQuasiStaticThe batched quasi-static reduction of a model.
BatchedReductionThe quasi-static reduction at a batch of conditions (NumPy arrays).

Functions

NameDescription
batched_scanReturn 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

NameTypeDescription
modelModelThe model; its network must be linear in the states.

Raises

ValueError
A reaction has two heavy reactants.

modelattributeinstance attribute#

model = model

assemblemethod#

def assemble(te: np.ndarray, ne: np.ndarray, drivers: tuple[str, ...], excited: tuple[str, ...], coefficients: np.ndarray, effective: np.ndarray, rates: np.ndarray) -> BatchedReduction

Return 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

Mb=N diag(kb ne,bae) S,b=1,…,BM_b = N\,\mathrm{diag}\big(k_b\, n_{e,b}^{a_e}\big)\, S, \qquad b = 1, \dots, B

Assumptions:

  • NN the net stoichiometry (states ×\times reactions), SS the selector of each reaction’s one heavy reactant (reactions ×\times states), aea_e the electrons among the reactants
  • one dense einsum on cunumpy’s xp (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) -> BatchedReduction

Return 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

Cb=−MQQ,b−1MQP,b,Mbeff=MPP,b+MPQ,b CbC_b = -M_{QQ,b}^{-1} M_{QP,b}, \qquad M^{\mathrm{eff}}_b = M_{PP,b} + M_{PQ,b}\, C_b

pec

PECd,b=kA,b Cud,bne,b\mathrm{PEC}_{d,b} = \frac{k_{A,b}\, C_{ud,b}}{n_{e,b}}

Assumptions:

  • one heavy reactant per reaction and a given nen_e; the driver densities do not enter (the system is linear)
  • one batched dense xp.linalg.solve for all BB points; the reference is the per-point sparse quasi_static

Built from:

  • opencr.backends.batched.BatchedQuasiStatic.matrices
  • opencr.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

NameTypeDescription
electron_temperaturesnp.ndarrayT_e in eV, shape (B,).
electron_densitiesnp.ndarrayn_e in m^-3, shape (B,).
driverstuple[str, ...]The names of the prescribed states P.
excitedtuple[str, ...]The names of the quasi-static states Q.
coefficientsnp.ndarrayC with shape (B, len(excited), len(drivers)).
effectivenp.ndarrayM_eff with shape (B, len(drivers), len(drivers)) in s^-1.
ratesnp.ndarrayk_r in SI with shape (B, n_reactions).
linestuple[str, ...]The names of the spontaneous emissions.
pecnp.ndarrayThe photon emissivity coefficients (B, len(lines), len(drivers)) in m^3/s.

coefficientsattributeinstance attribute#

coefficients: np.ndarray

driversattributeinstance attribute#

drivers: tuple[str, ...]

effectiveattributeinstance attribute#

effective: np.ndarray

electron_densitiesattributeinstance attribute#

electron_densities: np.ndarray

electron_temperaturesattributeinstance attribute#

electron_temperatures: np.ndarray

excitedattributeinstance attribute#

excited: tuple[str, ...]

linesattributeinstance attribute#

lines: tuple[str, ...]

pecattributeinstance attribute#

pec: np.ndarray

ratesattributeinstance attribute#

rates: np.ndarray

effective_ratemethod#

def effective_rate(source: str, target: str) -> np.ndarray

Return M_eff[target, source] / n_e in m^3/s for every point.

population_coefficientmethod#

def population_coefficient(state: str, driver: str) -> np.ndarray

Return n_state / (n_e n_driver) in m^3 for every point.

to_datasetmethod#

def to_dataset() -> xr.Dataset

Return 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.Dataset

Return 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.