Lamniar flame speed with Matlab's Cantera toolbox.

3,783 views
Skip to first unread message

Geoffrey

unread,
Feb 23, 2012, 1:35:19 PM2/23/12
to Cantera User's Group
Hello all,
Im new to using cantera and I would like to calculate the laminar
flame speed of different reactive gaz mixtures using Cantera on
Matlab. I Know there are python (adiabatic_flame.py) and c++
(flamespeed.cpp) demos which provides laminar flames speed but
unfortunately the 1D expamples in matlab folder don't include the free
flame calculation only the burner flame case example is available and
I did not found any complete manual for matlab's cantera toolbox.

I searched on this Cantera user's group and yahoo's one and I found
several posts asking the same question but never the answer was
posted, did they finaly solve the problem ?

I have started out by first comparing the provided demos Flame1.m and
flame1.py in an attempt to understand the differences between the
simulations in Matlab and Python. I have also been looking through the
tutorial files provided with Cantera for both Matlab and Python.

Then I tried to transpose the Python's example named
adiabatic_flame.py wich calculate the laminar flame speed but it uses
the function FreeFlame.py wich is not available for matlab in the 1.8
Cantera version I have. Finaly I found a Freeflame.m on the online
sources of cantera's website (http://code.google.com/
codesearch#YbwRwnBOdvE/cantera18/changes/liquidTransportDevelop/
Cantera/matlab/cantera/1D/FreeFlame.m) I am not sure it is the correct
equivalent for matlab but I tried and it doesn't work.

I provide you my current matlab code and the error message.

%
% ADIABATIC_FLAME - A freely-propagating, premixed methane/air flat
% flame with multicomponent transport properties
%

%helpadiabatic_flame;
%disp('press any key to begin the simulation');
%pause;
clc;
t0 = cputime; % record the starting time


% parameter values
p = oneatm; % pressure
tin = 300.0; % unburned temperature
mdot = 0.04; % kg/m^2/s

comp = 'CH4:0.45, O2:1, N2:3.76'; % premixed gas composition

initial_grid = [0.0, 0.001, 0.01, 0.02, 0.029, 0.03] % m

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

loglevel = 1; % amount of diagnostic output (0
% to 5)

refine_grid = 1; % 1 to enable refinement, 0 to
% disable
max_jacobian_age = [50, 50];

%%%%%%%%%%%%%%%% create the gas object %%%%%%%%%%%%%%%%%%%%%%%%
%
% This object will be used to evaluate all thermodynamic, kinetic,
% and transport properties
%

gas = GRI30('Multi');

% set its state to that of the unburned gas at the burner
set(gas,'T', tin, 'P', p, 'X', comp);


%%%%%%%%%%%%%%%% create the flow object: freeflame %%%%%%%%%%%%%%%%%%%%
%%%

ff = FreeFlame(gas,'ff');
set(ff, 'P', p, 'grid', initial_grid);
set(ff, 'tol', tol_ss, 'tol-time', tol_ts);

%%%%%%%%%%%%%%% create the inlet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The burner is an Inlet object. The temperature, mass flux,
% and composition (relative molar) may be specified.
%
in = Inlet('in');
set(in, 'T', tin, 'MassFlux', mdot, 'X', comp);


%%%%%%%%%%%%%% create the outlet %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The type of flame is determined by the object that terminates
% the domain. An Outlet object imposes zero gradient boundary
% conditions for the temperature and mass fractions, and zero
% radial velocity and radial pressure gradient.
%
s = Outlet('out');


%%%%%%%%%%%%% create the flame object %%%%%%%%%%%%
%
% Once the component parts have been created, they can be assembled
% to create the flame object.
%
fl = flame(gas, in, ff, s);
setMaxJacAge(fl, max_jacobian_age(1), max_jacobian_age(2));

% if the starting solution is to be read from a previously-saved
% solution, uncomment this line and edit the file name and solution
id.
%restore(fl,'h2flame2.xml', 'energy')

solve(fl, loglevel, refine_grid);

%%%%%%%%%%%% enable the energy equation %%%%%%%%%%%%%%%%%%%%%
%
% The energy equation will now be solved to compute the
% temperature profile. We also tighten the grid refinement
% criteria to get an accurate final solution.
%


enableEnergy(fl);
setRefineCriteria(fl, 10, 0.2, 0.02, -0.00005);
solve(fl, 1, 1);
saveSoln(fl,'h2fl.xml','energy',['solution with energy' ...
' equation']);



%%%%%%%%%% show statistics %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
writeStats(fl);
elapsed = cputime - t0;
e = sprintf('Elapsed CPU time: %10.4g',elapsed);
disp(e);


%%%%%%%%%% make plots %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clf;
figure(1);
plotSolution(fl, 'flow', 'T');
title('Temperature [K]');
figure(2);
plotSolution(fl, 'flow', 'u');
title('Axial Velocity [m/s]');



############################################################################################
############################################################################################
############################################################################################
COMMAND WINDOWS
############################################################################################
############################################################################################
############################################################################################

..............................................................................

Attempt Newton solution of steady-state problem... failure.

..............................................................................
??? Error using ==> ctmethods


************************************************
Cantera Error!
************************************************


Procedure: MultiNewton::step
Error: Jacobian is singular for domain ff, component CH3CHO at point
5
(Matrix row 343)
see file bandmatrix.csv


Error in ==> stack_methods at 13
v = ctmethods(90, n, job, a, b);

Error in ==> Stack.solve at 4
stack_methods(s.stack_id, 104, loglevel, refine_grid);

Error in ==> adiabatic_flame at 82
solve(fl, loglevel, refine_grid);



Ray Speth

unread,
Mar 1, 2012, 12:03:18 PM3/1/12
to canter...@googlegroups.com
Geoffrey,

The problem is related to the one part of the original script that you weren't able to translate, setting the fixed point for the temperature profile. Unfortunately, this function is not currently available in Cantera's Matlab interface. If you submit a bug report at http://code.google.com/p/cantera/issues/list it will remind me to fix this problem when I get a chance.

In the mean time, if you understand the Python version well enough to translate it to Matlab, you should be able to use that.

Ray

Miguel

unread,
Feb 20, 2016, 9:46:38 PM2/20/16
to Cantera Users' Group, geoffrey...@gmail.com
Hi Geoffrey,

I was googling for the same reason. We normally use chemkin to solve for flame speed. But I am interested din using cantera matlab, though as you mentioned I have found no solution around. 
I was wondering if you have got your script working or yet you have found no way to arrange it.

Thanks for sharing, you post was really helpful.

Miguel

EZ hassan

unread,
Oct 19, 2016, 3:09:00 PM10/19/16
to Cantera Users' Group, geoffrey...@gmail.com
Hello,
I am also facing the same issue and was wondering if this has been resolved or if someone has an m file that works

Santosh Shanbhogue

unread,
Oct 19, 2016, 3:15:54 PM10/19/16
to Cantera Users' Group, geoffrey...@gmail.com
Can you state which Cantera version you are using ? And a sample code that does not work ? That will be help us debug the problem. The original post in the thread is from 2012 and since then Cantera has undergone several updates 

Thanks
Santosh

Ray Speth

unread,
Oct 19, 2016, 5:23:43 PM10/19/16
to Cantera Users' Group, geoffrey...@gmail.com
Hi,

Essentially nothing has changed with regards to support for flame simulations in Matlab, and nothing is likely to change in the foreseeable future. If you want to model flames in Cantera, you should use the Python interface.

Regards,
Ray


On Wednesday, October 19, 2016 at 3:09:00 PM UTC-4, EZ hassan wrote:

EZ hassan

unread,
Oct 20, 2016, 10:54:19 AM10/20/16
to Cantera Users' Group, geoffrey...@gmail.com
OK:
Thanks for the reply. I am assuming something is fundamentally difficult to change with the MATLAB flame code?
Ez
Reply all
Reply to author
Forward
0 new messages