majordome.reactor#

General utilities#

class majordome.reactor.NormalFlowRate(mech: str | Path, *, X: str | dict[str, float] | None = None, Y: str | dict[str, float] | None = None, T_ref: float = 273.15, P_ref: float = 101325.0, name: str | None = None)#

Compute normal flow rate for a given composition.

This class makes use of the user defined state to create a function object that converts industrial scale flow rates in normal cubic meters per hour to kilograms per second. Nothing more, nothing less, it aims at helping the process engineer in daily life for this quite repetitive need when performing mass balances.

Parameters:
mech: str | Path

Path to Cantera mechanism used to compute mixture properties.

X: CompositionType | None = None

Composition specification in mole fractions. Notice that both X and Y are mutally exclusive keyword arguments.

Y: CompositionType | None = None

Composition specification in mass fractions. Notice that both X and Y are mutally exclusive keyword arguments.

T_ref: float = constants.T_NORMAL

Reference temperature of the system. If your industry does not use the same standard as the default values, and only in that case, please consider updating this keyword.

P_ref: float = constants.P_NORMAL

Reference pressure of the system. If your industry does not use the same standard as the default values, and only in that case, please consider updating this keyword.

name: str | None = None

Name of phase in mechanism, if more than one are specified within the same Cantera YAML database file.

property TPX: tuple[float, float, dict[str, float]]#

Provides access to the state of internal solution.

property density: float#

Provides access to the density of internal solution [kg/m³].

classmethod new_from_solution(sol: Solution | Quantity, **kwargs) NormalFlowRate#

Creates a new NormalFlowRate from a Cantera solution.

report(**kwargs) str#

Provides a report of the mixture state.

majordome.reactor.toggle_reactor_warnings(*, toggle_non_key_value: bool = True, toggle_missing_species_name: bool = True, toggle_unknown_species: bool = True, **kwargs) None#

Reverse truth value of warning flags.

majordome.reactor.composition_to_dict(Y: str, species_names: list[str] = []) dict[str, float]#

Convert a Cantera composition string to dictionary.

majordome.reactor.composition_to_array(Y: str, species_names: list[str]) ndarray[tuple[Any, ...], dtype[float64]]#

Convert a Cantera composition string to array.

majordome.reactor.solution_report(sol: Solution | Quantity, specific_props: bool = True, composition_spec: str = 'mass', selected_species: list[str] = [], **kwargs) list[tuple[str, str, Any]]#

Generate a solution report for tabulation.

Parameters:
sol: SolutionLikeType

Cantera solution object for report generation.

specific_props: bool = True

If true, add specific heat capacity and enthalpy.

composition_spec: str = “mass”

Composition units specification, mass or mole.

selected_species: list[str] = []

Selected species to display; return all if a composition specification was provided.

Returns:
list[tuple[str, str, Any]]

A list of data entries intended to be displayed externally, e.g. with tabulate.tabulate or appended.

Raises:
ValueError

If in invalid composition specification is provided. If species filtering lead to an empty set of compositions.

majordome.reactor.copy_solution(sol: Solution) Solution#

Makes a hard copy of a Solution object.

majordome.reactor.copy_quantity(qty: Quantity) Quantity#

Makes a hard copy of a ct.composite.Quantity object.

Plug-flow reactors (PFR)#

class majordome.reactor.PlugFlowChainCantera(mechanism: str, phase: str, z: ndarray[tuple[Any, ...], dtype[float64]], V: ndarray[tuple[Any, ...], dtype[float64]], P: float = 101325.0, K: float = 1.0, smoot_flux: bool = False, cantera_steady: bool = True)#

Plug-flow reactor as a chain of 0-D reactors with Cantera.

Parameters:
mechanism: str

Name or path to Cantera mechanism to be used.

phase: str

Name of phase to simulate (not inferred, even if a single is present!).

z: NDArray[np.float64]

Spatial coordinates of reactor cells [m].

V: NDArray[np.float64]

Volumes of reactor cells [m³].

P: float = ct.one_atm

Reactor operating pressure [Pa].

K: float = 1.0

Valve response constant (do not use unless simulation fails).

smoot_flux: bool = False

Apply a smoot transition function when internal stepping is performed; this is intended to avoid unphysical steady state approximations.

cantera_steady: bool = True

If true, use Cantera’ s advance_to_steady_state to solve problem; otherwise advance over meaninful time-scale of the problem.

property contents: Solution#

Provides direct access to reactor contents.

property failures: list[str]#

List of failures encountered during last loop.

loop(m_source: ndarray[tuple[Any, ...], dtype[float64]], h_source: ndarray[tuple[Any, ...], dtype[float64]], Y_source: ndarray[tuple[Any, ...], dtype[float64]], Q: ndarray[tuple[Any, ...], dtype[float64]] | None = None, save_history: bool = False, **opts) DataFrame | None#

Loop over the slices of the plug-flow reactor.

In case of solver failure, one might try the following configurations; it is recommended to start by reducing max_time_step before tweaking other parameters.

`python pfc.network.atol = 1.0e-12 pfc.network.rtol = 1.0e-06 pfc.network.max_time_step = 0.1 pfc.network.linear_solver_type = "GMRES" pfc.network.max_err_test_fails = 10 pfc.network.max_order = 5 pfc.network.max_steps = 2000 `

property n_reactors: int#

Number of reactors in mechanism.

property n_species: int#

Number of species in mechanism.

property network: ReactorNet#

Provides access to the reactor network.

register_heat_flow(func: Callable[[int, float], float]) None#

Provides registration of heat flux function.

property states: SolutionArray#

Provides access to the states of the reactor.

update(source: PlugFlowAxialSources, **kwargs) DataFrame | None#

Wraps call to loop when using a data structure.

use_cantera_steady_solver(state: bool) None#

Select method to approach steady-state solution.

use_smooth_flux(state: bool) None#

Select if smoothed heat flux is to be used.

PFR utilities#

class majordome.reactor.PlugFlowAxialSources(n_reactors: int, n_species: int)#

Provides a data structure for use with PlugFlowChainCantera.

Helper data class for use with the solution method loop of the plug-flow reactor implementation. It provides the required memory for storage of source terms distributed along the reactor.

Parameters:
n_reactors: int

Number of reactors in chain.

n_species: int

Number of species in mechanism.

Attributes:
Q: NDArray[np.float64]

Array of external heat source [W].

m: NDArray[np.float64]

Array of axial mass source terms [kg/s].

h: NDArray[np.float64]

Array of enthalpy of axial mass source terms [J/kg].

Y: NDArray[np.float64, np.float64]

Array of mass fractions of axial mass source terms [-].

reset() None#

Reset values of all arrays to zero.

majordome.reactor.get_reactor_data(pfr: PlugFlowChainCantera) PlugFlowAxialSources#

Wrapper to allocate properly dimensioned solver data.