Challenge

Week 4.1- Handling Mixtures with Cantera

Week 4.1- Handling Mixtures with Cantera

  • Aim : To run the sample code and test different functions to answer the questions.
  • Sample Code :

Q1. Use the "moles" method/function of the A object and explain how it was calculated. You need to use this after line number 9.

Ans : In the physical sciences, some properties of mixtures relate to mole fraction, or mole percent, of one of the mixture’s components. The mole represents a quantity of substance, but relates to the number of atoms or molecules rather than mass or volume. Specifically, 1 mole represents 6.022 x 10^23 atoms or molecules of substance. You calculate the number of moles by dividing the mass of substance by the substance’s atomic or molecular weight. You then find the mole fraction by dividing the moles of one substance in a mixture by the total number of moles of all substances in the mixture.

"""
Sample code to vary
"""

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(A.moles)


B = ct.Quantity(gas)
B.TPX = 298.15,ct.one_atm,'CH4:1546'
B.moles = 1


# following step is used 
M = A + B
M.equilibrate('HP')
print(M.T)

The output obtained after running this code gives value of A.moles = 0.0346615.

We know that mole fraction of `O_2` = 0.21 and that of `N_2` = 0.79.

Atomic weight of 1 mole of `O_2` = 16 * 2 gm = 32 gm (approx)

Atomic weight of 1 mole of `N_2` = 14 * 2 gm = 28 gm (approx)

Number of moles of `O_2` per gram = 1/32 = 0.03125

Number of moles of `N_2` per gram = 1/28 = 0.03571

Total number of moles in A = mass fraction of `O_2` * number of moles of `O_2` + mass fraction of `N_2` * number of moles of `N_2`

= 0.21 * 0.03125 + 0.79 * 0.03571

= 0.006562 + 0.02821

= 0.03477

The two answers are approximately close.

Q2. 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()).

Ans :

"""
Sample code to vary
"""

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(A.moles)
print(A.mole_fraction_dict())
print(A.mass_fraction_dict())

B = ct.Quantity(gas)
B.TPX = 298.15,ct.one_atm,'CH4:1546'
B.moles = 1


# following step is used 
M = A + B
M.equilibrate('HP')
print(M.T)

The output for above code is obtained as

0.03466156784836224
{'N2': 0.79, 'O2': 0.21}
{'N2': 0.7670829987741036, 'O2': 0.23291700122589645}
374.14235446229526
[Finished in 4.2s]

Now,

Mass of 1 mole of`O_2` = 32 gms and Mass of 1 mole of `N_2` = 28 gms (approx).

Therefore mass of 1 mole of A = 0.21*32 + 0.79*28

= 6.72 + 22.12

= 22.84 gm.

Therefore mass fraction of `O_2` = 6.72/22.84

= 0.2330

Similarly mass fraction of `N2` = 22.12/22.84

= 0.7669

As we can see both the values are approximately the same.

Q3. What is happenging in lines 15 and 16? Make sure you explain what 1546 means? Is that reasonable?

Ans : In line 15 we define B in Quantity class and in line 16 we define the mixture in temperature, pressure and mass fraction form. As mole fraction cannot be more than '1', the value 1546 doesn't affect the outcome of the results. Also we define `CH_4` as one single entity, mole fraction is automatically considered to be 1.

Q4. What changes do you need to put in place to get the right value of AFT in line 22?. The right answer is 2224K.

Ans : The chemical reaction for this problem is

`CH_4 + 2*(O_2+3.76N_2) = CO_2 + 2*H_2O+7.52N_2`

So, number of moles of methane `CH_4` is 1 and number of moles of atmospheric air is 2*(1+3.76) = 9.52.

Defining correct values of moles is necessary to obtain accurate value of AFT. So number of moles of mixture A need to be mentioned in the code. If we don't assign proper values to numberof moles, cantera presumes values and gives inaccurate results.

Corrected code is below:

"""
Sample code to vary
"""

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


B = ct.Quantity(gas)
B.TPX = 298.15,ct.one_atm,'CH4:1546'
B.moles = 1


# following step is used 
M = A + B
M.equilibrate('HP')
print(M.T)

Output:

2224.4118993147463
[Finished in 3.0s]

Now we get accurate value of AFT = 2224.4118.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.