Challenge

Week 3 - Adiabatic Flame Temperature calculation

the above program utilizes the cantera library in the python and calculates the Adiabatic flame Temperature by varying equivalence ratios,

import cantera as ct
import numpy as np
import math 
import sys
import csv
import matplotlib.pyplot as plt

"""" RICH mixture
CH4+(2/PHI)(O2+3.76N2)-> (4/PHI-3)CO2 +2H2O+ (7.52/PHI) N2 + (4-4/PHI)CO

LEAN MIXTURE
CH4 +(2/PHI)(O2+3.76N2) ---> CO2 +2H2O+ (7.52/PHI) N2 + (2/PHI-2)O2
"""

Pi=101.325;

"Reactants"
a_ch4_l =(5.14987613E+00,-1.36709788E-02,4.91800599E-05,-4.84743026E-08,1.66693956E-11,-1.02466476E+04,-4.64130376E+00)
a_o2_l=(3.78245636E+00,-2.99673416E-03,9.84730201E-06,-9.68129509E-09,3.24372837E-12,-1.06394356E+03,3.65767573E+00)
 
a_n2_l=(0.03298677E+02,0.14082404E-02,-0.03963222E-04,0.05641515E-07,-0.02444854E-10,-0.10208999E+04,0.03950372E+02)
"products"
a_h2o_h =(3.03399249E+00,2.17691804E-03,-1.64072518E-07,-9.70419870E-11,1.68200992E-14,
-3.00042971E+04,4.96677010E+00) 
a_n2_h=(0.02926640E+02,0.14879768E-02,-0.05684760E-05,0.10097038E-09,-0.06753351E-13,
-0.09227977E+04,0.05980528E+02)
a_co2_h=(3.85746029E+00,4.41437026E-03,-2.21481404E-06,5.23490188E-10,-4.72084164E-14,    
-4.87591660E+04,2.27163806E+00)
a_co_h=(2.71518561E+00 ,2.06252743E-03,-9.98825771E-07,2.30053008E-10,-2.03647716E-14,-1.41518724E+04)
a_o2_h=(3.28253784E+00,1.48308754E-03,-7.57966669E-07, 2.09470555E-10,-2.16717794E-14,-1.08845772E+03)

"constant volume specific enthalpy calculation"

def h(a,T):
    R=8.314;
    Enthalpy = R*T*(a[0] +(a[1]*T*0.5) + (a[2]*pow(T,2)*(1/3)) + (a[3]*pow(T,3)*(1/4)) + (a[4]*pow(T,4)*(1/5)) + (a[5]/T));
    return Enthalpy

def f(T,phi):
  Ti =298.16;
  Ru=8.314;
  """"

LEAN MIXTURE
CH4 +(2/PHI)(O2+3.76N2) ---> (CO2 +2H2O+ (7.52/PHI) N2 + (2/PHI-2)O2
 
 RICH mixture
CH4+(2/PHI)(O2+3.76N2)-> (4/PHI-3)CO2 +2H2O+ (7.52/PHI) N2 + (4-4/PHI)CO
"""
  if phi < 1:
      hr = h(a_ch4_l,Ti) + (2/phi)*h(a_o2_l,Ti) + (7.52/phi)*h(a_n2_l,Ti);
      hp = (h(a_co2_h,T) + 2*h(a_h2o_h,T) + (7.52/phi)*h(a_n2_h,T) + ((2/phi)-2)*h(a_o2_h,T));
      output = (hr-hp)-(Ru*((1+(2/phi)+(7.52/phi))*(Ti)-((1+(2)+(7.52/phi)+((2/phi)-2))*(T))))
  else:
      hr = h(a_ch4_l,Ti) + (2/phi)*h(a_o2_l,Ti) + (7.52/phi)*h(a_n2_l,Ti);
      hp = ((4/phi)-3)*h(a_co2_h,T) + 2*h(a_h2o_h,T) + (7.52/phi)*h(a_n2_h,T) + (4-(4/phi))*h(a_co_h,T);
      output = (hr-hp)-(Ru*((1+(2/phi)+(7.52/phi))*(Ti)-((4/phi-3)+(2)+(7.52/phi)+(4-4/phi))*(T))) 
  return output
   
def  fprime(T,phi):
    return  (f(T+1e-6,phi)-f(T,phi))/(1e-6)
tol =0.001
Tguess = 1500
iter=0
alpha = 0.2
temp=[]
n = np.linspace(0.1,2,50)
for phi in n:
  while (abs(f(Tguess,phi)) > tol): 
    Tguess = Tguess - (alpha*(f(Tguess,phi)/fprime(Tguess,phi)))
    iter = iter+1
  temp.append(Tguess)
