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
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
| Name | Description |
|---|---|
MissingDensityError | A prescribed state has no density in the conditions. |
PopulationSystem | The 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
| Name | Type | Description |
|---|---|---|
network | ReactionNetwork | The reaction network. |
rates | np.ndarray | k_r for every reaction (RateEvaluator). |
conditions | Conditions | The conditions: n_e and the prescribed densities. |
evolving | Sequence[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 = conditionsevolvingattributeinstance attribute#
evolving = tuple(evolving)indexattributeinstance attribute#
index = indexmax_orderattributeinstance attribute#
max_order = widthnetworkattributeinstance attribute#
network = networkprescribedattributeinstance attribute#
prescribed = tuple((n for n in network.state_names if n not in self.evolving))ratesattributeinstance attribute#
rates = ratesstoichiometryattributeinstance attribute#
stoichiometry = sps.csr_matrix((values, (rows, cols)), shape=(len(self.evolving), n_r))is_linearproperty#
is_linear: boolWhether R is linear in the evolving densities (given n_e, one evolving reactant).
sizeproperty#
size: intThe 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
Assumptions:
- the atoms of element in evolving state ; checked to
- 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) -> floatReturn n_e for the evolving densities n.
Numerics
quasi neutral
Assumptions:
- the sum runs over every charged state, prescribed and evolving; the electron is never a state
- with
Conditions.electron_densitygiven, is that value
jacobianmethod#
def jacobian(n: np.ndarray) -> sps.csr_matrixReturn dR/dn as a sparse matrix.
Numerics
jacobian
Assumptions:
- the second term only for a quasi-neutral
- 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
Assumptions:
- at most one evolving reactant per reaction and a given
Built from:
opencr.kinetics.system.PopulationSystem.rhsopencr.kinetics.system.PopulationSystem.jacobian
reaction_ratesmethod#
def reaction_rates(n: np.ndarray) -> np.ndarrayReturn w_r in m^-3 s^-1 for every reaction at the densities n.
Numerics
rate
Assumptions:
- the multiplicity of state among the reactants (a state listed twice counts twice), that of the electron
- the prescribed states (
Conditions.densities), the evolving ones; and the prescribed densities are folded into one factor per reaction - mass action: in m/s for reactants
Built from:
opencr.kinetics.system.PopulationSystem.electron_density
rhsmethod#
def rhs(n: np.ndarray) -> np.ndarrayReturn R(n) = dn/dt for the evolving states.
Numerics
balance
Assumptions:
- 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.