You are on page 1of 11

Plug Flow Reactor Module Using Matlab

The primary Matlab program for simulating a plug flow reactor is called: plugr1.
Before it is executed, a data file must be constructed that holds compound property
data as well as the reactor parameters. The FORTRAN program: start403a facilitates
the construction of such a file. In addition, a Matlab program must be written that
specifies the reaction kinetics. We will show how these programs are used in a
simulation of a plug flow reactor using data that was given in the 1995 ammonia plant
design for CENG 404.
First we construct the a compound data file. The name used for the file is arbitrary,
but htscomp was chosen in this example.
stationnm%start403a
Copyright 1997 Rice University
All rights reserved
Give the name used for your data file. It stores
compound property data and reaction rates.
The name should be no more than 16 characters long.
htscomp
<-- The file name used for the data
If your compound data file already exists, and you
do not want to change it, reply: y

<-- We have not yet set up the compound data file


Setting up the compound data file called:htscomp
Give the number of compounds:
6
<-- We have six compounds
If you want to see names, formulae or headings used in
the 301 data base, execute the FORTRAN program:
shownoh.
Give
H2
Give
CH4
Give
N2
Give
CO
Give
CO2
Give
H2O
Give
2

the name for compound #

<-- You may give either the name or the formula


the name for compound #

the name for compound #

the name for compound #

the name for compound #

the name for compound #

the number of reactions to set or 0 to skip.

Enter the coefficient for each compound in the


same order the compounds are listed.

Coefficients of reactants should be negative and


coefficients of products should be positive.
Enter the coefficients for reaction
H2 CH4 N2 CO CO2 H2O
3 -1 0 -1 0
-1 <-- For CH4

+ H2O -> 3H2 + CO, but it


WARNING ! The element C
was typed wrong so we get this
is not balanced in that equation. message
WARNING ! The element O
is not balanced in that equation.
If you want to redo the equation, reply: y
y
<-- Let's correct it.
Enter the coefficients for reaction
H2 CH4 N2 CO CO2 H2O
3 -1 0 1 0
-1
<-- This works

better!
<-- Our program agrees.

the equation is balanced


If you want to redo the equation, reply: y

<-- We are satisfied


Enter the coefficients for reaction
H2 CH4 N2 CO CO2 H2O
1 0
0 -1 1
-1
<-- The water

gas shift:
CO + H2O -> CO2 + H2

the equation is balanced


If you want to redo the equation, reply: y

<-- Just a return again

If you want to set plug flow reactor parms, reply: y


y

Now we will set up a second file to hold the parameters associated with the
reactor. Again the name is arbitrary, but we will chhose: htsreact.
Give the name of your reactor data file,
it should be no more than 16 characters long.
htsreact
Give a title for your simulation.
It will be used on your plots.
High Temp. Shift
Give the name of your reaction rate file.
ratehts2
<-- The file ratehts2.m must

be stored
If the reaction fluid is a liquid, reply: y.
<-- Our reactor fluid is a vapor

Give your bed dimensions: diameter and length in meters.


3.19 10
<-- Either spaces or commas may be

used to separate data


Give the pressure in atm and inlet temp. in C.
30 350
Give the bed properties: density in kg/m3 and porosity.
1200 0.48
If your reactor is isothermal rather than adiabatic,
Reply: y

<-- We will simulate an adiabatic reactor


Give the inlet molar flow rate: mols/second.
2110
Give the inlet mol fractions for each compound:
So far the sum of the mol fractions is:
0. The number
of compounds left to be given is: 6
Give the Mol Fraction of: hydrogen
0.305
So far the sum of the mol fractions is:
0.305000 The
of compounds left to be given is: 5
Give the Mol Fraction of: methane
0.1
So far the sum of the mol fractions is:
0.405000 The
of compounds left to be given is: 4
Give the Mol Fraction of: nitrogen
0.15
So far the sum of the mol fractions is:
0.555000 The
of compounds left to be given is: 3
Give the Mol Fraction of: carbon monoxide
0.098
So far the sum of the mol fractions is:
0.653000 The
of compounds left to be given is: 2
Give the Mol Fraction of: carbon dioxide
0.04
So far the sum of the mol fractions is:
0.693000 The
of compounds left to be given is: 1
Give the Mol Fraction of: water
0.307
The sum of mol fractions is:
1.00000
whale%

number

number

number

number

number

The compound data file: htscomp created by this process is quite long and contains a
lot of property data that is not required in the plug flow simulator. Here is a partial
listing of the file.

The data file: htscomp


nc
cnms
1
2
3
4
5
6
form
1
2
3
4
5
6
mw

6
1
6
hydrogen
methane
nitrogen
carbon monoxide
carbon dioxide
water
6
1
6
H2
CH4
N2
CO
CO2
H2O
6
1
6

