Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ck2yaml argparse / yaml2k fixes #1616

Merged
merged 9 commits into from
Sep 9, 2023
Merged

Conversation

ischoegl
Copy link
Member

@ischoegl ischoegl commented Sep 5, 2023

Changes proposed in this pull request

  • Switch ck2yaml to argparse in order to be consistent with other converter scripts
  • Update documentation; taking advantage of sphinx-argparse
  • Address Solution.write_chemkin bugs

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

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

@ischoegl ischoegl added the Input Input parsing and conversion (for example, ck2yaml) label Sep 5, 2023
@ischoegl ischoegl marked this pull request as ready for review September 5, 2023 15:50
@codecov
Copy link

codecov bot commented Sep 5, 2023

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%) ⬆️
interfaces/cython/cantera/yaml2ck.py 65.49% <66.66%> (+2.81%) ⬆️
interfaces/cython/cantera/ck2yaml.py 84.65% <72.97%> (+0.30%) ⬆️

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

@ischoegl ischoegl requested a review from a team September 5, 2023 16:35
@ischoegl ischoegl force-pushed the ck2yaml-arparse branch 3 times, most recently from 21fb071 to 17a211b Compare September 5, 2023 20:06
@ischoegl ischoegl removed the request for review from a team September 5, 2023 22:38
@ischoegl ischoegl marked this pull request as draft September 5, 2023 22:38
@ischoegl ischoegl changed the title Ck2yaml arparse ck2yaml arparse / yaml2k fixes Sep 5, 2023
@ischoegl ischoegl changed the title ck2yaml arparse / yaml2k fixes ck2yaml argparse / yaml2k fixes Sep 5, 2023
@ischoegl ischoegl marked this pull request as ready for review September 5, 2023 23:23
@ischoegl ischoegl requested a review from a team September 6, 2023 00:40
@ischoegl
Copy link
Member Author

ischoegl commented Sep 6, 2023

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

Copy link
Member

@bryanwweber bryanwweber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny changes, thanks for taking this on!

@ischoegl
Copy link
Member Author

ischoegl commented Sep 8, 2023

@bryanwweber ... thank you for the suggestions!

@ischoegl ischoegl requested a review from bryanwweber September 8, 2023 20:54
@ischoegl ischoegl merged commit 475d855 into Cantera:main Sep 9, 2023
@ischoegl ischoegl deleted the ck2yaml-arparse branch September 9, 2023 23:16
speth added a commit to speth/conda-recipes that referenced this pull request Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Input Input parsing and conversion (for example, ck2yaml)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid default arguments for Solution.to_chemkin
2 participants