{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Flame Speed with Sensitivity Analysis"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this example we simulate a freely-propagating, adiabatic, 1-D flame and\n",
"* Calculate its laminar burning velocity\n",
"* Perform a sensitivity analysis of its kinetics\n",
"\n",
"The figure below illustrates the setup, in a flame-fixed co-ordinate system. The reactants enter with density $\\rho_{u}$, temperature $T_{u}$ and speed $S_{u}$. The products exit the flame at speed $S_{b}$, density $\\rho_{b}$ and temperature $T_{b}$."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Import Modules"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running Cantera Version: 2.3.0a3\n"
]
}
],
"source": [
"from __future__ import print_function\n",
"from __future__ import division\n",
"\n",
"import cantera as ct\n",
"import numpy as np\n",
"\n",
"print(\"Running Cantera Version: \" + str(ct.__version__))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Define the reactant conditions, gas mixture and kinetic mechanism associated with the gas"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#Inlet Temperature in Kelvin and Inlet Pressure in Pascals\n",
"#In this case we are setting the inlet T and P to room temperature conditions\n",
"To = 300\n",
"Po = 101325\n",
"\n",
"#Define the gas-mixutre and kinetics\n",
"#In this case, we are choosing a GRI3.0 gas\n",
"gas = ct.Solution('gri30.cti')\n",
"\n",
"# Create a stoichiometric CH4/Air premixed mixture \n",
"gas.set_equivalence_ratio(1.0, 'CH4', {'O2':1.0, 'N2':3.76})\n",
"gas.TP = To, Po"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Define flame simulation conditions"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Domain width in metres\n",
"width = 0.014\n",
"\n",
"# Create the flame object\n",
"flame = ct.FreeFlame(gas, width=width)\n",
"\n",
"# Define tolerances for the solver\n",
"flame.set_refine_criteria(ratio=3, slope=0.1, curve=0.1)\n",
"\n",
"# Define logging level\n",
"loglevel = 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Solve"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"************ Solving on 8 point grid with energy equation enabled ************\n",
"\n",
"..............................................................................\n",
"Attempt Newton solution of steady-state problem... failure. \n",
"Take 10 timesteps 2.136e-05 5.446\n",
"Attempt Newton solution of steady-state problem... failure. \n",
"Take 10 timesteps 0.0003649 4.417\n",
"Attempt Newton solution of steady-state problem... failure. \n",
"Take 10 timesteps 4.871e-05 5.791\n",
"Attempt Newton solution of steady-state problem... failure. \n",
"Take 10 timesteps 2.601e-05 5.905\n",
"Attempt Newton solution of steady-state problem... failure. \n",
"Take 10 timesteps 0.0009998 4.303\n",
"Attempt Newton solution of steady-state problem... success.\n",
"\n",
"Problem solved on [9] point grid(s).\n",
"\n",
"..............................................................................\n",
"grid refinement disabled.\n",
"\n",
"******************** Solving with grid refinement enabled ********************\n",
"\n",
"..............................................................................\n",
"Attempt Newton solution of steady-state problem... success.\n",
"\n",
"Problem solved on [9] point grid(s).\n",
"\n",
"..............................................................................\n",
"##############################################################################\n",
"Refining grid in flame.\n",
" New points inserted after grid points 0 1 2 3 4 5 6 \n",
" to resolve C C2H2 C2H3 C2H4 C2H5 C2H6 C3H7 C3H8 CH CH2 CH2(S) CH2CHO CH2CO CH2O CH2OH CH3 CH3CHO CH3O CH3OH CH4 CO CO2 H H2 H2O H2O2 HCCO HCCOH HCN HCNO HCO HNCO HO2 N N2 N2O NCO NH NO NO2 O O2 OH T u \n",
"##############################################################################\n",
"\n",
"..............................................................................\n",
"Attempt Newton solution of steady-state problem... failure. \n",
"Take 10 timesteps 0.0001709 5.099\n",
"Attempt Newton solution of steady-state problem... failure. \n",
"Take 10 timesteps 0.0003649 4.857\n",
"Attempt Newton solution of steady-state problem... failure. \n",
"Take 10 timesteps 7.306e-05 5.011\n",
"Attempt Newton solution of steady-state problem... success.\n",
"\n",
"Problem solved on [16] point grid(s).\n",
"\n",
"..............................................................................\n",
"##############################################################################\n",
"Refining grid in flame.\n",
" New points inserted after grid points 3 4 5 6 7 8 9 10 \n",
" to resolve C C2H C2H2 C2H3 C2H4 C2H5 C2H6 C3H7 C3H8 CH CH2 CH2(S) CH2CHO CH2CO CH2O CH2OH CH3 CH3CHO CH3O CH3OH CH4 CO CO2 H H2 H2O H2O2 HCCO HCCOH HCN HCNN HCNO HCO HNCO HO2 N N2 N2O NCO NH NH2 NH3 NO NO2 O O2 OH T u \n",
"##############################################################################\n",
"\n",
"..............................................................................\n",
"Attempt Newton solution of steady-state problem... success.\n",
"\n",
"Problem solved on [24] point grid(s).\n",
"\n",
"..............................................................................\n",
"##############################################################################\n",
"Refining grid in flame.\n",
" New points inserted after grid points 4 5 6 7 8 9 10 11 12 13 14 15 20 \n",
" to resolve C C2H C2H2 C2H3 C2H4 C2H5 C2H6 C3H7 C3H8 CH CH2 CH2(S) CH2CHO CH2CO CH2O CH2OH CH3 CH3CHO CH3O CH3OH CH4 CO CO2 H H2 H2O H2O2 HCCO HCCOH HCN HCNO HCO HNCO HO2 N N2 N2O NCO NH NH2 NH3 NO NO2 O O2 OH T u \n",
"##############################################################################\n",
"\n",
"..............................................................................\n",
"Attempt Newton solution of steady-state problem... success.\n",
"\n",
"Problem solved on [37] point grid(s).\n",
"\n",
"..............................................................................\n",
"##############################################################################\n",
"Refining grid in flame.\n",
" New points inserted after grid points 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 \n",
" to resolve C C2H C2H2 C2H3 C2H4 C2H5 C2H6 C3H7 C3H8 CH CH2 CH2(S) CH2CHO CH2CO CH2O CH2OH CH3 CH3CHO CH3O CH3OH CH4 CO CO2 H H2 H2O H2O2 HCCO HCCOH HCN HCNO HCO HNCO HO2 N N2 N2O NCO NO NO2 O O2 OH T u \n",
"##############################################################################\n",
"\n",
"..............................................................................\n",
"Attempt Newton solution of steady-state problem... success.\n",
"\n",
"Problem solved on [52] point grid(s).\n",
"\n",
"..............................................................................\n",
"##############################################################################\n",
"Refining grid in flame.\n",
" New points inserted after grid points 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 \n",
" to resolve C C2H C2H2 C2H3 C2H4 C2H5 C2H6 C3H7 C3H8 CH CH2 CH2(S) CH2CHO CH2CO CH2O CH2OH CH3 CH3CHO CH3O CH3OH CH4 CO CO2 H H2 H2O H2O2 HCCO HCCOH HCN HCNO HCO HNCO HO2 N N2 NO NO2 O O2 OH T u \n",
"##############################################################################\n",
"\n",
"..............................................................................\n",
"Attempt Newton solution of steady-state problem... success.\n",
"\n",
"Problem solved on [70] point grid(s).\n",
"\n",
"..............................................................................\n",
"##############################################################################\n",
"Refining grid in flame.\n",
" New points inserted after grid points 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 67 \n",
" to resolve C C2H C2H2 C2H3 C2H4 C2H5 C2H6 C3H7 C3H8 CH CH2 CH2(S) CH2CHO CH2CO CH2O CH2OH CH3 CH3CHO CH3O CH3OH CH4 CO H H2 H2O H2O2 HCCO HCCOH HCN HCO HNCO HO2 N2 NO NO2 O O2 OH T u \n",
"##############################################################################\n",
"\n",
"..............................................................................\n",
"Attempt Newton solution of steady-state problem... success.\n",
"\n",
"Problem solved on [99] point grid(s).\n",
"\n",
"..............................................................................\n",
"##############################################################################\n",
"Refining grid in flame.\n",
" New points inserted after grid points 28 29 30 31 32 33 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 97 \n",
" to resolve C C2H2 C2H3 C2H4 C2H5 C2H6 C3H8 CH CH2 CH2(S) CH2CO CH2OH CH3 CH3CHO CH3O HCCO HCO point 97 \n",
"##############################################################################\n",
"\n",
"..............................................................................\n",
"Attempt Newton solution of steady-state problem... success.\n",
"\n",
"Problem solved on [129] point grid(s).\n",
"\n",
"..............................................................................\n",
"no new points needed in flame\n",
"Flame Speed is: 37.99 cm/s\n"
]
}
],
"source": [
"flame.solve(loglevel=loglevel, auto=True)\n",
"Su0 = flame.u[0]\n",
"print(\"Flame Speed is: {:.2f} cm/s\".format(Su0*100))\n",
"\n",
"#Note that the variable Su0 will also be used downsteam in the sensitivity analysis"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plot figures\n",
"\n",
"Check and see if all has gone well. Plot temperature and species fractions to see"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Import plotting modules and define plotting preference\n",
"import matplotlib.pylab as plt\n",
"%matplotlib notebook\n",
"\n",
"plt.rcParams['axes.labelsize'] = 14\n",
"plt.rcParams['xtick.labelsize'] = 12\n",
"plt.rcParams['ytick.labelsize'] = 12\n",
"plt.rcParams['legend.fontsize'] = 10\n",
"plt.rcParams['figure.figsize'] = (8,6)\n",
"\n",
"# Get the best of both ggplot and seaborn\n",
"plt.style.use('ggplot')\n",
"plt.style.use('seaborn-deep')\n",
"\n",
"plt.rcParams['figure.autolayout'] = True"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Temperature Plot"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"application/javascript": [
"/* Put everything inside the global mpl namespace */\n",
"window.mpl = {};\n",
"\n",
"mpl.get_websocket_type = function() {\n",
" if (typeof(WebSocket) !== 'undefined') {\n",
" return WebSocket;\n",
" } else if (typeof(MozWebSocket) !== 'undefined') {\n",
" return MozWebSocket;\n",
" } else {\n",
" alert('Your browser does not have WebSocket support.' +\n",
" 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
" 'Firefox 4 and 5 are also supported but you ' +\n",
" 'have to enable WebSockets in about:config.');\n",
" };\n",
"}\n",
"\n",
"mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
" this.id = figure_id;\n",
"\n",
" this.ws = websocket;\n",
"\n",
" this.supports_binary = (this.ws.binaryType != undefined);\n",
"\n",
" if (!this.supports_binary) {\n",
" var warnings = document.getElementById(\"mpl-warnings\");\n",
" if (warnings) {\n",
" warnings.style.display = 'block';\n",
" warnings.textContent = (\n",
" \"This browser does not support binary websocket messages. \" +\n",
" \"Performance may be slow.\");\n",
" }\n",
" }\n",
"\n",
" this.imageObj = new Image();\n",
"\n",
" this.context = undefined;\n",
" this.message = undefined;\n",
" this.canvas = undefined;\n",
" this.rubberband_canvas = undefined;\n",
" this.rubberband_context = undefined;\n",
" this.format_dropdown = undefined;\n",
"\n",
" this.image_mode = 'full';\n",
"\n",
" this.root = $('