1
2
3
4
5
6
Aabc
1
2

2.016
16.043
28.013
28.010
44.010
18.015
6
3
12.784
13.584

6
1
232.32
968.13

8.0800
-3.7200

Here is where we omit some of the data in the file. Note that the data for some
compounds are missing; such as the melting point for the fifth compound and the
specific heats for all solids except water as seen in:
TmpK
1
2
3
4
6
cpl
1
2
3
4
5
6
cps
6
cpv
1
2
3
4
5
6
critP
1
2
3
4
5
6
critT
1
2
3
4
5
6
critZ
1
2
3

6
13.960
90.650
63.150
68.050
273.15
6
58.866
-5.7070
14.714
14.967
11.042
18.296
6
-2.4167
6
17.630
38.380
29.410
29.000
19.020
34.040
6
1315.2
4640.7
3398.4
3498.6
7380.5
22109.
6
33.191
191.06
126.27
132.95
304.20
647.30
6
0.30400
0.28900
0.29100

4
5

6
1
-0.23069
1.0256
2.2026
2.1440
1.1595
0.47211
1
1
0.24405
6
1
0.67000E-01
-0.73660E-01
-0.30100E-02
0.24900E-02
0.79620E-01
-0.96500E-02
6
1

-0.80421E-01 0.13777E-02
-0.16656E-02 -0.19750E-04
-0.35214E-01 0.17996E-03
-0.32470E-01 0.15804E-03
-0.72313E-02 0.15501E-04
-0.13387E-02 0.13142E-05
-0.77632E-03

0.15743E-05

-0.13140E-03 0.10580E-06 -0.29100E-10


0.29090E-03 -0.26380E-06 0.80060E-10
0.54500E-05 0.51310E-08 -0.42530E-11
-0.18640E-04 0.47980E-07 -0.28720E-10
-0.73700E-04 0.37450E-07 -0.81330E-11
0.32990E-04 -0.20440E-07 0.43020E-11

4
5
6
dHComb
1
2
4
stoic
1
2

0.29400
0.27400
0.23000
6
-241.80
-802.31
-283.00
2
3.00
1.00

6
2
-1.00
0.00

1
0.00
0.00

1.00
-1.00

0.00
1.00

-1.00
-1.00

The last set of data is the stoichiometric array that defines the two reactions.
The reactor data file: htsreact created by use of start403a is short and may be listed in
its entirety. You can recognize most of the answers given to prompts in the session
with start403a.

The data file: htsreact


CMPDAT htscomp <-- Gives the name of the compound
titl
1
1
1
0
1
High Temp. Shift
ratefn
1
1
1
0
1
ratehts2
LVQ
1
1
1
0
1
v
DHTS
1
1
1
1
1
3.1900
LHTS
1
1
1
1
1
10.000
P
1
1
1
1
1
30.000
T1c
1
1
1
1
1
350.00
DBED
1
1
1
1
1
1200.0
PBED
1
1
1
1
1
0.48000
ISOTH
1
1
1
1
1
0
FLOW1
1
1
1
1
1
2110.0
y1vec
1
6
1
1
1
0.30500 0.10000 0.15000 0.09800 0.04000 0.30700

data file

Now we must create a Matlab program that can be used to specify the reaction
kinetics. We said it would be called ratehts2, so we must put a file called that with the
Matlab appendage: ".m" in our Matlab path. Here is the file by that name used in our
simulation:

Kinetics File: ratehts2.m


function r = ratehts2(T,P,yvec)
%
%
r = ratehts(T,P,yvec)
%
% This function calculates the rates of the hts wgs reaction
%
together with the methane reforming rxn to CO and H2.
% Function inputs:
%
% T
= temperature
(K)
% P
= pressure
(atm)
% yvec
= vector of mole fractions
%
H2, CH4, N2, CO, CO2, H2O
% Function outputs:
% r
= reaction rates
(mol/m3-sec)
%
r(1) = CH4 reforming to CO and H2
%
r(2) = Water Gas Shift reaction
%
%----------------------------------------------------------%
%
Declare global variables
%
global DBED%
%
Get mole fractions of hydrogen, methane, carbon monoxide,
%
water and carbon dioxide from yvec.
%
yh = yvec(1);
% H2
ym = yvec(2);
% Methane
yc = yvec(4);
% CO
yd = yvec(5);
% CO2
yw = yvec(6);
% H2O
%
%
Set kinetic parameters
%
% For the first reaction
km = 5.517e6;
% mol/kg-s-atm
Kh = 4.053;
% 1/atm
Ea1 = 1.849e5; % J/mol
% For the second reaction
A
= 4.95e8; % mol/kg-s
Ea2 = 1.163e5; % J/mol
%
%
Compute the rates
%
% First the Equilibrium constants
keq
= kequil(T);
% Then rate of the first reaction
r= DBED*km*exp(-Ea1/(8.3143*T))*P*ym/(1+Kh*P*yh);
% Finally add the rate of the second reaction
r = [r;DBED*A*exp(-Ea2/(8.3143*T))*(yc*yw-(yd*yh/keq(2)))];
% NOTE: This makes r into a column vector!!!
%
Exit
%

Note that the comments in the function show exactly how the rates are calculated.

Executing plugr2
Before we can execute the plug flow simulator in Matlab, we must make sure that
Matlab can find:
1. the compound data file
2. the reactor data file and
3. the kinetic rate program.
If you have stored the kinetic in your Matlab directory or another place which is in
Matlab's search path, this program will be found. The data files (in our
example htscomp and htsreact) may have to be moved to a directory that is searched
by Matlab. An even more serious problem can occur if you have multiple copies of
either of the files or the program. In the case of the kinetic program, you may want to
use the Matlab whichcommand to make sure Matlab will find the version of program
that you desire. Unfortunately, this command can not be used to see what data file will
be found. The plugr2 program:
prints the names of the compounds,
lists the reactions and
shows that name you gave to your simulation.
You should make sure that this information is unique so you can tell that you are using
the correct data.
Here is our simulation executed in the Matlab Command Window:
>>plugr2
Copyright 1997 Rice University
All rights reserved
If you have not run the FORTRAN program start403a to
produce a compound data file, do so before you go on.
You may also want to use the same program to produce
a file of operating data for your system.
If you have an operating data file, you should give
that file name in response to the following prompt:

At this point, double-click on the file name you have


created
using the menu that should have just popped up on your
screen.
It should look like:

Note the white line around the file name that was selected, make sure it is there;
otherwise the file may not really be selected. You may then click on the Done button.
How many streams will there be?0
Here are your compounds' names:
hydrogen
methane
nitrogen
carbon monoxide
carbon dioxide
water
Here are your reactions:
CH4 + H2O --> 3 H2 + CO
CO + H2O --> H2 + CO2
High Temp. Shift
Would you like to see a table or plot or stop?

<-- A menu allows you to choose among these options.

I chose first to see a table of data and specified with the following menu that it should
be molfractions of the gas.

Length m
0
0.0781
0.7031
1.3281
1.9531
2.5781
3.2031

Mole Fractions
H2
CH4
0.3050
0.1000
0.3054
0.1000
0.3092
0.1000
0.3133
0.1000
0.3179
0.1000
0.3229
0.1000
0.3284
0.1000

N2
0.1500
0.1500
0.1500
0.1500
0.1500
0.1500
0.1500

CO
0.0980
0.0976
0.0938
0.0897
0.0851
0.0801
0.0746

CO2
0.0400
0.0404
0.0442
0.0483
0.0529
0.0579
0.0634

H2O
0.3070
0.3066
0.3028
0.2987
0.2941
0.2891
0.2836

3.8281
4.4531
5.0781
5.7031
6.3281
6.9531
7.5781
8.2031
8.8281
9.4531
10.0000

0.3344
0.3409
0.3477
0.3546
0.3612
0.3670
0.3717
0.3751
0.3774
0.3789
0.3797

0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000
0.1000

0.1500
0.1500
0.1500
0.1500
0.1500
0.1500
0.1500
0.1500
0.1500
0.1500
0.1500

0.0686
0.0621
0.0553
0.0484
0.0418
0.0360
0.0313
0.0279
0.0256
0.0241
0.0233

0.0694
0.0759
0.0827
0.0896
0.0962
0.1020
0.1067
0.1101
0.1124
0.1139
0.1147

0.2776
0.2711
0.2643
0.2574
0.2508
0.2450
0.2403
0.2369
0.2346
0.2331
0.2323

These results compare favorably with those numbers generated by Aspen.

Would you like to see a table or plot or stop?

Next I chose a plot and asked to look at the temperature profile..

Would you like to see a table or plot or stop?

<-- Here I stopped.

After choosing to either see a table or plot results, you have eight items to choose
from:
1. Mass Fractions of the compounds,
2. Mol Fraction of the compounds,
3. Molar flow rate of the compounds,
4. Temperature of the gas,
5. Gas Velocity,
6. Gas Density,
7. Average molecular weight of the gas,
8. Total molar flow of the gas.
Note that in making a new run to simulate similar conditions, it may not be necessary
to execute start403a to create your reactor data file. The file may be readily edited to
change one or more pieces of data. You should be careful to give your new simulation
a distinct name so that you can tell in the Matlab run, what data was used.

You might also like