{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Cantera Tutorial: Python"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Getting Started"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "Open a new Jupyter Notebook. If unfamiliar with Jupyter Notebooks see the [Jupyter Documentation](https://jupyter.readthedocs.io/en/latest/install.html) for installation and basic use instructions. Import the Cantera Python module and NumPy by running:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cantera as ct\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When using Cantera, the first thing you usually need is an object representing some phase of matter. Here, we'll create a gas mixture:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "gas1 = ct.Solution('gri30.xml')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To view the state of the mixture, *call* the `gas1` object as if it were a function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "  gri30:\n",
      "\n",
      "       temperature             300  K\n",
      "          pressure          101325  Pa\n",
      "           density       0.0818891  kg/m^3\n",
      "  mean mol. weight         2.01588  amu\n",
      "\n",
      "                          1 kg            1 kmol\n",
      "                       -----------      ------------\n",
      "          enthalpy           26470        5.336e+04     J\n",
      "   internal energy     -1.2109e+06       -2.441e+06     J\n",
      "           entropy           64914        1.309e+05     J/K\n",
      "    Gibbs function     -1.9448e+07        -3.92e+07     J\n",
      " heat capacity c_p           14312        2.885e+04     J/K\n",
      " heat capacity c_v           10187        2.054e+04     J/K\n",
      "\n",
      "                           X                 Y          Chem. Pot. / RT\n",
      "                     -------------     ------------     ------------\n",
      "                H2              1                1         -15.7173\n",
      "     [  +52 minor]              0                0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "gas1()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What you have just done is created an object `gas1` that implements GRI-Mech 3.0, the 53-species, 325-reaction natural gas combustion mechanism developed by Gregory P. Smith, David M. Golden, Michael Frenklach, Nigel W. Moriarty, Boris Eiteneer, Mikhail Goldenberg, C. Thomas Bowman, Ronald K. Hanson, Soonho Song, William C. Gardiner, Jr., Vitali V. Lissianski, and Zhiwei Qin.  See the [GRI-Mech Home Page](http://combustion.berkeley.edu/gri-mech/) for more information.\n",
    "\n",
    "The `gas1` object has properties you would expect for a gas mixture: a temperature, a pressure, species mole and mass fractions, etc. As we will soon see, it has many more properties.\n",
    "\n",
    "The summary of the state of `gas1` that you found above shows that the new objects created from the `gri30.xml` input file start out with a temperature of 300 K, a pressure of 1 atm, and have a composition that consists of only one species, in this case hydrogen. There is nothing special about H2 - it just happens to be the first species listed in the input file defining GRI-Mech 3.0. In general, whichever species is listed first will initially have a mole fraction of 1.0, and all others will be zero."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setting the State"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The state of the object can easily be changed. For example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "gas1.TP = 1200, 101325"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "sets the temperature to 1200 K and the pressure to 101325 Pa (Cantera always uses SI Units). After this statement, calling `gas1()` results in:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "  gri30:\n",
      "\n",
      "       temperature            1200  K\n",
      "          pressure          101325  Pa\n",
      "           density       0.0204723  kg/m^3\n",
      "  mean mol. weight         2.01588  amu\n",
      "\n",
      "                          1 kg            1 kmol\n",
      "                       -----------      ------------\n",
      "          enthalpy      1.3296e+07         2.68e+07     J\n",
      "   internal energy      8.3462e+06        1.682e+07     J\n",
      "           entropy           85228        1.718e+05     J/K\n",
      "    Gibbs function     -8.8978e+07       -1.794e+08     J\n",
      " heat capacity c_p           15378          3.1e+04     J/K\n",
      " heat capacity c_v           11253        2.269e+04     J/K\n",
      "\n",
      "                           X                 Y          Chem. Pot. / RT\n",
      "                     -------------     ------------     ------------\n",
      "                H2              1                1         -17.9775\n",
      "     [  +52 minor]              0                0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "gas1()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Notice that the temperature has been changed as requested, but the density has changed too. The pressure and the composition have not.\n",
    "\n",
    "Thermodynamics generally requires that *two* properties in addition to composition information be specified to fix the intensive state of a substance (or mixture). The state of the mixture can be set using several combinations of two properties. The following are all equivalent:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "gas1.TP = 1200, 101325            # temperature, pressure\n",
    "gas1.TD = 1200, 0.0204723         # temperature, density\n",
    "gas1.HP = 1.32956e7, 101325       # specific enthalpy, pressure\n",
    "gas1.UV = 8.34619e6, 1/0.0204723  # specific internal energy, specific volume\n",
    "gas1.SP = 85227.6, 101325         # specific entropy, pressure\n",
    "gas1.SV = 85227.6, 1/0.0204723    # specific entropy, specific volume"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In each case, the values of the extensive properties must be entered *per unit mass*.\n",
    "\n",
    "Properties may be read independently, such as"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1200.0044548350836"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gas1.T"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "13295636.190310445"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gas1.h"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or together:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8346238.627182945, 48.84649013545132)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gas1.UV"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The composition can be set in terms of either mole fractions (`X`) or mass fractions (`Y`):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "gas1.X = 'CH4:1, O2:2, N2:7.52'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Mass and mole fractions can also be set using the `dict` object, for cases where the composition is stored in a variable or being computed:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "phi = 0.8\n",
    "gas1.X = {'CH4':1, 'O2':2/phi, 'N2': 2*3.76/phi}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When the composition alone is changed, the temperature and density are held constant. This means that the pressure and other intensive properties will change. The composition can also be set in conjunction with the intensive properties of the mixture:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "  gri30:\n",
      "\n",
      "       temperature            1200  K\n",
      "          pressure          101325  Pa\n",
      "           density        0.280629  kg/m^3\n",
      "  mean mol. weight         27.6332  amu\n",
      "\n",
      "                          1 kg            1 kmol\n",
      "                       -----------      ------------\n",
      "          enthalpy      8.6194e+05        2.382e+07     J\n",
      "   internal energy      5.0088e+05        1.384e+07     J\n",
      "           entropy          8914.3        2.463e+05     J/K\n",
      "    Gibbs function     -9.8352e+06       -2.718e+08     J\n",
      " heat capacity c_p          1397.3        3.861e+04     J/K\n",
      " heat capacity c_v          1096.4         3.03e+04     J/K\n",
      "\n",
      "                           X                 Y          Chem. Pot. / RT\n",
      "                     -------------     ------------     ------------\n",
      "                O2       0.190114         0.220149         -28.7472\n",
      "               CH4       0.095057        0.0551863          -35.961\n",
      "                N2       0.714829         0.724665         -25.6789\n",
      "     [  +50 minor]              0                0\n",
      "\n"
     ]
    }
   ],
   "source": [
    "gas1.TPX = 1200, 101325, 'CH4:1, O2:2, N2:7.52'\n",
    "gas1()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The composition above was specified using a string. The format is a comma-separated list of `<species name>:<relative mole numbers>` pairs. The mole numbers will be normalized to produce the mole fractions, and therefore they are \"relative\" mole numbers. Mass fractions can be set this way too by changing `X` to `Y` in the above statements.\n",
    "\n",
    "The composition can also be set using an array, which must have the same size as the number of species. For example, to set all 53 mole fractions to the same value, do this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "gas1.X = np.ones(53)  # NumPy array of 53 ones"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Or, to set all the mass fractions to equal values:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "gas1.Y = np.ones(53)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When setting the state, you can control what properties are held constant by passing the special value `None` to the property setter. For example, to change the specific volume to 2.1 m<sup>3</sup>/kg while holding entropy constant:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "gas1.SV = None, 2.1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Or to set the mass fractions while holding temperature and pressure constant:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "gas1.TPX = None, None, 'CH4:1.0, O2:0.5'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Working with a Subset of Species"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Many properties of a [`Solution`](https://cantera.org/documentation/dev/sphinx/html/cython/importing.html#cantera.Solution) provide values for each species present in the phase. If you want to get values only for a subset of these species, you can use Python's \"slicing\" syntax to select data for just the species of interest. To get the mole fractions of just the major species in `gas1`, in the order specified, you can write:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "Xmajor = gas1['CH4','O2','CO2','H2O','N2'].X"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you want to use the same set of species repeatedly, you can keep a reference to the sliced phase object:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "major = gas1['CH4','O2','CO2','H2O','N2']\n",
    "cp_major = major.partial_molar_cp\n",
    "wdot_major = major.net_production_rates"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The slice object and the original object share the same internal state, so modifications to one will affect the other."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Working with Mechanism Files"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the previous example, we created an object that models an ideal gas mixture with the species and reactions of GRI-Mech 3.0, using the `gri30.xml` input file included with Cantera. This is a \"pre-processed\" XML input file written in a format that is easy for Cantera to parse, but hard for humans to write. Cantera also supports an input file format that is easier for humans to write, called *CTI*. Several reaction mechanism files in this format are included with Cantera, including ones that model high-temperature air, a hydrogen/oxygen reaction mechanism, and a few surface reaction mechanisms. These files are usually located in the `data` subdirectory of the Cantera installation directory, e.g. `C:\\\\Program Files\\\\Cantera\\\\data` on Windows or `/usr/local/cantera/data/` on Unix/Linux/Mac OS X machines, depending on how you installed Cantera and the options you specified.\n",
    "\n",
    "If, for some reason, Cantera has difficulty finding where these files are on your system, set environment variable `CANTERA_DATA` to the directory or directories (separated using `;` on Windows or `:` on other operating systems) where they are located. Alternatively, you can call function [`add_directory`](https://cantera.org/documentation/dev/sphinx/html/cython/importing.html#cantera.add_directory) to add a directory to the Cantera search path:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "ct.add_directory('/usr/local/cantera/my_data_files')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Cantera input files are plain text files, and can be created with any text editor. See the guide *[Defining Phases](https://cantera.org/tutorials/cti/defining-phases.html)* for more information.\n",
    "\n",
    "A Cantera input file may contain more than one phase specification, or may contain specifications of interfaces (surfaces). Here, we import definitions of two bulk phases and the interface between them from the file `diamond.cti`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "gas2 = ct.Solution('diamond.cti', 'gas')\n",
    "diamond = ct.Solution('diamond.cti', 'diamond')\n",
    "diamond_surf = ct.Interface('diamond.cti', 'diamond_100', [gas2, diamond])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that the bulk (i.e., 3D or homogenous) phases that participate in the surface reactions must also be passed as arguments to [`Interface`](https://cantera.org/documentation/dev/sphinx/html/cython/importing.html#cantera.Interface)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Converting CK-format files"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "See *[Converting CK-format files](https://cantera.org/tutorials/ck2cti-tutorial.html)* in the *[Working with Input Files](https://cantera.org/tutorials/input-files.html)* documentation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Getting Help"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In addition to the *[Python Module Documentation](https://cantera.org/documentation/index.html)*, documentation of the Python classes and their methods can be accessed from within the Python interpreter as well.\n",
    "\n",
    "Suppose you have created a Cantera object and want to know what methads are avialable for it, and get help on using the methods:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "g = ct.Solution('gri30.xml')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To get help on the Python class that this object is an instance of, put a question mark `?` after the variable:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "g?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For a simple list of the properties and methods of this object:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['DP',\n",
       " 'DPX',\n",
       " 'DPY',\n",
       " 'HP',\n",
       " 'HPX',\n",
       " 'HPY',\n",
       " 'ID',\n",
       " 'P',\n",
       " 'P_sat',\n",
       " 'SP',\n",
       " 'SPX',\n",
       " 'SPY',\n",
       " 'SV',\n",
       " 'SVX',\n",
       " 'SVY',\n",
       " 'T',\n",
       " 'TD',\n",
       " 'TDX',\n",
       " 'TDY',\n",
       " 'TP',\n",
       " 'TPX',\n",
       " 'TPY',\n",
       " 'T_sat',\n",
       " 'UV',\n",
       " 'UVX',\n",
       " 'UVY',\n",
       " 'X',\n",
       " 'Y',\n",
       " '__call__',\n",
       " '__class__',\n",
       " '__copy__',\n",
       " '__delattr__',\n",
       " '__dir__',\n",
       " '__doc__',\n",
       " '__eq__',\n",
       " '__format__',\n",
       " '__ge__',\n",
       " '__getattribute__',\n",
       " '__getitem__',\n",
       " '__gt__',\n",
       " '__hash__',\n",
       " '__init__',\n",
       " '__init_subclass__',\n",
       " '__le__',\n",
       " '__lt__',\n",
       " '__module__',\n",
       " '__ne__',\n",
       " '__new__',\n",
       " '__pyx_vtable__',\n",
       " '__reduce__',\n",
       " '__reduce_ex__',\n",
       " '__repr__',\n",
       " '__setattr__',\n",
       " '__sizeof__',\n",
       " '__slots__',\n",
       " '__str__',\n",
       " '__subclasshook__',\n",
       " '_check_kinetics_species_index',\n",
       " '_check_phase_index',\n",
       " '_check_reaction_index',\n",
       " '_full_states',\n",
       " '_init_cti_xml',\n",
       " '_init_parts',\n",
       " '_references',\n",
       " 'activities',\n",
       " 'activity_coefficients',\n",
       " 'add_reaction',\n",
       " 'add_species',\n",
       " 'atomic_weight',\n",
       " 'atomic_weights',\n",
       " 'basis',\n",
       " 'binary_diff_coeffs',\n",
       " 'chemical_potentials',\n",
       " 'concentrations',\n",
       " 'cp',\n",
       " 'cp_mass',\n",
       " 'cp_mole',\n",
       " 'creation_rates',\n",
       " 'critical_density',\n",
       " 'critical_pressure',\n",
       " 'critical_temperature',\n",
       " 'cv',\n",
       " 'cv_mass',\n",
       " 'cv_mole',\n",
       " 'delta_enthalpy',\n",
       " 'delta_entropy',\n",
       " 'delta_gibbs',\n",
       " 'delta_standard_enthalpy',\n",
       " 'delta_standard_entropy',\n",
       " 'delta_standard_gibbs',\n",
       " 'density',\n",
       " 'density_mass',\n",
       " 'density_mole',\n",
       " 'destruction_rates',\n",
       " 'electric_potential',\n",
       " 'electrical_conductivity',\n",
       " 'electrochemical_potentials',\n",
       " 'element_index',\n",
       " 'element_name',\n",
       " 'element_names',\n",
       " 'elemental_mass_fraction',\n",
       " 'elemental_mole_fraction',\n",
       " 'enthalpy_mass',\n",
       " 'enthalpy_mole',\n",
       " 'entropy_mass',\n",
       " 'entropy_mole',\n",
       " 'equilibrate',\n",
       " 'equilibrium_constants',\n",
       " 'forward_rate_constants',\n",
       " 'forward_rates_of_progress',\n",
       " 'g',\n",
       " 'get_equivalence_ratio',\n",
       " 'gibbs_mass',\n",
       " 'gibbs_mole',\n",
       " 'h',\n",
       " 'int_energy_mass',\n",
       " 'int_energy_mole',\n",
       " 'is_reversible',\n",
       " 'isothermal_compressibility',\n",
       " 'kinetics_species_index',\n",
       " 'kinetics_species_name',\n",
       " 'kinetics_species_names',\n",
       " 'mass_fraction_dict',\n",
       " 'max_temp',\n",
       " 'mean_molecular_weight',\n",
       " 'min_temp',\n",
       " 'mix_diff_coeffs',\n",
       " 'mix_diff_coeffs_mass',\n",
       " 'mix_diff_coeffs_mole',\n",
       " 'mobilities',\n",
       " 'modify_reaction',\n",
       " 'modify_species',\n",
       " 'mole_fraction_dict',\n",
       " 'molecular_weights',\n",
       " 'multi_diff_coeffs',\n",
       " 'multiplier',\n",
       " 'n_atoms',\n",
       " 'n_elements',\n",
       " 'n_phases',\n",
       " 'n_reactions',\n",
       " 'n_selected_species',\n",
       " 'n_species',\n",
       " 'n_total_species',\n",
       " 'name',\n",
       " 'net_production_rates',\n",
       " 'net_rates_of_progress',\n",
       " 'partial_molar_cp',\n",
       " 'partial_molar_enthalpies',\n",
       " 'partial_molar_entropies',\n",
       " 'partial_molar_int_energies',\n",
       " 'partial_molar_volumes',\n",
       " 'product_stoich_coeff',\n",
       " 'product_stoich_coeffs',\n",
       " 'products',\n",
       " 'reactant_stoich_coeff',\n",
       " 'reactant_stoich_coeffs',\n",
       " 'reactants',\n",
       " 'reaction',\n",
       " 'reaction_equation',\n",
       " 'reaction_equations',\n",
       " 'reaction_phase_index',\n",
       " 'reaction_type',\n",
       " 'reactions',\n",
       " 'reference_pressure',\n",
       " 'report',\n",
       " 'reverse_rate_constants',\n",
       " 'reverse_rates_of_progress',\n",
       " 's',\n",
       " 'selected_species',\n",
       " 'set_equivalence_ratio',\n",
       " 'set_multiplier',\n",
       " 'set_unnormalized_mass_fractions',\n",
       " 'set_unnormalized_mole_fractions',\n",
       " 'species',\n",
       " 'species_index',\n",
       " 'species_name',\n",
       " 'species_names',\n",
       " 'species_viscosities',\n",
       " 'standard_cp_R',\n",
       " 'standard_enthalpies_RT',\n",
       " 'standard_entropies_R',\n",
       " 'standard_gibbs_RT',\n",
       " 'standard_int_energies_RT',\n",
       " 'state',\n",
       " 'thermal_conductivity',\n",
       " 'thermal_diff_coeffs',\n",
       " 'thermal_expansion_coeff',\n",
       " 'transport_model',\n",
       " 'u',\n",
       " 'v',\n",
       " 'viscosity',\n",
       " 'volume_mass',\n",
       " 'volume_mole']"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(g)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To get help on a specific method, e.g. the `species_index` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "g.species_index?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For properties, getting the documentation is slightly trickier, as the usual method will give you help for the *result*, e.g.:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "g.T?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "provides help on Python's `float` class. To get the help for the temperature property, ask for the attribute of the class object itself:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "g.__class__.T?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Help can also be obtained using the `help` function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function species_index:\n",
      "\n",
      "species_index(...) method of cantera.composite.Solution instance\n",
      "    ThermoPhase.species_index(self, species) -> int\n",
      "    \n",
      "    The index of species *species*, which may be specified as a string or\n",
      "    an integer. In the latter case, the index is checked for validity and\n",
      "    returned. If no such species is present, an exception is thrown.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(g.species_index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Chemical Equilibrium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To set a gas mixture to a state of chemical equilibrium, use the `equilibrate` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "g = ct.Solution('gri30.xml')\n",
    "g.TPX = 300.0, ct.one_atm, 'CH4:0.95, O2:2, N2:7.52'\n",
    "g.equilibrate('TP')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The above statement sets the state of object `g` to the state of chemical equilibrium holding temperature and pressure fixed. Alternatively, the specific enthalpy and pressure can be held fixed:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "g.TPX = 300.0, ct.one_atm, 'CH4:0.95, O2:2, N2:7.52'\n",
    "g.equilibrate('HP')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Other options are:\n",
    "* `'UV'` for fixed specific internal energy and specific volume\n",
    "* `'SV'` for fixed specific entropy and specific volume\n",
    "* `'SP'` for fixed specific entropy and pressure\n",
    "\n",
    "How can you tell if `equilibrate` has correctly found the chemical equilibrium state? One way is to verify that the net rates of progress of all reversible reactions are zero. Here is the code to do this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "g.TPX = 300.0, ct.one_atm, 'CH4:0.95, O2:2, N2:7.52'\n",
    "g.equilibrate('HP')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     0   -4.756e-15  \n",
      "     1   -3.332e-15  \n",
      "     2   -3.936e-16  \n",
      "     3   -3.751e-15  \n",
      "     4   -6.626e-15  \n",
      "     5   -1.503e-15  \n",
      "     6    5.377e-15  \n",
      "     7   -1.609e-15  \n",
      "     8    1.267e-14  \n",
      "     9   -1.587e-16  \n",
      "    10   -4.093e-15  \n",
      "    11     7.16e-15  \n",
      "    12   -9.032e-15  \n",
      "    13    -1.72e-15  \n",
      "    14   -2.147e-16  \n",
      "    15   -5.203e-15  \n",
      "    16   -1.743e-15  \n",
      "    17    5.791e-15  \n",
      "    18    1.957e-15  \n",
      "    19   -5.548e-15  \n",
      "    20    1.886e-15  \n",
      "    21    1.421e-15  \n",
      "    22    1.223e-16  \n",
      "    23    9.182e-15  \n",
      "    24    2.055e-15  \n",
      "    25   -5.119e-15  \n",
      "    26    3.383e-15  \n",
      "    27    -1.44e-14  \n",
      "    28   -3.495e-16  \n",
      "    29   -1.949e-15  \n",
      "    30    1.452e-14  \n",
      "    31    1.048e-14  \n",
      "    32    3.608e-15  \n",
      "    33    -3.47e-15  \n",
      "    34   -3.443e-15  \n",
      "    35    9.966e-15  \n",
      "    37    8.611e-16  \n",
      "    38   -4.981e-15  \n",
      "    39   -1.486e-15  \n",
      "    40   -8.614e-15  \n",
      "    41   -1.518e-15  \n",
      "    42   -1.232e-15  \n",
      "    43   -6.832e-15  \n",
      "    44   -5.306e-15  \n",
      "    45   -9.065e-15  \n",
      "    46     -9.2e-15  \n",
      "    47   -1.436e-14  \n",
      "    48   -7.131e-15  \n",
      "    49   -1.415e-15  \n",
      "    50   -1.151e-16  \n",
      "    51     2.08e-15  \n",
      "    52   -7.122e-15  \n",
      "    53   -6.697e-15  \n",
      "    54   -1.066e-14  \n",
      "    55    4.771e-15  \n",
      "    56    1.255e-15  \n",
      "    57   -2.753e-15  \n",
      "    58   -1.199e-14  \n",
      "    59   -7.143e-15  \n",
      "    60   -1.246e-14  \n",
      "    61    -1.46e-14  \n",
      "    62   -8.636e-15  \n",
      "    63      4.3e-15  \n",
      "    64    -3.79e-15  \n",
      "    65   -7.982e-15  \n",
      "    66   -1.074e-14  \n",
      "    67    3.123e-15  \n",
      "    68   -1.094e-15  \n",
      "    69   -5.515e-15  \n",
      "    70   -8.543e-15  \n",
      "    71    8.996e-15  \n",
      "    72    4.953e-15  \n",
      "    73    6.249e-15  \n",
      "    74    -1.42e-14  \n",
      "    75   -8.455e-15  \n",
      "    76   -1.624e-14  \n",
      "    77   -2.242e-16  \n",
      "    78   -6.353e-15  \n",
      "    79   -3.199e-15  \n",
      "    80   -3.712e-15  \n",
      "    81    7.139e-16  \n",
      "    82     5.75e-15  \n",
      "    83    3.837e-15  \n",
      "    84    8.785e-15  \n",
      "    85    1.055e-15  \n",
      "    86    3.893e-15  \n",
      "    87   -5.307e-15  \n",
      "    88   -5.318e-15  \n",
      "    89    1.908e-16  \n",
      "    90    1.085e-14  \n",
      "    91    7.232e-15  \n",
      "    92    2.015e-15  \n",
      "    93    7.362e-15  \n",
      "    94   -1.295e-15  \n",
      "    95    2.142e-15  \n",
      "    96   -2.141e-15  \n",
      "    97   -3.184e-15  \n",
      "    98    6.945e-15  \n",
      "    99    3.564e-16  \n",
      "   100    1.851e-15  \n",
      "   101    -1.03e-14  \n",
      "   102   -6.984e-15  \n",
      "   103    7.083e-15  \n",
      "   104    3.502e-15  \n",
      "   105    8.553e-16  \n",
      "   106    2.694e-15  \n",
      "   107    2.082e-15  \n",
      "   108    2.527e-15  \n",
      "   109   -1.614e-15  \n",
      "   110     1.44e-14  \n",
      "   111   -1.036e-14  \n",
      "   112    1.086e-14  \n",
      "   113   -5.672e-15  \n",
      "   114   -3.447e-15  \n",
      "   115    -3.33e-15  \n",
      "   116   -3.541e-15  \n",
      "   117   -5.337e-15  \n",
      "   118   -9.301e-16  \n",
      "   119    1.057e-14  \n",
      "   120    6.485e-15  \n",
      "   121   -1.702e-15  \n",
      "   122    2.113e-15  \n",
      "   123    3.496e-15  \n",
      "   124    5.331e-15  \n",
      "   125    3.978e-15  \n",
      "   126    5.315e-15  \n",
      "   127   -3.337e-15  \n",
      "   128   -6.885e-15  \n",
      "   129    1.692e-16  \n",
      "   130    4.969e-15  \n",
      "   131    7.138e-15  \n",
      "   132    1.494e-16  \n",
      "   133   -1.433e-14  \n",
      "   135    2.202e-15  \n",
      "   136   -3.558e-15  \n",
      "   137    1.705e-15  \n",
      "   138   -5.142e-15  \n",
      "   139    2.187e-15  \n",
      "   140   -1.063e-14  \n",
      "   141    4.121e-15  \n",
      "   143    1.518e-15  \n",
      "   144    3.739e-15  \n",
      "   145     6.05e-15  \n",
      "   146    2.349e-15  \n",
      "   147    4.067e-15  \n",
      "   148    5.183e-15  \n",
      "   149   -4.704e-16  \n",
      "   150    4.195e-15  \n",
      "   151    -2.67e-15  \n",
      "   152   -3.171e-15  \n",
      "   153     6.19e-15  \n",
      "   154    2.475e-15  \n",
      "   155    1.559e-15  \n",
      "   156   -2.177e-15  \n",
      "   157    2.065e-15  \n",
      "   158    1.207e-14  \n",
      "   159   -1.072e-14  \n",
      "   160     4.26e-15  \n",
      "   161    9.977e-15  \n",
      "   162    5.986e-15  \n",
      "   163   -7.571e-15  \n",
      "   164    1.389e-14  \n",
      "   165   -2.985e-15  \n",
      "   166   -8.343e-15  \n",
      "   167   -1.873e-14  \n",
      "   168     1.15e-14  \n",
      "   169    1.584e-14  \n",
      "   170    6.844e-15  \n",
      "   171    1.539e-15  \n",
      "   172    6.997e-15  \n",
      "   173   -3.021e-15  \n",
      "   174   -9.388e-15  \n",
      "   175   -1.301e-14  \n",
      "   176    -1.29e-14  \n",
      "   177    1.794e-15  \n",
      "   178    3.525e-15  \n",
      "   179    2.044e-15  \n",
      "   180    5.211e-15  \n",
      "   181    3.137e-15  \n",
      "   182   -5.092e-16  \n",
      "   183    2.429e-15  \n",
      "   184    6.597e-15  \n",
      "   185    4.338e-15  \n",
      "   186     5.61e-16  \n",
      "   187   -2.652e-16  \n",
      "   188    -7.74e-15  \n",
      "   189    1.885e-15  \n",
      "   190   -4.779e-15  \n",
      "   191    7.254e-15  \n",
      "   192    2.737e-15  \n",
      "   193    1.462e-15  \n",
      "   194   -2.185e-15  \n",
      "   195    -3.68e-15  \n",
      "   196   -3.195e-15  \n",
      "   197            0  \n",
      "   198    1.844e-16  \n",
      "   199   -6.266e-15  \n",
      "   200    1.042e-15  \n",
      "   201   -2.691e-15  \n",
      "   202    1.096e-15  \n",
      "   203    5.445e-16  \n",
      "   204    4.599e-16  \n",
      "   205    3.419e-15  \n",
      "   206    1.975e-15  \n",
      "   207   -2.171e-16  \n",
      "   208   -3.651e-15  \n",
      "   209   -6.822e-15  \n",
      "   210   -3.846e-15  \n",
      "   211   -1.802e-16  \n",
      "   212    -3.82e-15  \n",
      "   213   -5.635e-15  \n",
      "   214   -1.592e-15  \n",
      "   215   -1.546e-16  \n",
      "   216   -8.714e-15  \n",
      "   217   -3.328e-15  \n",
      "   218   -4.757e-15  \n",
      "   219    1.028e-15  \n",
      "   220    2.253e-15  \n",
      "   221   -1.891e-15  \n",
      "   222            0  \n",
      "   223    3.906e-15  \n",
      "   224   -3.623e-15  \n",
      "   225     1.41e-14  \n",
      "   226   -8.518e-16  \n",
      "   227   -5.316e-15  \n",
      "   228    7.057e-15  \n",
      "   229    4.955e-15  \n",
      "   230   -2.811e-15  \n",
      "   231   -1.608e-15  \n",
      "   232    2.607e-16  \n",
      "   233    1.704e-14  \n",
      "   234    1.288e-14  \n",
      "   235   -2.403e-15  \n",
      "   236   -4.359e-16  \n",
      "   237   -3.755e-15  \n",
      "   238    5.284e-15  \n",
      "   239    -3.91e-16  \n",
      "   240    1.543e-15  \n",
      "   241    1.687e-15  \n",
      "   242    6.066e-15  \n",
      "   243    6.419e-15  \n",
      "   244    1.869e-16  \n",
      "   245   -1.777e-15  \n",
      "   246   -5.017e-15  \n",
      "   247    7.063e-15  \n",
      "   248    7.223e-15  \n",
      "   249    -3.68e-15  \n",
      "   250    2.928e-15  \n",
      "   251    1.082e-14  \n",
      "   252   -3.555e-15  \n",
      "   253    3.688e-15  \n",
      "   254   -3.464e-15  \n",
      "   255   -7.992e-16  \n",
      "   256    -5.37e-16  \n",
      "   257   -8.861e-15  \n",
      "   258    1.002e-14  \n",
      "   259    1.473e-15  \n",
      "   260   -3.605e-15  \n",
      "   261    5.441e-15  \n",
      "   262   -1.404e-14  \n",
      "   263    -8.87e-15  \n",
      "   264   -1.509e-14  \n",
      "   265   -1.192e-14  \n",
      "   266   -1.179e-15  \n",
      "   267   -1.684e-15  \n",
      "   268   -9.065e-15  \n",
      "   269    5.379e-15  \n",
      "   270   -7.503e-15  \n",
      "   271   -1.064e-14  \n",
      "   272   -3.506e-15  \n",
      "   273    1.121e-16  \n",
      "   274    1.825e-15  \n",
      "   275   -7.158e-15  \n",
      "   276   -1.008e-14  \n",
      "   277    4.998e-16  \n",
      "   278   -6.989e-15  \n",
      "   279   -1.959e-14  \n",
      "   280   -7.091e-15  \n",
      "   281   -1.734e-16  \n",
      "   282    -5.24e-15  \n",
      "   284    6.646e-15  \n",
      "   285   -1.078e-14  \n",
      "   286    3.836e-15  \n",
      "   288    2.384e-15  \n",
      "   290            0  \n",
      "   293    1.232e-14  \n",
      "   294    8.698e-15  \n",
      "   295    1.071e-14  \n",
      "   298    7.763e-15  \n",
      "   303    3.944e-15  \n",
      "   307   -4.906e-15  \n",
      "   308   -7.438e-15  \n",
      "   309   -1.769e-14  \n",
      "   310    7.541e-15  \n",
      "   311    7.415e-15  \n",
      "   312   -1.229e-14  \n",
      "   313   -8.027e-15  \n",
      "   314    -4.22e-15  \n",
      "   315    -8.59e-16  \n",
      "   316   -1.138e-15  \n",
      "   317    1.371e-14  \n",
      "   318   -5.547e-15  \n",
      "   319   -1.629e-15  \n",
      "   320   -8.262e-15  \n",
      "   321      1.1e-14  \n",
      "   322   -4.614e-15  \n",
      "   324    1.068e-14  \n"
     ]
    }
   ],
   "source": [
    "rf = g.forward_rates_of_progress\n",
    "rr = g.reverse_rates_of_progress\n",
    "for i in range(g.n_reactions):\n",
    "    if g.is_reversible(i) and rf[i] != 0.0:\n",
    "        print('  %4i   %10.4g  ' % (i, (rf[i] - rr[i])/rf[i]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If the magnitudes of the numbers in this list are all very small (which in this case they are), then each reversible reaction is very nearly equilibrated, which only occurs if the gas is in chemical equilibrium.\n",
    "\n",
    "You might be wondering how `equilibrate` works. (Then again, you might not.) Method `equilibrate` invokes Cantera's chemical equilibrium solver, which uses an element potential method. The element potential method is one of a class of equivalent *nonstoichiometric* methods that all have the characteristic that the probelm reduces to solving a set of $M$ nonlinear algebraic equations, where $M$ is the number of elements (not species). The so-called *stoichiometric* methods, on the other hand (including the Gibbs minimization), require solving $K$ nonlinear equations, where $K$ is the number of species (usually $K >> M$). See Smith and Missen's \"Chemical Reaction Equilibrium Analysis\" for more information on the various algorithms and their characteristics.\n",
    "\n",
    "Cantera uses a damped Newton method to solve these equations, and does a few other things to generate a good starting guess and to produce a reasonably robust algorithm. If you want to know more about the details, look at the on-line documentated source code of Cantera C++ class [`ChemEquil`](https://cantera.org/documentation/dev/doxygen/html/da/d0e/classCantera_1_1ChemEquil.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Chemical Kinetics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[`Solution`](https://cantera.org/documentation/dev/sphinx/html/cython/importing.html#cantera.Solution) objects are also [`Kinetics`](https://cantera.org/documentation/dev/sphinx/html/cython/kinetics.html#cantera.Kinetics) objects, and provide all of the methods necessary to compute the thermodynamic quantities associated with each reaction, reaction rates, and species creation and destruction rates. They also provide methods to inspect the quantities that define each reaction, such as the rate constants and the stoichiometric coefficients. The rate calculation functions are used extensively within Cantera's *[reactor network model](https://cantera.org/documentation/dev/sphinx/html/cython/zerodim.html#sec-cython-zerodim)* and *[1D flame model](https://cantera.org/documentation/dev/sphinx/html/cython/onedim.html#sec-cython-onedim)*.\n",
    "\n",
    "Information about individual reactions that are independent of the thermodynamic state can be obtained by accessing [`Reaction`](https://cantera.org/documentation/dev/sphinx/html/cython/kinetics.html#cantera.Reaction) objects with the [`Kinetics.reaction`](https://cantera.org/documentation/dev/sphinx/html/cython/kinetics.html#cantera.Kinetics.reaction) method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<ElementaryReaction: H2 + O <=> H + OH>"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g = ct.Solution('gri30.cti')\n",
    "r = g.reaction(2)  # get a Reaction object\n",
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'H2': 1.0, 'O': 1.0}"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.reactants"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'H': 1.0, 'OH': 1.0}"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.products"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Arrhenius(A=38.7, b=2.7, E=2.61918e+07)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.rate"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we are interested in only certain types of reactions, we can use this information to filter the full list of reactions to find just the ones of interest. For example, here we find the indices of just those reactions which convert `CO` into `CO2`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CO + O (+M) <=> CO2 (+M)\n",
      "CO + O2 <=> CO2 + O\n",
      "CO + OH <=> CO2 + H\n",
      "CO + HO2 <=> CO2 + OH\n"
     ]
    }
   ],
   "source": [
    "II = [i for i, r in enumerate(g.reactions()) if 'CO' in r.reactants and 'CO2' in r.products]\n",
    "\n",
    "for i in II:\n",
    "    print(g.reaction(i).equation)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "(Actually, we should also include the reactions where the reaction is written such that `CO2` is a reactant and `CO` is a product, but for this example, we'll just stick to this smaller set of reactions.) Now, let's set the composition to an interesting state:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "g.TPX = 300, 101325, {'CH4':0.6, 'O2':1.0, 'N2':3.76}\n",
    "g.equilibrate('HP')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can verify that this is an equilibrium state by seeing that the net reactions rates are essentially zero:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-8.80914265e-20, -1.03761536e-20, -1.77635684e-15, -4.99749439e-20])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g.net_rates_of_progress[II]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now let's see what happens if we decrease the temperature of the mixture:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3.18644948e-05, 5.00489577e-08, 1.05964923e-01, 2.89502609e-06])"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g.TP = g.T-100, None\n",
    "g.net_rates_of_progress[II]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "All of the reaction rates are positive, favoring the formation of `CO2` from `CO`, with the third reaction, `CO + OH <=> CO2 + H` proceeding the fastest. If we look at the enthalpy change associated with each of these reactions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-5.33034657e+08, -2.23248515e+07, -8.76650086e+07, -2.49169628e+08])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g.delta_enthalpy[II]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "we see that the change is negative in each case, indicating a net release of thermal energy. The total heat release rate can be computed either from the reaction rates:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-58013370.72088288"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(g.net_rates_of_progress, g.delta_enthalpy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or from the species production rates:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-58013370.72088274"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(g.net_production_rates, g.partial_molar_enthalpies)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The contribution from just the selected reactions is:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-9307123.262565034"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(g.net_rates_of_progress[II], g.delta_enthalpy[II])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "or about 16% of the total heat release rate."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
