How to output results after combustion

447 views
Skip to first unread message

Potten

unread,
Aug 28, 2018, 7:44:54 AM8/28/18
to Cantera Users' Group
Hello!

I am working with python 3.5 on a windows computer.

My aim is to write a code, which delivers me the results of a combustion with three different gases in the python console.
I want to get information about the mass flow (kg/s) and the composition of the resulting exhaust stream (molar proportions or mass proportions, temperature, pressure and enthalpy).

My code is so far:

import cantera as ct

# Use GRI-Mech-3.0
gas = ct.Solution('gri30.xml')
gas1 = ct.Solution('gri30.xml')
gas2 = ct.Solution('gri30.xml')
gas3 = ct.Solution('gri30.xml')
Exhaust = ct.Solution('gri30.xml')

# Use Reservoir for fuel
gas1.TPX = 300.0, ct.one_atm, 'CH4:0.9, N2:0.1'
fuel_in = ct.Reservoir(gas1)

# Use Reservoir for air
gas2.TPX = 300.0, ct.one_atm, 'O2:0.21, N2:0.77, AR:0.01'
air_in = ct.Reservoir(gas2) 

# Use Reservoir for H-Atoms for igniter, to enable the combustion reaction
gas3.TPX = 300.0, ct.one_atm, 'H:1.0'
igniter = ct.Reservoir(gas3)

# Combustion Chamber
gas.TPX = 300.0, ct.one_atm, 'N2:1.0'
combustor = ct.IdealGasReactor(gas)
combustor.volume = 10

# Use Reservoir for the resulting exhaust stream
Exhaust = ct.Reservoir(gas)

# MassFlowController to adjust the mass flows
m1 = ct.MassFlowController(fuel_in, Brennkammer, mdot=13.2)
m2 = ct.MassFlowController(air_in, Brenn:kammer, mdot=455)
m3 = ct.MassFlowController(igniter, Brennkammer, mdot=1)

# Connecting the combustion chamber with the exhaust
v = ct.Valve(Brennkammer, Abgas, K=1.0)

# the simulation only contains one reactor
sim = ct.ReactorNet([Brennkammer])



And now i want python to output the results about the properties of the exhaust stream.
In other examples it was possible to call the properties with this command:

Exhaust()

But this didn´t work.


Thank your for reading my problem!


Bryan W. Weber

unread,
Aug 28, 2018, 8:51:53 AM8/28/18
to Cantera Users' Group
Hi,

What other examples are you referring to, and what was the specific error code or message that you got when you tried Exhaust()?

Best,
Bryan

Nick Curtis

unread,
Aug 28, 2018, 9:19:57 AM8/28/18
to Cantera Users' Group
Additionally, the state of a Reservoir never changes after initialization.
Hence, the state will always be that of the gas during the call:

Exhaust = ct.Reservoir(gas)

If you want the state of the combustor's exhaust through the valve (and there does seem to be bugs in your code regarding initially naming the combustor 'combustor' and later referring to it as 'Brennkammer'), simply query the state of the combustor, as it its homogeneous, e.g.:

combustor.thermo()

or by extracting the specific quantities of interest

Nick

Potten

unread,
Aug 28, 2018, 9:25:11 AM8/28/18
to Cantera Users' Group
The example i am referring to is the "combustor" from the examples with this code:


"""
A combustor. Two separate stream - one pure methane and the other air, both at
300 K and 1 atm flow into an adiabatic combustor where they mix and burn.

We are interested in the steady-state burning solution. Since at 300 K no
reaction will occur between methane and air, we need to use an 'igniter' to
initiate the chemistry. A simple igniter is a pulsed flow of atomic hydrogen.
After the igniter is turned off, the system approaches the steady burning
solution.
"""

import math
import csv

import cantera as ct

# use reaction mechanism GRI-Mech 3.0

gas = ct.Solution('gri30.xml')

# create a reservoir for the fuel inlet, and set to pure methane.
gas.TPX = 300.0, ct.one_atm, 'CH4:1.0'
fuel_in = ct.Reservoir(gas)
fuel_mw = gas.mean_molecular_weight

# use predefined function Air() for the air inlet
air = ct.Solution('air.xml')
air_in = ct.Reservoir(air)
air_mw = air.mean_molecular_weight

# to ignite the fuel/air mixture, we'll introduce a pulse of radicals. The
# steady-state behavior is independent of how we do this, so we'll just use a
# stream of pure atomic hydrogen.
gas.TPX = 300.0, ct.one_atm, 'H:1.0'
igniter = ct.Reservoir(gas)

# create the combustor, and fill it in initially with N2
gas.TPX = 300.0, ct.one_atm, 'N2:1.0'
combustor = ct.IdealGasReactor(gas)
combustor.volume = 1.0

# create a reservoir for the exhaust
exhaust = ct.Reservoir(gas)

# lean combustion, phi = 0.5
equiv_ratio = 0.5

