All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM - To calculate the adiabatic flame temperature using python and cantera OBJECTIVES - To calculate the adiabatic flame temperature in a constant volume chamber with variation in rquivalence ratio. To calculate the flame temperature with variation in the heat loss To calcualte the adiabatic flame…
Amol Patel
updated on 03 Sep 2021
AIM -
To calculate the adiabatic flame temperature using python and cantera
OBJECTIVES -
To calculate the adiabatic flame temperature in a constant volume chamber with variation in rquivalence ratio.
To calculate the flame temperature with variation in the heat loss
To calcualte the adiabatic flame temperature variation with respect to alkane, alkene and alkyne
To calcualte the adaibatic flame temperature variation with respect to number of carbon atoms
INTRODUCTION -
Adiabatic flame temperature is the temperature of the flame that is generated when a given amount of fuel in burnt completely inside an adiabatic chamber either with constant volume or constant pressure.
To calculate the adiabatic flame temperature we will be using a method called as Newton Raphson Method. In this method good approximation for the roots of a real valued function can be found out quickly. It uses the idea that a continuous and differentiable function can be approximated by a straigh line tangent to it.
Suppose you need to find the root of a continuous, differentiable function f(x), and you know the root you are looking for is near the point x=xo. Then Newton's method tells us that a better approximation for the root is
x1=xo-f(xo)f′(xo)
This process is repeated until the desired accuracy is reached , in general for any x having value xn the next value can be given by
xn+1=xn-f(xn)f′(xn)
the graphical representation of the Newton-Raphson method is shown below
NASA Polynomials to calulate the thermodynamic properties :
To calculate the thermodynamic properties like the specific heat, enthalpy and entropy we will be using the nasa polynomials that are shown below
in this polynomials the coefficients a1, a2, a3 untill a7 can be found in the Thermodynamic CHEMKIN file from the website of the university of Berkeley. this file contains the data for the coefficients for alot of chemical species , a small number of species can be seen in the following image
there are two sets of coefficients for each species one set is for temperature above 1000K and another set is for temperature below 1000K this coefficients are listed in the row 2,3,4 as numbered on the right side.
PART 1 - Adiabatic flame temperature variation with Equivalence ratio (In constant volume-chamber) :
In this part we will be :
For Methane as fuel the chemical reation will be
CH4 + 2 (O2 + 3.76 N2) => CO2 + 2 H2O + 7.52 N2
here we have a constant volume chamber so ΔV=0
enthalpy : H=U+PV
differenetiating enthalpy : ΔH=ΔU+ΔP.V...............(1)
also from the first law : dU=dQ-PΔV
since we have a constant volume and adiabatic chamber dU=0............(2)
from (1) and (2) we get
ΔH-VΔP=0........(3)
now we know
PV=nRuT
so for the reactants we have PiV=nrRuTi
and for the products PfV=npRuTforad
So the equation (3) becomes
Hr-Hp-Ru.(nrTi-npTad)=0
So we have our equation that we will be using in the Newton Raphson method to find the roots that is the adiabatic flame temperature
also in this case we will be having a range of equivalence ratio so that we can observe that variation in the adiabatic flame temperature with change in the equivalence ratio.
equivalence ratio (ϕ)=fuelair(fuelair)∣stoichiometric
When thare is excess of air present in the mixture , the equivalence ratio is lower than 1 and the mixture of fuel and air is called lean mixture and oxygen is present in the products part as well.
For Lean Mixture : CH4 + x (O2 + 3.76 N2) => a CO2 + b H2O + 3.76*x N2 + c O2
ϕ=1x12
therefore , x=2ϕ
carbon : a = 1,
hydrogen: b = 2,
oxygen: 2x = 2a + b + 2c => c = x - 2 => c = 2ϕ- 2
the equation for lean mixture (ϕ<1) becomes :
CH4 + 2ϕ ( O2 + 3.76 N2) => CO2 + 2 H2O + 7.52ϕ N2 + 2ϕ-2 O2
When there is excess of fuel present in the mixture , the equivalence ratio becomes greater than 1 and the mixture is called rich mixture and we get incompletely burnt fuel as cabon monooxide on the products side
For Rich Mixture : CH4 + x (O2 + 3.76 N2) => a CO2 + b H2O + 3.76*x N2 + c CO
from the equivalence ratio: x = 2ϕ
carbon: 1 = a+c
hydrogen: 4=2b => b=2
oxygen: 2x = 2a + b + c => 2*2ϕ = a + b + (a+c) => a = 4ϕ- 3
c = 4 - 4ϕ
the equation for rich mixture (ϕ>1) becomes :
CH4 + 2ϕ ( O2 + 3.76 N2) => 4ϕ- 3 CO2 + 2 H2O + 7.52ϕ N2 + 4 - 4ϕ O2
To calculate the AFT using cantera first we will import the cantera library than use the 'gri30.xml' Solution to assign gas as methane here we will give the STP conditions and the mole factions as the inputs and use the equilibrate method to find the AFT and for the parameter we will use UV as the internal energy and the volume is constant in ur combustion of constant volume chamber and use the solver parameter as 'auto'.
The python code for the calculation of Adiabatic flame temperature is given below:
"""
In this code we are going to write the program to calculate the
Adiabatic Flame Temperature(AFT) at constant volume at different
equivalence ratios
Chemical equation
For Stiochometric ratio :: CH4 + 2 (O2 + 3.76 N2) => CO2 + 2 H2o + 7.52 N2
For lean mixture:: CH4 + 2/eq (O2 + 3.76 N2) => CO2 + 2 H2o + (7.52/eq) N2 + (2/eq - 2) O2
For Rich mixture:: CH4 + 2/eq (O2 + 3.76 N2) => (4/eq - 3) CO2 + 2 H2O + (7.52/eq) N2 + (4-4/eq) CO
Program by - Amol Patel
"""
import matplotlib.pyplot as plt
import math
import numpy as np
# universal gas constant
R = 8.314 #[J/mol-K]
def h (T, co_effs):
"""
Function to calculate the Enthalpy
"""
a1 = co_effs[0]
a2 = co_effs[1]
a3 = co_effs[2]
a4 = co_effs[3]
a5 = co_effs[4]
a6 = co_effs[5]
a7 = co_effs[6]
return (a1 + a2*T/2 + a3*pow(T,2)/3 + a4*pow(T,3)/4 + a5*pow(T,4)/5 + a6/T)*R*T
ch4_coeffs_l = [5.14987613E+00,-1.36709788E-02, 4.91800599E-05,-4.84743026E-08, 1.66693956E-11,-1.02466476E+04,-4.64130376E+00]
o2_coeffs_l = [3.78245636E+00,-2.99673416E-03 ,9.84730201E-06,-9.68129509E-09 ,3.24372837E-12,-1.06394356E+03 ,3.65767573E+00]
o2_coeffs_h = [3.28253784E+00 ,1.48308754E-03,-7.57966669E-07 ,2.09470555E-10,-2.16717794E-14,-1.08845772E+03 ,5.45323129E+00]
n2_coeffs_l = [0.03298677E+02 ,0.14082404E-02,-0.03963222E-04,0.05641515E-07,-0.02444854E-10,-0.10208999E+04 ,0.03950372E+02]
n2_coeffs_h = [0.02926640E+02 ,0.14879768E-02,-0.05684760E-05 ,0.10097038E-09,-0.06753351E-13,-0.09227977E+04 ,0.05980528E+02]
co2_coeffs_h = [3.85746029E+00 ,4.41437026E-03,-2.21481404E-06 ,5.23490188E-10,-4.72084164E-14,-4.87591660E+04 ,2.27163806E+00]
h2o_coeffs_h = [3.03399249E+00 ,2.17691804E-03,-1.64072518E-07,-9.70419870E-11 ,1.68200992E-14,-3.00042971E+04 ,4.96677010E+00]
co_coeffs_h = [2.71518561E+00 ,2.06252743E-03,-9.98825771E-07 ,2.30053008E-10,-2.03647716E-14,-1.41518724E+04 ,7.81868772E+00]
# eq is the notation for equivalence ratio
def f(T,eq):
"""
Function that represents root finding problem
"""
# temp at STP
Tstd = 298.15 #[K]
# enthaly for each reactant
h_ch4_r = h(Tstd,ch4_coeffs_l)
h_o2_r = h(Tstd,o2_coeffs_l)
h_n2_r = h(Tstd,n2_coeffs_l)
# total enthalpy of the reactants
H_reactants = h_ch4_r + 2/eq*(h_o2_r + 3.76*h_n2_r)
# number of moles of reactant
N_reactants = 1+2/eq*(1+3.76)
# enthaly for each product
h_co2_p = h(T,co2_coeffs_h)
h_h2o_p = h(T,h2o_coeffs_h)
h_n2_p = h(T,n2_coeffs_h)
h_o2_p = h(T,o2_coeffs_h)
h_co_p = h(T,co_coeffs_h)
#for lean mixture
if eq <= 1:
# total enthalpy of products for lean mixture
H_products = h_co2_p + 2*h_h2o_p + 7.52/eq*h_n2_p +(2/eq -2)*h_o2_p
# total number of moles of product
N_products = 1 + 2 + 7.52/eq + 2/eq- 2
#for rich mixture
else:
# total enthalpy of products for rich mixture
H_products = (4/eq - 3)*h_co2_p + 2*h_h2o_p + 7.52/eq*h_n2_p + (4 - 4/eq)*h_co_p
# total number of moles of product
N_products = 4/eq -3 + 2 + 7.52/eq + 4 - 4/eq
return (H_reactants - H_products - R*(N_reactants*Tstd - N_products*T))
def fprime(T,eq):
"""
fuction of find the derivative of the Function f
"""
return (f(T+1e-6,eq) - f(T,eq))/1e-6
# temperature array for the python part
T_python = []
# assigning a range for equivalence ratio
eq = np.linspace(0.2,2.0,50)
for i in eq:
#guess value for temp
T_guess = 1000
alpha = 0.5 # relaxation factor
iter = 0 # iteration number
tol = 1e-6 # tollerence
# Newton_Raphson Method
while (abs(f(T_guess,i) > tol)):
T_guess = T_guess - alpha*(f(T_guess,i)/(fprime(T_guess,i)))
iter = iter + 1
# adding the temp for each value of equivalence ratio in the temperature array
T_python.append(T_guess)
# plotting the variation of temperature with change in equivalence ratio
plt.plot(i,T_guess,"*", color = "red")
print("Temperature by Python: \n",T_python)
################################## CANTERA-PART #######################################################
import cantera as ct
#temperature array for the cantera part
T_ct = []
for j in eq:
# assigning gas a methane
gas = ct.Solution("gri30.xml")
# assigning the STP value and the mole fraction for the gas
gas.TPX = 298.15, 101325, {'CH4':1 , 'O2':2/j, 'N2':7.52/j}
# using the gas equilibrate method with constant internal energy and volume along with "auto" solver
gas.equilibrate('UV', 'auto')
# adding the value of temperature in the array
T_ct.append(gas.T)
# plotting the variation of temperature with change in the equivalence ratio
plt.plot(j,gas.T,"o", color = 'blue')
print("Temperature by Cantera: \n",T_ct)
# adding labels to plot
plt.xlabel("equivalence-ratio")
plt.ylabel("temperature")
plt.grid("on")
plt.show()
after runnig the code we get the output of the plot as shown below
also the temperature array will be printed on the output window
Conclusion for part 1:
PART 2 - Flame temperature variation with Heat loss (In constant pressure-chamber) :
In this part we will :
For Methane as fuel the chemical reation will be
CH4 + 2 (O2 + 3.76 N2) => CO2 + 2 H2O + 7.52 N2
here we have a constant pressure chamber so ΔP=0
enthalpy : H=U+PV
differenetiating enthalpy : ΔH=ΔU+ΔP.V+P.ΔV
∴ΔH=ΔU+P.ΔV................(1)
also from the first law : dU=dQ-PΔV...............(2)
from (1) and (2) we get
ΔH=ΔQ-P.ΔV+P.ΔV
ΔH=ΔQ
∴ΔH- ΔQ=0............(3)
in the above equation it is assumed all the heat is lost but for our calcualtion we will have to vary the heat loss factor that is the amount of heat lost from the chamber.
ΔQ=Loss
for maximum heat loss for the reaction is given in the above image has the enthalpy at the STP temperature and it is known as Lower Heating Value (LHV)
The total loss will be the product of heat loss factor and the maximum heat loss
Loss=H_loss_factor⋅Maximum heat loss(LHV)
now our equation (3) becomes
Hr-Hp-Loss
Now we have our equation which is a fucntion of temperature that will be used to calculate the flame temperture using the Newton-Raphson method
here we will be varying the heat loss factor from 0 to 1 to see the variation in the flame temperature
The Python code for the same is shown below:
"""
Program to calculate the Flame Temperature variation with Heat loss in constant pressure chamber
Chemical equation
CH4 + 2 (O2 + 3.76 N2) => CO2 + 2 H2o + 7.52 N2
Program by - Amol Patel
"""
import matplotlib.pyplot as plt
import math
import numpy as np
def h(T,co_effs):
"""
function to evaluate enthalpy
"""
R = 8.314 #J/mol-K
a1 = co_effs[0]
a2 = co_effs[1]
a3 = co_effs[2]
a4 = co_effs[3]
a5 = co_effs[4]
a6 = co_effs[5]
a7 = co_effs[6]
return (a1 + a2*T/2 + a3*pow(T,2)/3 + a4*pow(T,3)/4 + a5*pow(T,4)/5 + a6/T )*R*T
ch4_coeffs_l = [5.14987613E+00,-1.36709788E-02, 4.91800599E-05,-4.84743026E-08 ,1.66693956E-11,-1.02466476E+04,-4.64130376E+00]
o2_coeffs_l = [3.78245636E+00,-2.99673416E-03 ,9.84730201E-06,-9.68129509E-09, 3.24372837E-12,-1.06394356E+03 ,3.65767573E+00]
n2_coeffs_l = [0.03298677E+02 ,0.14082404E-02,-0.03963222E-04,0.05641515E-07,-0.02444854E-10,-0.10208999E+04 ,0.03950372E+02 ]
n2_coeffs_h = [0.02926640E+02 ,0.14879768E-02,-0.05684760E-05 ,0.10097038E-09,-0.06753351E-13,-0.09227977E+04 ,0.05980528E+02]
co2_coeffs_h = [3.85746029E+00 ,4.41437026E-03,-2.21481404E-06, 5.23490188E-10,-4.72084164E-14,-4.87591660E+04 ,2.27163806E+00]
co2_coeffs_l = [ 2.35677352E+00 ,8.98459677E-03,-7.12356269E-06,2.45919022E-09,-1.43699548E-13,-4.83719697E+04 ,9.90105222E+00]
h2o_coeffs_h = [3.03399249E+00, 2.17691804E-03,-1.64072518E-07,-9.70419870E-11, 1.68200992E-14,-3.00042971E+04 ,4.96677010E+00]
h2o_coeffs_l = [4.19864056E+00,-2.03643410E-03 ,6.52040211E-06,-5.48797062E-09 ,1.77197817E-12,-3.02937267E+04,-8.49032208E-01]
def f(T,H_loss_factor):
"""
Function that represents the root finding problem
"""
# enthalpy of each products
h_co2_p = h(T,co2_coeffs_h)
h_h2o_p = h(T,h2o_coeffs_h)
h_n2_p = h(T,n2_coeffs_h)
# total enthalpt of products
H_products = h_co2_p + 2*h_h2o_p + 7.52*h_n2_p
# temperature at STP
Tstd = 298.15
# enthalpy for each reactants
h_ch4_r = h(Tstd,ch4_coeffs_l)
h_o2_r = h(Tstd,o2_coeffs_l)
h_n2_r = h(Tstd,n2_coeffs_l)
# total enthalpy of the reactants
H_reactants = h_ch4_r + 2*h_o2_r + 7.52*h_n2_r
# Lower Heating Values
LHV = (h(Tstd,co2_coeffs_l) + 2*h(Tstd,h2o_coeffs_l) + 7.52*h(Tstd,n2_coeffs_l)) - (h(Tstd,ch4_coeffs_l) + 2*h(Tstd,o2_coeffs_l) + 7.52*h(Tstd,n2_coeffs_l))
# loss in heat genrated
Loss = H_loss_factor * LHV
return (H_products - H_reactants) - Loss
def fprime(T,H_loss_factor):
"""
function to get the derivative of the function f
"""
return (f(T+1e-6,H_loss_factor) -f(T,H_loss_factor))/1e-6
# guess values for temperature
T_guess = 1500
# range of heat loss factor is between 0 and 1
H_loss_factor = np.linspace(0,1,101)
# assigning a empty array for the temperature values to be stored after calculation for each value of heat loss factor
temp = []
for i in H_loss_factor:
tol = 1e-6 # tollerence
ct = 0 # number of iteration
alpha = 0.5 # relaxation factor
# Newton Raphson Method
while (abs(f(T_guess,i)) > tol):
T_guess = T_guess - alpha*((f(T_guess,i)/fprime(T_guess,i)))
ct = ct + 1
# plotting for variation of temperature with the heat loss factor
plt.plot(i,T_guess,"o", color = 'blue')
temp.append(T_guess) # adding the the calculated value of temperature to the array
#output as temperature array
print("temperature: \n",temp)
plt.xlabel("Heat-loss-factor")
plt.ylabel("temperature")
plt.grid("on")
plt.show()
the output for the temperature in the output window is shown below
also the output plot for the variation in flame temperature with variation in heat loss factor is shown below
Conclusioin for part 2 :
PART 3 - Adiabatic flame temperature variation with respect to Alkane, Alkene, Alkyne :
In this part we will
For this part, the Chemical reaction for alkane, alkene and alkyne for 2 carbon atoms can be given as
Alkane Reaction: C2H6 + 7/2 ( O2 + 3.76 N2) => 2 CO2 + 3 H2O + 7/2*3.76 N2
Alkene Reaction: C2H4 + 3 (O2 + 3.76 N2) => 2 CO2 + 2 H2O + 3*3.76 N2
Alkyne Reaction: C2H2 + 5/2 (O2 + 3.76 N2) => 2 CO2 + H2O + 5/2*3.76 N2
Using this above reation assuming constant pressure and the equivalence ratio is 1, we will calculate the Adiabatic Flame Temerature
the equation this is the function of temperature for this case will be as shown below
ΔH=0
∴Hreactant-Hproduct=0
The Python code for the same calculation is shown below:
"""
In this code we are going to write a program to calculate the AFT of alkane, alkene and alkyne
that is for a 2 carbon atom chain with differnt number of bonds
Chemical equations:
ALkanes
C2H6 + 7/2 ( O2 + 3.76 N2 ) => 2 CO2 + 3 H2O + 7/2*3.76 N2
Alkenes
C2H4 + 3 ( O2 + 3.76 N2 ) => 2 CO2 + 2 H2O + 3*3.76 N2
Alkynes
C2H2 + 5/2 ( O2 +3.76 N2 ) => 2 CO2 + H2O + 5/2*3.76 N2
Program by - Amol Patel
"""
import matplotlib.pyplot as plt
import math
import numpy as np
def h(T,co_effs):
"""
function to evaluate enthalpy
"""
R = 8.314 #J/mol-K
a1 = co_effs[0]
a2 = co_effs[1]
a3 = co_effs[2]
a4 = co_effs[3]
a5 = co_effs[4]
a6 = co_effs[5]
a7 = co_effs[6]
return (a1 + a2*T/2 + a3*pow(T,2)/3 + a4*pow(T,3)/4 + a5*pow(T,4)/5 + a6/T )*R*T
c2h6_coeffs_l = [4.29142492E+00,-5.50154270E-03 ,5.99438288E-05,-7.08466285E-08 ,2.68685771E-11,-1.15222055E+04 ,2.66682316E+00]
c2h4_coeffs_l = [3.95920148E+00,-7.57052247E-03 ,5.70990292E-05,-6.91588753E-08 ,2.69884373E-11 ,5.08977593E+03 ,4.09733096E+00]
c2h2_coeffs_l = [8.08681094E-01, 2.33615629E-02,-3.55171815E-05, 2.80152437E-08,-8.50072974E-12, 2.64289807E+04, 1.39397051E+01]
o2_coeffs_l = [3.78245636E+00,-2.99673416E-03 ,9.84730201E-06,-9.68129509E-09, 3.24372837E-12,-1.06394356E+03 ,3.65767573E+00]
n2_coeffs_l = [0.03298677E+02 ,0.14082404E-02,-0.03963222E-04,0.05641515E-07,-0.02444854E-10,-0.10208999E+04 ,0.03950372E+02 ]
n2_coeffs_h = [0.02926640E+02 ,0.14879768E-02,-0.05684760E-05 ,0.10097038E-09,-0.06753351E-13,-0.09227977E+04 ,0.05980528E+02]
co2_coeffs_h = [3.85746029E+00 ,4.41437026E-03,-2.21481404E-06, 5.23490188E-10,-4.72084164E-14,-4.87591660E+04 ,2.27163806E+00]
h2o_coeffs_h = [3.03399249E+00, 2.17691804E-03,-1.64072518E-07,-9.70419870E-11, 1.68200992E-14,-3.00042971E+04 ,4.96677010E+00]
def f(T,n_bonds):
"""
Function that represents the root finding problem
"""
Tstd = 298.15
# calculating the enthalpy of each species on the reactants side
h_o2_r = h(Tstd,o2_coeffs_l)
h_n2_r = h(Tstd,n2_coeffs_l)
h_c2h6_r = h(Tstd,c2h6_coeffs_l)
h_c2h4_r = h(Tstd,c2h4_coeffs_l)
h_c2h2_r = h(Tstd,c2h2_coeffs_l)
# calculating the enthalpy of each species on the products side
h_co2_p = h(T,co2_coeffs_h)
h_h2o_p = h(T,h2o_coeffs_h)
h_n2_p = h(T,n2_coeffs_h)
# n_bonds is the number of bonds between carbon atoms
if n_bonds == 1:
# for alkane
# enthalpy of reactant and products
H_reactants = h_c2h6_r + 7/2*(h_o2_r + 3.76*h_n2_r)
H_products = 2*h_co2_p + 3*h_h2o_p + 7/2*3.76*h_n2_p
elif n_bonds == 2:
# for alkene
# enthalpy of reactant and products
H_reactants = h_c2h4_r + 3*(h_o2_r + 3.76*h_n2_r)
H_products = 2*h_co2_p + 2*h_h2o_p + 3*3.76*h_n2_p
else:
#for alkyne
# enthalpy of reactant and products
H_reactants = h_c2h2_r +5/2*(h_o2_r + 3.76*h_n2_r)
H_products = 2*h_co2_p + h_h2o_p + 5/2*3.76*h_n2_p
return H_products - H_reactants
def fprime(T,n_bonds):
"""
function to get the derivative of the function f
"""
return (f(T+1e-6,n_bonds) -f(T,n_bonds))/1e-6
# guess value of temperature
T_guess = 1500
# giving value for tollerance, iteration(ct) and ralaxation-factor(alpha)
tol = 1e-6
ct = 0
alpha = 0.5
# giving the values for the number of bonds as 1 , 2 and 3
n_bonds = np.linspace(1,3,3)
# defining temperature array to store the values of temperature corresponding to the number of bonds
Temp = []
for i in n_bonds:
# newton-raphson method
while (abs(f(T_guess,i)) > tol):
T_guess = T_guess - alpha*((f(T_guess,i)/fprime(T_guess,i)))
ct = ct +1
plt.plot(i,T_guess,"*",color = "red")
# adding value to the temperature array
Temp.append(T_guess)
# getting the output as derired
print("Temp_alkane =" , Temp[0] ,"\nTemp_alkene =", Temp[1], "\nTemp_alkyne =" ,Temp[2])
plt.xlabel("number of bonds")
plt.ylabel("temperature")
plt.show()
after running the code we get the following output for the plot
and in the output window the temperature values are shown as below
Conclusion for part 3 :
PART 4 - Adiabatic flame temperature variation with respect to number of Carbon atom chains :
In this part we will be
The chemical reaction for the general alkanes from 1 to 3 carbon atom assuming that we have a constant pressure chamber and the equivalence ratio is 1 , we will calculate the Adiabatic Flame Temperature
The Pyhton code for this calculation is shown below:
"""
In this code we are going to write a program to calculate the AFT of general alkane with carbon atoms from 1 to 3
Chemical equations
C1
CH4 + 2 (O2 + 3.76 N2) => CO2 + 2 H2o + 7.52 N2
C2
C2H6 + 7/2 ( O2 + 3.76 N2 ) => 2 CO2 + 3 H2O + 7/2*3.76 N2
C3
C3H8 + 5 (O2 + 3.76 N2) => 3 CO2 + 4 H2O + 5*3.76 N2
Program by - Amol Patel
"""
import matplotlib.pyplot as plt
import math
import numpy as np
def h(T,co_effs):
"""
function to evaluate enthalpy
"""
R = 8.314 #J/mol-K
a1 = co_effs[0]
a2 = co_effs[1]
a3 = co_effs[2]
a4 = co_effs[3]
a5 = co_effs[4]
a6 = co_effs[5]
a7 = co_effs[6]
return (a1 + a2*T/2 + a3*pow(T,2)/3 + a4*pow(T,3)/4 + a5*pow(T,4)/5 + a6/T )*R*T
ch4_coeffs_l = [5.14987613E+00,-1.36709788E-02, 4.91800599E-05,-4.84743026E-08 ,1.66693956E-11,-1.02466476E+04,-4.64130376E+00]
c2h6_coeffs_l = [4.29142492E+00,-5.50154270E-03 ,5.99438288E-05,-7.08466285E-08 ,2.68685771E-11,-1.15222055E+04 ,2.66682316E+00]
c3h8_coeffs_l = [0.93355381E+00 ,0.26424579E-01 ,0.61059727E-05,-0.21977499E-07 ,0.95149253E-11,-0.13958520E+05 ,0.19201691E+02]
c2h4_coeffs_l = [3.95920148E+00,-7.57052247E-03 ,5.70990292E-05,-6.91588753E-08 ,2.69884373E-11 ,5.08977593E+03 ,4.09733096E+00]
c2h2_coeffs_l = [8.08681094E-01, 2.33615629E-02,-3.55171815E-05, 2.80152437E-08,-8.50072974E-12, 2.64289807E+04, 1.39397051E+01]
o2_coeffs_l = [3.78245636E+00,-2.99673416E-03 ,9.84730201E-06,-9.68129509E-09, 3.24372837E-12,-1.06394356E+03 ,3.65767573E+00]
n2_coeffs_l = [0.03298677E+02 ,0.14082404E-02,-0.03963222E-04,0.05641515E-07,-0.02444854E-10,-0.10208999E+04 ,0.03950372E+02 ]
n2_coeffs_h = [0.02926640E+02 ,0.14879768E-02,-0.05684760E-05 ,0.10097038E-09,-0.06753351E-13,-0.09227977E+04 ,0.05980528E+02]
co2_coeffs_h = [3.85746029E+00 ,4.41437026E-03,-2.21481404E-06, 5.23490188E-10,-4.72084164E-14,-4.87591660E+04 ,2.27163806E+00]
h2o_coeffs_h = [3.03399249E+00, 2.17691804E-03,-1.64072518E-07,-9.70419870E-11, 1.68200992E-14,-3.00042971E+04 ,4.96677010E+00]
def f(T,n_carbons):
"""
Function that represents the root finding problem
"""
Tstd = 298.15
# calculating the enthalpy of each species on the reactant side
h_o2_r = h(Tstd,o2_coeffs_l)
h_n2_r = h(Tstd,n2_coeffs_l)
h_ch4_r = h(Tstd,ch4_coeffs_l)
h_c2h6_r = h(Tstd,c2h6_coeffs_l)
h_c3h8_r = h(Tstd,c3h8_coeffs_l)
# calculating the enthalpy of each species on the product side
h_co2_p = h(T,co2_coeffs_h)
h_h2o_p = h(T,h2o_coeffs_h)
h_n2_p = h(T,n2_coeffs_h)
if n_carbons == 1:
# for C1
# Total enthalpy of reactants and products
H_reactants = h_ch4_r + 2*(h_o2_r + 3.76*h_n2_r)
H_products = h_co2_p + 2*h_h2o_p + 2*3.76*h_n2_p
elif n_carbons == 2:
# for C2
# Total enthalpy of reactants and products
H_reactants = h_c2h6_r + 7/2*(h_o2_r + 3.76*h_n2_r)
H_products = 2*h_co2_p + 3*h_h2o_p + 7/2*3.76*h_n2_p
else:
# for C3
# Total enthalpy of reactants and products
H_reactants = h_c3h8_r +5*(h_o2_r + 3.76*h_n2_r)
H_products = 3*h_co2_p + 4*h_h2o_p + 5*3.76*h_n2_p
return H_products - H_reactants
def fprime(T,n_carbons):
"""
function to get the derivative of the function f
"""
return (f(T+1e-6,n_carbons) -f(T,n_carbons))/1e-6
# guess value for temerature
T_guess = 1500
# giving tollerence, iteration number (ct) and relaxation factor (alpha)
tol = 1e-6
ct = 0
alpha = 0.5
# number of carbon atoms
n_carbons = np.linspace(1,3,3)
# assigning empty array for temperature values
Temp = []
for i in n_carbons:
# Newton-Raphson Method
while (abs(f(T_guess,i)) > tol):
T_guess = T_guess - alpha*((f(T_guess,i)/fprime(T_guess,i)))
#plt.plot(ct,T_guess,"*", color = "red")
#print(T_guess)
ct = ct +1
plt.plot(i,T_guess,"*",color = "red")
# addign calcualted temperature values in the temp array
Temp.append(T_guess)
# getting the desired output
print("Temp_c1 = ",Temp[0],"\nTemp_c2 =",Temp[1], "\nTemp_c3 =", Temp[2])
plt.xlabel("number of carbons")
plt.ylabel("temperature")
plt.show()
the output in the from of plot can be seen as given below
also the temperature values in the output window is shown below
Conclusion for part 4 :
CONCLUSIONS -
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week 6: Conjugate Heat Transfer Simulation
AIM- To simulate a Conjugate Heat Transfer flow through a pipe, while the inlet Reynolds number should be 7000. To run the grid independance test on 3 grids and show that the outlet temperature converges to a particular value To observe the effect of various supercycle stage interval on the total simulation time.…
09 Nov 2022 06:55 AM IST
Week 7: Shock tube simulation project
AIM - To set up a transient shock tube simulation Plot the pressure and temperature history in the entire domain Plot the cell count as a function of time SHOCK TUBE- The shock tube is an instrument used to replicate and direct blast waves at a sensor or a model in order to simulate actual explosions…
07 Nov 2022 09:18 PM IST
Week 5: Prandtl Meyer Shock problem
AIM - 1. To understand what is a shock wave. 2. To understand the what are the different boundary conditions used for a shock flow problems. 3. To understand the effect of SGS parameter on shock location. 4. To simulate Prandalt Meyer Shcok Wave. OBJECTIVE - Que 1. What is Shock Wave? A shock wave or shock,…
01 Nov 2022 06:36 PM IST
Week 4.2: Project - Transient simulation of flow over a throttle body
AIM - Transient simulation of flow over a throttle body. OBJECTIVE - Setup and run transient state simulation for flow over a throttle body. Post process the results and show pressure and velocity contours. Show the mesh (i.e surface with edges) Show the plots for pressure, velocity, mass flow rate and total…
12 Feb 2022 07:08 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.