Вы находитесь на странице: 1из 5

Lab1IntroductiontoCantera:Thermodynamicsand

ChemicalKinetics

(Recommendedmaterial:Chapter2Thermodynamics)

Video demonstrations of this lab can be found on YouTube at


http://www.youtube.com/user/FndmtlsofCombustion

Introduction

The purpose of this lab is to learn to use the computer software Cantera
(http://code.google.com/p/cantera/), developed by Prof. David Goodwin of the
CaliforniaInstituteofTechnology.YouwilluseCanterathroughoutthecoursefor
homework assignments. In lab #4, we will use Cantera to calculate premixed
laminar flame speeds and examine flame structure. Cantera is an opensource
combustioncodeavailabletouseandmodifyforfree.Itcanbeusedtoexamine
multiphasechemicalequilibrium,onedimensionalflames,reactionpathdiagrams
andmuchmore.

CanteraInstallation

ThoughCanteracanbeusedwithLinuxandMacOSXand/orrunthroughC++
and Fortran, we will briefly describe howto install Cantera on a PC running
Matlab and the free scripting language Python. Take care to use compatible
versionsofCantera,Python,Numpy,and,ifneeded,Numarray.Wheninstalling
CanteraandPython,makethefilepathsasshortaspossible.Inotherwords,dont
burytheminsideotherfoldersthatareinsideanother,etc.
DownloadCanterafromhttp://code.google.com/p/cantera/Olderversions
ofCanteracanbefoundathttp://sourceforge.net/projects/cantera
DownloadPythonfromhttp://www.python.org
o Download Numpy and Numarray from
http://prdownloads.sourceforge.net/numpy/
InstallPython
InstallNumpyandNumarrayifneeded
Set the environmental variables in the Control Panel. Make sure the
PATHvariableincludesc:\pythonXX\
2

InstallCantera
InstalltheCanteraPythoninterface(.exeinsideCanterafolder)
Start Matlab and add the folder c:\program
files\Cantera\MATLAB\toolbox\canteratoitspath
TesttheCanterainstallationbyexecutingoneofthetutorials
TestthePython/numeric/numarrayinstallation.Startacommandprompt
andnavigatetoC:\ProgramFiles\Cantera\demos\Python\flames.Runthe
adiabatic_flame.py script by typing adiabatic_flame.py at the
commandprompt.
AdditionalhelpandinformationonCanteracanbefoundat:
http://sourceforge.net/projects/cantera/
http://tech.groups.yahoo.com/group/cantera/
http://code.google.com/p/cantera/

GettingStarted

AgoodplacetostartlearninghowtouseCanteraistheMATLABtutorialsthat
aredistributedwithCantera. Theseare.mfilesthatshouldnowbelocatedin
c:\Cantera\tutorials\MATLAB.FromMATLAB,openthefileinthisfoldercalled
tut1.m(i.e.tutorial1).ThiscanberunbyhittingF5.Betteryet,readthroughthe
.m file and paste the uncommented MATLAB commands into the command
window and execute them one at a time. The tutorials are short, and it is
recommendedyoucompleteatleasttutorials1,3,4,5,and7.Theseshouldgive
you an idea of how Cantera works and the types of calculations that can be
performedwithCantera.

ExamplesofEquilibriumCalculationswithCanteraand
MATLAB

a)UseCanteratocalculatetheadiabaticequilibriumflametemperatureand
mixturecompositionforastoichiometricmethaneairmixtureinitiallyat300K
and101.3kPa(usetheGRI3.0mechanism).
EnterthefollowingintotheMATLABcommandwindow:
g=IdealGasMix('gri30.cti');
set(g,'T',300,'P',1.013e5,'X','CH4:1.0001,N2:7.52,O2:2');
equilibrate(g,'HP')

Thefirstlinecreatesanobjectgwhichisanidealgasmixture.Thepartinside
the single quotes specifies that the species, kinetics, and thermodynamics are
3