# compute fuel and air mass flow rates
factor = 0.1
air_mdot = factor * 9.52 * air_mw
fuel_mdot = factor * equiv_ratio * fuel_mw

# create and install the mass flow controllers. Controllers m1 and m2 provide
# constant mass flow rates, and m3 provides a short Gaussian pulse only to
# ignite the mixture
m1 = ct.MassFlowController(fuel_in, combustor, mdot=fuel_mdot)

# note that this connects two reactors with different reaction mechanisms and
# different numbers of species. Downstream and upstream species are matched by
# name.
m2 = ct.MassFlowController(air_in, combustor, mdot=air_mdot)

# The igniter will use a Gaussian time-dependent mass flow rate.
fwhm = 0.2
amplitude = 0.1
t0 = 1.0
igniter_mdot = lambda t: amplitude * math.exp(-(t-t0)**2 * 4 * math.log(2) / fwhm**2)
m3 = ct.MassFlowController(igniter, combustor, mdot=igniter_mdot)

# put a valve on the exhaust line to regulate the pressure
v = ct.Valve(combustor, exhaust, K=1.0)

# the simulation only contains one reactor
sim = ct.ReactorNet([combustor])

# take single steps to 6 s, writing the results to a CSV file for later
# plotting.
tfinal = 6.0
tnow = 0.0
Tprev = combustor.T
tprev = tnow
states = ct.SolutionArray(gas, extra=['t','tres'])

while tnow < tfinal:
    tnow = sim.step()
    tres = combustor.mass/v.mdot(tnow)
    Tnow = combustor.T
    if abs(Tnow - Tprev) > 1.0 or tnow-tprev > 2e-2:
        tprev = tnow
        Tprev = Tnow
        states.append(gas.state, t=tnow, tres=tres)

states.write_csv('combustor.csv', cols=('t','T','tres','X'))


I want to adapt this example to my problem. First I would like to create a combustion chamber where air, fuel and pure oxygen gets into a reactor and get burn. After this, the exhaust gas goes into a turbine, where the gas expands (high pressure turbine). After the turbine the exhaust gets into a second combustion chamber with additional fuel and oxygen and the exhaust gas goes into the low pressure turbine where it expands another time.

My aim is to plot the composition of the exhaust gas and the influence of additional oxygen in the combustion chambers for the resulting efficiency of this process.

When i try Exhaust():

    Abgas1()
TypeError: 'cantera._cantera.Reservoir' object is not callable



Potten

unread,
Aug 28, 2018, 9:26:36 AM8/28/18
to Cantera Users' Group
Thank you! Sorry i translated the code from german into english. "Brennkammer" means "combustion chamber", i forgot to change it into english.

Ray Speth

unread,
Aug 28, 2018, 11:25:31 AM8/28/18
to Cantera Users' Group
Hi,

I recently re-wrote this example to get rid of some things that I think tended to mislead users. Please see the updated version at https://cantera.org/examples/python/reactors/combustor.py.html. This may be a better basis for the problem you are trying to model.

Regards,
Ray

Potten

unread,
Aug 29, 2018, 3:00:35 AM8/29/18
to Cantera Users' Group
Hello. I saw your new example, but i dont understand how to output the results of the combustion in a simple way like:

print(Exhaust.report())

This dont work. In this very simple example it is possible:


import cantera as ct

gas = ct.Solution('gri30.xml')

#Gas A is air with constant enthalpy and pressure
A = ct.Quantity(gas, constant='HP')
A.TPX = 300.0, ct.one_atm, 'O2:0.21, N2:0.78, AR:0.01'

#Gas B is methane with constant enthalpy and pressure
B = ct.Quantity(gas, constant='HP')
B.TPX = 300.0, ct.one_atm, 'CH4:1'

#Gas C is oxygen with constant enthalpy and pressure
C = ct.Quantity(gas, constant='HP')
C.TPX = 300.0, ct.one_atm, 'O2:1'

M = A + B + C
M.equilibrate('TP')

#Output of the results of the exhaust gas
print(M.report())


This works. But i have to use a igniter and i want to use a combustion chamber, MassflowController and Reservoir...

Isn´t there a possibility to get me the results just in the console, without plotting them or to use excel?

Thank you very much!






Ray Speth

unread,
Aug 29, 2018, 9:55:00 AM8/29/18
to Cantera Users' Group
Hi,

Did you read Nick's post? He already gave you the answer.

Regards,
Ray

Potten

unread,
Aug 29, 2018, 10:11:14 AM8/29/18
to Cantera Users' Group
Hello, yes i have tried this.
But python gives me the the characteristics from the initial conditions of the combustion chamber:

gas.TPX = 300.0, ct.one_atm, 'N2:1.0'
combustor = ct.IdealGasReactor(gas)
combustor.volume = 10

combustor.thermo()


But i think there should be the results of the combustion. Do i have a thinking error about this?

Nick Curtis

