Vous êtes sur la page 1sur 6

Cantera Tutorial

1-D Premixed Free Flame with CANTERA

23 avril 2015

Introduction - Objectives

The aim of this tutorial is to walk non-experienced CANTERA users through the computation of
a 1-D steady-state free flame simulation, with the Python interface.
The script presented here deals with a Methane-Air premixed free flame, at stoechiometry and
under atmospheric conditions ; but can easily be altered for other fuels or operating points. The
mechanism used is the GRIMECH 3.0 with mixture transport properties, but it is also straightforward
to continue the computation if different transport models need to be considered. The saving format
can as easily be adapted.

Steps

2.1

Get the script and mechanism

The script can be downloaded here : http://www.cerfacs.fr/cantera/docs/scripts/flames/


adiabatic_flame.py
And the .cti file here : http://www.cerfacs.fr/cantera/docs/mechanisms/methane-air/
Gri30/gri30.cti
They should be placed in a CANTERA sub-directory of your choice.
If later on, you whish to go further, similar scripts can be found here : http://www.cerfacs.fr/
cantera/docs/scripts/flames/ .
As said previously, it will run a 1-D free flame for which methane CH4 is the fuel species.
Other mechanism than the GRIMECH 3.0 could be used, such as those presented on the website :
http://www.cerfacs.fr/cantera/mechanisms/meth.php.

2.2

Load the CANTERA module

# ! Remember to source the code ! #


Open a terminal and simply type :
module load cantera/2.1.1
This will enable you to run your CANTERA scripts.

2.3

Launch your computation

Now, on the same terminal, go into your CANTERA sub-directory and type :
python adiabatic_flame.py
If all is going well, the program will automatically refine the mesh where needed in the flame
domain, to predict brutal changes, until convergence is reached. The simulation is first computed with
the energy equation disabled, to help the newton algorithm approach the final solution, and then switched on before refinement can take place. It takes about 50 seconds to get the results on a standard
local machine.
By the end you will be able to read the mixture-averaged flame speed along with some statistics
pertaining to your run, directly on your terminal :
Problem solved on [265] point grid(s).
..............................................................................
no new points needed in flame
mixture averaged flamespeed = 0.370268579822
Solution saved to ch4_adiabatic.csv.
Statistics:
Grid
9
11
11
17
23
29
35
41
48
55
55
69
69
111
119
119
166
173
173
173
235
264
267

Functions
1646
14
108
1014
508
574
287
46
14
12
2
10
2
12
8
2
8
4
4
2
6
4
4

Time
1.9900
0.0200
0.1900
3.1300
2.2000
3.3100
2.0600
0.3800
0.1500
0.1300
0.0200
0.1400
0.0200
0.2700
0.1900
0.0400
0.3000
0.1600
0.1500
0.0700
0.3100
0.2400
0.2400

Jacobians
15
1
1
9
6
6
5
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

Time
0.8400
0.0800
0.0800
1.4500
1.4200
1.8800
1.9400
0.4700
0.5500
0.6500
0.6600
0.8500
0.8600
1.5000
1.6100
1.6100
2.4100
2.5300
2.5400
2.5400
3.7200
4.3100
4.3700

You will also see a plot pop up in front of your terminal, with a number of quantities plotted. Note
that you will need to import matplotlib for this to work !

2.4

Saving files

Datas are written in a .csv output file that can be imported into Excel. A .xml file is also created.
You can look up other scripts available at http://www.cerfacs.fr/cantera/docs/scripts/flames/
to see other common type of output files.

To go further

3.1

Change your initial grid

If you would like to change the grid used, you will need to open the adiabatic flame1.py with a
text editor. You will see this :

