Week 4.1- Handling Mixtures with Cantera
Handling Mixtures with Cantera
Aim:
In this challange, we will know about the quantity class which is used to add capabilities either like mass or number of moles in solution class.
"""
Writing code to know how to handle the Mixtures in cantera
CxHy + a(O2 + 3.76N2) = xCO2 + yH2O + 3.76aN2.
For stoichometric combustion, Considering Methane
CH4 + 2(O2 + 3.76N2) = CO2 + 2H2O + 7.52N2
"""
import cantera as ct
gas = ct.Solution('gri30.cti')
#Creating an object as 'Air'
Air = ct.Quantity(gas)
#Setting the temperature, pressure and mole fractions of air
Air.TPX= 298.15,ct.one_atm,{'O2':0.21,'N2':0.79}
# Defining the number of moles of air
Air.moles = 9.52
print('Mole fraction of air = ',Air.mole_fraction_dict()) #gas.mole_fraction_dict() is used to get mole fractions
print('Mass fraction of air = ',Air.mass_fraction_dict())
#Creating another object as 'fuel'
Fuel = ct.Quantity(gas)
Fuel.TPX = 298.15,ct.one_atm,'CH4:1546'
Fuel.moles = 1
print('Mole fraction of Fuel = ',Fuel.mole_fraction_dict())
#Adding both the mixtures
M = Air + Fuel
M.equilibrate('HP')
print('Value of AFT :',M.T)
1. Use the "moles" method/function of the A object and explain how it was calculated. You need to use this after line number 9:
As per the sample code given in the challenge, the object A is air and object B is fuel. We are defining the quantity of moles of air and fuel participating in the combustion. We know for any hydro carbon combustion along with air stoichometrically, the chemical reaction is as follows:
CxHy + a(O2 + 3.76N2) = xCO2 + yH2O + 3.76aN2.
From the above equation, it is clear that moles of air is (a+3.76a). In the sample code, we are considering the hydrocarbon as fuel is Methane. So the stoichometric reaction is
CH4 + 2(O2 + 3.76N2) = CO2 + 2H2O + 7.52N2
From above reaction, we can get to know, a = 2;
Total number of moles of air = (a+3.76a) = 9.52 mol.
So we will define the quantity of moles by creating Air as as object by using quanity class. Quantities have properties which provide access to extensive properties:
Air.moles = 9.52
2. Use the method mole_fraction_dict() of the A object and explain the result that you get. Here is how you need to use it. print(A.mass_fraction_dict()):
Mole_fraction_dict(), is a method in Cantera used to get the molar composition of the species. In real to caluculate manually we need to follow these steps:
Species involved in air are O2 is 2 moles and N2 = 7.52 moles. We know the molar mass(MW) of Oxygen molecule is 32 and Nitrogen is 28.
Mole fraction of oxygen,O2 = 2/9.52 = 0.21008
Mole fraction of Nitrogen,N2 = 7.52/9.52 = 0.78991
Mass of the oxygen,O2 = 2 * 32 = 64gms
Mass of the nitrogen = 7.52 * 28 = 210.56gms
Total mass = 64 + 210.56 = 274.56gms
Mass fraction of oxygen = 64/274.56 = 0.23310
Mass fraction of Nitrogen,N2 = 210.56/ 274.56 = 0.766899
But by using using mole_fraction_dict() and mass_fraction_dict(), we can directly get the results as follows:
3. What is happenging in lines 15 and 16? Make sure you explain what 1546 means? Is that reasonable?:
The method .TPX is used to set/define the temperature, pressure and mole fraction of the species involving in the reaction to avoid the software assuming any predefined values. As the CH4 is the only species involving in the reaction, there wont be any effect to the result, if we mention 1546 mole fraction as it automatically takes it as 1 mole because we know the sum of value of mole fraction is always equal to one. By using mole_fraction_dict(), we can get an idea:

4. What changes do you need to put in place to get the right value of AFT in line 22?. The right answer is 2224K. Hint: The change needs to be done in line number 10. You have to compute the right number of moles of A:
Even though by using 'TPX' method, we are setting the values, we are not defined number of moles involving in the reaction as we are defining the individual species molefraction. So by defining the number of moles of Air involved, we will get the right values of AFT. One more thing, we need to define right value of moles for fuel also, otherwise, we will get a different solution.
So in the line number 10, we need to define Air.moles = 9.52.