opencr
Type part of a name or a dotted path
OpenCR: collisional-radiative models of low-temperature plasmas.
OpenCR builds collisional-radiative (CR) models from explicit states and
reactions with traceable data, and solves their population equations: steady
states, quasi-static excited states with effective rate coefficients, and time
evolution. The physics is defined independently of the numerical backend; the
reference implementation uses NumPy and SciPy, cunumpy and JAX are optional.
Cross sections and Maxwellian rates come from plasmacoll.
Classes
| Name | Description |
|---|---|
Conditions | Plasma conditions, SI with temperatures in eV. |
Model | A reaction network with its default drivers. |
RadiationTrapping | The escape-factor configuration of a solve (see opencr.kinetics.radiation). |
Result | A steady state. |
Functions
| Name | Description |
|---|---|
available_models | Return the names of the predefined models with one sentence each. |
load_model | Return the predefined model name built with options. |
scan | Solve model on a grid of conditions. |
Modules
analysisResults and what can be read from them.backendsThe array layer: cunumpy, with explicit execution boundaries.cliThe opencr command: list the predefined models and print their manifests.constantsPhysical constants (CODATA 2018, through scipy.constants) and unit helpers.coreModel definitions independent of any array backend.dataPhysical data with provenance.inferenceSensitivities, uncertainty propagation and inverse modelling on top of the solver.kineticsFrom a network and conditions to numbers.mlOptional machine-learning surrogates of the CR solver. Imports scikit-learn only when used.modelA CR model: a reaction network with its drivers, and the solves on it.modelsPredefined models, loaded by name with load_model.solversSteady-state solutions of the population equations.tablesEffective-rate tables for the codes that use OpenCR's results.
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).
Modelclass#
opencr.modelView sourceclass Model(network: ReactionNetwork, drivers: Sequence[str] = (), description: str = '')A reaction network with its default drivers.
Parameters
descriptionattributeinstance attribute#
description = descriptiondriversattributeinstance attribute#
drivers = tuple(drivers)evaluatorattributeinstance attribute#
evaluator = RateEvaluator(network)networkattributeinstance attribute#
network = networknameproperty#
name: strThe network’s name.
state_namesproperty#
state_names: tuple[str, ...]The state names.
effective_ratesmethod#
def effective_rates(conditions: Conditions) -> QuasiStaticReturn the quasi-static reduction with the prescribed states of conditions.
manifestmethod#
def manifest() -> dict[str, Any]Return the network’s manifest with the drivers and the description.
rate_coefficientsmethod#
def rate_coefficients(conditions: Conditions) -> dict[str, float]Return every reaction’s rate coefficient (SI) by name.
scaled_ratesmethod#
def scaled_rates(conditions: Conditions, factors: Mapping[str, float] | None = None) -> np.ndarrayReturn the rate coefficients with some multiplied by factors (by name).
A detailed-balance inverse takes the factor of its forward reaction (unless it has its own), so the scaled network keeps detailed balance: this is what sensitivities and uncertainty propagation perturb.
Numerics
scaled
Assumptions:
- an inverse moves with its forward reaction, so the scaled network keeps detailed balance: what sensitivities and uncertainty propagation perturb
solve_steady_statemethod#
def solve_steady_state(conditions: Conditions, mode: str = 'quasi-static', initial: dict[str, float] | None = None, rtol: float = 1e-09, factors: Mapping[str, float] | None = None)Return the steady state as a Result.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
conditions | Conditions | required | The conditions. In "quasi-static" mode the drivers
need densities; in "full" mode the conserved elements need totals. |
mode | str | 'quasi-static' | One of MODES. |
initial | dict[str, float] | None | None | Starting densities by state name for a nonlinear solve, in m^-3 (or quantities). |
rtol | float | 1e-09 | The tolerance of the relative residual. |
factors | Mapping[str, float] | None | None | Multiply the rate coefficients of these reactions (by
name) by these factors (see scaled_rates). |
Numerics
fixed point
update
stop
Assumptions:
- only with
Conditions.trapping: the first solve is optically thin apart from the given factors (an absent counts as 1) - the result returned was solved with the previous factors; at
max_iterationsaConvergenceErroris raised - the damping never goes back to 1
Built from:
opencr.solvers.steady.solve_steadyopencr.kinetics.radiation.escape_factors
solve_transientmethod#
def solve_transient(conditions: Conditions | Callable[[float], Conditions], initial: dict[str, float], times: np.ndarray, method: str = 'BDF', rtol: float = 1e-06, atol: float | None = None)Return the populations against time as a TransientResult.
The states with a density in the conditions stay prescribed (constant,
or following conditions(t)); the others evolve from initial.
initial, times and atol take astropy quantities or strings
such as "1 us" as well as numbers in their documented units.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
conditions | Conditions | Callable[[float], Conditions] | required | The conditions, or a function of the time in s returning them (same prescribed states at every time). |
initial | dict[str, float] | required | The densities in m^-3 at times[0] by state name; an
evolving state not listed starts empty. |
times | np.ndarray | required | The output times in s, increasing. |
method | str | 'BDF' | "BDF" (default), "Radau" or "LSODA". |
rtol | float | 1e-06 | The relative tolerance. |
atol | float | None | None | The absolute tolerance in m^-3 (default 1e-12 of the
largest initial, prescribed or total density). |
systemmethod#
def system(conditions: Conditions, rates: np.ndarray | None = None) -> PopulationSystemReturn the population equations with the prescribed states of conditions.
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-06Resultclass#
opencr.analysis.resultsView sourceclass Result(model: Model, conditions: Conditions, rates: np.ndarray, system: PopulationSystem, evolving: np.ndarray, report: SolverReport)A steady state.
Attributes
| Name | Description |
|---|---|
model | The model solved. |
conditions | The conditions. |
rates | The rate coefficient of every reaction (SI), in network order. |
system | The population equations. |
evolving | The steady densities of the evolving states (m^-3). |
report | The solver’s report. |
conditionsattributeinstance attribute#
conditions = conditionsevolvingattributeinstance attribute#
evolving = np.asarray(evolving, dtype=float)modelattributeinstance attribute#
model = modelratesattributeinstance attribute#
rates = ratesreportattributeinstance attribute#
report = reportsystemattributeinstance attribute#
system = systemelectron_densityproperty#
electron_density: floatn_e in m^-3.
fluxespropertycached#
fluxes: dict[str, float]The rate of every reaction in m^-3 s^-1, by name.
modeproperty#
mode: strThe solve: "quasi-static" or "full".
populationspropertycached#
populations: dict[str, float]The density of every state in m^-3, by name, in network order.
reductionpropertycached#
reduction: QuasiStaticThe quasi-static reduction at these conditions (population and effective coefficients).
dominant_processesmethod#
def dominant_processes(state: str, number: int = 5) -> list[dict[str, Any]]Return the largest gains and losses of state.
Each entry has the reaction name, its equation, the rate of
change of the state (m^-3 s^-1; negative for a loss) and its fraction
of the state’s total gain or total loss. Sorted by |rate|.
emissionmethod#
def emission(air: bool = False) -> xr.DatasetReturn the lines: wavelength, emissivity and power (line_table).
emission_spectrummethod#
def emission_spectrum(wavelength: np.ndarray | None = None, fwhm: float = 0.0, air: bool = False, quantity: str = 'power') -> xr.DataArrayReturn a synthetic spectrum: the lines Doppler broadened at the gas temperature.
exportmethod#
def export(path: str | Path) -> PathWrite to_dataset to a NetCDF file and return its path.
photon_emissivity_coefficientsmethod#
def photon_emissivity_coefficients() -> xr.DataArrayReturn PEC_d of every line per driver in m^3/s (quasi-static only).
emissivity = n_e sum_d PEC_d n_d; for atomic hydrogen the H(n=1)
part is the excitation component and the H+ part the recombination one.
Numerics
pec
Assumptions:
- a quasi-static solve: ; zero for a line whose upper state is a driver
- for atomic hydrogen the H(n=1) part is the excitation component, the H part the recombination one
References:
Built from:
opencr.kinetics.effective.quasi_staticopencr.analysis.emission.line_table
populationmethod#
def population(state: str) -> floatReturn the density of state in m^-3.
to_datasetmethod#
def to_dataset() -> xr.DatasetReturn the populations, rates, fluxes and lines as one xarray dataset.
The conditions, the solver report and the model’s manifest are in the attributes, as JSON.
available_modelsfunction#
opencr.modelsView sourcedef available_models() -> dict[str, str]Return the names of the predefined models with one sentence each.
load_modelfunction#
opencr.modelsView sourcedef load_model(name: str, **options: Any) -> ModelReturn the predefined model name built with options.
scanfunction#
opencr.analysis.scanView sourcedef scan(model: Model, conditions: Conditions, mode: str = 'quasi-static', effective: bool = True, lines: bool = True, **axes: Sequence[float]) -> xr.DatasetSolve model on a grid of conditions.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
model | Model | required | The model. |
conditions | Conditions | required | The conditions every point starts from. |
mode | str | 'quasi-static' | The steady-state mode. |
effective | bool | True | Add effective_rate (target driver, source driver) and, with
lines, pec (line, driver) for quasi-static solves. |
lines | bool | True | Add the line emissivities. |
**axes | Sequence[float] | {} | The condition fields to scan and their values, e.g.
electron_temperature=np.geomspace(0.5, 50, 20). Use
{"density:H(n=1)": [...]} or {"total:H": [...]} unpacked with **.
The values are in eV or m^-3, or quantities. |
Returns
xr.Dataset- A dataset over the axes (and
state,line,driver).