Challenge

Week 4 - Handling Mixtures with Cantera

The methane combustion reaction

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

Here we see that 1 mole of methane require 2 moles of air which is a mixture of oxygen and nitrogen required to have combustion if mole fraction oxygen (O2) and Nitrogen is considered then value then it is calculated  by

No of mole fraction =No of moles of a specie/( No moles of Total combined species)

No of moles in O2=2

Total No of Moles=2+2*3.76=9.52

No of mole fraction in O2=2/(2+2*3.76)=0.21

No of moles fraction in N2=(2*3.76)/(2+2*3.76)=0.79

Here in programme CH4 is designated by B and Air is designated by A

That value of moles fractions of O2 and N2 are given input in line 9

and the total number of mole is given in the programme is 9.52

mole_fraction_dict()  is dictionary object that is used to call the mole fraction of any element specified in the mixture.To print the result we use print(A.mole_fraction_dict()) and to print the mass fraction we use the command print(A.mass_fraction_dict())

Mole Fraction

{'N2': 0.79, 'O': 0.21}

Mass Fraction

{'N2': 0.7670829987741036, 'O2': 0.23291700122589645}

Inline 15 and 16 we defining the fuel's temperature, pressure and mole function and no of moles.As with assigning that big of 1546 doesn't have any effect since there mole fraction is cannot be greater than 1 and moreover only methane gas is defined

To get the correct result we just need to specify the no of moles for A at line number 10

The correct code is 

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=2/A.mole_fraction_dict()['O2']
print(A.mole_fraction_dict())

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

#The following command is to have a molar balance
M=A+B
M.equilibrate('HP')
print(M.T)

Result

{'N2': 0.79, 'O2': 0.21}
2224.224370856459
[Finished in 1.0s]

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.