gas2 = ct.Solution("gri30.yaml")
Tad =[]
X=[]
for i in range(len(n)):
    gas2.TP = 298.16, ct.one_atm
    gas2.set_equivalence_ratio(n[i], "CH4", "O2:1, N2:3.76")
    gas2.equilibrate("UV",'auto')
    Tad.append(gas2.T)
    X.append(n[i])

plt.plot(X,Tad,"*",color='red')
plt.plot(X,temp,"*",color='blue')

plt.xlabel("equivalence_ratio")
plt.ylabel("AFT")
plt.title("equivalence_ratio vs AFT")
plt.show()

this gives the following output

Graph

The above graph shows the variation of Adiabatic flame temperature in a constant volume process with respect to equivalence ratio, the blue line represents the adiabatic flame temparature calculated by python code, and red line by using the cantera library.

Its observed that the AFT calculated for cantera is smaller at the equivalence ratio closer to stoichometric and the leaner mixture, since the number of species are more in the cantera where as we have a maximum of 6 in python code. Hence the high temperature of AFT .

"""
import cantera as ct
import numpy as np
import math 
import sys
import csv
import matplotlib.pyplot as plt

"""" RICH mixture
CH4+(2/PHI)(O2+3.76N2)-> (4/PHI-3)CO2 +2H2O+ (7.52/PHI) N2 + (4-4/PHI)CO

LEAN MIXTURE
CH4 +(2/PHI)(O2+3.76N2) ---> CO2 +2H2O+ (7.52/PHI) N2 + (2/PHI-2)O2
"""

Pi=101.325;

"Reactants"
a_ch4_l =(5.14987613E+00,-1.36709788E-02,4.91800599E-05,-4.84743026E-08,1.66693956E-11,-1.02466476E+04,-4.64130376E+00)
a_o2_l=(3.78245636E+00,-2.99673416E-03,9.84730201E-06,-9.68129509E-09,3.24372837E-12,-1.06394356E+03,3.65767573E+00)
 
a_n2_l=(0.03298677E+02,0.14082404E-02,-0.03963222E-04,0.05641515E-07,-0.02444854E-10,-0.10208999E+04,0.03950372E+02)
"products"
a_h2o_h =(3.03399249E+00,2.17691804E-03,-1.64072518E-07,-9.70419870E-11,1.68200992E-14,
-3.00042971E+04,4.96677010E+00) 
a_n2_h=(0.02926640E+02,0.14879768E-02,-0.05684760E-05,0.10097038E-09,-0.06753351E-13,
-0.09227977E+04,0.05980528E+02)
a_co2_h=(3.85746029E+00,4.41437026E-03,-2.21481404E-06,5.23490188E-10,-4.72084164E-14,    
-4.87591660E+04,2.27163806E+00)
a_co_h=(2.71518561E+00 ,2.06252743E-03,-9.98825771E-07,2.30053008E-10,-2.03647716E-14,-1.41518724E+04)
a_o2_h=(3.28253784E+00,1.48308754E-03,-7.57966669E-07, 2.09470555E-10,-2.16717794E-14,-1.08845772E+03)

"constant volume specific enthalpy calculation"

def h(a,T):
    R=8.314;
    Enthalpy = R*T*(a[0] +(a[1]*T*0.5) + (a[2]*pow(T,2)*(1/3)) + (a[3]*pow(T,3)*(1/4)) + (a[4]*pow(T,4)*(1/5)) + (a[5]/T));
    return Enthalpy

def f(T,hf):
  Ti =298.16;
  Ru=8.314;
  phi=1;
  """"
