Week 4.1- Handling Mixtures with Cantera
Aim : To answer the following questions by keeping the code snippet as a reference .
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.
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())
3. What is happenging in lines 15 and 16? Make sure you explain what 1546 means? Is that reasonable?
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.

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.
import cantera as ct
gas=ct.Solution('gri30.cti')
A=ct.Quantity(gas)
A.TPX=298.15,ct.one_atm,{'O2':0.21,'N2':0.79}
A.moles
print("Number of moles of species in one gram of air is :",A.moles)
Output :
Number of moles of species in one gram of air is : 0.0346612761450006
Explaination :
Atomic weight of Oxygen = 15.9994 g/mol
Since oxygen is a diatomic molecule ,the atomic weight of one mole of O2 = 2*15.9994 g/mol = 31.9988 g/mol
One gram of each species = 1/(Atomic weight of one mole of the species)
So, one gram of O2 would be = 1/31.9988 g/mol = 0.03124 g/mol
Atomic weight of Nitrogen = 14.0067 g/mol
Since oxygen is a diatomic molecule ,the atomic weight of one mole of N2 = 2*14.0067 g/mol = 28.0134 g/mol
One gram of each species = 1/(Atomic weight of one mole of the species)
So, one gram of N2 would be = 1/28.0134 g/mol = 0.0357 g/mol
Since the air contains a mixture of Oxygen and Nitrogen as major components and their mole fractions are 0.21 & 0.79 respectively
So, number of moles present in one gram of oxygen = mole fraction of O2 * One gram of O2
= 0.21 * 0.03124 g/mol = 0.006504 g/mol
So, number of moles present in one gram of nitrogen = mole fraction of N2 * One gram of N2
= 0.79 * 0.0357 g/mol = 0.028203 g/mol
Total moles of oxygen and nitrogen in air = Number of moles present in one gram of oxygen + Number of moles present in one gram of nitrogen
Total moles of oxygen and nitrogen in air =0.006504 g/mol + 0.028203 g/mol = 0.034707 g/mol
So this verifies the values obtained from cantera and hand calculation .
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())
import cantera as ct
gas=ct.Solution('gri30.cti')
A=ct.Quantity(gas)
A.TPX=298.15,ct.one_atm,{'O2':0.21,'N2':0.79}
print("Mass fraction of components of air (O2 & N2) = ",A.mass_fraction_dict())
Output :
Mass fraction of components of air (O2 & N2) = {'N2': 0.7670907820415769, 'O2': 0.2329092179584231}
Explaination :
| Species | Mole fraction (X) |
Molar mass(g/mol) | Mass=X*m(g/mol) |
Mass fraction |
| `O_2` |
0.21 |
32 |
6.72 |
0.2325 |
| `N_2` |
0.79 |
28 |
22.12 |
0.7674 |
| `sumX=1` |
`summass=28.84` |
`sumY=1` |
`Y_(O_2)`=(Mass of O2)/(`summass`)
= 6.72/28.84
= 0.2325
`Y_(N_2)`=(Mass of N2)/(`summass`)
= 22.12/28.84
= 0.7674`
Hence, the values of mass fraction of the species match with that obtained from cantera .
3. What is happenging in lines 15 and 16? Make sure you explain what 1546 means? Is that reasonable?
""" Sample code to vary the temprature of air and oxidiser individually """
import cantera as ct
gas=ct.Solution('gri30.cti')
A=ct.Quantity(gas)
A.TPX=298.15,ct.one_atm,{'O2':0.21,'N2':0.79}
B=ct.Quantity(gas)
B.TPX=298.15,ct.one_atm,{'O2':0.21,'N2':0.79}
B=ct.Quantity(gas)
# inspecting the next couple of lines
B.TPX=298.15,ct.one_atm,'CH4:1546'
B.moles=1
#The following step is used to apply the right molar balance
M=A+B
M.equilibrate('HP')
print("Temprature value (AFT in Kelvin) = ",M.T)
Output :
Temprature value (AFT in Kelvin) = 374.14176246326326
Explaination :
1. Code without "B.moles = 1" : To check if there is any change in temprature without us initialising a value to "B.moles"


Output :
Temprature value (AFT in Kelvin) = 767.6432480456276
Discussion :
- Here we can see that for basically any value of 'CH4:1546' the same value of temprature is obtained ,so it can be concluded that the without the "B.moles=1" line in the code there is a change in temprature value (in the first code snippet from the same subsection the tempratutre value obtained was 374.14 K) but had no change in temprature value when we changed the integer value beside CH4 (CH4 must not be 0 to avoid error ie., 'CH4:0' is unacceptable) to any other value (Ex : "CH4:15" or "CH4:1" etc).
- One reason why this is happening because we must only pass a valid hydrocarbon species to "B.TPX" in order to calculate a temprature value & if we pass a null value then an error occours.
2. Code without "B.moles : To understand how the tempraure value changes with change in "B.moles" value
i)

Output :
Temprature value (AFT in Kelvin) = 374.14176246326326
ii)

Output :
Temprature value (AFT in Kelvin) = 314.27469947930706
iii)

Output :
Temprature value (AFT in Kelvin) = 302.2241867884771
iv)

Output :
CanteraWarning: ChemEquil::equilibrate: Temperature (298.965894738886 K) outside valid range of 300.0 K to 3000.0 K
Temprature value (AFT in Kelvin) = 298.965894738886
Discussion :
- There is no effect of the integer value beside the CH4 within inverted commas hence there can be any value beside 'CH4'.
- As we keep on increasing the value of "B.moles" there is a very slow decrease in the final temprature values .
- So it is important to keep the value of "B.moles" equal to 1.
- "B.moles" describes the number of moles of 'Quantity' 'B' which is the hydrocarbon .
Meaning of line 15 & 16 :

a) Line 15 :
This line gives TPX(Temprature ,Pressure & mole fraction) values to quantity B at STP condition with species detail CH4 at the end .
It is compulsory to have a positive integer value beside CH4 but we dont have to have that particular value of 1546 along with 'CH4'. From above excercise we have seen that irrespective of the value(except of 0, all integer values are valid) beside CH4 ,cantera generates the same value for temprature.
b) Line 16 :
This line of code is initialising value to number of moles of the fuel ,this value can be changed and an appropriate temprature value is printed out .
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.
import cantera as ct
gas=ct.Solution('gri30.cti')
A=ct.Quantity(gas)
A.TPX=298.15,ct.one_atm,{'O2':0.21,'N2':0.79}
A.moles=9.52 # moles of O2 = 2, moles of N2 = 7.52 => moles of O2 + moles of N2 = 9.52
B=ct.Quantity(gas)
# inspecting the next couple of lines
B.TPX=298.15,ct.one_atm,'CH4:1546'
B.moles=1
#The following step is used to apply the right molar balance
M=A+B
M.equilibrate('HP')
print("Temprature value (AFT in Kelvin) = ",M.T)
Output :
Temprature value (AFT in Kelvin) = 2224.4118993147486
Explaination :
The change required at this stage is an additional line "A.moles=9.52" which is the value for number of moles of air which must be considered in the reaction which is used to calculate the temprature value .
This is because we have specified the number of moles of the fuel as 1 in 'B.moles=1' & hence we must add the number of moles of air of 'A' to get correct value of temprature .