opencr.solvers.diagnostics
What a solve reports: convergence, residuals, conservation and positivity.
Every solve returns a SolverReport. A solve that does not converge
raises ConvergenceError with the report attached; an underdetermined
system (a conserved element without a total) raises
UnderdeterminedError; a singular one
SingularSystemError.
Classes
| Name | Description |
|---|---|
ConvergenceError | A solve did not converge; report says how far it got. |
SingularSystemError | The quasi-static system has no unique solution; the message says which states. |
SolverReport | The diagnostics of one solve. |
UnderdeterminedError | The steady state is not unique: a conserved quantity has no given total. |
Functions
| Name | Description |
|---|---|
relative_residual | Return max_i |R_i| / (sum_r |N_ir| w_r), the residual relative to the gross flow. |
ConvergenceErrorclass#
class ConvergenceError(message: str, report: SolverReport)Bases: RuntimeError
A solve did not converge; report says how far it got.
SingularSystemErrorclass#
opencr.kinetics.effectiveView sourceclass SingularSystemError(ValueError)Bases: ValueError
The quasi-static system has no unique solution; the message says which states.
SolverReportclassdataclass#
class SolverReport(mode: str, method: str, converged: bool = True, iterations: int = 0, residual: float = 0.0, conservation: dict[str, float] = dict(), minimum: float = 0.0, clipped: list[str] = list(), messages: list[str] = list())The diagnostics of one solve.
Attributes
| Name | Type | Description |
|---|---|---|
mode | str | "quasi-static" or "full". |
method | str | The numerical method, e.g. "sparse LU" or "Newton". |
converged | bool | Whether the tolerances were met. |
iterations | int | Newton iterations or integrator steps. |
residual | float | The largest |R_i| relative to the gross flow through state
i (the sum of all its gains and losses), see relative_residual. |
conservation | dict[str, float] | The relative error of each conserved total. |
minimum | float | The smallest density divided by the largest. |
clipped | list[str] | States whose small negative densities (round-off) were set to zero. |
messages | list[str] | Anything worth knowing, in sentences. |
clippedattributeclass attributeinstance attribute#
clipped: list[str] = field(default_factory=list)conservationattributeclass attributeinstance attribute#
conservation: dict[str, float] = field(default_factory=dict)convergedattributeclass attributeinstance attribute#
converged: bool = Trueiterationsattributeclass attributeinstance attribute#
iterations: int = 0messagesattributeclass attributeinstance attribute#
messages: list[str] = field(default_factory=list)methodattributeinstance attribute#
method: strminimumattributeclass attributeinstance attribute#
minimum: float = 0.0modeattributeinstance attribute#
mode: strresidualattributeclass attributeinstance attribute#
residual: float = 0.0UnderdeterminedErrorclass#
class UnderdeterminedError(ValueError)Bases: ValueError
The steady state is not unique: a conserved quantity has no given total.
relative_residualfunction#
def relative_residual(system: PopulationSystem, n: np.ndarray) -> floatReturn max_i |R_i| / (sum_r |N_ir| w_r), the residual relative to the gross flow.
Numerics
residual
conservation
Assumptions:
- the residual over the gross flow through state (1 where there is none)
- the conservation error is reported (and enters the continuation’s stopping test), but never raises on its own