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

Invalid reactions no longer reliably raise InputFileError #1281

Closed
speth opened this issue May 12, 2022 · 2 comments · Fixed by #1330
Closed

Invalid reactions no longer reliably raise InputFileError #1281

speth opened this issue May 12, 2022 · 2 comments · Fixed by #1330
Assignees
Labels
Input Input parsing and conversion (for example, ck2yaml) Kinetics

Comments

@speth
Copy link
Member

speth commented May 12, 2022

Problem description

In Cantera 2.5, a YAML reaction definition without any rate constant information would raise an InputFileError showing the problematic reaction definition. Now, an error is thrown by ArrheniusBase::validate which does not show the corresponding input location.

Also, reactions containing undeclared species only produce the desired error message if the reaction rate is specified as a dict, but not if it is specified as a list.

Steps to reproduce

  1. Create an input file with the following contents:
phases:
- name: gas
  thermo: ideal-gas
  species: [{h2o2.yaml/species: all}]
  kinetics: gas
  reactions: all
  state: {T: 300.0, P: 1 atm, X: {O2: 0.21, N2: 0.79}}

reactions:
- equation: 2 OH (+M) <=> H2O2 (+M)
  type: falloff
- equation: O + H2 <=> H + OH
- equation: CH3 + OH => CH3O + H
  rate-constant: {A: 1.0, b: 0, Ea: 0}
- equation: CH3 + OH => CH3O + H
  rate-constant: [0, 0, 0]
  1. Import the phase in Python

Behavior

In Cantera 2.6.0, this raises an exception where an InputFileError is only given for the third reaction:

*******************************************************************************
CanteraError thrown by addReactions:

*******************************************************************************
CanteraError thrown by ArrheniusBase::validate:
Rate object for reaction '2 OH (+M) <=> H2O2 (+M)' is not configured.
*******************************************************************************

*******************************************************************************
CanteraError thrown by ArrheniusBase::validate:
Rate object for reaction 'H2 + O <=> H + OH' is not configured.
*******************************************************************************

*******************************************************************************
InputFileError thrown by Reaction::checkSpecies:
Error on line 12 of ./bad.yaml:
Reaction 'CH3 + OH => CH3O + H'
contains undeclared species: 'CH3', 'CH3O'
|  Line |
|     7 | 
|     8 | reactions:
|     9 | - equation: 2 OH (+M) <=> H2O2 (+M)
|    10 |   type: falloff
|    11 | - equation: O + H2 <=> H + OH
>    12 > - equation: CH3 + OH => CH3O + H
            ^
|    13 |   rate-constant: {A: 1.0, b: 0, Ea: 0}
|    14 | - equation: CH3 + OH => CH3O + H
|    15 |   rate-constant: [0, 0, 0]
*******************************************************************************

*******************************************************************************
CanteraError thrown by ArrheniusBase::validate:
Rate object for reaction 'CH3 + OH => CH3O + H' is not configured.
*******************************************************************************
*******************************************************************************

In Cantera 2.5.1, this input file produced useful error InputFileError messages for all four reactions:

***********************************************************************
CanteraError thrown by addReactions:

***********************************************************************
InputFileError thrown by AnyMap::operator[]:
Error on line 9 of ./bad.yaml:
Key 'low-P-rate-constant' not found.
Existing keys: equation, type
|  Line |
|     4 |   species: [{h2o2.yaml/species: all}]
|     5 |   kinetics: gas
|     6 |   reactions: all
|     7 | 
|     8 | reactions:
>     9 > - equation: 2 OH (+M) <=> H2O2 (+M)
            ^
|    10 |   type: falloff
|    11 | - equation: O + H2 <=> H + OH
|    12 | - equation: CH3 + OH => CH3O + H
***********************************************************************

***********************************************************************
InputFileError thrown by AnyMap::operator[]:
Error on line 11 of ./bad.yaml:
Key 'rate-constant' not found.
Existing keys: equation
|  Line |
|     6 |   reactions: all
|     7 | 
|     8 | reactions:
|     9 | - equation: 2 OH (+M) <=> H2O2 (+M)
|    10 |   type: falloff
>    11 > - equation: O + H2 <=> H + OH
            ^
|    12 | - equation: CH3 + OH => CH3O + H
|    13 |   rate-constant: {A: 1.0, b: 0, Ea: 0}
|    14 | - equation: CH3 + OH => CH3O + H
***********************************************************************

***********************************************************************
InputFileError thrown by Kinetics::addReaction:
Error on line 12 of ./bad.yaml:
Reaction 'CH3 + OH => CH3O + H' contains the undeclared species 'CH3'
|  Line |
|     7 | 
|     8 | reactions:
|     9 | - equation: 2 OH (+M) <=> H2O2 (+M)
|    10 |   type: falloff
|    11 | - equation: O + H2 <=> H + OH
>    12 > - equation: CH3 + OH => CH3O + H
            ^
|    13 |   rate-constant: {A: 1.0, b: 0, Ea: 0}
|    14 | - equation: CH3 + OH => CH3O + H
|    15 |   rate-constant: [0, 0, 0]
***********************************************************************

***********************************************************************
InputFileError thrown by Kinetics::addReaction:
Error on line 14 of ./bad.yaml:
Reaction 'CH3 + OH => CH3O + H' contains the undeclared species 'CH3'
|  Line |
|     9 | - equation: 2 OH (+M) <=> H2O2 (+M)
|    10 |   type: falloff
|    11 | - equation: O + H2 <=> H + OH
|    12 | - equation: CH3 + OH => CH3O + H
|    13 |   rate-constant: {A: 1.0, b: 0, Ea: 0}
>    14 > - equation: CH3 + OH => CH3O + H
            ^
|    15 |   rate-constant: [0, 0, 0]
***********************************************************************
***********************************************************************

System information

  • Cantera version: 2.6.0
@speth speth added Input Input parsing and conversion (for example, ck2yaml) Kinetics labels May 12, 2022
@ischoegl
Copy link
Member

Good catch - the error message isn't ideal, but a fix should be relatively easy. Ideally, I'd like to prevent construction without a rate object to catch this much earlier, but I recall that there is a legacy FalloffReaction constructor that prevented that approach when constructing things from the Python interface. From that perspective, I'd like to defer a permanent fix until after Cantera/enhancements#149 is resolved.

@speth speth changed the title Reactions with missing rate constant no longer raise InputFileError Invalid reactions no longer reliably raise InputFileError May 15, 2022
@speth
Copy link
Member Author

speth commented May 15, 2022

I ran into a (presumably related) case where ArrheniusBase::validate errors were coming up for reactions with undeclared species, rather than the expected InputFileError, and updated the example above accordingly.

@ischoegl ischoegl self-assigned this Jun 7, 2022
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) Kinetics
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants