aquakin.PlugFlowReactor#

class aquakin.PlugFlowReactor(model, conditions, n_points, length, velocity, *, rtol=1e-06, atol=None, integrator=IntegratorConfig(order=3, factormax=3.0, colored_jacobian='auto', dtmax=None, max_steps=100000, solver=None), diff=DifferentiationConfig(mode='reverse', method='stable', check_finite=True, adjoint_max_steps=100000, adjoint_low_memory=False))[source]#

Bases: GradientCheckMixin

Steady-state plug-flow reactor.

The chemistry RHS is integrated along the reactor axis:

\[\frac{dC}{dx} = \frac{1}{v}\, \mathbf{S}^T\, r(C, p, \theta(x))\]

Condition fields supplied at n_locations grid points are linearly interpolated to the integrator’s current x.

Parameters:
  • model (CompiledModel)

  • conditions (SpatialConditions) – Either a uniform single-location conditions object, or a spatially resolved one with n_locations >= 2. Grid points are assumed evenly spaced over [0, length].

  • n_points (int) – Number of axial output points at which to record the solution.

  • length (float) – Reactor length.

  • velocity (float) – Bulk velocity through the reactor.

  • rtol (float, optional) – Relative tolerance for the ODE solver.

  • atol (float or jnp.ndarray, optional) – Absolute tolerance, scalar or shape (n_species,). Defaults to None -> a per-component noise floor scaled off the model reference concentrations (see BatchReactor for the per-species rationale).

  • integrator (IntegratorConfig, optional) – Integrator / step-size configuration (ESDIRK order, factormax, dtmax, max_steps, an explicit solver). See BatchReactor. Set dtmax for reverse-mode differentiation of a stiff model.

  • diff (DifferentiationConfig, optional) – Autodiff configuration (mode, method). See BatchReactor.

__init__(model, conditions, n_points, length, velocity, *, rtol=1e-06, atol=None, integrator=IntegratorConfig(order=3, factormax=3.0, colored_jacobian='auto', dtmax=None, max_steps=100000, solver=None), diff=DifferentiationConfig(mode='reverse', method='stable', check_finite=True, adjoint_max_steps=100000, adjoint_low_memory=False))[source]#
Parameters:
Return type:

None

Methods

__init__(model, conditions, n_points, ...[, ...])

check_gradient_finite(grad_value, *[, what])

Raise a friendly error if a reverse-mode gradient is non-finite.

solve(C0, *[, params, conditions])

Integrate the steady-state PFR.

solve_sensitivity(C0, *, params, sens_params)

Solve and return the forward sensitivity dC/dtheta along the axis.

solve(C0, *, params=None, conditions=None)[source]#

Integrate the steady-state PFR.

Parameters:
  • C0 (jnp.ndarray) – Inlet concentration vector, shape (n_species,).

  • params (jnp.ndarray, optional) – Rate constant vector, shape (n_params,). Defaults to model.default_parameters().

  • conditions (SpatialConditions, optional) – Override the conditions stored on the reactor for this call. Must match the constructor-time n_locations so the precomputed x_grid remains valid.

Return type:

PFRSolution

solve_sensitivity(C0, *, params, sens_params, conditions=None, sens_rtol=None, sens_atol=None, param_scale=None, shared_factor=None)[source]#

Solve and return the forward sensitivity dC/dtheta along the axis.

Integrates the augmented [C; S] system over the reactor length with adaptive control over both, so the sensitivity profile is exact and finite without a dtmax cap (see aquakin.integrate.forward_sensitivity).

Parameters:
  • C0 (Array) – As for solve().

  • conditions (SpatialConditions | None) – As for solve().

  • params (jnp.ndarray) – Full parameter vector; keyword-only, matching solve().

  • sens_params (list of str or int) – Namespaced parameter names (or integer indices into params).

  • sens_rtol (float | None) – Sensitivity error-control tolerances (CVODES defaults).

  • sens_atol – Sensitivity error-control tolerances (CVODES defaults).

  • param_scale – Sensitivity error-control tolerances (CVODES defaults).

  • shared_factor (bool, optional) – CVODES simultaneous-corrector linear solve. None (default) auto-selects True for more than one sensitivity parameter, else False.

Returns:

  • sol (PFRSolution) – The usual axial concentration profile.

  • S (jnp.ndarray) – Sensitivity dC/dtheta at the axial output points, shape (n_points, n_species, n_sens_params).

Return type:

tuple[PFRSolution, Array]