opencr.solvers.transient
Time evolution of the populations with stiff integrators.
solve_transient integrates dn/dt = R(n, t) for the evolving states
of a PopulationSystem from initial densities
with SciPy’s implicit methods (BDF by default, Radau or LSODA) and, for BDF
and Radau, the analytic sparse Jacobian of the system. The rates span 1e-3 to 1e9 s^-1 in a CR model, so the
problem is stiff; explicit methods are refused.
The conditions are prescribed: constant (one system), or given as a function
of time (system_at(t) returns the system of that moment, built by
solve_transient from conditions(t)). The
report records the integrator’s statistics, the drift of every element total
the evolving states conserve (the particle balance; the charge balance holds
by construction with a given n_e or quasi-neutrality) and the smallest
density reached.
Attributes
| Name | Description |
|---|---|
METHODS | No description. |
Classes
| Name | Description |
|---|---|
TransientReport | The diagnostics of a time integration. |
Functions
| Name | Description |
|---|---|
solve_transient | Return the densities of the evolving states at times and the report. |
METHODSattributemodule attribute#
METHODS = ('BDF', 'Radau', 'LSODA')TransientReportclassdataclass#
class TransientReport(method: str, success: bool = True, evaluations: int = 0, jacobians: int = 0, factorisations: int = 0, conservation: dict[str, float] = dict(), minimum: float = 0.0, messages: list[str] = list())The diagnostics of a time integration.
Attributes
| Name | Type | Description |
|---|---|---|
method | str | The integrator. |
success | bool | Whether the integration reached the final time. |
evaluations | int | Right-hand-side evaluations. |
jacobians | int | Jacobian evaluations. |
factorisations | int | LU factorisations of the iteration matrix. |
conservation | dict[str, float] | The largest relative drift of each conserved total over the output times. |
minimum | float | The smallest density reached divided by the largest. |
messages | list[str] | Anything worth knowing, in sentences. |
conservationattributeclass attributeinstance attribute#
conservation: dict[str, float] = field(default_factory=dict)evaluationsattributeclass attributeinstance attribute#
evaluations: int = 0factorisationsattributeclass attributeinstance attribute#
factorisations: int = 0jacobiansattributeclass attributeinstance attribute#
jacobians: int = 0messagesattributeclass attributeinstance attribute#
messages: list[str] = field(default_factory=list)methodattributeinstance attribute#
method: strminimumattributeclass attributeinstance attribute#
minimum: float = 0.0successattributeclass attributeinstance attribute#
success: bool = Truesolve_transientfunction#
def solve_transient(system: PopulationSystem, initial: np.ndarray, times: np.ndarray, method: str = 'BDF', rtol: float = 1e-06, atol: float | None = None, system_at: Callable[[float], PopulationSystem] | None = None) -> tuple[np.ndarray, TransientReport]Return the densities of the evolving states at times and the report.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
system | PopulationSystem | required | The population equations (the structure, and the rates when
system_at is not given). |
initial | np.ndarray | required | The densities of the evolving states at times[0] (m^-3). |
times | np.ndarray | required | The output times in s, increasing; the integration runs from the first to the last. |
method | str | 'BDF' | One of METHODS. |
rtol | float | 1e-06 | The relative tolerance of the integrator. |
atol | float | None | None | The absolute tolerance in m^-3; by default 1e-12 times the
largest density of the problem (initial, prescribed or a total). |
system_at | Callable[[float], PopulationSystem] | None | None | For time-dependent conditions, the system at a time t
(same network and evolving states); called at every evaluation. |
Returns
tuple[np.ndarray, TransientReport]- The densities with shape
(len(times), system.size)and the report.
Raises
ValueError- An explicit method, or times that do not increase.
RuntimeError- The integrator failed (the report is in the message).
Numerics
ode
tolerance
drift
Assumptions:
- stiff integrators only (
BDF, the default,Radau,LSODA): CR rates span to s - BDF and Radau get the analytic sparse Jacobian; LSODA forms its own by finite differences
- time-dependent conditions rebuild the rates and the system at each new time (a one-entry cache); the prescribed states stay the same
- negative output densities are set to zero, with a message
References:
- Virtanen et al., Nat. Methods 17, 261 (2020) (
solve_ivp)
Built from:
opencr.kinetics.system.PopulationSystem.rhsopencr.kinetics.system.PopulationSystem.jacobian