#determine number of mole of hydrogen and oxygen
nH2=12/2. ##molecular mass og hydrogen =2kg/kmol
nO2=8/32. ##Molecular mass of O2=32kg/kmol
print'%s %.f %s'%("No. of kilomoles of H2",nH2,"")
print'%s %.2f %s'%("No. of kilomoles of O2",nO2,"")
import math
#calculate lower and higher heating values of hydrogen
T=298.16 ##in K
dhf=-241827. ##heat of formation of H2O(g in kJ.
n=1 ##kmol
Qr=n*dhf ##kJ/kmol
LHV=(-1.)*Qr/2.
print'%s %.1f %s'%("LHV in",LHV,"kJ/kg")
HHV=LHV+9*2443
print'%s %.1f %s'%("HHV in ",HHV,"kJ/kg")
import math
#calcualte the ratio Nh2/no2 of the reactants and fuel oxdizer and adiabatic flame temperature
##from equation CH4+2.4(O2+3.76N2)-->CO2+2H2O+0.4O2+9.02N2
f=(12+4.)/(2.4*(32.+3.76*28.)) ##fuel to air ratio based on mass.
fs=(12+4.)/(2.*(32.+3.76*28.)) ##fuel to air ratio based on stoichometric condition.
feq=f/fs
print'%s %.7f %s'%("fuel to air ratio based on mass",f,"")
print'%s %.7f %s'%("fuel to air ratio based on stoichometric condition",fs,"")
print'%s %.7f %s'%("Equivalent ratio",feq,"")
dH=-802303 ##kJ
dC=484.7 ##kJ
Dt=(-1)*dH/dC ##Dt=T2-Tf
Tf=25+273
T2=Dt+Tf
print'%s %.4f %s'%("The diabatic flame temperature in",T2," K")
import math
import numpy
#calculate mole fraction of N2 at equlibrium when pm is 1 atm and 10 atms
print("Example 6.6")
Kp=0.1
pm=1.
y=2
d=numpy.roots(y)
x=0.1561738
print'%s %.2f %s '%("(a)Mole fraction of N2 at equilibrium when pm is 1 atm:",x,"")
#part (b)
Kp=0.1
pm=10.
x=0.0499376
y=- 0.1 + 40.1*x
d=numpy.roots(y)
i=numpy.linspace(1,2,num=1);
print'%s %.2f %s '%("(b)Mole fraction of N2 at equilibrium when pm is 10 atm:",x,"")