Cantera / cantera

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

yaml2ck: Check if third body is in species list #1696

Closed corykinney closed 3 weeks ago

corykinney commented 1 month ago

Changes proposed in this pull request

This pull request adds a check in yaml2ck for third body efficiencies for species that might not be present in the ct.Solution object due to the skip-undeclared-third-bodies: true flag.

Closes #1683

Using the provided example from the issue referenced:

phases:
- name: test
  thermo: ideal-gas
  elements: [O, H, C, Ar]
  species:
  - gri30.yaml/species: all
  kinetics: gas
  skip-undeclared-elements: true
  skip-undeclared-third-bodies: true
  reactions:
  - gri30.yaml/reactions: declared-species
  transport: mixture-averaged
  state: {T: 300.0, P: 1 atm}

The outputted Chemkin file from python -m cantera.yaml2ck test.yaml --overwrite before the change:

H + O2 + M <=> HO2 + M           2.8000000000000005e+18 -0.86 0.0
AR/0.000E+00/ C2H6/1.500E+00/ CO/7.500E-01/ CO2/1.500E+00/ H2O/0.000E+00/ N2/0.000E+00/ O2/0.000E+00/

versus after the change:

H + O2 + M <=> HO2 + M           2.8000000000000005e+18 -0.86 0.0
AR/0.000E+00/ C2H6/1.500E+00/ CO/7.500E-01/ CO2/1.500E+00/ H2O/0.000E+00/ O2/0.000E+00/

The N2 efficiency is omitted from the list as desired.

Feedback

An example file still needs to be added with a corresponding test case, but before doing so, I wanted to solicit feedback on potential edge cases. What behavior would be expected if no explicit third body species are present in the mechanism? Are there any other possible cases that need to be accounted for proactively?

Checklist

speth commented 3 weeks ago

What behavior would be expected if no explicit third body species are present in the mechanism?

I didn't try it, but I think your patch would add a blank line to the output. I don't see a problem with that.

corykinney commented 3 weeks ago

@speth I implemented your suggestions and added the necessary test case. It should be good to go, but let me know if I missed anything in the test.

codecov[bot] commented 3 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 75.69%. Comparing base (d37a76b) to head (39816e4). Report is 19 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1696 +/- ## ========================================== - Coverage 75.69% 75.69% -0.01% ========================================== Files 443 443 Lines 60975 60971 -4 Branches 9551 9552 +1 ========================================== - Hits 46158 46154 -4 Misses 11786 11786 Partials 3031 3031 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.