Week 4 - Handling Mixtures with Cantera
#Aim:1.Use 'moles' method/function for finding moles of a Quantity and understand the calculation cantera doing in finding it.
2.Use mas_fraction_dict method.
3.Correct the values of No. of moles of Quantity(A) to achieve correct value of AFT.
Introduction: Basically in this challenge,we are not taking a combined mixture of Fuel(CH4) and Air but
we are mixing them separately.So mixing them separately allows us to set different properties to gases
while defining them.Like if we to increase temperature of fuel and air , we can set separately.
#Coding Approach:
1.We created a instance object of '.Solution' class.
2.In addition to the properties which can be computed for class .Solution, class .Quantity provides several
additional capabilities. A .Quantityobject is created from a Solution with either the mass or number of
moles specified.
3.We mix both fuel and air,then used equilibrate method(to set a gas mixture to a state of chemical
equilibrium, use the equilibrate() method.)
4.Then we set program accordingly to get coorect value of AFT for this case.
------------------------------------**************************--------------------------------------------
Questions
1. Use the "moles" method/function of the A object and explain how it was calculated:
Ans.
import cantera as ct
gas=ct.Solution('gri30.xml')
A=ct.Quantity(gas)
A.TPX=298.15,ct.one_atm,{'O2':0.21,'N2':0.79} #Defining Air
properties(Temperature,Pressure,Mole Fraction)
print(A.moles)
So cantera gives value of moles as:(in Kmol)

#Calculation cantera did for getting this value of moles:
Since,
32kg of O2----------------------------------1 Kmol of O2
So,
1kg of O2------------------------------------(1/32) Kmol of O2=0.03125 Kmol
Similarly,
28kg of N2----------------------------------1 Kmol of N2
So,
1kg of N2------------------------------------(1/32) Kmol of N2=0.035714 Kmol(round of to 6 places of decimal)
As we know
In Air contains 21% O2 and 79 % N2.
So, Mole fraction of O2 =0.21
Mole fraction of N2= 0.79
Therefore
Moles of O2 in 1kg of air =0.03125*0.21=0.0065625
Moles of N2 in 1kg of air=0.035714*0.79=0.02821406
So,
Total moles of Air=0.0065625+0.02821406=0.03477656 Kmol
Results given by Cantera and our calculation almost same.
-------------------------------***********************************----------------------------------
2.Use the method mass_fraction_dict() of the A object and explain the result that you get.
Ans.
import cantera as ct
gas=ct.Solution('gri30.xml')
A=ct.Quantity(gas)
A.TPX=298.15,ct.one_atm,{'O2':0.21,'N2':0.79}
#A.moles=9.52
print(A.moles)
print(A.mole_fraction_dict())
print(A.mass_fraction_dict())
Using this program code,Cantera gives Mass fraction as:

#Calculation of Mass fraction:
Mole fraction of O2=0.21
Molecular Weight of O2=32 g/mol
Mole fraction of N2=0.79
Molecular Weight of N2=28 g/mol
Since,
Mass fraction of a species in a gas =(Mole fraction of species*Molecular Weight of species)/(Sum of product of Mole fraction and Molecular weight of all present species in gas)
Therfore,
Mass fraction of O2= `(0.21*32)/((0.21*32)+(0.79*28))`
Mass fraction of O2=0.2330098
Mass fraction of N2= `(0.79*28)/((0.21*32)+(0.79*28))`
Mass fraction of N2=0.7669902
--------------------------------------------------****************-------------------------------------------
3.Explain about 'CH4':1546 in the sample program shown.
Ans.

At line 14 we defined Quantity B.
So in line 15,we are defining Temperature,Pressure and Mole fraction of Quantity B(that is fuel CH4).
In line 16,we defined number of moles of Quantity B that is 1.
Basically 'CH4':1546 is defining Mole fraction of CH4 .Here only one spcies present so whatever value we
give here will be treated as 1,because maximum value of mole fraction is 1.
So 1546 here doesn't make any sense,its value here is considered as 1 by cantera.
-------------------------------------***************************-----------------------------------------
##Here the program for this challenge:
"""
Handling Mixture with Cantera
"""
import cantera as ct
gas=ct.Solution('gri30.xml')
A=ct.Quantity(gas) #Quantity A defined which is Air.
"""
CH4+2*(O2+3.76N2)==Co2+2*H20+7.52*N2
"""
A.TPX=298.15,ct.one_atm,{'O2':0.21,'N2':0.79} #Temperature,pressure and mole fraction set.
A.moles=9.52 #Moles of A defined
print(A.moles)
print(A.mole_fraction_dict())
print(A.volume)
print(A.mass_fraction_dict())
B=ct.Quantity(gas) #Quantity B is defined which is fuel(CH4)
B.TPX=298.15,ct.one_atm,{'CH4':1} #Temperature,pressure and mole fraction set.
B.moles=1 #Moles of B defined
print(B.mole_fraction_dict())
print(B.volume)
M=A+B #Both quantities mixed
M.equilibrate('HP') #To set a gas mixture to a state of chemical equilibrium
print(M.T)
4. What changes do you need to put in place to get the right value of AFT?
Ans.
The chemical equation for stoichiometric combustion of methane - CH4 - with air can be expressed as
CH4+2*(O2+3.76N2)==Co2+2*H20+7.52*N2
So from above equation we can see that ,for one mole of CH4,we require 2 moles of O2 and 7.52 moles of N2.
That makes total of 9.52 moles combining both O2 and N2 moles.
So we need to define
A.moles=9.52
For getting right value of AFT that is 2224.411 kelvin.