Skip to content
Projects

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_state with mode="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

NameDescription
MODESNo description.

Classes

NameDescription
ModelA 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

NameTypeDefaultDescription
networkReactionNetworkrequiredThe reaction network.
driversSequence[str]()The states a quasi-static solve needs densities for (for atomic hydrogen H(n=1) and H+); checked against the conditions.
descriptionstr''One sentence on what the model is.

descriptionattributeinstance attribute#

description = description

driversattributeinstance attribute#

drivers = tuple(drivers)

evaluatorattributeinstance attribute#

evaluator = RateEvaluator(network)

networkattributeinstance attribute#

network = network

nameproperty#

name: str

The network’s name.

state_namesproperty#

state_names: tuple[str, ...]

The state names.

effective_ratesmethod#

def effective_rates(conditions: Conditions) -> QuasiStatic

Return 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.ndarray

Return 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

kr←fr kr,finv=ffwd for a detailed-balance inverse without a factor of its ownk_r \leftarrow f_r\, k_r, \qquad f_{\mathrm{inv}} = f_{\mathrm{fwd}} \ \text{for a detailed-balance inverse without a factor of its own}

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

NameTypeDefaultDescription
conditionsConditionsrequiredThe conditions. In "quasi-static" mode the drivers need densities; in "full" mode the conserved elements need totals.
modestr'quasi-static'One of MODES.
initialdict[str, float] | NoneNoneStarting densities by state name for a nonlinear solve, in m^-3 (or quantities).
rtolfloat1e-09The tolerance of the relative residual.
factorsMapping[str, float] | NoneNoneMultiply the rate coefficients of these reactions (by name) by these factors (see scaled_rates).

Numerics

fixed point

gnew(k)=g(τ0[nl(g(k))]),given factors override computed ones line by lineg^{(k)}_{\mathrm{new}} = g\big(\tau_0[n_l(g^{(k)})]\big), \qquad \text{given factors override computed ones line by line}

update

g(k+1)=g(k)+d (gnew(k)−g(k)),d=1→0.5 once the largest change growsg^{(k+1)} = g^{(k)} + d\,\big(g^{(k)}_{\mathrm{new}} - g^{(k)}\big), \qquad d = 1 \to 0.5 \ \text{once the largest change grows}

stop

max⁡lines∣gnew(k)−g(k)∣≤tolerance\max_{\mathrm{lines}} \big|g^{(k)}_{\mathrm{new}} - g^{(k)}\big| \le \texttt{tolerance}

Assumptions:

  • only with Conditions.trapping: the first solve is optically thin apart from the given factors (an absent gg counts as 1)
  • the result returned was solved with the previous factors; at max_iterations a ConvergenceError is raised
  • the damping never goes back to 1

Built from:

  • opencr.solvers.steady.solve_steady
  • opencr.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

NameTypeDefaultDescription
conditionsConditions | Callable[[float], Conditions]requiredThe conditions, or a function of the time in s returning them (same prescribed states at every time).
initialdict[str, float]requiredThe densities in m^-3 at times[0] by state name; an evolving state not listed starts empty.
timesnp.ndarrayrequiredThe output times in s, increasing.
methodstr'BDF'"BDF" (default), "Radau" or "LSODA".
rtolfloat1e-06The relative tolerance.
atolfloat | NoneNoneThe 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) -> PopulationSystem

Return the population equations with the prescribed states of conditions.