bloc.chem.mechanism#

Mechanism conversion utilities focused on composition transformation.

This module provides functions to convert compositions between different mechanisms without creating unnecessary Solution objects, improving performance in iterative algorithms like Forward-Backward Sweep.

Functions#

convert_composition_between_mechanisms(...[, htol, ...])

Convert composition from source mechanism to target mechanism.

create_gas_from_composition(mechanism, composition, ...)

Create a Solution object from composition data.

find_temperature_from_enthalpy(h_mass, X, P_bar, mechanism)

Return the temperature in °C for a given enthalpy in J/kg and for a given gas composition and pressure.

switch_mechanism(gas, new_mechanism[, htol, Xtol, verbose])

Switch the mechanism of a gas object.

Module Contents#

bloc.chem.mechanism.convert_composition_between_mechanisms(source_composition, source_T, source_P, source_mechanism, target_mechanism, htol=0.0001, Xtol=0.0001, verbose=False)#

Convert composition from source mechanism to target mechanism.

This function performs mechanism switching by returning composition data rather than Solution objects, avoiding unnecessary object creation in iterative algorithms.

Parameters:
  • source_composition (Dict[str, float]) – Mole fractions in source mechanism

  • source_T (float) – Temperature in K

  • source_P (float) – Pressure in Pa

  • source_mechanism (str) – Source mechanism path

  • target_mechanism (str) – Target mechanism path

  • htol (float) – Tolerance for enthalpy variation

  • Xtol (float) – Tolerance for mole fraction variation

  • verbose (bool) – Print conversion details

Returns:

  • target_composition (Dict[str, float]) – Mole fractions in target mechanism

  • target_T (float) – Temperature in K (adjusted for enthalpy conservation)

  • target_P (float) – Pressure in Pa (unchanged)

Raises:

ValueError – If enthalpy or composition variations exceed tolerances

bloc.chem.mechanism.create_gas_from_composition(mechanism, composition, temperature, pressure, use_cached=True)#

Create a Solution object from composition data.

This function provides a clean interface for creating Solution objects from composition data, with the option to use cached solutions for performance optimization.

Parameters:
  • mechanism (str) – Mechanism path

  • composition (Dict[str, float]) – Mole fractions

  • temperature (float) – Temperature in K

  • pressure (float) – Pressure in Pa

  • use_cached (bool) – Whether to use cached Solution (default True) Set to False for iterative property calculations

Returns:

gas – Solution object at specified state

Return type:

ct.Solution

bloc.chem.mechanism.find_temperature_from_enthalpy(h_mass, X, P_bar, mechanism)#

Return the temperature in °C for a given enthalpy in J/kg and for a given gas composition and pressure.

Parameters:
  • h_mass (-) – Specific enthalpy target in J/kg

  • X (-) – Composition of the gas in mole fraction

  • P_bar (-) – Pressure in bar

  • mechanism (-) – Path to the mechanism file

bloc.chem.mechanism.switch_mechanism(gas, new_mechanism, htol=0.0001, Xtol=0.0001, verbose=False)#

Switch the mechanism of a gas object.

Useful to switch from plasma to reactor simulation for instance. As some species may not be present in the new mechanism, we compute the adjust the temperature of the new gas object to match the enthalpy of the old gas object, so that energy is conserved. Still, if the chemical enthalpy variation exceed htol, an error is raised. Similarly, if the mole fraction variation exceed Xtol, a error is raised.

Parameters:
  • gas (ct.Solution) – Gas object

  • new_mechanism (str) – Path to the new mechanism file

  • htol (float) – Tolerance for the chemical enthalpy variation between the two mechanisms. Default is 1e-4.

  • Xtol (float) – Tolerance for the mole fraction variation between the two mechanisms. Default is 1e-4.

  • verbose (bool) – If True, print information about the process. Default is False.

Returns:

gas_new – Gas object with the new mechanism

Return type:

ct.Solution