calculatedaccordingtotheGRI3.0mechanismformethane.Theinitialconditions
(temperature,pressure,composition)aresetbythesecondline.Notethat1.0001
molesareusedinsteadof1becausetheCanteraequilibriumsolversometimes
cannot converge for exactly stoichiometric conditions. The last line finds the
equilibrium composition at constant enthalpy (H) and pressure (P). The
thermodynamicpropertiesoftheequilibratedmixtureanditscompositionshould
beprintedtothescreen.

b)UsetheCanteraequilibriumsolvertocalculatetheheatofreactionforthe
combustionofastoichiometricmixtureofmethaneandair,initiallyat300Kand
101.3kPa(usetheGRI3.0mechanism).

EnterthefollowingintotheMATLABcommandwindow:
g=IdealGasMix('gri30.cti');
set(g,'T',300,'P',1.013e5,'X','CH4:1.0001,N2:7.52,O2:2');
Qr=enthalpy_mass(g);
equilibrate(g,'TP')
Qp=enthalpy_mass(g);

Theinitialtwolinesaresimilartocasea).Thethirdlinestorestheenthalpyof
themixtureinthevariableQr,andthefourthlineequilibratesthemixtureunder
constantpressureandtemperature(notethe'TP'insteadof'HP').Thefifthline
storestheenthalpyofthemixtureinthevariableQp.Theheatofreaction(inJ/kg
ofmixture)isthenQpQr.ThiscanbeconvertedtoanenthalpyofreactioninJ/kg
offuel,whichisequalinmagnitudetotheheatofcombustion.

ExplosioninaZeroDimensionalHomogeneousMixture

Here we will simulate a kineticallycontrolled explosion of a methane/air


mixture in a constant volume adiabatic homogeneous reactor. The reactor is
essentiallyaperfectlyinsulatedvolumeofgas,andthistypeofproblemisknown
as zerodimensional kinetics because the system has no explicit spatial
dimensionsbutitevolvesintime.WewillusetheGRI3.0methanemechanism.
1.)OpenanewMatlabscriptandtypethefollowinglinesofcode:
%Zerodimensionalkinetics.
%Constantvolumeandinternalenergy

%Creategasobject:
gas=IdealGasMix('gri30.xml');

%Getmolecularweightandnumberofspecies:
mw=molecularWeights(gas);
4

nsp=nSpecies(gas);

%Setgastemperature,pressure,andinitialmolefractions:
set(gas,'T',350.0,'P',oneatm,'X','CH4:1,O2:2,N2:7.52');

%SetanarrayusedbytheODEsolver
y0=[temperature(gas)
massFractions(gas)];

%Thefollowinglinesetsthetimeinterval(inseconds)thatwillbesimulated.
%Youwillhavetochangethesecondnumber(theendtime).
tel=[02e25];

options=odeset('RelTol',1.e5,'AbsTol',1.e12,'Stats','on');
t0=cputime;
out=ode15s(@conuv,tel,y0,options,gas,mw);
disp(['CPUtime='num2str(cputimet0)]);

%Makeplots:
figure(1);
plot(out.x,out.y(1,:));
xlabel('time');
ylabel('Temperature');
title(['FinalT='num2str(out.y(1,end))'K']);

figure(2);
ioh=speciesIndex(gas,'OH');
plot(out.x,out.y(1+ioh,:));
xlabel('time');
ylabel('MassFraction');
title('OHMassFraction');

figure(3);
ino=speciesIndex(gas,'NO');
plot(out.x,out.y(1+ino,:));
xlabel('time');
ylabel('MassFraction');
title('NOMassFraction');

2.)Saveandexecutetheabovecommands.Aftercrunchingnumbersforafew
seconds,Canterashouldgenerateplotsoftemperature,OHconcentration,andNO
concentrationasafunctionoftime.
3.)Theignitiondelaytimecanbeconsideredthetimeatwhichthereaction
takes off. For our purposes, this can be considered the time at which the
5

temperature rise corresponds to approximately 50% of the final value. Try


experimentingwithdifferentinitialtemperatures,pressures,etc.toseehowthis
affectstheignitiondelaytime.

Вам также может понравиться