LEAN MIXTURE
CH4 +(2/PHI)(O2+3.76N2) ---> (CO2 +2H2O+ (7.52/PHI) N2 + (2/PHI-2)O2
 RICH mixture
CH4+(2/PHI)(O2+3.76N2)-> (4/PHI-3)CO2 +2H2O+ (7.52/PHI) N2 + (4-4/PHI)CO
"""
  hr = h(a_ch4_l,Ti) + (2/phi)*h(a_o2_l,Ti) + (7.52/phi)*h(a_n2_l,Ti);
  hp= h(a_co2_h,T) + 2*h(a_h2o_h,T) + (7.52/phi)*h(a_n2_h,T) + ((2/phi)-2)*h(a_o2_h,T)
  #evaluate the enthalpy of the products
  LHV =hr - (h(a_co2_h,Ti) + 2*h(a_h2o_h,Ti) + (7.52/phi)*h(a_n2_h,Ti) + ((2/phi)-2)*h(a_o2_h,Ti));
  output = (hr-hp)-hf*LHV;
  return output
   
def  fprime(T,hf):
    return  (f(T+1e-6,hf)-f(T,hf))/(1e-6)
tol =0.001
Tguess = 1500
iter=0
alpha = 0.2
temp=[]
n = np.linspace(0,1,10)
for hf in n:
  while (abs(f(Tguess,hf)) > tol): 
    Tguess = Tguess - (alpha*(f(Tguess,hf)/fprime(Tguess,hf)))
    iter = iter+1
  temp.append(Tguess)

plt.plot(n,temp,"*",color='blue')
plt.xlabel("Heat loss factor")
plt.ylabel("AFT")
plt.title("Heat loss factor vs AFT")
plt.show()

The above code depicts the variation of adiabatic flame temperature with heat loss factor,

The heat loss factor is fraction which varies from 0 to 1 , this is an multiplier to LHV, which is the maximum amount of heat capacity which is released when the reactants are combusted.

The above plot shows the heat loss factor vs the adiabatic flame temperature

In the last part of this challenge we calculate the adiabatic flame temperature by varying the number of bonds , viz: alkane , alkene and alkyne

# -*- coding: utf-8 -*-
"""
Created on Sat Oct 29 23:29:21 2022

@author: saikr
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Oct 29 18:45:27 2022

@author: saikr
"""

# -*- coding: utf-8 -*-
"""AFT_UPDATED.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/19f5kOlBprpzGnRWywh-Yhj9tQBHILnGg
"""
import cantera as ct
import numpy as np
import math 
import sys
import csv
import matplotlib.pyplot as plt

"""" RICH mixture
CH4+(2/PHI)(O2+3.76N2)-> (4/PHI-3)CO2 +2H2O+ (7.52/PHI) N2 + (4-4/PHI)CO

LEAN MIXTURE
CH4 +(2/PHI)(O2+3.76N2) ---> CO2 +2H2O+ (7.52/PHI) N2 + (2/PHI-2)O2
"""

Pi=101.325;

"Reactants"
a_ch4_l =(5.14987613E+00,-1.36709788E-02,4.91800599E-05,-4.84743026E-08,1.66693956E-11,-1.02466476E+04,-4.64130376E+00)
a_o2_l=(3.78245636E+00,-2.99673416E-03,9.84730201E-06,-9.68129509E-09,3.24372837E-12,-1.06394356E+03,3.65767573E+00)
a_c2h2_l =(8.08681094E-01,2.33615629E-02,-3.55171815E-05,2.80152437E-08,-8.50072974E-12, 2.64289807E+04, 1.39397051E+01)
a_c2h4_l=(3.95920148E+00,-7.57052247E-03, 5.70990292E-05,-6.91588753E-08, 2.69884373E-11, 5.08977593E+03, 4.09733096E+00)
a_n2_l=(0.03298677E+02,0.14082404E-02,-0.03963222E-04,0.05641515E-07,-0.02444854E-10,-0.10208999E+04,0.03950372E+02)
"products"
a_h2o_h =(3.03399249E+00,2.17691804E-03,-1.64072518E-07,-9.70419870E-11,1.68200992E-14,
-3.00042971E+04,4.96677010E+00) 
a_n2_h=(0.02926640E+02,0.14879768E-02,-0.05684760E-05,0.10097038E-09,-0.06753351E-13,
-0.09227977E+04,0.05980528E+02)
a_co2_h=(3.85746029E+00,4.41437026E-03,-2.21481404E-06,5.23490188E-10,-4.72084164E-14,    
-4.87591660E+04,2.27163806E+00)
a_co_h=(2.71518561E+00 ,2.06252743E-03,-9.98825771E-07,2.30053008E-10,-2.03647716E-14,-1.41518724E+04)
a_o2_h=(3.28253784E+00,1.48308754E-03,-7.57966669E-07, 2.09470555E-10,-2.16717794E-14,-1.08845772E+03)

"constant volume specific enthalpy calculation"

def h(a,T):
    R=8.314;
    Enthalpy = R*T*(a[0] +(a[1]*T*0.5) + (a[2]*pow(T,2)*(1/3)) + (a[3]*pow(T,3)*(1/4)) + (a[4]*pow(T,4)*(1/5)) + (a[5]/T));
    return Enthalpy

def f(T,n):
  Ti =298.16;
  Ru=8.314;
  phi=1;
  if n==1:
      hr = h(a_ch4_l,Ti) + (2/phi)*h(a_o2_l,Ti) + (7.52/phi)*h(a_n2_l,Ti);
      hp= h(a_co2_h,T) + 2*h(a_h2o_h,T) + (7.52/phi)*h(a_n2_h,T) + ((2/phi)-2)*h(a_o2_h,T)
      #evaluate the enthalpy of the products
      output = (hr-hp);
  if n == 2:
      hr = h(a_c2h4_l,Ti) + 3*h(a_o2_l,Ti) + (7.52/phi)*h(a_n2_l,Ti);
      hp= 3*h(a_co2_h,T) + 2*h(a_h2o_h,T) + (7.52/phi)*h(a_n2_h,T); 
      #evaluate the enthalpy of the products
      output = (hr-hp);
  if n==3:
       hr = 2*h(a_c2h2_l,Ti) + 5*h(a_o2_l,Ti) + (7.52/phi)*h(a_n2_l,Ti);
       hp= 4*h(a_co2_h,T) + 2*h(a_h2o_h,T) + (7.52/phi)*h(a_n2_h,T) 
       #evaluate the enthalpy of the products
       output = (hr-hp);
   
      
  """"
LEAN MIXTURE
CH4 +(2/PHI)(O2+3.76N2) ---> (CO2 +2H2O+ (7.52/PHI) N2 + (2/PHI-2)O2
alkyne
2C2H2 +5O2---> 4CO2+2H2O
alkene
C2H4 + 3O2 ---> 3CO2 + 2H2O
 RICH mixture
CH4+(2/PHI)(O2+3.76N2)-> (4/PHI-3)CO2 +2H2O+ (7.52/PHI) N2 + (4-4/PHI)CO
"""
  
  return output
   
def  fprime(T,n):
    return  (f(T+1e-6,n)-f(T,n))/(1e-6)
tol =0.001
Tguess = 1500
iter=0
alpha = 0.2
temp=[]
k = np.linspace(1,3,3)
print(k)
for j in k:
  while (abs(f(Tguess,j)) > tol): 
    Tguess = Tguess - (alpha*(f(Tguess,j)/fprime(Tguess,j)))
    iter = iter+1
  temp.append(Tguess)

plt.plot(k,temp,"*",color='blue')
plt.xlabel("ALkane , alkene, alkyne ")
plt.ylabel("AFT")
plt.title("Type of bonds vs AFT")
plt.show()

The above code uses n =1 to 3 for alkane , alkene and alkyne respectively , the output of the code gives the below plot

It can be seen from the above plot that as we increase the no of bonds AFT also raises , highest is alkynes and lowest is for alkane (Methane) in our case

Last part of the challenge deals with increasing the number of carbon chains in alkane group ch4,c2h6 and c3h8

# -*- coding: utf-8 -*-
"""
Created on Sat Oct 29 23:29:21 2022

@author: saikr
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Oct 29 18:45:27 2022

@author: saikr
"""

# -*- coding: utf-8 -*-
"""AFT_UPDATED.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/19f5kOlBprpzGnRWywh-Yhj9tQBHILnGg
"""
import cantera as ct
import numpy as np
import math 
import sys
import csv
import matplotlib.pyplot as plt

"""" RICH mixture
CH4+(2/PHI)(O2+3.76N2)-> (4/PHI-3)CO2 +2H2O+ (7.52/PHI) N2 + (4-4/PHI)CO

LEAN MIXTURE
CH4 +(2/PHI)(O2+3.76N2) ---> CO2 +2H2O+ (7.52/PHI) N2 + (2/PHI-2)O2
"""

Pi=101.325;

"Reactants"
a_ch4_l =(5.14987613E+00,-1.36709788E-02,4.91800599E-05,-4.84743026E-08,1.66693956E-11,-1.02466476E+04,-4.64130376E+00)
a_o2_l=(3.78245636E+00,-2.99673416E-03,9.84730201E-06,-9.68129509E-09,3.24372837E-12,-1.06394356E+03,3.65767573E+00)
a_c2h2_l =(8.08681094E-01,2.33615629E-02,-3.55171815E-05,2.80152437E-08,-8.50072974E-12, 2.64289807E+04, 1.39397051E+01)
a_c2h4_l=(3.95920148E+00,-7.57052247E-03, 5.70990292E-05,-6.91588753E-08, 2.69884373E-11, 5.08977593E+03, 4.09733096E+00)
a_c2h6_l=(4.29142492E+00,-5.50154270E-03, 5.99438288E-05, -7.08466285E-08, 2.68685771E-11,-1.15222055E+04, 2.66682316E+00)
a_c3h8_l=(0.93355381E+00, 0.26424579E-01, 0.61059727E-05,-0.21977499E-07, 0.95149253E-11,-0.13958520E+05 ,0.19201691E+02)
a_n2_l=(0.03298677E+02,0.14082404E-02,-0.03963222E-04,0.05641515E-07,-0.02444854E-10,-0.10208999E+04,0.03950372E+02)
"products"
a_h2o_h =(3.03399249E+00,2.17691804E-03,-1.64072518E-07,-9.70419870E-11,1.68200992E-14,
-3.00042971E+04,4.96677010E+00) 
a_n2_h=(0.02926640E+02,0.14879768E-02,-0.05684760E-05,0.10097038E-09,-0.06753351E-13,
-0.09227977E+04,0.05980528E+02)
a_co2_h=(3.85746029E+00,4.41437026E-03,-2.21481404E-06,5.23490188E-10,-4.72084164E-14,    
-4.87591660E+04,2.27163806E+00)
a_co_h=(2.71518561E+00 ,2.06252743E-03,-9.98825771E-07,2.30053008E-10,-2.03647716E-14,-1.41518724E+04)
a_o2_h=(3.28253784E+00,1.48308754E-03,-7.57966669E-07, 2.09470555E-10,-2.16717794E-14,-1.08845772E+03)

"constant volume specific enthalpy calculation"

def h(a,T):
    R=8.314;
    Enthalpy = R*T*(a[0] +(a[1]*T*0.5) + (a[2]*pow(T,2)*(1/3)) + (a[3]*pow(T,3)*(1/4)) + (a[4]*pow(T,4)*(1/5)) + (a[5]/T));
    return Enthalpy

def f(T,n):
  Ti =298.16;
  Ru=8.314;
  phi=1;
  if n==1:
      hr = h(a_ch4_l,Ti) + (2/phi)*h(a_o2_l,Ti) + (7.52/phi)*h(a_n2_l,Ti);
      hp= h(a_co2_h,T) + 2*h(a_h2o_h,T) + (7.52/phi)*h(a_n2_h,T) + ((2/phi)-2)*h(a_o2_h,T)
      #evaluate the enthalpy of the products
      output = (hr-hp);
  if n == 2:
      hr = h(a_c2h6_l,Ti) + 4*h(a_o2_l,Ti) + (7.52/phi)*h(a_n2_l,Ti);
      hp= 4*h(a_co2_h,T) + 6*h(a_h2o_h,T) + (7.52/phi)*h(a_n2_h,T); 
      #evaluate the enthalpy of the products
      output = (hr-hp);
  if n==3:
       hr = 2*h(a_c3h8_l,Ti) + 5*h(a_o2_l,Ti) + (7.52/phi)*h(a_n2_l,Ti);
       hp= 3*h(a_co2_h,T) + 4*h(a_h2o_h,T) + (7.52/phi)*h(a_n2_h,T) 
       #evaluate the enthalpy of the products
       output = (hr-hp);
   
      
  """"
LEAN MIXTURE
CH4 +(2/PHI)(O2+3.76N2) ---> (CO2 +2H2O+ (7.52/PHI) N2 + (2/PHI-2)O2
alkyne
2C2H2 +5O2---> 4CO2+2H2O
alkene
C2H4 + 3O2 ---> 3CO2 + 2H2O
 RICH mixture
CH4+(2/PHI)(O2+3.76N2)-> (4/PHI-3)CO2 +2H2O+ (7.52/PHI) N2 + (4-4/PHI)CO
"""
  
  return output
   
def  fprime(T,n):
    return  (f(T+1e-6,n)-f(T,n))/(1e-6)
tol =0.001
Tguess = 1500
iter=0
alpha = 0.2
temp=[]
k = np.linspace(1,3,3)
print(k)
for j in k:
  while (abs(f(Tguess,j)) > tol): 
    Tguess = Tguess - (alpha*(f(Tguess,j)/fprime(Tguess,j)))
    iter = iter+1
  temp.append(Tguess)

plt.plot(k,temp,"*",color='blue')
plt.xlabel("ch4,c2h6,c3h8 ")
plt.ylabel("AFT")
plt.title("Number of carbon chains vs AFT")
plt.show()

the below plot shows the variation of AFT for the three

its observed the C2H6 has highest AFT .

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.