...
#Different initial grid, chosen to be 0.02cm long :
# - Refined grid at inlet and outlet, 6 points in x-direction :
initial grid = 2*array([0.0, 0.001, 0.01, 0.02, 0.029, 0.03],d)/3 # m
# - Uniform grid, 6 points in x-direction :
#initial grid = 0.02*array([0.0, 0.2, 0.4, 0.6, 0.8, 1.0],d) # m
# - Uniform grid of 300 points using numpy :
#initial grid = numpy.linspace(0,0.02 , 300)
...
Uncomment the one youd like to use (delete the hashtag # at the begining of the line) and make
the sure the others are commented.
The grid is set to be 0.02cm long. If youd like to change this, youll need to change the value
highlighted in magenta above for the grid youve chosen.

3.2

Change transport properties

The first argument in the importPhase module should be the name of the .cti mechanism used.
The second argument is the name of the transport model used, also referenced in the .cti mechanism
file. This file needs to be in your working directory.
The common transport models are :
multi : this model uses multi component properties,
mix : a model that implements a mixture-average formulation,
avbp : the Cerfacs AVBP transport model will be used, on mechanisms that allow it. Additional
files are needed for this model.
In general, the results of the mixture-averaged transport model are less accurate than those obtained with the multicomponent model, but are far less expensive to compute. It all depends upon
the fuel you are using and the accuracy required ! Usually however, you will have to start with the
mixture-averaged transport model before switching to any other one.
The transport property chosen in the original script is mixture averaged, but will be switched to
multicomponent model by adding this line in the adiabatic flame.py file :

...
#Import gas phases with mixture transport model
gas = Solution(gri30.cti, gri30_mix)
...
...
gas.transport_model(Multi)
f.solve(loglevel, refine_grid)
#Calculation and saving of the results should always be done
f.save(ch4_adiabatic.xml,energy_multi,
solution with the multicomponent transport and energy equation enabled)
print mixture averaged flamespeed = ,f.u[0]
...
If you change the transport properties from mixture averaged to multicomponent in the flame
considered in this tutorial, you will notice a small difference in the flamespeed, and a negligeably small
difference in the final adiabatic temperature (of the order of 0.1 K). However, the computational
price is quite high, as can be seen when reading the statistics :
Problem solved on [221] point grid(s).
no new points needed in flame
Solution saved to file ch4_adiabatic.xml as solution energy continuation.
mixture-averaged flamespeed = 0.379154102712
..............................................................................
Attempt Newton solution of steady-state problem...

success.

Problem solved on [221] point grid(s).


##############################################################################
Refining grid in flame.
New points inserted after grid points 192
to resolve H
..............................................................................
Attempt Newton solution of steady-state problem...

success.

Problem solved on [222] point grid(s).


no new points needed in flame
Solution saved to file ch4_adiabatic.xml as solution energy_multi_1.
multicomponent flamespeed = 0.383687979055
solution saved to adiabatic_flame.csv
Statistics:
Grid
9
9
13

Functions
549
221
861

Time
0.1500
0.0700
0.4200

Jacobians
12
2
13

Time
0.2400
0.0500
0.4700
4

21
30
41
54
69
77
88
106
130
130
218
222
223
223
224

1188
950
779
81
51
20
12
10
8
2
8
4
4
33
18

0.7400
1.0900
1.1700
0.1800
0.1500
0.0600
0.0000
0.0600
0.0400
0.0000
0.0700
0.0500
0.0300
34.3200
18.7900

14
13
18
3
1
1
1
1
1
1
1
1
1
3
2

0.9800
1.3700
2.7000
0.6100
0.2600
0.3000
0.3600
0.4200
0.5300
0.5400
0.9400
0.9600
0.9600
2.9200
1.9400

real 2m3.851s
user 1m59.340s
sys 0m0.659s

3.3

Change operating conditions

There are some operating conditions that can be changed in the first lines of the script :
Temperature and Pressure conditions
#Parameter values
p
=
1.e5
# pressure
tin
=
300.0
# unburned gas temperature
Gas composition
phi
= 1. # premixed gas composition
Try any other values ! You may have to alter the inital grid, or change the computing properties
to reach convergence ...

3.4

Change computing properties

The following computing properties can (and often : should !) be changed. In a text editor again,
open the adiabatic flame1.py script :
Tolerance properties on steady-state or time steps :
tol_ss
= [1.0e-5, 1.0e-9]
# [rtol atol] for steady-state problem
tol_ts
= [1.0e-5, 1.0e-9]
# [rtol atol] for time stepping
Refinement criteria :
#Set Refinement Criteria
f.set_refine_criteria(ratio = 10.0, slope = 1, curve = 1)

ratio : Additional points will be added if the ratio of the spacing on either side
of a grid point exceeds this value
slope : Maximum difference in value between two adjacent points, scaled by the
maximum difference in the profile (0.0 < slope < 1.0).
Adds points in regions of high slope.
curve : Maximum difference in slope between two adjacent intervals, scaled by the
maximum difference in the profile (0.0 < curve < 1.0).
Adds points in regions of high curvature.

There are other refinement criteria when the energy equation is set on ...
Time steps :
#Set time Steps
f.set_time_step(1.0e-5, [2, 5, 10, 20, 50]) #s
In case the Newton convergence fails, the program undergoes a sequence of time steps to try
and enter the Newton convergence domain. The first number is the absolute value of the time
steps (here, 0.01 ms) and the following sequence is the number of time steps taken each time
the Newton algorithm fails.
Note that this line can be commented so that the time steps are chosen automatically.
Jacobian matrix :
f.set_max_jac_age(50, 50)
It sets the number of time the Jacobian will be used before it must be re-evaluated, either
during the steady-state mode (first number) or during time-stepping mode (second one).

Convergence hints

Depending upon the complexity of the mechanism, the transport model used, the grid used (...)
convergence issues may arise.
Here are some hints to try and handle these common problems :
Coarsen the grid : Use a initial grid with fewer points. Try an uniform grid.
Increase slope and curve parameters : it will decrease the number of points in the solution
(maximum value of 1). Of course, at the expense of accuracy... but values of around 0.1 for
slope and 0.2 for curve will usually give well-resolved profiles.
Decrease time steps : problems can arise from too large time stepping,
Decrease both the tolerances for steady-state problem and time-stepping.
If you still have convergence problems, you might want to increase the value of the loglevel to
about 5, which will generate a great deal of information, including which solution component wont
converge.

Vous aimerez peut-être aussi