Skip to content
Projects

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_e given) 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 = 0 is singular; one equation per conserved element is replaced by its total from totals. A conserved element without a total raises UnderdeterminedError.
  • Quasi-neutral systems that are linear for a given n_e are a 1D root in ln 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 = R whose dt grows 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 as dt grows. 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

NameDescription
constraint_rowsReturn the rows to replace, the constraint matrix and the totals.
solve_steadyReturn 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

Rie(n) → ∑icei ni−Ne=0,ie=arg⁡max⁡icei (first unused, stable order)R_{i_e}(\mathbf n) \ \to\ \sum_i c_{ei}\, n_i - N_e = 0, \qquad i_e = \arg\max_i c_{ei} \ \text{(first unused, stable order)}

Assumptions:

  • one row per conserved element replaced by its total NeN_e from Conditions.totals; a missing total raises UnderdeterminedError
  • for atomic hydrogen in full mode 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

NameTypeDefaultDescription
systemPopulationSystemrequiredThe population equations.
totalsMapping[str, float] | NoneNoneThe total density of each conserved element (m^-3).
initialnp.ndarray | NoneNoneA 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.
modestr'quasi-static'The name of the solve for the report.
rtolfloat1e-09The tolerance of the relative residual.
max_iterationsint200Continuation steps.

Raises

UnderdeterminedError
A conserved element has no total.
SingularSystemError
The linear system is singular.
ConvergenceError
A nonlinear solve did not converge.

Numerics

linear

J(0) n=−R(0)by sparse LU, one step of iterative refinementJ(\mathbf 0)\,\mathbf n = -R(\mathbf 0) \quad \text{by sparse LU, one step of iterative refinement}

quasi neutral

ln⁡∑jzjnj(ne)−ln⁡ne=0by Brent’s method in ln⁡ne, each evaluation a linear solve\ln\sum_j z_j n_j(n_e) - \ln n_e = 0 \quad \text{by Brent's method in } \ln n_e, \ \text{each evaluation a linear solve}

continuation

(FΔt−J) δn=R(n),Fi={1free row0constraint row,Δt0=1max⁡(max⁡i∣Jii∣,1)\Big(\frac{F}{\Delta t} - J\Big)\,\delta\mathbf n = R(\mathbf n), \qquad F_i = \begin{cases} 1 & \text{free row} \\ 0 & \text{constraint row} \end{cases}, \qquad \Delta t_0 = \frac{1}{\max(\max_i |J_{ii}|, 1)}

damping

f=min⁡i: ni+δni<00.9 ni−δni (≥10−6),n←max⁡(n+f δn,0)f = \min_{i:\, n_i + \delta n_i < 0} \frac{0.9\, n_i}{-\delta n_i} \ (\ge 10^{-6}), \qquad \mathbf n \leftarrow \max(\mathbf n + f\,\delta\mathbf n, 0)

relaxation

Δt←Δt clip ⁣(2∥R∥∗,old∥R∥∗,new, 0.5, 103),∥R∥∗=∥R∥2∑i∣ni∣\Delta t \leftarrow \Delta t\ \mathrm{clip}\!\left(\frac{2\|R\|_{*,\mathrm{old}}}{\|R\|_{*,\mathrm{new}}},\ 0.5,\ 10^3\right), \qquad \|R\|_* = \frac{\|R\|_2}{\sum_i |n_i|}

Assumptions:

  • linear systems (one evolving reactant, given nen_e): one LU solve; a zero diagonal (a state without losses) raises SingularSystemError
  • quasi-neutral and linear for given nen_e, without a start: the bracket [10−30,10] s[10^{-30}, 10]\,s (ss the total charge scale) widened by ×100\times 100 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 ∥R∥∗\|R\|_* tenfold undamped is rejected with Δt←Δt/4\Delta t \leftarrow \Delta t/4, a non-finite one with Δt←Δt/10\Delta t \leftarrow \Delta t/10
  • the default start puts each total in the lowest-energy neutral holder (10% in the lowest ion when quasi-neutral), plus 10−12max⁡(N,1)10^{-12}\max(N, 1) in every state
  • negatives within 10−810^{-8} of the largest density are zeroed; only the relative residual decides failure, above max⁡(rtol,10−6)\max(\mathrm{rtol}, 10^{-6})

References:

Built from:

  • opencr.solvers.steady.constraint_rows
  • opencr.solvers.diagnostics.relative_residual
  • opencr.kinetics.system.PopulationSystem.jacobian