[Go to previous section: 1.2| Go
to next section: 1.4]
[ Go to CENG301 Homepage
| CENG301 Notes Table of Contents]
Part 2
The names you put into cnms are used in the display of the
flow rates produced by the function showm. The showm function
gives a compact display of all flow rates in the streams that enter
and leave a unit. There are four arguments to showm. Comments in the
function tell what each argument specifies. The working part of showm
is a single line that calls a much longer function called
dsplay.
Note that the listing of this and many other Matlab programs is color coded to help you see important parts of the program. This coding came from the PC version of Matlab 5.1 and includes:
We hope this coding will be helpful, but we know it will cause one difficulty. You can not copy lines of code from such listings to a text editor where you might want to use them. You can find all the programs in the ceng301 matlab directory and copy from those files.
The function called by showm, dsplay,
returns a character matrix. If you want to store the character array
returned by dsplay in a file, you may use the function
mprintc for that purpose. The comments in
mprintc tells us how this is done.
>> help mprintc function mprintc(c,f) Stores in the file f, the character array c. If file f already has information in it the new data is added on. Ex: mprintc(['abc';'123'],'t.t') will add the lines: abc 123 to the contents of the file: t.t
The function showm will be demonstrated for each of the four
types of modules described in this section of the notes. The result
of using help on dsplay is shown below:
>> help dsplay function c=dsplay(in,out,s,d) Argument List: Argument Gives in the inlet stream numbers. out the exit stream numbers s the number of spaces for each flow. d the number of decimals to display flows. ex: cmix=dsplay([1 2],3,10,3)
We will see that showm presents the table of flows transposed
from what we saw in our previous flow tables. This was done because
the function normally will need to show only a small number of
streams while the number of compounds is unlimited. The reactor
module involves only two streams and the separator three. The mixer
and splitter could involve any number of streams but more than four
would be quite unusual. Thus the table was easier to format with the
molar flows in each stream arranged in a column. In contrast the
number of streams in an entire plant is most likely to exceed the
number of compounds being separated. Thus the original Table of Flows
for a Plant had each stream information in a row.
The function sep simulates the behavior of a separator. It takes one inlet stream and separates it into two outlet streams. Three arguments must be given to sep:
The help notes for the function tell us:
Sep: mass-balance separator module function sep(t,in,out) Simulates the behavior of a separator. It takes one inlet stream and separates it into two outlet streams. Argument Gives t(j) the fraction of ns(in,j) that goes to the first outlet stream. Can be a vector. in the index of the inlet stream. out the indices of the two exit streams. The exit streams are ordered. For additional help and picture, see PICSEP OKB, TYLC Example: >> sep([0.2 0.3 0.8 0.5],1,[2 3]) Would separate stream 1 (which contains 4 compounds: a,b,c,d) into exit streams 2 and 3 Stream 2 is the first outlet stream because it is the the first stream specified in the vector, out (3rd argument of sep) and would get 20% of cmpd a in Stream 1 30% of cmpd b in Stream 1 80% of cmpd c in Stream 1 50% of cmpd d in Stream 1 Stream 3 is the other outlet stream and would get the remaining amounts of the cmpds NOTE that the sum of the t vector does NOT necessarily equal one!
A picture and full listing of the program may be found in section 5.1.
The first five lines of code in sep check to see that the
user has given the correct amount of data in the first argument. The
two lines that do all the calculations in sep are quite straight
forward. The first line does an element by element multiply of the
vector t with the vector of flows for the inlet stream. This
result becomes the flow rates for the first exit stream. All of the
rest of the flow in the inlet stream is put into the second exit
stream.
The following problem is easily solved with sep. We have a
small plant with five streams and four compounds. One of the units is
a distillation tower that separates the four compounds. The streams
to and from the unit and the compound names are given below together
with the separation achieved in the unit.
Stream Name Component Name Fraction of Feed sent to Distillate 3 Feed 1 propane 0.99 2 Distillate 2 i-butane 0.75 4 Bottoms 3 n-butane 0.25 4 i-pentane 0.01
The names were entered using start301 using option (1)
Other, using no compound data:
>> start301 1: Click (1) to start a new session 2: Click (2) to enter the name of a datafile from a previous session, in the current directory 3: Click (3) to use compound names not in the CENG 301 database WARNING...if you hit (3) no compound data will be available <-- (3) was the selection for this example You have chosen to not use any compound data If you wish to enter data for a compound, exit (control-C) then execute "create", then run a "new session", choice (1) Enter the number of compounds: 4 Compound names must be less than 25 characters long! Give the name of compound # 1: propane Compound names must be less than 25 characters long! Give the name of compound # 2: i-butane Compound names must be less than 25 characters long! Give the name of compound # 3: n-butane Compound names must be less than 25 characters long! Give the name of compound # 4: i-pentane <-- choice (3) was necessary since i-butane is not a recognized compound Enter the number of streams: 5 >> who Your variables are: cnms nc nst ns
The feed flowrates were set by:
>> ns(3,:)=[20 30 30 20] ns = 0 0 0 0 0 0 0 0 20 30 30 20 0 0 0 0 0 0 0 0
The inlet stream is number 3 and the outlet streams are 2 and 4. The
out argument in sep is given with the "top" or distillate stream
number then the "bottom". The choice of which is the top and which
the bottom is arbitrary, but the one designated in the top position
must be the one for which we give the fractions in the first
argument. To achieve the separation specified we then call
sep by:
>> sep([.99 .75 .25 .01],3,[2 4])
Note the use of '[' and ']' to make the first and last
arguments into vectors. This is required and will be repeated
frequently in MATLAB. Then our flow matrix lists as:
>> ns ns = 0 0 0 0 19.8000 22.5000 7.5000 0.2000 20.0000 30.0000 30.0000 20.0000 0.2000 7.5000 22.5000 19.8000 0 0 0 0
This information is more readable as presented by showm. All we need
to tell it is the stream information: 3, [2 4] as it was
given to sep. We also need to tell how much printing
space each flow will occupy and the number of decimal places as
in:
>> showm(3,[2 4],10,1) Compound Inlet | Outlet Stream 3 | 2 4 Total propane 20.0 | 19.8 0.2 20.0 isobutane 30.0 | 22.5 7.5 30.0 n-butane 30.0 | 7.5 22.5 30.0 isopentane 20.0 | 0.2 19.8 20.0 Total 100.0 | 50.0 50.0 100.0
We may enter this data into our Flow Table to see that after the
separator analysis we know the flows in 3 of our five streams.
Comp No. |
1 |
2 |
3 |
4 |
Total |
||
---|---|---|---|---|---|---|---|
Stream |
From Unit* |
To Unit* |
|||||
1 |
|
|
ns(1,1) |
ns(1,2) |
ns(1,3) |
ns(1,4) |
sum(ns(1,:)) |
2 |
Still |
|
19.8 |
22.5 |
7.5 |
0.2 |
50.0 |
3 |
|
Still |
20.0 |
30.0 |
30.0 |
20.0 |
100.0 |
4 |
Still |
|
0.2 |
7.5 |
22.5 |
19.8 |
50.0 |
5 |
|
|
ns(5,1) |
ns(5,2) |
ns(5,3) |
ns(5,4) |
sum(ns(5,:)) |
The function split simulates the behavior of a splitter. It
takes an inlet stream and splits it into n branches. Each branch will
have the same composition as the inlet stream. Three arguments must
be given to split:
1) t, gives the fraction of the incoming stream which goes to each branch. Therefore, sum(t) must equal 1.0;
2) in, is the index of the inlet stream;
3) out, is a vector whose elements give the indices of the outlet streams.
The help notes for the function give more information:
split: mass-balance splitter module function split(t,in,out) Argument List Argument Gives t the fraction of the inlet stream that goes to each exit stream. in the index of the inlet stream. out the indices of the exit streams. OKB Ex: split([.2 .3 .5],1,2:4) would split stream 1 into streams 2, 3 and 4. Stream 2 would get 20% of the flow, stream 3 would get 30% and stream 4 the rest.
A flow diagram and full listing of split may be seen in Section 5.2.
Most of the lines of code in split check the arguments to make
sure that they are consistent. A loop is used to set the flow in each
outlet stream in exactly the way that the comments suggest.
Let's do Example Problem 2.17 in the text. There are four
streams and three components.
|
Component Name Stream Name Flow 1 malt 1 Feed 1000 2 hops 2 Branch 2 F2 = 2F3. 3 water 3 Branch 3 F3 4 Branch 4 F4 = 3F3.
The names must be put into cnms and make space for four
streams in ns. We can do this with start301,
selection (1) Other without creating a data file by:
>> start301 Copyright 1998 Rice University All rights reserved 1: Click (1) to start a new session 2: Click (2) to enter the name of a datafile from a previous session, in the current directory 3: Click (3) to use compound names not in the CENG 301 database WARNING...if you hit (3) no compound data will be available You have chosen to not use any compound data If you wish to enter data for a compound, exit (control-C) then execute "create", then run a "new session", choice (1) Enter the number of compounds: 3 Compound names must be less than 25 characters long! Give the name of compound # 1: malt Compound names must be less than 25 characters long! Give the name of compound # 1: hops Compound names must be less than 25 characters long! Give the name of compound # 1: water Enter the number of streams: 5 >> who Your variables are: cnms nc ns nst
Let the streams be numbered as in Figure 2.27 so the index
of the inlet stream is 1 and the vector of outlet indices is:
[2 3 4] or 2:4.
The inlet stream flowrates are given by:
>> ns(1,:)=[200 100 700] ns = 200 100 700 0 0 0 0 0 0 0 0 0
Since the flowrate of branch 2 is twice the flowrate of branch 3 and
the flowrate of branch 4 is three times the flowrate of branch 3, the
fractions of the feed sent to each exit stream are:
[2 1 3]/6
Now, execute the program split.
>> split([2 1 3]/6,1,2:4)
Let's look at the flows:
>> showm(1,2:4,10,2) Compound Inlet | Outlet Stream 1 | 2 3 4 Total malt 200.00 | 66.67 33.33 100.00 200.00 hops 100.00 | 33.33 16.67 50.00 100.00 water 700.00 | 233.33 116.67 350.00 700.00 Total 1000.00 | 333.33 166.67 500.00 1000.00
The problem asks for the flowrates of each of the branches. These are
shown in the Total row as: 333.3, 166.7, and 500. We can also enter
these calculated values in a Table of Flows for a Splitter.
Comp No. |
1 |
2 |
3 |
Total |
||
---|---|---|---|---|---|---|
Stream |
From Unit* |
To Unit* |
||||
1 |
|
Splitter |
200.0 |
100.0 |
700.0 |
1000.0 |
2 |
Splitter |
|
66.67 |
33.33 |
233.33 |
333.33 |
3 |
Splitter |
|
33.33 |
16.67 |
116.67 |
166.67 |
4 |
Splitter |
|
100.0 |
50.00 |
350.00 |
500.00 |