opencr.model
A CR model: a reaction network with its drivers, and the solves on it.
Model is what opencr.load_model returns and what a custom
network is wrapped in. It evaluates the rate coefficients (once per set of
conditions), builds the population equations and solves them (see the guide
“The CR model”):
Model.solve_steady_statewithmode="quasi-static"(the default): the states with a density in the conditions are prescribed, the rest are in steady state;mode="full": a closed steady state with the element totals of the conditions;Model.effective_rates: the quasi-static reduction to effective rate and population coefficients;Model.solve_transient: the populations against time from initial densities, with constant or time-dependent conditions.
Attributes
| Name | Description |
|---|---|
MODES | No description. |
Classes
| Name | Description |
|---|---|
Model | A reaction network with its default drivers. |
MODESattributemodule attribute#
MODES = ('quasi-static', 'full')Modelclass#
class Model(network: ReactionNetwork, drivers: Sequence[str] = (), description: str = '')A reaction network with its default drivers.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
network | ReactionNetwork | required | The reaction network. |
drivers | Sequence[str] | () | The states a quasi-static solve needs densities for (for atomic hydrogen H(n=1) and H+); checked against the conditions. |
description | str | '' | One sentence on what the model is. |
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.