Week 4.1- Handling Mixtures with Cantera
To work with the Quantity class of Cantera to create various mixtures and explain how the mixture calculations are performed.
1. Use the "moles" method/function, calculate the number of moles of the object A and explain how it is calculated analytically. You need to use this after line number 9 by using the predefined function ‘A.moles’
From the equation of combustion for the methane: given below:
CH4 + 2(O2 + 3.76N2) → CO2 + 2H2O + 2(3.76N2)
we mentioned that = 02=.21 and N2= 0.79 which equals to 1
Composition: AIr contains O2 and N2 in the ratio of 0.21 and 0.79 and it is 2 moles as per the balanced equation
Mole fraction = (Number of moles of particular species) / (Total number of moles)
- Number of moles of = 2*3.76 = 7.52
- Number of moles of = 2
- Total number of moles = 2+2*3.76 = 9.52
Mole fraction of O2 =(2/9.52)=0.21008
Mole fraction of N2 =(7.52/9.52)=0.7891
Hint : For the analytical part you need to calculate the number of moles in 1g of Air.
2. Use the method mass_fraction_dict() of the A object and explain it analytically
Hint : Here is how you use it. print(A.mass_fraction_dict())
This function calculates the mole fraction(mass fraction) of the species.
When used as a print(A.mass_fraction_dict()), it calculates the mass fraction of the species in object A. This is calculated as given in the below table


3. What is happening in lines 15 and 16? Make sure you explain what 1546 means? Is that reasonable?
B.TPX = 298.15, cnt.one_atm, 'CH4:1546'
In this command we are declaring the fuel composition along with the numerics of the fuel being used. Since we are introducing only methane as the fuel we are specifying the methane directly in the quotes, if we have a mixture then we need to specify them in the dictionary format.
The format is "Temperature", "Pressure", Mole fraction. The mole fraction needs to be more than unity and here it is specified as 1546 as a random number.
In the line number 16: B.moles=1
we are actually specifying the number of moles of the fuel i.e. methane being used for the combustion.
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.
To get the right AFT which is 2224K, we need to replace the number of moles of A i.e. Oxygen+nitrogen and no of moles of fuel to the stoichiometric value:
- A.moles = 9.52
- B.moles = 1

the complete code is as follows:
# Week 4 challenge code written by Noble sharma as a part of TSE-CFD training
import cantera as cnt
gas=cnt.Solution('gri30.yaml')
# Stream of air
A=cnt.Quantity(gas)
A.TPX=298.15, cnt.one_atm, {'O2': 0.21, 'N2': 0.79}
A.moles = 9.52
# Stream B (methane)
B = cnt.Quantity(gas)
B.TPX = 298.15, cnt.one_atm, 'CH4:1546'
B.moles = 1
M=A+B
M.equilibrate('HP')
print(M.T)