Skip to content
Projects

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

NameDescription
ConvergenceErrorA solve did not converge; report says how far it got.
SingularSystemErrorThe quasi-static system has no unique solution; the message says which states.
SolverReportThe diagnostics of one solve.
UnderdeterminedErrorThe steady state is not unique: a conserved quantity has no given total.

Functions

NameDescription
relative_residualReturn 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.

reportattributeinstance attribute#

report = report

SingularSystemErrorclass#

class 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

NameTypeDescription
modestr"quasi-static" or "full".
methodstrThe numerical method, e.g. "sparse LU" or "Newton".
convergedboolWhether the tolerances were met.
iterationsintNewton iterations or integrator steps.
residualfloatThe largest |R_i| relative to the gross flow through state i (the sum of all its gains and losses), see relative_residual.
conservationdict[str, float]The relative error of each conserved total.
minimumfloatThe smallest density divided by the largest.
clippedlist[str]States whose small negative densities (round-off) were set to zero.
messageslist[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 = True

iterationsattributeclass attributeinstance attribute#

iterations: int = 0

messagesattributeclass attributeinstance attribute#

messages: list[str] = field(default_factory=list)

methodattributeinstance attribute#

method: str

minimumattributeclass attributeinstance attribute#

minimum: float = 0.0

modeattributeinstance attribute#

mode: str

residualattributeclass attributeinstance attribute#

residual: float = 0.0

summarymethod#

def summary() -> str

Return the report as a few lines of text.

UnderdeterminedErrorclass#

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) -> float

Return max_i |R_i| / (sum_r |N_ir| w_r), the residual relative to the gross flow.

Numerics

residual

ϵR=max⁡i∣Ri∣∑r∣νir∣ wr\epsilon_R = \max_i \frac{|R_i|}{\sum_r |\nu_{ir}|\, w_r}

conservation

ϵe=∣∑iceini−Ne∣Ne\epsilon_e = \frac{\big|\sum_i c_{ei} n_i - N_e\big|}{N_e}

Assumptions:

  • the residual over the gross flow through state ii (1 where there is none)
  • the conservation error is reported (and enters the continuation’s stopping test), but never raises on its own