Week 4.1- Handling Mixtures with Cantera
Aim: To work and get acquanited with the 'Quantity' class of Cantera library and handle mixtures with different aspects.
Objectives:
1. Use the 'moles' method to calculate the nimber of moles of the object A in the given code and explain how to calculate analytically.
2. Use the mass_fraction_dict() method of the A object.
3. Explain the working of 15th and 16th line of the code and give reason for the 1546, used with CH4.
4. What changes are needed to print correct value of AFT(2224 K).
Theory: Quantity Class: Quantity class in Canter is used to represent a specific quantity of a Solution class object. It is used when there are different mixtures to handle. This class helps us to define various characteristics such as the mass and the number of moles or mole and mass fraction of the gas species that has been considered.
Quantity is a class in cantera so it is used by creating a Quantity type object. The Quantity object is created from Solution class with moles and mass of the species specified.
Approach/Answers:
1. Use the 'moles' method to calculate the nimber of moles of the object A in the given code and explain how to calculate analytically.
- Analytical Calculation of moles :
In the given image, the values specified for the A object of mixture is in 'mole fractions' terms. It is defined as the ratio of number of moles of a specific substance by the sum of total number of moles in the mixture.
So for object A the moles of O2 and N2 are calculated by like this:
`X_(O2) = n_(O2)/(n_(O2) + n_(N2)`
where `n_(O2) + n_(N2)` = `n_(air)`
`therefore X_(O2) = 2/(9.56) = 0.21` `because n_(O2) + n_(N2) = 2 + 7.56 = 9.56`
Similarly the mole of N2 is calculated: `X_(N2) = n_(N2)/(n_(O2) + n_(N2)` = `7.56/(9.56)`= 0.79
The A.moles is the total number of moles of Air. In mole terms the A.moles = 2, but for in terms of mole fraction the A.moles is equal to `n_(air)` which is 9.56
`therefore`A.moles = 9.56
2. Use the mass_fraction_dict() method of the A object.
The mass fraction is the concentration of the substance in whole composition or mixture. It is defined as the ratio of
Mass of the specific substance by the total mass of the mixture/composition.
So to calculate the mass fraction to use the mass_fraction_dict() method, first calculate the masses of the A object mixture that is mass of O2, N2 from givem moles/moles fraction.
The mass fraction of O2 can be calculated :
`M_(O2) = (X_(O2)*Molar Mass_(O2))/(X_(O2)*Molar Mass_(O2)+X_(N2)*Molar Mass_(N2)`
`X_(O2)*Molar Mass_(O2)+X_(N2)*Molar Mass_(N2) = M_(air)`
where X is the mole fraction of the substance. This is done because of Mass = number of moles * molar mass.
Similarly mass fraction of N2 is calculated by:
`M_(N2) = (X_(N2)*Molar Mass_(N2))/(M_(air))`
Since molar mass of O2 and N2 are 32 and 28 respectively. The value of M_air = 28.84
Therefore `M_(O2) = (0.21*32)/28.84 -> 0.233` and `M_(N2) = (0.79*28)/28.84 -> 0.766`
These values are calculated analytically.
3. Explain the working of 15th and 16th line of the code and give reason for the 1546, used with CH4.
The line 15th of the above given code is setting the value of the Temperature, Pressure and specifiying the mole fraction value of CH4. Line 16th is specifying the number of moles of the species in mixture B that is 1.
The value 1564 is just a arbitarary value with no relation to the mole fraction or mass fraction of CH4, also in line 16 there is a syntax error where the mole fraction of CH4 is not specified using Python Dictionary.
4. What changes are needed to print correct value of AFT(2224 K).
To produce the correct answer the modified code is present below with this modifications:
a. Adding the A.moles value that is 9.56
b. Correcting the mole fraction of CH4 and writing in the form of dictionary which is the proper syntax to specify the moles or moles fraction of a mixture.
For the code as it iis shown in above image after adding the moles of A mixture and running as it is, the code throws this error
- Correct code with Output:
"""
Handling Mixtures with Cantera - Week 4.1 Challenge
Objective: Quality class of Cantera.
Solving for AFT at constant pressure with the values of species
specified with mole fraction values.
The mixture A (air) = 0.21*O2 + 0.79*N2 values are specified in mole fraction
The mixture B (fuel) = CH4
"""
import cantera as ct
gas = ct.Solution('gri30.yaml') #gas is object of Class Solution
A = ct.Quantity(gas) #A is object of Class Quantity Inherited from gas
A.TPX = 298.15, ct.one_atm, {'O2':0.21, 'N2':0.79} #instead of mole, values are in mole fraction
A.moles = 9.56 #total moles of air mixture (2+7.59)
B = ct.Quantity(gas)
B.TPX = 298.15, ct.one_atm, {'CH4': 1}
B.moles = 1
M = A+B #adding the mixture i.e, CH4 + 2O2 + 7.52N2
M.equilibrate('HP') #calculating the temperature at constant enthalpy and Pressure
print('Value of Temperature for correct code:\n',M.T)
print(A.mass_fraction_dict())

Results:
| Analytical Value | Cantera Value | |
| `O_2`mass fraction | 0.233 | 0.232 |
| `N_2` mass fraction | 0.766 | 0.767 |
| AFT | 2224 K | 2222.35 |