Challenge

Python&Cantera - Handling Mixtures with Cantera

Aim: Write a Python code that processes air-fuel mixture using Cantera module

Objectives:

  • Handle mixtures of given hydrocarbon (here, methane) and air
  • Compute its AFT by balancing of moles
  • Understanding and implementing 'Quantity' class in Cantera

Methodology:

The balanced combustion equation for methane is as follows:

`CHunderset(4)`` + 2(Ounderset(2)`` + 3.76Nunderset(2)``) -> COunderset(2) ``+ 2Hunderset(2)``O + 7.52Nunderset(2)`

Here is the snippet of code that was provided

The code shown above calculates AFT as `374.14K`

, which is incorrect. This happened because the moles of the substance A wasn't specified. For this, we look on the balanced reaction and calculate mole fration as shown:

This can be done by applying mole_fraction_dict() . This is a dictionary object and we can use it to call the values of mole fraction as required. But instead, we use mass_fraction_dict and calculate the result.

For substance B, as it is a single compound (i.e. methane) any number provided in the dictionary, it would get converted to single mole fraction automatically. However, it is better practice to take mole fractions that sum up to one. Hence, we replace 1546 to 1.

Hence, the above methods answers all the questions asked and we have the following code with corrections as:

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']

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

#The following stepo is used to apply the right molar balance
M = A + B
M.equilibrate('HP')
print(M.T)

Which gives the following output:

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.