unread,
Aug 29, 2018, 10:57:26 AM8/29/18
to Cantera Users' Group
import cantera as ct
gas = ct.Solution('gri30.cti')
gas.TPX = 1000, 101325, 'CH4:1.0, O2:2, N2:7.52'
reac = ct.IdealGasReactor(gas)
net = ct.ReactorNet([reac])
while reac.thermo.T < 2000:
    net.step()

print(reac.thermo.report())
>>>gri30:

       temperature         2001.48  K
          pressure          214058  Pa
           density        0.336755  kg/m^3
  mean mol. weight         26.1799  amu

                          1 kg            1 kmol
                       -----------      ------------
          enthalpy      9.2271e+05        2.416e+07     J
   internal energy      2.8707e+05        7.515e+06     J
           entropy          9850.9        2.579e+05     J/K
    Gibbs function     -1.8794e+07        -4.92e+08     J
 heat capacity c_p          1490.3        3.902e+04     J/K
 heat capacity c_v          1172.7         3.07e+04     J/K

                           X                 Y          Chem. Pot. / RT
                     -------------     ------------     ------------
                H2      0.0351107       0.00270355         -22.0827
                 H      0.0027195      0.000104702          -8.4894
                 O    0.000679828      0.000415465         -13.6308
                O2       0.084289         0.103023         -30.4935
                OH     0.00204784       0.00133034         -28.9939
               H2O       0.111414        0.0766679         -43.4514
               HO2     0.00016421       0.00020703         -40.1019
              H2O2    4.14408e-06      5.38426e-06         -54.8496
                 C    4.43048e-07      2.03264e-07          7.53443
                CH    4.63596e-06       2.3054e-06         -1.53622
               CH2    8.55893e-05      4.58576e-05         -13.5255
            CH2(S)    1.09497e-05      5.86673e-06         -12.5558
               CH3     0.00360062       0.00206779         -25.6781
               CH4     0.00955996       0.00585823         -37.8731
                CO      0.0614565        0.0657535         -36.3901
               CO2     0.00675976        0.0113635         -59.5984
               HCO    7.11854e-05      7.89032e-05         -38.5498
              CH2O     0.00100584       0.00115362         -45.2821
             CH2OH    9.52767e-06      1.12943e-05         -49.2433
              CH3O    6.99475e-06      8.29171e-06          -45.232
             CH3OH    4.25563e-05      5.20855e-05         -58.9961
               C2H    2.44261e-06      2.33532e-06         -9.90511
              C2H2     0.00111783       0.00111177         -23.9056
              C2H3    6.72616e-05      6.94862e-05         -27.0914
              C2H4     0.00134764        0.0014441          -38.199
              C2H5    2.86918e-05        3.185e-05         -42.7849
              C2H6    9.51156e-05      0.000109247         -52.7478
              HCCO    8.19721e-05      0.000128467         -35.4301
             CH2CO    0.000916381       0.00147144         -47.2138
             HCCOH    5.49974e-06      8.83097e-06         -44.5993
                 N    7.28482e-08      3.89751e-08         -8.35374
                NH    7.26305e-09      4.16549e-09         -22.1606
               NH2    1.09851e-09       6.7231e-10         -36.7093
               NH3    7.76261e-10      5.04973e-10         -52.1228
               NNH    9.23365e-09      1.02358e-08         -35.0776
                NO    3.50072e-07      4.01236e-07         -38.0037
               NO2     4.1206e-10      7.24105e-10         -53.5524
               N2O    6.51679e-08      1.09558e-07         -43.4912
               HNO    1.22198e-09      1.44762e-09          -45.189
                CN    1.14749e-09      1.14038e-09         -21.8046
               HCN    8.40918e-07      8.68083e-07         -35.2611
              H2CN    3.89026e-09      4.16571e-09         -37.4326
              HCNN    5.21435e-09      8.17257e-09         -28.5332
              HCNO    3.32003e-09      5.45626e-09         -45.4474
              HOCN    1.05831e-09      1.73927e-09         -57.0582
              HNCO    1.11704e-08      1.83578e-08         -61.1488
               NCO    6.39464e-09       1.0263e-08         -44.4023
                N2       0.677233         0.724664         -26.5756
              C3H7    8.68906e-08       1.4301e-07         -59.7416
              C3H8    2.69106e-07      4.53273e-07         -69.7248
            CH2CHO    6.16433e-06      1.01354e-05         -51.9671
            CH3CHO    5.16087e-05      8.68424e-05         -61.9413
     [   +1 minor]              0                0
Message has been deleted

Potten

unread,
Aug 30, 2018, 4:12:58 AM8/30/18
to Cantera Users' Group
Hello, thank you very much!

while reac.thermo.T < 2000:
    net.step()

What does exactly the "net.step()" command? Is there a loop running in the reactor until the temperature of 2000 K is reached?

Is there another possibility for this command? I want the loop to stop until the state of the cumbustion is steady-state. For example to plot me the results if the composition is constant.

Greets

Bryan W. Weber

unread,
Aug 30, 2018, 8:26:50 AM8/30/18
to Cantera Users' Group
Reply all
Reply to author
Forward
0 new messages