Week 4.1- Handling Mixtures with Cantera
AIM: To handle mixtures with Cantera.
OBJECTIVE: To work with the Quantity class of Cantera to create various mixtures and to explain how the mixture calculations are performed.

- Use the "moles" method/function, calculate the number of moles of object A and explain how it is calculated analytically.
- Use method mass_fraction_dict() of the A object and explain it analytically.
- What is happening in lines 15 and 16? Make sure you explain what 1546 means? Is that reasonable?
- What changes do you need to put in place to get the right value of AFT in line 22? The right answer is 2224K.
SOLUTION:
Introduction:
In this challenge, we are going to determine the Adiabatic Flame Temperature for the combustion of methane and air at the stoichiometric conditions and constant pressure by handling mixtures of methane and air as two separate quantities using the quantity class in Cantera.
Theory:
When two or more substances mix with each other without participating in a chemical change, the resulting substance is called a Mixture. The result formed due to the combination of substances does not lose its individually nor are they combined chemically. Mixtures are the one product of a mechanical blending or mixing of mechanical substances such as elements and compounds. The different components of any combination do not unite through any chemical changes. As a result, the components retain their distinct characteristics.
Answers to the questions:
1. Use the "moles" method/function, calculate the number of moles of object A and explain how it is calculated analytically.
The Stoichiometric mixture of Methane and Air:
`CH_4 + 2(O_2 + 3.76N_2) => CO_2 + 2H_2O + 7.52N_2`
Here 1 mole of `CH_4` reacts with 2 moles of air which is a mixture of Oxygen(`O_2`) and Nitrogen (`N_2`). `O_2` and 2*3.76 mole of `N_2`
Here A = mixture of `O_2` and `N_2`, hence A contains 2 moles.
Mole fraction can be given as,
`X_(species) = (N_(species))/(N_t)`
Where,
`X_(species)` = Mole fraction of species of interest.
`N_(species)` = Number of moles of species of interest.
`N_t` = Total number of moles of all species present in the mixture
Moles of `O_2` = 2
Moles of `N_2` = 2*3.76 = 7.52
Total number of moles present in the mixture = 2 + 2*3.76 = 9.52
Mole fraction of `O_2`, `X_(O_2)` = 2/9.52 = 0.21
Mole fraction of `N_2`, `X_(N_2)` = 7.52/9.52 = 0.79
The moles can be calculated for the air by using the formula,
`X_(O_2) = N_(O_2)/(N_(O_2) + N_(N_2) ) = (N_(O_2))/(N_(air))`
OR
`X_(N_2) = N_(N_2)/(N_(O_2) + N_(N_2) ) = (N_(N_2))/(N_(air))`
From the above equation we can write,
`N_(air) = N_(O_2)/(X_(O_2)`
Moles of air, `N_(air)` = 2/0.21 = 9.5238
Hence the total number of moles of Air is 9.5238, which is represented in code as A.moles = 9.5238
2. Use the method mass_fraction_dict() of the A object and explain it analytically.
Moles of `O_2` = 2
Moles of `N_2` = 7.52
The molecular weight of `O_2` = 32 g/mole
The molecular weight of `N_2` = 28 g/mole
Mass of `O_2` = 2*32 = 64 g
Mass of `N_2` = 7.52*28 = 210.56 g
Total mass = mass of `O_2` + mass of `N_2`
= 64 + 210.56 = 274.56 g
Mass fraction of `O_2` = 64/274.56 = 0.2331
Mass fraction of `N_2` = 210.56/274.56 = 0.7668
This is the same we got from the Cantera.

3. What is happening in lines 15 and 16? Make sure you explain what 1546 means? Is that reasonable?
In the 15th line, fuel and its initial conditions are defined using another instance 'B'. We are setting the values of Temperature, Pressure, and Mole fraction of object B.
1546 represents the mole fraction of `CH_4`. Since we have considered only 1 species (i.e. `CH_4`), this value can be any value more than 0 because, in line 16, B.moles = 1 indicates that only one mole of B is taken into consideration and if there are only 1 species, the mole fraction of `CH_4` is 1 by default. Thus 1546 is not significant and does not affect the solution. The number 1546 is just an arbitrary number. It must be noted that 0 is not acceptable.
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.
AFT temperature depends on the number of moles of fuel(object B), and oxidizer(object A) which react at constant pressure. Thus we need to provide the correct number of moles for both objects. The number of moles of object A is defined in line 10 as A.moles = 9.5238
Modified Code:
"""
Sample code to vary the temperature of air and oxidizer 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}
A.moles = 9.5238 # 2/A.mole_fraction_dict()['O2']
print(A.mass_fraction_dict())
B = ct.Quantity(gas)
B.TPX = 298.15,ct.one_atm,{'CH4':1546}
B.moles = 1
print(B.mass_fraction_dict())
#The following step is used to apply the right molar balance
M=A+B
M.equilibrate('HP')
print(M.T)
RESULT:

The calculated Adiabatic Flame Temperature is 2224.2248 K.