1661 lines
48 KiB
Text
1661 lines
48 KiB
Text
{
|
|
"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": {
|
|
"collapsed": true
|
|
},
|
|
"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": {
|
|
"collapsed": true
|
|
},
|
|
"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": {
|
|
"collapsed": true
|
|
},
|
|
"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 pressure has changed too. The density 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": {
|
|
"collapsed": true
|
|
},
|
|
"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": {
|
|
"collapsed": true
|
|
},
|
|
"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": {
|
|
"collapsed": true
|
|
},
|
|
"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": {
|
|
"collapsed": true
|
|
},
|
|
"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": {
|
|
"collapsed": true
|
|
},
|
|
"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": {
|
|
"collapsed": true
|
|
},
|
|
"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": {
|
|
"collapsed": true
|
|
},
|
|
"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`](http://cantera.github.io/docs/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": {
|
|
"collapsed": true
|
|
},
|
|
"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": {
|
|
"collapsed": true
|
|
},
|
|
"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`](http://cantera.github.io/docs/sphinx/html/cython/importing.html#cantera.add_directory) to add a directory to the Cantera search path:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 19,
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"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 document *[Defining Phases](http://cantera.github.io/docs/sphinx/html/cti/index.html#sec-defining-phases)* 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": {
|
|
"collapsed": true
|
|
},
|
|
"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`](http://cantera.github.io/docs/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](http://cantera.github.io/docs/sphinx/html/cti/input-files.html#sec-ck-format-conversion)* in the *[Working with Input Files](http://cantera.github.io/docs/sphinx/html/cti/input-files.html#sec-input-files)* documentation."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Getting Help"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"In addition to the Sphinx-generated *[Python Module Documentation](http://cantera.github.io/docs/sphinx/html/cython/index.html#sec-cython-documentation)*, 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",
|
|
" '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",
|
|
" 'element_potentials',\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",
|
|
" '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",
|
|
" '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",
|
|
" '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",
|
|
" '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": {
|
|
"collapsed": true
|
|
},
|
|
"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": {
|
|
"collapsed": true
|
|
},
|
|
"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": {
|
|
"collapsed": true
|
|
},
|
|
"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 5.285e-16 \n",
|
|
" 1 -3.147e-15 \n",
|
|
" 2 -2.362e-15 \n",
|
|
" 3 -1.667e-15 \n",
|
|
" 4 4.733e-15 \n",
|
|
" 5 1.065e-14 \n",
|
|
" 6 7.075e-15 \n",
|
|
" 7 -2.011e-16 \n",
|
|
" 8 1.046e-14 \n",
|
|
" 9 1.745e-15 \n",
|
|
" 10 8.84e-15 \n",
|
|
" 11 5.404e-16 \n",
|
|
" 12 -3.656e-15 \n",
|
|
" 13 -3.441e-15 \n",
|
|
" 14 1.932e-15 \n",
|
|
" 15 5.203e-15 \n",
|
|
" 16 3.312e-15 \n",
|
|
" 17 -1.808e-14 \n",
|
|
" 18 -1.598e-14 \n",
|
|
" 19 -1.07e-14 \n",
|
|
" 20 7.04e-15 \n",
|
|
" 21 1.265e-14 \n",
|
|
" 22 7.091e-15 \n",
|
|
" 23 2.623e-16 \n",
|
|
" 24 1.028e-14 \n",
|
|
" 25 6.891e-15 \n",
|
|
" 26 5.921e-15 \n",
|
|
" 27 2.879e-15 \n",
|
|
" 28 8.738e-16 \n",
|
|
" 29 6.928e-15 \n",
|
|
" 30 -2.736e-15 \n",
|
|
" 31 2.515e-15 \n",
|
|
" 32 2.115e-15 \n",
|
|
" 33 8.353e-15 \n",
|
|
" 34 8.335e-15 \n",
|
|
" 35 8.207e-15 \n",
|
|
" 37 -2.829e-15 \n",
|
|
" 38 1.423e-16 \n",
|
|
" 39 3.43e-16 \n",
|
|
" 40 3.903e-15 \n",
|
|
" 41 -3.341e-15 \n",
|
|
" 42 5.475e-16 \n",
|
|
" 43 -3.504e-15 \n",
|
|
" 44 -5.306e-15 \n",
|
|
" 45 -3.81e-15 \n",
|
|
" 46 7.042e-15 \n",
|
|
" 47 6.951e-15 \n",
|
|
" 48 5.15e-15 \n",
|
|
" 49 1.929e-15 \n",
|
|
" 50 -5.408e-15 \n",
|
|
" 51 -4.728e-15 \n",
|
|
" 52 4.812e-15 \n",
|
|
" 53 -1.395e-15 \n",
|
|
" 54 -7.24e-15 \n",
|
|
" 55 -1.122e-14 \n",
|
|
" 56 -8.41e-15 \n",
|
|
" 57 -2.878e-15 \n",
|
|
" 58 1.857e-14 \n",
|
|
" 59 1.409e-14 \n",
|
|
" 60 9.723e-15 \n",
|
|
" 61 3.338e-15 \n",
|
|
" 62 1.655e-14 \n",
|
|
" 63 -1.881e-15 \n",
|
|
" 64 1.077e-14 \n",
|
|
" 65 7.982e-15 \n",
|
|
" 66 1.713e-15 \n",
|
|
" 67 -2.162e-14 \n",
|
|
" 68 -1.374e-14 \n",
|
|
" 69 -1.379e-14 \n",
|
|
" 70 5.819e-15 \n",
|
|
" 71 7.647e-15 \n",
|
|
" 72 -5.403e-15 \n",
|
|
" 73 -5.381e-15 \n",
|
|
" 74 -7.317e-15 \n",
|
|
" 75 -6.764e-15 \n",
|
|
" 76 8.83e-15 \n",
|
|
" 77 2.803e-15 \n",
|
|
" 78 -2.353e-16 \n",
|
|
" 79 -3.039e-15 \n",
|
|
" 80 8.536e-15 \n",
|
|
" 81 -3.427e-15 \n",
|
|
" 82 7.58e-15 \n",
|
|
" 83 4.796e-15 \n",
|
|
" 84 5.406e-16 \n",
|
|
" 85 5.275e-16 \n",
|
|
" 86 -6.901e-15 \n",
|
|
" 87 -1.658e-15 \n",
|
|
" 88 -1.72e-15 \n",
|
|
" 89 7.25e-15 \n",
|
|
" 90 1.447e-14 \n",
|
|
" 91 8.796e-15 \n",
|
|
" 92 -3.166e-15 \n",
|
|
" 93 8.89e-15 \n",
|
|
" 94 7.953e-15 \n",
|
|
" 95 -6.425e-15 \n",
|
|
" 96 -6.243e-15 \n",
|
|
" 97 3.487e-15 \n",
|
|
" 98 0 \n",
|
|
" 99 -1.069e-14 \n",
|
|
" 100 1.697e-15 \n",
|
|
" 101 1.078e-14 \n",
|
|
" 102 1.072e-14 \n",
|
|
" 103 -1.094e-14 \n",
|
|
" 104 -1.537e-14 \n",
|
|
" 105 -5.474e-15 \n",
|
|
" 106 1.27e-14 \n",
|
|
" 107 1.624e-14 \n",
|
|
" 108 1.965e-14 \n",
|
|
" 109 2.119e-14 \n",
|
|
" 110 3.669e-15 \n",
|
|
" 111 -2.852e-15 \n",
|
|
" 112 -6.13e-15 \n",
|
|
" 113 -4.862e-15 \n",
|
|
" 114 -1.206e-14 \n",
|
|
" 115 -1.234e-14 \n",
|
|
" 116 -3.541e-16 \n",
|
|
" 117 -3.296e-15 \n",
|
|
" 118 -5.448e-15 \n",
|
|
" 119 -1.78e-14 \n",
|
|
" 120 -9.215e-15 \n",
|
|
" 121 0 \n",
|
|
" 122 1.878e-15 \n",
|
|
" 123 -1.032e-14 \n",
|
|
" 124 1.05e-14 \n",
|
|
" 125 8.262e-15 \n",
|
|
" 126 1.26e-14 \n",
|
|
" 127 -3.641e-15 \n",
|
|
" 128 1.434e-16 \n",
|
|
" 129 1.269e-14 \n",
|
|
" 130 1.397e-15 \n",
|
|
" 131 1.414e-14 \n",
|
|
" 132 5.977e-16 \n",
|
|
" 133 -7.276e-15 \n",
|
|
" 135 1.762e-15 \n",
|
|
" 136 -1.105e-14 \n",
|
|
" 137 3.411e-16 \n",
|
|
" 138 9.284e-15 \n",
|
|
" 139 -3.977e-16 \n",
|
|
" 140 -3.641e-15 \n",
|
|
" 141 6.526e-15 \n",
|
|
" 143 3.036e-15 \n",
|
|
" 144 -3.935e-15 \n",
|
|
" 145 4.489e-15 \n",
|
|
" 146 1.506e-14 \n",
|
|
" 147 -3.013e-16 \n",
|
|
" 148 4.12e-15 \n",
|
|
" 149 9.76e-15 \n",
|
|
" 150 -2.996e-16 \n",
|
|
" 151 6.341e-15 \n",
|
|
" 152 1.402e-14 \n",
|
|
" 153 1.344e-14 \n",
|
|
" 154 -1.047e-14 \n",
|
|
" 155 -7.371e-15 \n",
|
|
" 156 -4.354e-15 \n",
|
|
" 157 -1.26e-14 \n",
|
|
" 158 -6.794e-15 \n",
|
|
" 159 -1.424e-14 \n",
|
|
" 160 -9.318e-16 \n",
|
|
" 161 -2.685e-14 \n",
|
|
" 162 -3.156e-14 \n",
|
|
" 163 -1.211e-14 \n",
|
|
" 164 3.935e-15 \n",
|
|
" 165 -5.618e-15 \n",
|
|
" 166 -5.607e-15 \n",
|
|
" 167 3.292e-15 \n",
|
|
" 168 1.261e-14 \n",
|
|
" 169 4.311e-15 \n",
|
|
" 170 -3.259e-16 \n",
|
|
" 171 -1.154e-14 \n",
|
|
" 172 2.461e-14 \n",
|
|
" 173 -1.329e-14 \n",
|
|
" 174 7.51e-15 \n",
|
|
" 175 -9.564e-16 \n",
|
|
" 176 -7.937e-16 \n",
|
|
" 177 3.23e-15 \n",
|
|
" 178 1.637e-15 \n",
|
|
" 179 3.705e-15 \n",
|
|
" 180 2.004e-16 \n",
|
|
" 181 3.797e-15 \n",
|
|
" 182 -3.904e-15 \n",
|
|
" 183 7.03e-15 \n",
|
|
" 184 2.849e-15 \n",
|
|
" 185 -2.256e-15 \n",
|
|
" 186 2.02e-15 \n",
|
|
" 187 3.979e-16 \n",
|
|
" 188 -1.811e-15 \n",
|
|
" 189 2.02e-15 \n",
|
|
" 190 -8.31e-16 \n",
|
|
" 191 0 \n",
|
|
" 192 2.007e-15 \n",
|
|
" 193 -2.79e-15 \n",
|
|
" 194 0 \n",
|
|
" 195 3.527e-15 \n",
|
|
" 196 -5.021e-15 \n",
|
|
" 197 -3.874e-15 \n",
|
|
" 198 -1.844e-15 \n",
|
|
" 199 5.081e-16 \n",
|
|
" 200 0 \n",
|
|
" 201 -4.036e-15 \n",
|
|
" 202 6.85e-16 \n",
|
|
" 203 -5.581e-15 \n",
|
|
" 204 -5.864e-15 \n",
|
|
" 205 1.635e-15 \n",
|
|
" 206 -7.294e-15 \n",
|
|
" 207 -8.683e-16 \n",
|
|
" 208 -3.651e-15 \n",
|
|
" 209 -1.312e-16 \n",
|
|
" 210 -6.959e-15 \n",
|
|
" 211 -4.865e-15 \n",
|
|
" 212 1.528e-15 \n",
|
|
" 213 -1.928e-15 \n",
|
|
" 214 -3.551e-15 \n",
|
|
" 215 3.246e-15 \n",
|
|
" 216 0 \n",
|
|
" 217 3.698e-15 \n",
|
|
" 218 1.74e-15 \n",
|
|
" 219 4.112e-15 \n",
|
|
" 220 -3.154e-15 \n",
|
|
" 221 1.719e-16 \n",
|
|
" 222 -1.883e-15 \n",
|
|
" 223 -1.395e-16 \n",
|
|
" 224 3.45e-15 \n",
|
|
" 225 3.525e-15 \n",
|
|
" 226 -4.259e-16 \n",
|
|
" 227 3.692e-15 \n",
|
|
" 228 1.502e-16 \n",
|
|
" 229 2.901e-15 \n",
|
|
" 230 4.818e-15 \n",
|
|
" 231 3.617e-15 \n",
|
|
" 232 1.173e-15 \n",
|
|
" 233 4.679e-15 \n",
|
|
" 234 4.893e-15 \n",
|
|
" 235 3.684e-15 \n",
|
|
" 236 7.41e-15 \n",
|
|
" 237 0 \n",
|
|
" 238 -1.761e-15 \n",
|
|
" 239 7.82e-16 \n",
|
|
" 240 1.306e-15 \n",
|
|
" 241 -7.974e-15 \n",
|
|
" 242 -1.807e-15 \n",
|
|
" 243 -7.132e-16 \n",
|
|
" 244 0 \n",
|
|
" 245 3.281e-15 \n",
|
|
" 246 8.649e-15 \n",
|
|
" 247 1.048e-14 \n",
|
|
" 248 3.319e-15 \n",
|
|
" 249 -4.6e-16 \n",
|
|
" 250 1.996e-15 \n",
|
|
" 251 3.33e-15 \n",
|
|
" 252 -1.226e-16 \n",
|
|
" 253 2.128e-15 \n",
|
|
" 254 -1.405e-14 \n",
|
|
" 255 -3.197e-15 \n",
|
|
" 256 3.222e-15 \n",
|
|
" 257 3.815e-15 \n",
|
|
" 258 1.361e-14 \n",
|
|
" 259 1.054e-14 \n",
|
|
" 260 7.209e-15 \n",
|
|
" 261 -7.213e-15 \n",
|
|
" 262 -1.652e-15 \n",
|
|
" 263 2.016e-16 \n",
|
|
" 264 -7.362e-16 \n",
|
|
" 265 -4.098e-15 \n",
|
|
" 266 -5.895e-15 \n",
|
|
" 267 -8.422e-16 \n",
|
|
" 268 -4.317e-16 \n",
|
|
" 269 3.407e-15 \n",
|
|
" 270 -2.196e-15 \n",
|
|
" 271 -2.216e-16 \n",
|
|
" 272 -3.187e-16 \n",
|
|
" 273 1.906e-15 \n",
|
|
" 274 4.433e-15 \n",
|
|
" 275 -3.722e-15 \n",
|
|
" 276 4.478e-15 \n",
|
|
" 277 2.749e-15 \n",
|
|
" 278 1.997e-15 \n",
|
|
" 279 6.178e-15 \n",
|
|
" 280 5.352e-15 \n",
|
|
" 281 3.816e-15 \n",
|
|
" 282 0 \n",
|
|
" 284 4.345e-15 \n",
|
|
" 285 1.062e-14 \n",
|
|
" 286 -7.052e-15 \n",
|
|
" 288 9.538e-15 \n",
|
|
" 290 6.84e-15 \n",
|
|
" 293 1.136e-14 \n",
|
|
" 294 2.485e-15 \n",
|
|
" 295 -1.321e-14 \n",
|
|
" 298 2.783e-15 \n",
|
|
" 303 6.31e-15 \n",
|
|
" 307 5.697e-15 \n",
|
|
" 308 -1.076e-14 \n",
|
|
" 309 7.356e-15 \n",
|
|
" 310 3.072e-15 \n",
|
|
" 311 -6.465e-15 \n",
|
|
" 312 6.144e-15 \n",
|
|
" 313 8.81e-15 \n",
|
|
" 314 7.097e-15 \n",
|
|
" 315 -8.59e-15 \n",
|
|
" 316 4.047e-15 \n",
|
|
" 317 3.918e-16 \n",
|
|
" 318 1.038e-14 \n",
|
|
" 319 -6.812e-15 \n",
|
|
" 320 6.885e-16 \n",
|
|
" 321 -1.572e-14 \n",
|
|
" 322 -7.739e-15 \n",
|
|
" 324 -5.967e-15 \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.h`](http://cantera.org/docs/doxygen/html/ChemEquil_8h.html)."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Chemical Kinetics"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"[`Solution`](http://cantera.github.io/docs/sphinx/html/cython/importing.html#cantera.Solution) objects are also [`Kinetics`](http://cantera.github.io/docs/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](http://cantera.github.io/docs/sphinx/html/cython/zerodim.html#sec-cython-zerodim)* and *[1D flame model](http://cantera.github.io/docs/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`](http://cantera.github.io/docs/sphinx/html/cython/kinetics.html#cantera.Reaction) objects with the [`Kinetics.reaction`](http://cantera.github.io/docs/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": {
|
|
"collapsed": true
|
|
},
|
|
"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([ -1.01643954e-19, -5.08219768e-21, -1.77635684e-15,\n",
|
|
" 9.91028548e-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,\n",
|
|
" 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,\n",
|
|
" -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.720880888"
|
|
]
|
|
},
|
|
"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.720880821"
|
|
]
|
|
},
|
|
"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.2625650223"
|
|
]
|
|
},
|
|
"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.6.2"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|