Niemeyer-Research-Group / pyMARS

Python-based (chemical kinetic) Model Automatic Reduction Software
https://niemeyer-research-group.github.io/pyMARS/
MIT License
61 stars 46 forks source link

Cantera group names are hard-coded? #60

Closed jcsutherland closed 5 years ago

jcsutherland commented 5 years ago

Background

Cantera allows specification of various ideal_gas objects to include different species/elements/reactions from the input file. It doesn't appear that pyMARS supports this, and it isn't clear if it is looking for a magic string somewhere.

ideal_gas(name = "gri30",
      elements = " O  H  C  N  Ar ",
      species = """ H2  H  O  O2  OH  H2O  HO2  H2O2  C  CH 
                   CH2  CH2(S)  CH3  CH4  CO  CO2  HCO  CH2O  CH2OH  CH3O 
                   CH3OH  C2H  C2H2  C2H3  C2H4  C2H5  C2H6  HCCO  CH2CO  HCCOH 
                   N  NH  NH2  NH3  NNH  NO  NO2  N2O  HNO  CN 
                   HCN  H2CN  HCNN  HCNO  HOCN  HNCO  NCO  N2  AR  C3H7 
                   C3H8  CH2CHO  CH3CHO """,
      reactions = "all",
      kinetics = "GRI30",
      initial_state = state(temperature = 300.0,
                        pressure = OneAtm)    )

ideal_gas(name = "gri30_mix",
      elements = " O  H  C  N  Ar ",
      species = """ H2  H  O  O2  OH  H2O  HO2  H2O2  C  CH 
                   CH2  CH2(S)  CH3  CH4  CO  CO2  HCO  CH2O  CH2OH  CH3O 
                   CH3OH  C2H  C2H2  C2H3  C2H4  C2H5  C2H6  HCCO  CH2CO  HCCOH 
                   N  NH  NH2  NH3  NNH  NO  NO2  N2O  HNO  CN 
                   HCN  H2CN  HCNN  HCNO  HOCN  HNCO  NCO  N2  AR  C3H7 
                   C3H8  CH2CHO  CH3CHO """,
      reactions = "all",
      kinetics = "GRI30",
      transport = "Mix",
      initial_state = state(temperature = 300.0,
                        pressure = OneAtm)    )

ideal_gas(name = "gri30_multi",
      elements = " O  H  C  N  Ar ",
      species = """ H2  H  O  O2  OH  H2O  HO2  H2O2  C  CH 
                   CH2  CH2(S)  CH3  CH4  CO  CO2  HCO  CH2O  CH2OH  CH3O 
                   CH3OH  C2H  C2H2  C2H3  C2H4  C2H5  C2H6  HCCO  CH2CO  HCCOH 
                   N  NH  NH2  NH3  NNH  NO  NO2  N2O  HNO  CN 
                   HCN  H2CN  HCNN  HCNO  HOCN  HNCO  NCO  N2  AR  C3H7 
                   C3H8  CH2CHO  CH3CHO """,
      reactions = "all",
      kinetics = "GRI30",
      transport = "Multi",
      initial_state = state(temperature = 300.0,
                        pressure = OneAtm)    )

It appears that this does not play well with pyMARS

Error description

When running against a cti file including the above examples, the following exception occurs:

  File "interfaces/cython/cantera/base.pyx", line 29, in cantera._cantera._SolutionBase.__cinit__
  File "interfaces/cython/cantera/base.pyx", line 78, in cantera._cantera._SolutionBase._init_cti_xml
cantera._cantera.CanteraError: 
***********************************************************************
CanteraError thrown by Factory::create:
No such type: 'gri30'
***********************************************************************

Steps to reproduce

Unzip the attached file and then run the following:

#!/bin/sh
pymars \
    --targets CH4 O2 H2 \
    --retained_species N2 CO CO2 H2O \
    --conditions methane-conditions.yaml \
    --method DRGEP \
    --error 10 \
    -m methane-gri30.cti

methanefiles.zip

kyleniemeyer commented 5 years ago

Hmm, this one is a little tricky. Right now pyMARS assumes a single ideal_gas object, but you're right that some files will have multiple.

What it should do is modify the lists of species and reactions in each object.

Where things get tricky is if the ideal_gas objects include different sets of species and/or reactions. I'll need to look into this a bit more.

kyleniemeyer commented 5 years ago

@jcsutherland so, this seems to be an issue with the methane-gri30.cti file you are using; if I just try to create a cantera.Solution object with it, Cantera throws the error above:

gas = ct.Solution('methane-gri30.cti')

---------------------------------------------------------------------------
CanteraError                              Traceback (most recent call last)
<ipython-input-2-3045edfef451> in <module>
----> 1 gas = ct.Solution('methane-gri30.cti')

interfaces/cython/cantera/base.pyx in cantera._cantera._SolutionBase.__cinit__()

interfaces/cython/cantera/base.pyx in cantera._cantera._SolutionBase._init_cti_xml()

CanteraError: 
***********************************************************************
CanteraError thrown by Factory::create:
No such type: 'gri30'
***********************************************************************

I think the issue is the kinetics = "GRI30", line that appears in each ideal_gas object. If I remove that, the file loads without error; in fact, the GRI Mech 3.0 included with Cantera does not have that line, and this is the model we use for a bunch of unit tests.

However, regarding the presence of multiple ideal_gas objects: the current behavior of pyMARS is to reduce whichever is loaded by default when creating a Cantera.Solution object from the CTI file. In the case of gri30.cti, this is the first one, without the transport field specified. The retained species objects contain their transport data, though.

kyleniemeyer commented 5 years ago

In the situation that the CTI file contains multiple ideal_gas objects, I don't think we want to try reducing each of them (in case they contain varying numbers/sets of species or reactions).

Instead, I think the best solution is to include the name of the object to be reduced as an optional reduction input (now contained in a single YAML file, per e6ec139).