In [1]:
import numpy as np
import cantera as ct
from cantera import ctml_writer

In [2]:
convert_data = ctml_writer.convert('cti_one.cti')

In [3]:
type(convert_data)


Out[3]:
NoneType

In [35]:
gas = ct.Solution('cti_one.cti')

In [36]:
gas.TPX = 300, 101325, 'PLIGC:1.7, PLIGH:0.26, PLIGO:0.3'

In [37]:
gas()


  ligpy:

       temperature             300  K
          pressure          101325  Pa
           density         13.4938  kg/m^3
  mean mol. weight         332.179  amu

                          1 kg            1 kmol
                       -----------      ------------
          enthalpy               0                0     J
   internal energy           -7509       -2.494e+06     J
           entropy          18.297             6078     J/K
    Gibbs function         -5489.2       -1.823e+06     J
 heat capacity c_p               0                0     J/K
 heat capacity c_v          -25.03            -8314     J/K

                           X                 Y          Chem. Pot. / RT
                     -------------     ------------     ------------
             PLIGH       0.115044          0.15116         -2.16244
             PLIGO       0.132743         0.168792         -2.01934
             PLIGC       0.752212         0.680048        -0.284737
     [  +91 minor]              0                0


In [41]:
def ignitionDelay(df, species):
    """
    This function computes the ignition delay from the occurence of the
    peak in species' concentration.
    """
    return df[species].argmax()

In [42]:
import time
import pandas as pd

r = ct.IdealGasReactor(contents=gas, name='Batch Reactor')
reactorNetwork = ct.ReactorNet([r])

# now compile a list of all variables for which we will store data
stateVariableNames = [r.component_name(item) for item in range(r.n_vars)]

# use the above list to create a DataFrame
timeHistory = pd.DataFrame(columns=stateVariableNames)

t0 = time.time()

# This is a starting estimate. If you do not get an ignition within this time, increase it
estimatedIgnitionDelayTime = 0.1
t = 0

counter = 1;
while(t < estimatedIgnitionDelayTime):
    t = reactorNetwork.step()
    if (counter%10 == 0):
        # We will save only every 10th value. Otherwise, this takes too long
        # Note that the species concentrations are mass fractions
        timeHistory.loc[t] = reactorNetwork.get_state()
    counter+=1

# We will use the 'oh' species to compute the ignition delay
tau = ignitionDelay(timeHistory, 'oh')

#Toc
t1 = time.time()

print('Computed Ignition Delay: {:.3e} seconds. Took {:3.2f}s to compute'.format(tau, t1-t0))

# If you want to save all the data - molefractions, temperature, pressure, etc
# uncomment the next line
# timeHistory.to_csv("time_history.csv")


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/Users/IvanC/miniconda3/lib/python3.5/site-packages/pandas/indexes/base.py in get_loc(self, key, method, tolerance)
   2133             try:
-> 2134                 return self._engine.get_loc(key)
   2135             except KeyError:

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4433)()

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4279)()

pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13742)()

pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13696)()

KeyError: 'oh'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-42-4a3a756a6526> in <module>()
     27 
     28 # We will use the 'oh' species to compute the ignition delay
---> 29 tau = ignitionDelay(timeHistory, 'oh')
     30 
     31 #Toc

<ipython-input-41-5e2c6fd4038f> in ignitionDelay(df, species)
      4     peak in species' concentration.
      5     """
----> 6     return df[species].argmax()

/Users/IvanC/miniconda3/lib/python3.5/site-packages/pandas/core/frame.py in __getitem__(self, key)
   2057             return self._getitem_multilevel(key)
   2058         else:
-> 2059             return self._getitem_column(key)
   2060 
   2061     def _getitem_column(self, key):

/Users/IvanC/miniconda3/lib/python3.5/site-packages/pandas/core/frame.py in _getitem_column(self, key)
   2064         # get column
   2065         if self.columns.is_unique:
-> 2066             return self._get_item_cache(key)
   2067 
   2068         # duplicate columns & possible reduce dimensionality

/Users/IvanC/miniconda3/lib/python3.5/site-packages/pandas/core/generic.py in _get_item_cache(self, item)
   1384         res = cache.get(item)
   1385         if res is None:
-> 1386             values = self._data.get(item)
   1387             res = self._box_item_values(item, values)
   1388             cache[item] = res

/Users/IvanC/miniconda3/lib/python3.5/site-packages/pandas/core/internals.py in get(self, item, fastpath)
   3541 
   3542             if not isnull(item):
-> 3543                 loc = self.items.get_loc(item)
   3544             else:
   3545                 indexer = np.arange(len(self.items))[isnull(self.items)]

/Users/IvanC/miniconda3/lib/python3.5/site-packages/pandas/indexes/base.py in get_loc(self, key, method, tolerance)
   2134                 return self._engine.get_loc(key)
   2135             except KeyError:
-> 2136                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   2137 
   2138         indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4433)()

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4279)()

pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13742)()

pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13696)()

KeyError: 'oh'

In [ ]: