tutorial flame

6

Click here to load reader

Upload: hom-sharma

Post on 05-Dec-2015

226 views

Category:

Documents


14 download

DESCRIPTION

Cantera tutorial

TRANSCRIPT

Page 1: Tutorial Flame

Cantera Tutorial

1-D Premixed Free Flame with CANTERA

23 avril 2015

1 Introduction - Objectives

The aim of this tutorial is to walk non-experienced CANTERA users through the computation ofa 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 andunder atmospheric conditions ; but can easily be altered for other fuels or operating points. Themechanism used is the GRIMECH 3.0 with mixture transport properties, but it is also straightforwardto continue the computation if different transport models need to be considered. The saving formatcan as easily be adapted.

2 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.

1

Page 2: Tutorial Flame

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 flamedomain, to predict brutal changes, until convergence is reached. The simulation is first computed withthe energy equation disabled, to help the newton algorithm approach the final solution, and then swit-ched on before refinement can take place. It takes about 50 seconds to get the results on a standardlocal machine.

By the end you will be able to read the mixture-averaged flame speed along with some statisticspertaining 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 Functions Time Jacobians Time

9 1646 1.9900 15 0.8400

11 14 0.0200 1 0.0800

11 108 0.1900 1 0.0800

17 1014 3.1300 9 1.4500

23 508 2.2000 6 1.4200

29 574 3.3100 6 1.8800

35 287 2.0600 5 1.9400

41 46 0.3800 1 0.4700

48 14 0.1500 1 0.5500

55 12 0.1300 1 0.6500

55 2 0.0200 1 0.6600

69 10 0.1400 1 0.8500

69 2 0.0200 1 0.8600

111 12 0.2700 1 1.5000

119 8 0.1900 1 1.6100

119 2 0.0400 1 1.6100

166 8 0.3000 1 2.4100

173 4 0.1600 1 2.5300

173 4 0.1500 1 2.5400

173 2 0.0700 1 2.5400

235 6 0.3100 1 3.7200

264 4 0.2400 1 4.3100

267 4 0.2400 1 4.3700

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

2

Page 3: Tutorial Flame

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.

3 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 atext 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 you’d like to use (delete the hashtag # at the begining of the line) and makethe sure the others are commented.

The grid is set to be 0.02cm long. If you’d like to change this, you’ll need to change the valuehighlighted in magenta above for the grid you’ve 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 mechanismfile. 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 ob-tained with the multicomponent model, but are far less expensive to compute. It all depends uponthe fuel you are using and the accuracy required ! Usually however, you will have to start with themixture-averaged transport model before switching to any other one.

The transport property chosen in the original script is mixture averaged, but will be switched tomulticomponent model by adding this line in the adiabatic flame.py file :

3

Page 4: Tutorial Flame

...

#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 flameconsidered in this tutorial, you will notice a small difference in the flamespeed, and a negligeably smalldifference in the final adiabatic temperature (of the order of 0.1 K). However, the computationalprice 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 Functions Time Jacobians Time

9 549 0.1500 12 0.2400

9 221 0.0700 2 0.0500

13 861 0.4200 13 0.4700

4

Page 5: Tutorial Flame

21 1188 0.7400 14 0.9800

30 950 1.0900 13 1.3700

41 779 1.1700 18 2.7000

54 81 0.1800 3 0.6100

69 51 0.1500 1 0.2600

77 20 0.0600 1 0.3000

88 12 0.0000 1 0.3600

106 10 0.0600 1 0.4200

130 8 0.0400 1 0.5300

130 2 0.0000 1 0.5400

218 8 0.0700 1 0.9400

222 4 0.0500 1 0.9600

223 4 0.0300 1 0.9600

223 33 34.3200 3 2.9200

224 18 18.7900 2 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 compositionphi = 1. # premixed gas composition

Try any other values ! You may have to alter the inital grid, or change the computing propertiesto 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)

5

Page 6: Tutorial Flame

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 tryand enter the Newton convergence domain. The first number is the absolute value of the timesteps (here, 0.01 ms) and the following sequence is the number of time steps taken each timethe Newton algorithm fails.Note that this line can be commented so that the time steps are chosen automa-tically.

— 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, eitherduring the steady-state mode (first number) or during time-stepping mode (second one).

4 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 forslope 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 toabout 5, which will generate a great deal of information, including which solution component won’tconverge.

6