Challenge

Week 4.1- Handling Mixtures with Cantera

The stoichiometric equation for methane is as below :

h4 + 2(O2+3.76N2) + Co2 + 2H20 + 7.52N2

1. Providing Number of Moles of air:

By using A.TPX ,we provide the initial conditions of the air

A.TPX = 298.15,ct.one_atm,{'O2':0.21,'N2':0.79}

which stands for the temperature of the air at the inlet is 298.15k, the pressure of air is 1 atm and X stands for the mole fraction of O2 and N2 in the air which is provided as a dictionary. Oxygen and Nitrogen in the air at 21% and 79% by molar percentage,respectively.

Until now we have just defined the mole fraction of air being used, Now we determine the number of moles of air involved in the stoichiometric equation by using a variable A.moles thorugh the quantity class.

Number of moles of Oxygen in Air = 2

Number of moles of Nitrogen in Air = 2*3.76 = 7.52

Total number of Moles of Air = 9.52 (i.e 2+7.52)

Now to define A.moles we can put it as 9.52 or 2/0.21 or 2/0.79 .

In the above to determine the total number of moles following formula is used.

total no. of moles = moles of individual compound/mole fraction of individual compound

A.moles = 9.52 or 2/ 0.21 or 7.52/0.79

If we do not define the total number of moles of the compound (i.e A.moles) , cantera by default assumes the number of moles per gram or (K-mol/kg) of compound which leads to wrong results. For example,

Mass of 1 mole of O2 = 31.9988 gm

Mass of 1 mole of O2 = 28.01348 gm

Number of moles in 1gm of O2 = 1/31.9988 = 0.03125117191

Number of moles in 1gm of N2 = 1/28.01348 = 0.0356971011

Number of moles in 1gm of air = 0.21*0.03125117191 + 0.79*0.0356971011 = 0.03476345518

Similary for Ch4

Mass of 1 mole of ch4 = 16.04 gm

Number of moles of 1 gm of ch4 = 0.0623441397

If we do not define the A.moles and B.moles, and print the value of A.moles and B.moles we get the above- calculated values of the number of moles per gm.

2. Determining mass Fraction or mole fraction using Dictionary:

A.mass_fraction_dict() to determine the mass fraction of compounds in the air.

A.mole_fraction_dict() to determine the mole fraction of compounds in the air.

To print same in the console the following command is used.

Print(A.mass_fraction_dict()) to print the mass fraction of compounds in the air.

Print(A.mass_fraction_dict()) to print the mass fraction of compounds in the air.

Calculation Procedure:

Species Moles Mass Fraction Molecular Weight(gm/mol) Mass(gms) Mole fraction

O2 2 0.2329092179 32 64 0.21

N2 7.52 0.767090782 28 210.56 0.79

Mass is obtained from the product of moles and molecular weight.

3. 15th and 16th Line :

In the line number 15 , we include the TPX command , TPX means Get the temperature[k], pressure[Pa], and the mole fraction.

And the number of 1546 represents the number of moles of the object. since only one compound is given the molar fraction plays no role here.

The value may be any rather than 0. Because the moles of the object B is given as 1.

We have taken one mole in the B object into consideration.

"""
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.52



B = ct.Quantity(gas)
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(M.T)

ch4 = 12(carbon)+4() = 16

4. Right calculation AFT :

Here i am using the equilibrate command for the Mixture object.

Uses Hp stands for set enthalpy and Pressure

As we have to solve the full case, a solver has to be applied and it is the Auto solver used. It uses an element potential method first and if it fail to solve, then Gibbs solver is used automatically.

By including the above tools, we can get the required answer, AFT as 2224.411899 k as shown in the result of the 2nd question.

"""
Creating mixtures
Ch4+2(O2+3.76N2)= Co2+2H2O+7.52N2
"""

import cantera as ct
0as = 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,'CH4:1'

print('mole fraction in air=',A.mole_fraction_dict())
print('mass fraction in air=',A.mass_fraction_dict())
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.