Skip to content
Projects

opencr.kinetics.system

The population equations dn/dt = R(n) of a network, with their Jacobian.

PopulationSystem compiles a network for one set of rate coefficients and conditions: which states evolve, the densities of the prescribed ones, and n_e (given, or quasi-neutral). Reaction r proceeds at

wr=kr neare∏pnparp∏iniari,w_r = k_r\, n_e^{a_{re}} \prod_p n_p^{a_{rp}} \prod_i n_i^{a_{ri}},

with p the prescribed and i the evolving reactants, and R = N w with the net stoichiometry N over the evolving states. The Jacobian dR/dn = N dw/dn is assembled analytically in sparse form, including the dependence of a quasi-neutral n_e on the charged states.

When every reaction has at most one evolving reactant and n_e is given, the system is linear, R = M n + b (PopulationSystem.linear_parts).

Classes

NameDescription
MissingDensityErrorA prescribed state has no density in the conditions.
PopulationSystemThe population equations of the evolving states.

MissingDensityErrorclass#

class MissingDensityError(ValueError)

Bases: ValueError

A prescribed state has no density in the conditions.

PopulationSystemclass#

class PopulationSystem(network: ReactionNetwork, rates: np.ndarray, conditions: Conditions, evolving: Sequence[str])

The population equations of the evolving states.

Parameters

NameTypeDescription
networkReactionNetworkThe reaction network.
ratesnp.ndarrayk_r for every reaction (RateEvaluator).
conditionsConditionsThe conditions: n_e and the prescribed densities.
evolvingSequence[str]The names of the evolving states; the others are prescribed and need a density in conditions.densities.

chargesattributeinstance attribute#

charges = np.array([network.state(n).charge for n in self.evolving], dtype=float)

conditionsattributeinstance attribute#

conditions = conditions

evolvingattributeinstance attribute#

evolving = tuple(evolving)

indexattributeinstance attribute#

index = index

max_orderattributeinstance attribute#

max_order = width

networkattributeinstance attribute#

network = network

prescribedattributeinstance attribute#

prescribed = tuple((n for n in network.state_names if n not in self.evolving))

ratesattributeinstance attribute#

rates = rates

stoichiometryattributeinstance attribute#

stoichiometry = sps.csr_matrix((values, (rows, cols)), shape=(len(self.evolving), n_r))

is_linearproperty#

is_linear: bool

Whether R is linear in the evolving densities (given n_e, one evolving reactant).

sizeproperty#

size: int

The number of evolving states.

conservationmethod#

def conservation() -> tuple[tuple[str, ...], np.ndarray]

Return the conserved elements and their matrix over the evolving states.

An element is conserved by the evolving states when no reaction moves it to or from a prescribed state or out of the system (wall losses, pumping).

Numerics

conserved

∑icei νir=0for every reaction r⇒ddt∑iceini=0\sum_i c_{ei}\, \nu_{ir} = 0 \quad \text{for every reaction } r \qquad \Rightarrow \qquad \frac{d}{dt}\sum_i c_{ei} n_i = 0

Assumptions:

  • ceic_{ei} the atoms of element ee in evolving state ii; checked to 10−1210^{-12}
  • elements only: charge is not a row, since the electron is not a state
  • a reaction that moves an element to a prescribed state or out of the system (wall loss, pumping) removes it from the list

densitiesmethod#

def densities(n: np.ndarray) -> Mapping[str, float]

Return every state’s density by name: the evolving n and the prescribed ones.

electron_densitymethod#

def electron_density(n: np.ndarray) -> float

Return n_e for the evolving densities n.

Numerics

quasi neutral

ne=max⁡(0, ∑jzjnj)n_e = \max\Big(0,\ \sum_j z_j n_j\Big)

Assumptions:

  • the sum runs over every charged state, prescribed and evolving; the electron is never a state
  • with Conditions.electron_density given, nen_e is that value

jacobianmethod#

def jacobian(n: np.ndarray) -> sps.csr_matrix

Return dR/dn as a sparse matrix.

Numerics

jacobian

∂Ri∂nc=∑rνir[krneare∏pnparp∂∂nc∏jnjarj+are kr neare−1zc∏pnparp∏jnjarj]\frac{\partial R_i}{\partial n_c} = \sum_r \nu_{ir} \left[ k_r n_e^{a_{re}} \prod_p n_p^{a_{rp}} \frac{\partial}{\partial n_c}\prod_j n_j^{a_{rj}} + a_{re}\, k_r\, n_e^{a_{re}-1} z_c \prod_p n_p^{a_{rp}} \prod_j n_j^{a_{rj}} \right]

Assumptions:

  • the second term only for a quasi-neutral nen_e
  • a reactant listed twice is two slots: the derivative of each slot is the product of the others, summed
  • assembled analytically as a sparse matrix

linear_partsmethod#

def linear_parts() -> tuple[sps.csr_matrix, np.ndarray]

Return M and b of R = M n + b for a linear system.

Numerics

linear

R(n)=Mn+b,M=J(0),b=R(0)R(\mathbf n) = M\mathbf n + \mathbf b, \qquad M = J(\mathbf 0), \qquad \mathbf b = R(\mathbf 0)

Assumptions:

  • at most one evolving reactant per reaction and a given nen_e

Built from:

  • opencr.kinetics.system.PopulationSystem.rhs
  • opencr.kinetics.system.PopulationSystem.jacobian

reaction_ratesmethod#

def reaction_rates(n: np.ndarray) -> np.ndarray

Return w_r in m^-3 s^-1 for every reaction at the densities n.

Numerics

rate

wr=kr neare∏pnparp∏iniariw_r = k_r\, n_e^{a_{re}} \prod_p n_p^{a_{rp}} \prod_i n_i^{a_{ri}}

Assumptions:

  • aria_{ri} the multiplicity of state ii among the reactants (a state listed twice counts twice), area_{re} that of the electron
  • pp the prescribed states (Conditions.densities), ii the evolving ones; krk_r and the prescribed densities are folded into one factor per reaction
  • mass action: krk_r in m3(k−1)^{3(k-1)}/s for kk reactants

Built from:

  • opencr.kinetics.system.PopulationSystem.electron_density

rhsmethod#

def rhs(n: np.ndarray) -> np.ndarray

Return R(n) = dn/dt for the evolving states.

Numerics

balance

dnidt=Ri(n)=∑rνir wr\frac{dn_i}{dt} = R_i(\mathbf n) = \sum_r \nu_{ir}\, w_r

Assumptions:

  • νir\nu_{ir} the net stoichiometry (products minus reactants) over the evolving states
  • zero-dimensional: no transport beyond explicit wall-loss and pumping reactions

References:

Built from:

  • opencr.kinetics.system.PopulationSystem.reaction_rates

source_by_prescribedmethod#

def source_by_prescribed() -> dict[str, np.ndarray]

Return b split by prescribed state: the source with only that state present.

The remainder (sources that need two prescribed states at once) is under "(mixed)" when it is not zero.