rizer.misc.ct_utils#

Functions#

plot_chemical_equilibrium(thermo, initial_solution, ...)

Plot main species under thermochemical equilibrium with [Cantera].

get_similar_reactions(→ dict[int, cantera.Reaction])

Get all reactions in a cantera.Solution that are similar to reaction.

to_cantera_format(→ str)

Convert a reaction rate constant to Cantera format.

return_x_y_from_hydrocarbon(→ tuple[int, int])

Return the number of carbon atoms and hydrogen atoms in a hydrocarbon.

Module Contents#

rizer.misc.ct_utils.plot_chemical_equilibrium(thermo: str | pathlib.Path, initial_solution: str | dict[str, float], temperatures: numpy.ndarray, unit: str = 'K', keep_only_first_species: int = 5, save_file_name: str | pathlib.Path | None = None, fraction: str = 'mole')#

Plot main species under thermochemical equilibrium with [Cantera].

Parameters:
  • thermo (str | Path) – Cantera thermo file.

  • initial_solution (str | dict[str,float]) – Initial solution (in mole).

  • temperatures (np.ndarray) – Temperatures to evaluate.

  • unit (str, optional) – Temperature unit (“K” or “C”), by default “K”

  • keep_only_first_species (int, optional) – Keep only the first majority species, by default 5

  • save_file_name (str | Path | None, optional) – Save file name, by default None

  • fraction (str, optional) – Display the result with “mole” or “mass” fraction, by default “mole”

rizer.misc.ct_utils.get_similar_reactions(reaction: str | cantera.Reaction, gas: cantera.Solution, verbose: bool = False) dict[int, cantera.Reaction]#

Get all reactions in a cantera.Solution that are similar to reaction.

Similarity is defined as:

  • all the reactants or reaction are a subset of the reactants of the reaction in gas.

  • all the products of reaction are a subset of the reactants of the reaction in gas (happens when the reaction is reversible)

This function is used to give a hint on mistyped reactions.

Parameters:
  • reaction (str | ct.Reaction) – Reaction to compare.

  • gas (ct.Solution) – Cantera gas object.

  • verbose (bool, optional) – If True, print the similar reactions, by default False

Returns:

Dictionary of similar reactions.

Return type:

dict[int, ct.Reaction]

Example

>>> import cantera as ct
>>> from rizer.misc.ct_utils import get_similar_reactions
>>> gas = ct.Solution("gri30.yaml")
>>> get_similar_reactions("H + CH4 <=> CH3 + H2", gas, verbose=True)
Reactions similar to H + CH4 <=> CH3 + H2, with ['H', 'CH4'] as either reactants or products,     are {52: CH4 + H <=> CH3 + H2    <Arrhenius>}
rizer.misc.ct_utils.to_cantera_format(A: float, b: float, Ea: float, plasma: bool, equation: str, note: str, commented: bool = False, source: None | str = None, nist_url: None | str = None, umist_url: None | str = None, temperature_range: None | tuple[float, float] = None, see_also: None | str = None) str#

Convert a reaction rate constant to Cantera format.

Parameters:
  • A (float) – Pre-exponential factor.

  • b (float) – Temperature exponent [-].

  • Ea (float) – Activation energy [K].

  • plasma (bool) – If True, the reaction is a plasma reaction.

  • equation (str) – Reaction equation.

  • note (str) – Note to add to the reaction.

  • commented (bool, optional) – If True, the reaction is commented, by default False.

  • source (None | str, optional) – Source of the reaction, by default None.

  • umist_url (None | str, optional) – URL to the UMIST database, by default None.

  • temperature_range (None | tuple[float, float], optional) – Temperature range validity of the reaction, by default None.

  • see_also (None | str, optional) – URL to a related reaction, by default None.

Returns:

Reaction rate constant in Cantera format.

Return type:

str

rizer.misc.ct_utils.return_x_y_from_hydrocarbon(hydrocarbon: str) tuple[int, int]#

Return the number of carbon atoms and hydrogen atoms in a hydrocarbon.

Parameters:

hydrocarbon (str) – The name of the hydrocarbon, like CH4 or C2H6.

Returns:

The number of carbon atoms and hydrogen atoms in the hydrocarbon.

Return type:

tuple[int, int]

Examples

>>> return_x_y_from_hydrocarbon("CH4")
(1, 4)
>>> return_x_y_from_hydrocarbon("C2H6")
(2, 6)
>>> return_x_y_from_hydrocarbon("C3H8")
(3, 8)
>>> return_x_y_from_hydrocarbon("C2")
(2, 0)
>>> return_x_y_from_hydrocarbon("C")
(1, 0)
>>> return_x_y_from_hydrocarbon("C2H")
(2, 1)
>>> return_x_y_from_hydrocarbon("C2H2")
(2, 2)
>>> return_x_y_from_hydrocarbon("H2")
(0, 2)
>>> return_x_y_from_hydrocarbon("N2")
ValueError: Cannot parse the hydrocarbon name N2.
>>> return_x_y_from_hydrocarbon("C2H2^+")
ValueError: Cannot parse the hydrocarbon name C2H2^+.