Skip to content
Projects

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

NameDescription
METHODSNo description.

Classes

NameDescription
TransientReportThe diagnostics of a time integration.

Functions

NameDescription
solve_transientReturn 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

NameTypeDescription
methodstrThe integrator.
successboolWhether the integration reached the final time.
evaluationsintRight-hand-side evaluations.
jacobiansintJacobian evaluations.
factorisationsintLU factorisations of the iteration matrix.
conservationdict[str, float]The largest relative drift of each conserved total over the output times.
minimumfloatThe smallest density reached divided by the largest.
messageslist[str]Anything worth knowing, in sentences.

conservationattributeclass attributeinstance attribute#

conservation: dict[str, float] = field(default_factory=dict)

evaluationsattributeclass attributeinstance attribute#

evaluations: int = 0

factorisationsattributeclass attributeinstance attribute#

factorisations: int = 0

jacobiansattributeclass attributeinstance attribute#

jacobians: int = 0

messagesattributeclass attributeinstance attribute#

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

methodattributeinstance attribute#

method: str

minimumattributeclass attributeinstance attribute#

minimum: float = 0.0

successattributeclass attributeinstance attribute#

success: bool = True

summarymethod#

def summary() -> str

Return the report as a few lines of text.

solve_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

NameTypeDefaultDescription
systemPopulationSystemrequiredThe population equations (the structure, and the rates when system_at is not given).
initialnp.ndarrayrequiredThe densities of the evolving states at times[0] (m^-3).
timesnp.ndarrayrequiredThe output times in s, increasing; the integration runs from the first to the last.
methodstr'BDF'One of METHODS.
rtolfloat1e-06The relative tolerance of the integrator.
atolfloat | NoneNoneThe absolute tolerance in m^-3; by default 1e-12 times the largest density of the problem (initial, prescribed or a total).
system_atCallable[[float], PopulationSystem] | NoneNoneFor 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

dndt=R(max⁡(n,0),t),n(t0)=n0\frac{d\mathbf n}{dt} = R\big(\max(\mathbf n, 0), t\big), \qquad \mathbf n(t_0) = \mathbf n_0

tolerance

atol=10−12max⁡(n0, nP, Ne) (1 if all zero)\mathrm{atol} = 10^{-12} \max\big(\mathbf n_0,\ \mathbf n_P,\ N_e\big) \ (1 \text{ if all zero})

drift

max⁡t∣∑iceini(t)−∑iceini(t0)∣∑iceini(t0)\max_t \frac{\big|\sum_i c_{ei} n_i(t) - \sum_i c_{ei} n_i(t_0)\big|}{\sum_i c_{ei} n_i(t_0)}

Assumptions:

  • stiff integrators only (BDF, the default, Radau, LSODA): CR rates span 10−310^{-3} to 10910^9 s−1^{-1}
  • 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:

Built from:

  • opencr.kinetics.system.PopulationSystem.rhs
  • opencr.kinetics.system.PopulationSystem.jacobian