Cantera / cantera

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

write_yaml produces inconsistant reactions sections #1522

Closed BangShiuh closed 11 months ago

BangShiuh commented 1 year ago

When the "reactions" in the cantera yaml input file contain multiple keys, the gas object will store the keys. However, when using write_yaml from the gas object, the output file only has the keys in the phases section.

Steps to reproduce

  1. unzip test.zip
  2. Run test.py

Behavior

InputFileError thrown by AnyMap::at: Error on line 1 of ./outfile.yaml: Key 'collisions' not found.

System information

Attachments

Additional context

test.zip

ischoegl commented 1 year ago

I'm not sure this is a bug. Cantera internally doesn't keep track of where reactions originated, so this behavior is expected (it writes out all reactions into a single field.

Presumably this is required for #1262? In case you indeed need a separate YAML collisions field, you'll have to incorporate an appropriate fix in your PR.

speth commented 1 year ago

Whether it's a bug to merge multiple reactions sections or not is debatable. But even if we do want to keep the current behavior of merging them, then the phase definition shouldn't reference the second, nonexistent section as demonstrated in this report.

ischoegl commented 1 year ago

@speth ... I did not catch that. For reference, this is the offending section in the serialized output

phases:
  - kinetics: gas
    name: discretized-electron-energy-plasma
    thermo: plasma
    elements: [O, E]
    species: [E, O2, O2-]
    electron-energy-distribution:
      type: discretized
      energy-levels: [0.0, 0.1, 1.0, 10.0]
      distribution: [0.0, 0.2, 0.7, 0.01]
      normalize: false
    state:
      T: 298.15
      density: 2.242267962000731e-05
      Y: {E: 1.0}
    reactions:
      - reactions: all
      - collisions: all

Whether it's a bug to merge multiple reactions sections or not is debatable.

... I think it's appropriate to merge.