YAML to Chemkin conversion#

See also

For documentation of the command line interface, see YAML to Chemkin conversion.

Module-level documentation#

Convert YAML input files or Solution instances to CHEMKIN input format. The supported CHEMKIN syntax follows the documentation in [Kee1989].

Added in version 3.0.

Supported Thermodynamics:

NASA7

Supported Reaction models:

Elementary, Three-Body, Falloff, Pressure-Dependent-Arrhenius (PLOG), Chebyshev

Unsupported Thermodynamic Property Models:

NASA9, Shomate, constant-Cp

Unsupported Reaction models (not comprehensive):

Chemically-activated, Blowers-Masel, Surface Reactions

[Kee1989]

Kee, RJ; Rupley, FM; Miller, JA. Chemkin-II: A Fortran chemical kinetics package for the analysis of gas-phase chemical kinetics, Sandia Report SAND-89-8009, September 1989.

class cantera.yaml2ck.HeaderTextWrapper(input_files: Iterable[str], *args, **kwargs)#

Bases: TextWrapper

Wrap header text from a YAML file, including Cantera metadata.

Parameters:

input_files – Iterable of string input file names to include in the header

Added in version 3.0.

wrap(text: string) [string]#

Reformat the single paragraph in ‘text’ so it fits in lines of no more than ‘self.width’ columns, and return a list of wrapped lines. Tabs in ‘text’ are expanded with string.expandtabs(), and all other whitespace characters (including newline) are converted to space.

cantera.yaml2ck.build_elements_text(elements: Iterable[Element], max_width=80) str#

Create element definition text.

Parameters:
  • elements – List of cantera.Element instances for the elements in this file.

  • max_width – The maximum width of a line in this section.

Added in version 3.0.

cantera.yaml2ck.build_reactions_text(reactions: Iterable[Reaction])#

Create the reaction definition section of this file.

Parameters:

reactions – An iterable of cantera.Reaction instances to be included.

Added in version 3.0.

cantera.yaml2ck.build_species_text(species: Iterable[Species], max_width=80) str#

Create species definition text.

Parameters:
  • species – List of cantera.Species instances of the species in this file.

  • max_width – The maximum width of a line in this section.

Added in version 3.0.

cantera.yaml2ck.build_thermodynamics_text(species: Iterable[Species], separate_file: bool = False) str#

Creates the thermodynamic definition text of all species.

Parameters:
  • species – An iterable of cantera.Species definitions for this file.

  • separate_file – A Boolean flag to indicate if the file will be written separately or in the mechanism file

The global/default temperature limits of the NASA polynomials are chosen as follows:

  • Lower temperature limit: Minimum of the lower temperature limits among all the species in the phase.

  • Midpoint temperature: 1000 K

  • Upper temperature limit: Maximum of the upper temperature limits among all the species in the phase.

These values are included in the CHEMKIN thermodynamic input format documentation in the heading information for the thermodynamic section/file, that is:

THERMO [ALL]
LOW_TEMP MID_TEMP HIGH_TEMP

Despite appearing in the documentation, these values do not appear to be used by CHEMKIN because CHEMKIN seems to require each species to contain the polynomial temperature limits for that species. However, this requirement is not documented and since modern CHEMKIN is closed-source (including the documentation), we cannot verify this.

Added in version 3.0.

cantera.yaml2ck.build_transport_text(species: Iterable[Species], separate_file: bool = False)#

Create the transport section of this file.

Parameters:
  • species – A list of cantera.Species instances to include in the file.

  • separate_file – A Boolean flag to indicate if the file will be written separately or in the mechanism file

Added in version 3.0.

cantera.yaml2ck.convert(solution: str | Path | Solution, phase_name: str = '', mechanism_path: str | Path | None = None, thermo_path: str | Path | None = None, transport_path: str | Path | None = None, sort_elements: Literal['alphabetical', 'molar-mass'] | None = None, sort_species: Literal['alphabetical', 'molar-mass'] | None = None, overwrite: bool = False) tuple[Path | None, Path | None, Path | None]#

Writes Cantera solution object to Chemkin-format file(s).

Parameters:
  • solution – Either the cantera.Solution object being converted or the path of a YAML input file as a str or pathlib.Path instance.

  • phase_name – If a YAML input file is provided with multiple phase definitions, the name provided here will be used to load a single phase from the input file. Otherwise, Cantera’s default behavior will load the first definition from the file.

  • mechanism_path – The path to the output mechanism file. Optional. If not provided, the name of the input file will be used, with the extension replaced by .ck. If a cantera.Solution instance is provided, the name attribute is used to generate the mechanism file name. If mechanism_path is an existing directory, the output files will be placed in that directory.

  • thermo_path – The path to the output thermodynamics database file. Optional. If not provided, the thermodynamic data will be included in the mechanism_path file.

  • transport_path – The path to the output transport database file. Optional. If not provided, the transport data will be included in the mechanism_path file.

  • sort_elements – Optional. One of 'alphabetical', 'molar-mass', or None. The former two options will sort the elements in the mechanism_path file alphabetically or by atomic mass, respectively. The default is to output elements in the same order defined in the input cantera.Solution.

  • sort_species – Optional. One of 'alphabetical', 'molar-mass', or None. The former two options will sort the species definitions and their thermodynamic data alphabetically or by molecular weight, respectively. The default is to output the species in the same order defined in the input cantera.Solution.

  • overwrite – Boolean flag to overwrite existing files.

Added in version 3.0.

cantera.yaml2ck.create_argparser()#

Create argparse parser

cantera.yaml2ck.main()#

Parse command line arguments and pass them to convert

Added in version 3.0.