opencr.core
Model definitions independent of any array backend.
Species, states, rate models, reactions, reaction networks and plasma conditions, as plain Python objects.
Attributes
| Name | Description |
|---|---|
ELECTRON | No description. |
ELECTRON_STATE | No description. |
RADIATIVE_KINDS | No description. |
REACTION_KINDS | No description. |
Classes
| Name | Description |
|---|---|
Arrhenius | k = a T^b exp(-c / T) with T in eV and k in SI. |
Conditions | Plasma conditions, SI with temperatures in eV. |
Constant | A rate coefficient independent of temperature, e.g. an Einstein A in s^-1. |
CrossSectionRate | A rate from a cross section averaged over a velocity distribution. |
DetailedBalance | The inverse of another reaction of the network, by detailed balance. |
Function | k(T) from a Python function of the temperature in eV (array in, array out). |
NetworkError | A reaction network is inconsistent; problems lists every problem found. |
RadiationTrapping | The escape-factor configuration of a solve (see opencr.kinetics.radiation). |
RateModel | Base class of the rate models; kind names the model in files. |
Reaction | One reaction. |
ReactionNetwork | States and reactions, with the model's assumptions. |
Species | A particle kind. |
State | One resolved state of a species. |
Tabulated | k(T) from a table, interpolated linearly in log k against log T. |
Functions
| Name | Description |
|---|---|
species_from_formula | Return the species of a simple formula such as "H", "H2+", "Ar" or "H-". |
Modules
conditionsThe plasma conditions of a solve.networkA reaction network: the states, the reactions between them and what is assumed.ratesHow the rate coefficient of a reaction is given.reactionsReactions between states.speciesSpecies and their quantum states.
ELECTRONattributemodule attribute#
opencr.core.speciesView sourceELECTRON = Species('e', -1, ELECTRON_MASS, {})ELECTRON_STATEattributemodule attribute#
opencr.core.speciesView sourceELECTRON_STATE = State(ELECTRON, weight=2.0)RADIATIVE_KINDSattributemodule attribute#
opencr.core.reactionsView sourceRADIATIVE_KINDS = ('spontaneous_emission', 'radiative_recombination')REACTION_KINDSattributemodule attribute#
opencr.core.reactionsView sourceREACTION_KINDS = (
'excitation',
'deexcitation',
'ionization',
'three_body_recombination',
'radiative_recombination',
'dielectronic_recombination',
'spontaneous_emission',
'dissociation',
'dissociative_excitation',
'dissociative_ionization',
'dissociative_recombination',
'attachment',
'dissociative_attachment',
'detachment',
'charge_exchange',
'mutual_neutralization',
'associative_detachment',
'penning_ionization',
'quenching',
'vibrational_transfer',
'proton_transfer',
'wall_loss',
'pumping',
'other'
)Arrheniusclassdataclass#
opencr.core.ratesView sourceclass Arrhenius(depends_on: str = 'electron', a: float = 0.0, b: float = 0.0, c: float = unit_field('eV', 0.0))Bases: RateModel
k = a T^b exp(-c / T) with T in eV and k in SI.
Attributes
Numerics
arrhenius
Assumptions:
- in eV, in the SI unit of the reaction’s order; is the threshold taken out before evaluation
aattributeclass attributeinstance attribute#
a: float = 0.0battributeclass attributeinstance attribute#
b: float = 0.0cattributeclass attributeinstance attribute#
c: float = unit_field('eV', 0.0)kindattributeclass attribute#
kind: str = 'arrhenius'Inherited from opencr.core.rates.RateModel
depends_onattributeclass attributeinstance attribute#
opencr.core.rates.RateModelView sourcedepends_on: str = 'electron'Conditionsclassdataclass#
opencr.core.conditionsView sourceclass Conditions(electron_temperature: float = unit_field('eV'), electron_density: float | None = unit_field('m-3', None), eedf: Any = None, densities: Mapping[str, float] = unit_field('m-3', default_factory=dict), totals: Mapping[str, float] = unit_field('m-3', default_factory=dict), ion_temperature: float | None = unit_field('eV', None), gas_temperature: float = unit_field('eV', 0.026), escape: Mapping[str, float] = dict(), trapping: RadiationTrapping | None = None)Plasma conditions, SI with temperatures in eV.
The temperatures and densities take quantities (see the module
docstring): Conditions("300 K", 1e12 * u.cm**-3).
Attributes
| Name | Type | Description |
|---|---|---|
electron_temperature | float | kT_e in eV. With a non-Maxwellian eedf it is
the temperature of the rates that are not cross sections and of
detailed balance; from_eedf sets it to 2/3 <eps>. |
electron_density | float | None | n_e in m^-3, or None for quasi-neutrality,
n_e = sum z_i n_i over every charged state (evolving and
prescribed). |
eedf | Any | The electron energy distribution (an
opencr.kinetics.eedf.EEDF), or None for a Maxwellian at
electron_temperature. |
densities | Mapping[str, float] | Densities in m^-3 of the prescribed states, by name: the
drivers of a quasi-static solve (e.g. H(n=1) and H+) and
fixed backgrounds (e.g. H2 in an atomic model). |
totals | Mapping[str, float] | For a closed steady state, the total density of each element in
m^-3 over the evolving states, e.g. {"H": 1e19}. |
ion_temperature | float | None | kT_i in eV; the gas temperature if None. |
gas_temperature | float | kT of the neutral gas in eV (0.026 eV is 300 K). |
escape | Mapping[str, float] | Escape factors in [0, 1] by reaction name, overriding the
reactions’ own and anything trapping computes. |
trapping | RadiationTrapping | None | Compute the escape factors of the lines self-consistently
from the populations (opencr.kinetics.radiation); None
for an optically thin plasma (apart from escape). |
densitiesattributeclass attributeinstance attribute#
densities: Mapping[str, float] = unit_field('m-3', default_factory=dict)eedfattributeclass attributeinstance attribute#
eedf: Any = Noneelectron_densityattributeclass attributeinstance attribute#
electron_density: float | None = unit_field('m-3', None)electron_temperatureattributeclass attributeinstance attribute#
electron_temperature: float = unit_field('eV')escapeattributeclass attributeinstance attribute#
escape: Mapping[str, float] = field(default_factory=dict)gas_temperatureattributeclass attributeinstance attribute#
gas_temperature: float = unit_field('eV', 0.026)ion_temperatureattributeclass attributeinstance attribute#
ion_temperature: float | None = unit_field('eV', None)totalsattributeclass attributeinstance attribute#
totals: Mapping[str, float] = unit_field('m-3', default_factory=dict)trappingattributeclass attributeinstance attribute#
trapping: RadiationTrapping | None = Noneheavy_temperatureproperty#
heavy_temperature: dict[str, float]The temperature of each kind of rate dependence (see opencr.core.rates).
quasi_neutralproperty#
quasi_neutral: boolWhether n_e follows from quasi-neutrality.
from_eedfmethodclassmethod#
def from_eedf(eedf: Any, **kwargs: Any) -> ConditionsReturn conditions with eedf and its effective temperature 2/3 <eps>.
replacemethod#
def replace(**changes: Any) -> ConditionsReturn a copy with changes applied.
to_dictmethod#
def to_dict() -> dict[str, Any]Return the conditions as plain data (the EEDF by its description).
Constantclassdataclass#
opencr.core.ratesView sourceclass Constant(depends_on: str = 'none', value: float = 0.0)Bases: RateModel
A rate coefficient independent of temperature, e.g. an Einstein A in s^-1.
Attributes
| Name | Type | Description |
|---|---|---|
value | float | k in the SI unit of the reaction’s order. |
Numerics
constant
Assumptions:
- no temperature (
depends_onisnone): Einstein coefficients, wall losses, pumping
depends_onattributeclass attributeinstance attribute#
depends_on: str = 'none'kindattributeclass attribute#
kind: str = 'constant'valueattributeclass attributeinstance attribute#
value: float = 0.0CrossSectionRateclassdataclass#
opencr.core.ratesView sourceclass CrossSectionRate(depends_on: str = 'electron', cross_section: CrossSection | None = None, mass: float = unit_field('kg', ELECTRON_MASS), incident_mass: float | None = unit_field('kg', None))Bases: RateModel
A rate from a cross section averaged over a velocity distribution.
For electrons (depends_on="electron") the average is over the electron
energy distribution of the conditions (Maxwellian by default); otherwise over
a Maxwellian of relative velocities at the ion or gas temperature.
Attributes
| Name | Type | Description |
|---|---|---|
cross_section | CrossSection | None | The cross section (m^2) against energy (eV). |
mass | float | The reduced mass in kg of the colliding pair. |
incident_mass | float | None | For a table against the incident particle’s energy with
the target at rest (the lab frame), the incident mass in kg; the
table is looked up at E incident_mass / mass. None for a
table in the centre-of-mass frame. For electrons both agree. |
Numerics
maxwellian
lab frame
eedf
Assumptions:
- a plasmacoll
CrossSection: linear between the table points, held at the last value above, zero below the threshold - a Maxwellian of the reduced mass at , or (
depends_on); for electrons the conditions’ EEDF when it is not Maxwellian - a lab-frame table (target at rest) is read at ; a centre-of-mass table at
References:
Built from:
opencr.kinetics.rates.MaxwellianIntegralopencr.kinetics.eedf.EEDF
cross_sectionattributeclass attributeinstance attribute#
cross_section: CrossSection | None = Noneincident_massattributeclass attributeinstance attribute#
incident_mass: float | None = unit_field('kg', None)kindattributeclass attribute#
kind: str = 'cross_section'massattributeclass attributeinstance attribute#
mass: float = unit_field('kg', ELECTRON_MASS)tableproperty#
table: CrossSectionThe cross section (never None after construction).
thresholdproperty#
threshold: floatThe threshold of the cross section in eV (in its own frame).
Inherited from opencr.core.rates.RateModel
depends_onattributeclass attributeinstance attribute#
opencr.core.rates.RateModelView sourcedepends_on: str = 'electron'DetailedBalanceclassdataclass#
opencr.core.ratesView sourceclass DetailedBalance(depends_on: str = 'electron', forward: str = '')Bases: RateModel
The inverse of another reaction of the network, by detailed balance.
De-excitation from excitation, three-body recombination from ionization,
and any other inverse whose forward reaction has the products as
reactants and an electron on both sides or one more on the forward
product side. The evaluation (opencr.kinetics.rates) uses the
state energies and weights: the Klein-Rosseland inverse cross section for
an electron-impact excitation (valid for any energy distribution), and
the Maxwellian relation (Boltzmann, Saha) otherwise.
Attributes
| Name | Type | Description |
|---|---|---|
forward | str | The name of the forward reaction. |
Numerics
inverse
klein rosseland
Assumptions:
- the products of the weights of the forward reactants and products (), the forward energy change from the state energies
- the same number of heavy particles on both sides of the forward reaction and extra electrons among its products: Boltzmann () or Saha ()
- with a non-Maxwellian EEDF an electron-impact excitation is inverted by its Klein-Rosseland cross section; a Saha inverse uses the Maxwellian forward rate at
References:
Built from:
opencr.kinetics.rates.RateEvaluator.coefficientsopencr.kinetics.rates.inverse_cross_section
forwardattributeclass attributeinstance attribute#
forward: str = ''kindattributeclass attribute#
kind: str = 'detailed_balance'Inherited from opencr.core.rates.RateModel
depends_onattributeclass attributeinstance attribute#
opencr.core.rates.RateModelView sourcedepends_on: str = 'electron'Functionclassdataclass#
opencr.core.ratesView sourceclass Function(depends_on: str = 'electron', function: Callable[[np.ndarray], np.ndarray] | None = None, label: str = '', threshold: float = unit_field('eV', 0.0), file_temperatures: tuple[float, ...] = unit_field('eV', default_factory=lambda : tuple(np.geomspace(0.01, 10000.0, 241).tolist())))Bases: RateModel
k(T) from a Python function of the temperature in eV (array in, array out).
Written to files as a table on file_temperatures.
Attributes
| Name | Type | Description |
|---|---|---|
function | Callable[[np.ndarray], np.ndarray] | None | k in SI as a function of T in eV. |
label | str | What the function is, e.g. "Kramers radiative recombination". |
threshold | float | As for Tabulated, used when the function is tabulated. |
file_temperatures | tuple[float, ...] | The temperatures (eV) of the table written to files. |
Numerics
function
tabulation
Assumptions:
- is host Python code; files and the JAX backend use its table
- itself is returned, so the threshold scaling does not protect it: underflows to zero once , and so does an inverse of it
Built from:
opencr.core.rates.Tabulated
file_temperaturesattributeclass attributeinstance attribute#
file_temperatures: tuple[float, ...] = unit_field('eV', default_factory=lambda : tuple(np.geomspace(0.01, 10000.0, 241).tolist()))functionattributeclass attributeinstance attribute#
function: Callable[[np.ndarray], np.ndarray] | None = Nonekindattributeclass attribute#
kind: str = 'function'labelattributeclass attributeinstance attribute#
label: str = ''thresholdattributeclass attributeinstance attribute#
threshold: float = unit_field('eV', 0.0)tabulatemethod#
def tabulate() -> TabulatedReturn the function as a Tabulated model on file_temperatures.
to_dictmethod#
def to_dict() -> dict[str, Any]Return the function tabulated (see tabulate).
Inherited from opencr.core.rates.RateModel
depends_onattributeclass attributeinstance attribute#
opencr.core.rates.RateModelView sourcedepends_on: str = 'electron'NetworkErrorclass#
opencr.core.networkView sourceclass NetworkError(problems: Sequence[str])Bases: ValueError
A reaction network is inconsistent; problems lists every problem found.
RadiationTrappingclassdataclass#
opencr.core.conditionsView sourceclass RadiationTrapping(length: float = unit_field('m'), model: str = 'mewe', lines: tuple[str, ...] | None = None, tolerance: float = 1e-06, max_iterations: int = 100)The escape-factor configuration of a solve (see opencr.kinetics.radiation).
The length takes a quantity (see the module docstring).
Attributes
| Name | Type | Description |
|---|---|---|
length | float | The absorption length L in m (the distance to the wall). |
model | str | One of ESCAPE_MODELS. |
lines | tuple[str, ...] | None | The names of the spontaneous_emission reactions to trap, or
None for all of them. |
tolerance | float | The self-consistent iteration stops when no escape factor changes by more than this. |
max_iterations | int | The limit of that iteration. |
lengthattributeclass attributeinstance attribute#
length: float = unit_field('m')linesattributeclass attributeinstance attribute#
lines: tuple[str, ...] | None = Nonemax_iterationsattributeclass attributeinstance attribute#
max_iterations: int = 100modelattributeclass attributeinstance attribute#
model: str = 'mewe'toleranceattributeclass attributeinstance attribute#
tolerance: float = 1e-06RateModelclassdataclass#
opencr.core.ratesView sourceclass RateModel(depends_on: str = 'electron')Base class of the rate models; kind names the model in files.
depends_onattributeclass attributeinstance attribute#
depends_on: str = 'electron'kindattributeclass attribute#
kind: str = ''Reactionclassdataclass#
opencr.core.reactionsView sourceclass Reaction(name: str, reactants: tuple[State, ...], products: tuple[State, ...], kind: str, rate: RateModel, provenance: Provenance | None = None, escape: float = 1.0)One reaction.
Attributes
| Name | Type | Description |
|---|---|---|
name | str | A unique name in its network, e.g. "exc:H(n=1)->H(n=2)". |
reactants | tuple[State, ...] | The reactant states; the electron is
ELECTRON_STATE. |
products | tuple[State, ...] | The product states. |
kind | str | One of REACTION_KINDS. |
rate | RateModel | The rate model. |
provenance | Provenance | None | The origin of the rate data. |
escape | float | For a spontaneous emission, the default escape factor of the line (1 for an optically thin plasma); conditions may override it. |
escapeattributeclass attributeinstance attribute#
escape: float = 1.0kindattributeinstance attribute#
kind: strnameattributeinstance attribute#
name: strproductsattributeinstance attribute#
products: tuple[State, ...]provenanceattributeclass attributeinstance attribute#
provenance: Provenance | None = Nonerateattributeinstance attribute#
rate: RateModelreactantsattributeinstance attribute#
reactants: tuple[State, ...]energy_changeproperty#
energy_change: floatThe internal energy of the products minus the reactants’ in eV.
equationproperty#
equation: strThe reaction as text, e.g. "e + H(n=1) -> e + H(n=2)".
is_inverseproperty#
is_inverse: boolWhether the rate is the detailed balance of another reaction.
netproperty#
net: dict[str, int]The net change of each state per reaction (products minus reactants).
orderproperty#
order: intThe number of reactant particles.
photon_energyproperty#
photon_energy: float | NoneFor a spontaneous emission, the photon energy in eV; otherwise None.
product_countsproperty#
product_counts: dict[str, int]How often each state is a product, by name.
reactant_countsproperty#
reactant_counts: dict[str, int]How often each state is a reactant, by name.
ReactionNetworkclass#
opencr.core.networkView sourceclass ReactionNetwork(states: Iterable[State], reactions: Iterable[Reaction], name: str = '', assumptions: Iterable[str] = (), check: bool = True)States and reactions, with the model’s assumptions.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
states | Iterable[State] | required | The states (the electron is implicit and must not be listed). |
reactions | Iterable[Reaction] | required | The reactions; every state they use must be in states. |
name | str | '' | The name of the network, e.g. "hydrogen/atomic/basic". |
assumptions | Iterable[str] | () | The model’s assumptions and omissions, one sentence each. |
check | bool | True | Raise NetworkError if problems finds any. |
assumptionsattributeinstance attribute#
assumptions: tuple[str, ...] = tuple(assumptions)nameattributeinstance attribute#
name = namereactionsattributeinstance attribute#
reactions: tuple[Reaction, ...] = tuple(reactions)statesattributeinstance attribute#
states: tuple[State, ...] = tuple(states)speciesproperty#
species: tuple[Species, ...]The species of the states, each once, in order of appearance.
state_namesproperty#
state_names: tuple[str, ...]The names of the states, in order.
conservationmethod#
def conservation() -> _ConservationReturn the conserved quantities over the states: the elements and the charge.
The matrix has one row per quantity and one column per state: the number of atoms of the element in the state, or its charge. Electrons are not states, so charge is conserved only together with them.
manifestmethod#
def manifest() -> dict[str, Any]Return the states, reactions, sources and assumptions as plain data.
mergemethod#
def merge(other: ReactionNetwork, name: str = '') -> ReactionNetworkReturn the union of two networks; shared states must be identical.
problemsmethod#
def problems() -> list[str]Return every inconsistency found, as sentences; empty if none.
reactionmethod#
def reaction(name: str) -> ReactionReturn the reaction called name.
reactions_ofmethod#
def reactions_of(state: str) -> tuple[Reaction, ...]Return the reactions that change the population of state.
statemethod#
def state(name: str) -> StateReturn the state called name.
state_indexmethod#
def state_index(name: str) -> intReturn the position of the state called name.
subsetmethod#
def subset(keep: Iterable[str], name: str | None = None) -> ReactionNetworkReturn the network of the states keep and the reactions among them only.
Speciesclassdataclass#
opencr.core.speciesView sourceclass Species(name: str, charge: int, mass: float = unit_field('kg'), composition: Mapping[str, int] = dict())A particle kind.
Attributes
chargeattributeinstance attribute#
charge: intcompositionattributeclass attributeinstance attribute#
composition: Mapping[str, int] = field(default_factory=dict)massattributeclass attributeinstance attribute#
mass: float = unit_field('kg')nameattributeinstance attribute#
name: strStateclassdataclass#
opencr.core.speciesView sourceclass State(species: Species, label: str = '', energy: float = unit_field('eV', 0.0), weight: float = 1.0, quantum_numbers: Mapping[str, Any] = dict())One resolved state of a species.
Attributes
| Name | Type | Description |
|---|---|---|
species | Species | The species. |
label | str | The quantum label, e.g. "n=2" or "X,v=3"; empty when the
species is not resolved further. |
energy | float | The energy in eV on the common scale of the element (see the module docstring). |
weight | float | The statistical weight g. |
quantum_numbers | Mapping[str, Any] | The quantum numbers by name, e.g. {"n": 2},
{"n": 2, "l": 1} or {"electronic": "X", "v": 3}. |
energyattributeclass attributeinstance attribute#
energy: float = unit_field('eV', 0.0)labelattributeclass attributeinstance attribute#
label: str = ''quantum_numbersattributeclass attributeinstance attribute#
quantum_numbers: Mapping[str, Any] = field(default_factory=dict)speciesattributeinstance attribute#
species: Speciesweightattributeclass attributeinstance attribute#
weight: float = 1.0chargeproperty#
charge: intThe charge in units of e.
nameproperty#
name: strThe state’s name, "H(n=2)", or the species’ name when unresolved.
Tabulatedclassdataclass#
opencr.core.ratesView sourceclass Tabulated(depends_on: str = 'electron', temperatures: tuple[float, ...] = unit_field('eV', ()), values: tuple[float, ...] = (), threshold: float = unit_field('eV', 0.0))Bases: RateModel
k(T) from a table, interpolated linearly in log k against log T.
A threshold (eV) removes the Boltzmann factor before interpolating,
log(k exp(threshold / T)), which keeps the interpolation accurate at
temperatures far below a threshold. Outside the table this scaled
quantity holds its end value, so k = k_end exp(threshold / T_end - threshold / T) there.
Attributes
Numerics
interpolation
extrapolation
Order of accuracy: 2.
Assumptions:
- the order is in the table spacing in , for a smooth
- outside the table the scaled quantity holds its end value, not itself
kindattributeclass attribute#
kind: str = 'tabulated'temperaturesattributeclass attributeinstance attribute#
temperatures: tuple[float, ...] = unit_field('eV', ())thresholdattributeclass attributeinstance attribute#
threshold: float = unit_field('eV', 0.0)valuesattributeclass attributeinstance attribute#
values: tuple[float, ...] = ()Inherited from opencr.core.rates.RateModel
depends_onattributeclass attributeinstance attribute#
opencr.core.rates.RateModelView sourcedepends_on: str = 'electron'species_from_formulafunction#
opencr.core.speciesView sourcedef species_from_formula(formula: str) -> SpeciesReturn the species of a simple formula such as "H", "H2+", "Ar" or "H-".
The formula is one element symbol, an optional atom count and the charge
as repeated signs ("H2+", "H-", "Ar++"). The mass is the sum of
the atomic masses minus the missing electrons (plus the extra ones of a
negative ion).