Cantera / cantera

Chemical kinetics, thermodynamics, and transport tool suite
https://cantera.org
Other
582 stars 342 forks source link

ck2yaml argparse / yaml2k fixes #1616

Closed ischoegl closed 9 months ago

ischoegl commented 10 months ago

Changes proposed in this pull request

If applicable, fill in the issue number this pull request is fixing

Closes #1611, partially addresses #1610

If applicable, provide an example illustrating new features this pull request is introducing

ck2yaml now has the following help text (generated by argparse)

% ck2yaml --help
usage: ck2yaml [-h] [-p] [-q] [-d] [--input INPUT] [--thermo THERMO] [--transport TRANSPORT]
               [--surface SURFACE] [--extra EXTRA] [--name NAME] [--single-intermediate-temperature]
               [--no-validate] [--output OUTPUT]

Convert Chemkin-format mechanisms to Cantera YAML input files

options:
  -h, --help            show this help message and exit
  -p, --permissive      This option allows certain recoverable parsing errors (for example, duplicate
                        thermo or transport data) to be ignored.
  -q, --quiet           Suppresses warning messages, such as those about duplicate thermo data.
  -d, --debug           Enables additional debugging output that may be helpful in identifying problems
                        in the input files or **ck2yaml** itself.
  --input INPUT         Chemkin-format chemistry input file, containing a list of all the element names
                        that are used, a list of all the species names, and a list of all the reactions
                        to be considered between the species. This file can also optionally contain
                        species THERMO and TRANSPORT data.
  --thermo THERMO       If the INPUT file does not contain THERMO data, a separate file containing
                        thermodynamic information must be specified. If no INPUT file is provided,
                        THERMO data are converted to a YAML file containing only species definitions
                        (which can be referenced from phase definitions in other input files).
  --transport TRANSPORT
                        If the INPUT file does not contain TRANSPORT data, a separate file containing
                        transport information may be specified. Transport data are required for Cantera
                        calculations that use transport properties such as one-dimensional flame
                        calculations; they are usually not required for zero-dimensional reactor
                        simulations.
  --surface SURFACE     For surface mechanisms, the SURFACE file defines surface species and reactions
                        occurring on the surface. Gas phase species and reactions should be defined in
                        the INPUT file.
  --extra EXTRA         This option specifies a YAML file which can be used to add to the
                        **description** field or to define custom fields that are included in the YAML
                        output.
  --name NAME           This specifies the name of the phase in the resulting YAML file. The default is
                        **gas**.
  --single-intermediate-temperature
                        This option should be used with thermo data where only a single break
                        temperature is used and the last value in the first line of each species thermo
                        entry is the molecular weight instead.
  --no-validate         Disables the validation step, where the YAML mechanism is imported in Cantera
                        to check for errors such as unlabeled duplicate reactions and discontinuous
                        thermodynamic data.
  --output OUTPUT       Specifies the OUTPUT file name. By default, the output file name is the input
                        file name with the extension changed to **.yaml**.

Example::

    ck2yaml --input=chem.inp --thermo=therm.dat --transport=tran.dat

If the **ck2yaml** script is not on your path but the Cantera Python module is,
**ck2yaml** can also be invoked by running::

    python -m cantera.ck2yaml --input=chem.inp --thermo=therm.dat --transport=tran.dat

In both cases, the equal sign in the options is optional.

While not the main issue, this now works:

import cantera as ct
gas = ct.Solution('h2o2.yaml')
gas.write_chemkin('test.ck')
gas.write_chemkin('test.ck', sort_species='alphabetical', overwrite=True)

Checklist

codecov[bot] commented 10 months ago

Codecov Report

Merging #1616 (78b187e) into main (b2f383a) will increase coverage by 0.03%. Report is 5 commits behind head on main. The diff coverage is 71.42%.

@@            Coverage Diff             @@
##             main    #1616      +/-   ##
==========================================
+ Coverage   72.66%   72.70%   +0.03%     
==========================================
  Files         370      370              
  Lines       56255    56257       +2     
  Branches    20353    20351       -2     
==========================================
+ Hits        40880    40903      +23     
+ Misses      12372    12357      -15     
+ Partials     3003     2997       -6     
Files Changed Coverage Δ
interfaces/cython/cantera/cti2yaml.py 70.87% <ø> (ø)
interfaces/cython/cantera/ctml2yaml.py 68.61% <ø> (ø)
interfaces/cython/cantera/solutionbase.pyx 94.55% <50.00%> (+2.91%) :arrow_up:
interfaces/cython/cantera/yaml2ck.py 65.49% <66.66%> (+2.81%) :arrow_up:
interfaces/cython/cantera/ck2yaml.py 84.65% <72.97%> (+0.30%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

ischoegl commented 10 months ago

Ended up adding fixes / bandaids for #1610 / #1611. This is ready for a review.

ischoegl commented 9 months ago

@bryanwweber ... thank you for the suggestions!