Week 4 - Handling Mixtures with Cantera
AIM
The aim of this challenge is to work on the quantity class of the cantera.
OBJECTIVE
The calculation of the adiabatic flame temperature of gas mixture using the quantity class
Python Code for Calculation for Mass and Mole Fraction of Air
import cantera as ct
gas = ct.Solution('gri30.cti')
air = ct.Quantity(gas)
air.TPX = 298.15,ct.one_atm,{'O2':0.21, 'N2':0.79}
print('number of moles of air = ',air.moles)
print('mole fraction of air = ',air.mole_fraction_dict())
print('mass fraction of air = ',air.mass_fraction_dict())
The Gas object is created for solving the problems related to combustion. Air is created with quantity class defined at STP condition. Then in print command we tell the Cantera to exrcute the code.
Output of the Code

if we take one mole of oxygen we can say that
Mass of one mole of diatomic oxygen O2 = 32 grams
Mass of one mole of diatomic nitrogen N2 = 28 grams
The mass of air can be then defined as the
mass of air = 0.21*32 + 0.79*28 = 28.84
mass fraction of oxygen = 0.21*32/28.84 = 0.23
mass fraction of nitrogen = 0.79*28/28.84 = 0.77
Sample Code

Here in this program in line 15 and in line 16 we defined a gas as name B and assign the Temperature Pressure and Mole Fraction Values at the STP Conditions. Here it can be noted that the Mole fraction of CH4 is defined as 1546 which is wrong. Therefore in line 16 we defined rthe moles of CH4 again as 1 and thus overwrite the previous value
For the correct reason we need to define the number of the moles of air to be used make the reaction stotiometric. Thus in line 10 we can define the air as the total number of moles used in .i.e. 9.52 to the correct reaction which will thus be multiplied by the mole fraction and thus give the correct reaction as
`CH4 + 2(Ounderset(2)() + 3.76 Nunderset(2)()) -> COunderset(2)() + Hunderset(2)()O + 7.52Nunderset(2)()`
The changes as told above have been made to the above code and can be seen below:
"""
Handling Mixtures using Cantera
"""
import cantera as ct
gas = ct.Solution('gri30.cti')
air = ct.Quantity(gas)
air.TPX = 298.15,ct.one_atm,{'O2':0.21,'N2':0.79}
air.moles = 9.52
fuel = ct.Quantity(gas)
fuel.TPX = 298.15,ct.one_atm,'CH4:1546'
fuel.moles = 1
M = air+fuel
air.constant = 'HP'
fuel.constant = 'HP'
M.equilibrate('HP')
print(M.T)
The Code output can be seen below:

here the result can be seen and the output temperature can be checked here and can be seen as 2224.41K
Conclusion
- The moles method has been used to define the moles of a compound in a certain class.
- The method mole_fraction_dict() was used in the code 1 to get the output of the mole fractions in a certain gas class.
- The lines 15 and 16 have been explained and the favourable changes have been made to the program.