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 from source mechanism to target mechanism. |
|
Create a Solution object from composition data. |
|
Return the temperature in °C for a given enthalpy in J/kg and for a given gas composition and pressure. |
|
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 mechanismsource_T (
float) – Temperature in Ksource_P (
float) – Pressure in Pasource_mechanism (
str) – Source mechanism pathtarget_mechanism (
str) – Target mechanism pathhtol (
float) – Tolerance for enthalpy variationXtol (
float) – Tolerance for mole fraction variationverbose (
bool) – Print conversion details
- Returns:
target_composition (
Dict[str,float]) – Mole fractions in target mechanismtarget_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 pathcomposition (
Dict[str,float]) – Mole fractionstemperature (
float) – Temperature in Kpressure (
float) – Pressure in Pause_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 objectnew_mechanism (
str) – Path to the new mechanism filehtol (
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