opencr.solvers.steady
Steady states of the population equations.
solve_steady finds R(n) = 0 for the evolving states of a
PopulationSystem:
- Linear systems (one evolving reactant per reaction,
n_egiven) are solved directly by sparse LU with one step of iterative refinement. - Conserved elements. When the evolving states exchange an element only
among themselves (a closed system),
R = 0is singular; one equation per conserved element is replaced by its total fromtotals. A conserved element without a total raisesUnderdeterminedError. - Quasi-neutral systems that are linear for a given
n_eare a 1D root inln n_e(Brent’s method), each evaluation a linear solve. - Other nonlinear systems (two evolving reactants, or a given start) use
a pseudo-transient continuation: implicit-Euler steps
(F/dt - J) dx = Rwhosedtgrows as the residual falls (switched evolution relaxation), which follows the physical relaxation and keeps the totals of a closed system, and tends to Newton’s method asdtgrows. There is no separate Newton phase, and no line search beyond damping the steps that would turn a density negative.
Every solve checks the relative residual, the conservation of the totals and
the positivity of the densities, and returns a
SolverReport.
Functions
| Name | Description |
|---|---|
constraint_rows | Return the rows to replace, the constraint matrix and the totals. |
solve_steady | Return the steady densities of the evolving states and the report. |
constraint_rowsfunction#
def constraint_rows(system: PopulationSystem, totals: Mapping[str, float] | None) -> tuple[np.ndarray, np.ndarray, np.ndarray, tuple[str, ...]]Return the rows to replace, the constraint matrix and the totals.
For each conserved element the equation of the state with the most atoms of it (the first such state not yet used) is replaced.
Raises
UnderdeterminedError- A conserved element has no total.
Numerics
constraint
Assumptions:
- one row per conserved element replaced by its total from
Conditions.totals; a missing total raisesUnderdeterminedError - for atomic hydrogen in
fullmode every state holds one H, so the H(n=1) row is replaced
Built from:
opencr.kinetics.system.PopulationSystem.conservation
solve_steadyfunction#
def solve_steady(system: PopulationSystem, totals: Mapping[str, float] | None = None, initial: np.ndarray | None = None, mode: str = 'quasi-static', rtol: float = 1e-09, max_iterations: int = 200) -> tuple[np.ndarray, SolverReport]Return the steady densities of the evolving states and the report.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
system | PopulationSystem | required | The population equations. |
totals | Mapping[str, float] | None | None | The total density of each conserved element (m^-3). |
initial | np.ndarray | None | None | A starting point for a nonlinear solve; by default the totals
are put in the lowest-energy state of each element, a tenth of it
ionized when n_e is quasi-neutral. |
mode | str | 'quasi-static' | The name of the solve for the report. |
rtol | float | 1e-09 | The tolerance of the relative residual. |
max_iterations | int | 200 | Continuation steps. |
Raises
UnderdeterminedError- A conserved element has no total.
SingularSystemError- The linear system is singular.
ConvergenceError- A nonlinear solve did not converge.
Numerics
linear
quasi neutral
continuation
damping
relaxation
Assumptions:
- linear systems (one evolving reactant, given ): one LU solve; a zero diagonal (a state without losses) raises
SingularSystemError - quasi-neutral and linear for given , without a start: the bracket ( the total charge scale) widened by up to 20 times; a negative excess at the lower end raises
- otherwise pseudo-transient continuation with switched evolution relaxation (no separate Newton phase); a step that raises tenfold undamped is rejected with , a non-finite one with
- the default start puts each total in the lowest-energy neutral holder (10% in the lowest ion when quasi-neutral), plus in every state
- negatives within of the largest density are zeroed; only the relative residual decides failure, above
References:
- Virtanen et al., Nat. Methods 17, 261 (2020) (
splu,brentq)
Built from:
opencr.solvers.steady.constraint_rowsopencr.solvers.diagnostics.relative_residualopencr.kinetics.system.PopulationSystem.jacobian