The Function mixe with setne and
showe

The three programs (mixe, sepe,
and reacte) will accomplish both material and
energy balances for the three operating units: the mixer, separator,
and reactor. A splitter requires essentially no modifications over
what was used as split. Before executing these
programs, a global array ne must be set with the proper
shape. The shape of ne is S by C+3, where S is the number of streams
and C is the number of components. The first column of ne stores the
stream temperatures with units given in the global variable Tdeg as
('C', 'F', 'R' or 'K'). The second column contains information about
the states of the streams. A 0 stored in the second column indicates
that the stream is a solid, a 1 indicates that it is a liquid and a 2
indicates it is a vapor. The third column contains the total enthalpy
of the stream:

Start301 will set ne to a zero matrix of
dimensions S by C+3. This is done after answering the prompt in
start301:

Enter the number of streams:

An auxiliary function helps in setting one stream's information in
ne. The comments in this function, setne
are shown next:

>> help setne
setne: used to set stream properties in ne
function setne(s,i,t,NS,j)
Argument List:
Argument Gives
s the state of the stream: 'l' for liquid,
'v' for vapor, 's' for solid.
i the index of the stream.
t the stream temperature in units of Tdeg.
NS the compound molar flow rates (mols/time) for the
compounds with indices j in cnms.
If the last argument is omitted, all compounds are
assumed to be given in NS.
Compounds with indices not in j will be given flow
rates of 0.
See also ISETNER, ISETNEV
Ex. setne('v',2,25,[2 5.5],[2 4])
will set the flows of compounds 2 and 4 as 2 and 5.5 mol/time
respectively. The rest of the flows will be set to 0.

The first argument is a character vector that must start with 'l' for
a liquid, 'v' for a vapor stream or 's' for a solid. A single
character is sufficient to designate the state of the stream. The
next argument gives the index of the stream; the next its temperature
in the units specified by Tdeg and the fourth argument the
component flow rates. If there is a fifth argument, it gives the
indices of the compounds that you want to set. The rest of the
compound flow rates will then be set to zeros. The function sets all
C+3 values in the row of data for the stream. Note the use of the
global variables cnms (and all its data arrays) and
Tdeg by the function. They must be set before
setne is executed (the easiest way to do this is
with start301).

Remember that an illustration of either a mass or energy module can
be accessed by simply typing the prefix pic to each module
name.

The mixer function: mixe

The mixer function mixe has four arguments as
shown in the listing:

function hdif=mixe(s,t,in,out)
% mixe - Energy balance mixer module
% function hdif=mixe(s,t,in,out)
% Argument List
% Argument Gives
% s the state of the exit stream:
% 'v' for vapor, 'l' for liquid, 's' for solid.
% t the temperature of the exit stream in Tdeg.
% in the indices of inlet streams,
% out the index of exit stream.
% hdif: the answer is the enthalpy out
% - the sum of the enthalpies in.
% Ex. mixe('v',55,[2 3 4],6)
% will mix streams 2, 3 and 4 to form stream 6.
% Stream 6 will be a vapor at 55Tdeg.
% For additional help and picture, see picmixe
% OKB, TYLC
global ne nc
if length(in)<2
ns=ne(in,4:(nc+3));
else
ns=sum(ne(in,4:(nc+3)));
end
j=find(ns);
setne(s,out,t,ns(j),j)
hdif=ne(out,3)-sum(ne(in,3));

The first line after the comments sets the names of global variables
used in the program. The next five lines of code determine where the
inlet flow rates are stored in ne and sums them to find the
component flows in the exit stream. The next line determines which of
the exit flows are non-zero so that in the fifth line, we can avoid
enthalpy calculations for missing components. The last line finds the
difference between the exit and the inlet enthalpies.

To illustrate the operation of
mixe with setne, we will use them
to do Example 7.25on p. 463 of the text. First, set the
names of the four compounds: C6H6, C6H5CH3, CH4 and H2 and specify
the number of streams for ne with the
start301 program. Then our solution of the problem
will follow from:

The function showe is used to
display the results in a readable form. It is quite short so we can
list all of it:

Note that it is short since most of the work is done by the much
longer function: dsplaye. The arguments are
identical to those with showm. If you wish to peruse
the longer function dsplaye, feel free to do so, but
you will find that it is the most complicated function in the
~ceng301/matlab/utilities directory. The first
argument of showe gives the inlet streams, the
second gives the exit streams. The last two arguments set the format
for printing flow rates.

3.3.3 Avoiding the Use of Missing Data

Since our data bank has lots of missing data, there are many cases
where the computer will generate meaningless enthalpies for
compounds. You should always remember that each stream must be a
single phase. If some of the compounds in the system being analyzed
do not have data that allows us to determine their enthalpies in that
phase, then we must avoid telling our programs to include them. The
energy modules, try to help with this by determining which compounds
in the exit stream(s) have zero flow rates. The modules then call the
functions HinkJ and setne with last
arguments that will get them to avoid the compounds that are missing.
You may have to follow this same procedure. Here is a session to show
how this can be done in calling setne. We have two
streams and three compounds: CO2, O2 and C. The
first stream has just C in it and the second one has CO2
and O2. If we try (after the start301
programs):

The Separator Function: sepe

The separator function operates in an analogous manner to the
mixer. The user must specify not only the fraction of each compound
that goes to the top stream but the temperature and state of each
exit stream. A listing of the function sepe is shown
next:

function hdif=sepe(stop,sbot,ttop,tbot,in,out,t)
% sepe: energy-balance separator module
% function hdif=sepe(stop,sbot,ttop,tbot,in,out,t)
% Argument List:
% Argument Gives
% stop state of the top stream: 'v', 'l', or 's'.
% sbot state of the bottom stream.
% ttop the temperature of the top stream in Tdeg.
% tbot the temperature of the bottom stream in Tdeg.
% in the index of feed,
% out the indices of the top and bottom streams
% in that order.
% t the fraction of each compound in the feed
% that goes to the top stream.
% sepe returns the sum of the enthalpies of the exit
% streams minus the enthalpy of the feed stream.
% Ex. sepe('v','l',120,150,2,[3 5],[.9 .35])
% might simulate a fractionator with stream 2 as the
% feed, 3 as the top product and 5 as the bottom.
% The top comes off as a vapor at 120Tdeg and gets
% 90% of the first component and 35% of the second.
% For additional help and picture, see PICSEPE
% OKB, TYLC
global ne nc
NS=ne(in,4:nc+3);
NST=NS.*t;
jt=find(NST);
NSB=NS-NST;
jb=find(NSB);
setne(stop,out(1),ttop,NST(jt),jt)
setne(sbot,out(2),tbot,NSB(jb),jb)
hdif=sum(ne(out,3))-ne(in,3);

The first line of code defines globals used by the function. The next
line extracts the feed flow rates into the vector NS and
puts the flows for the top exit stream in NST. The vector
jt stores the indices of the non-zero flow rates in this top
stream. The next two lines put the flows for the bottom stream in
NSB and the indices of non-zero flows in jb. The
function setne is used to set all the flow and state
conditions for the exit streams. Finally, the last line determines
and returns the difference between the enthalpies out and into the
separator.

A more general version of the separator module is called
sepen. It allows you to have multiple inlet and as
many exit streams as you want. Do a help in MATLAB for more
information.

The following problem may be readily solved with this separator
function. Fifty mols of benzene and toluene at 360K are separated
into a top stream that has 95% of the benzene and 5% of the toluene.
The top stream exits as a vapor at the normal boiling point of
benzene and the bottom stream exits as a liquid at the normal boiling
point of toluene. Find the net heat required for this separation.

The simulator solution with sepe follows (after
start301 was used to specify the two compounds,
choosing Kelvin for temperature:

The function sepen allows the user
to have multiple inlet and exit streams in a separator. It's help
code says:

Sepen: General purpose separator module
function hdif=sepen(s,tmp,in,out,t)
General purpose separator module:
The number of inlet and exit streams can be any integer >0.
Argument List:
Argument Gives
s vector of states of the exit stream(s).
('v', 'l', or 's')
tmp temperatures of exit streams in Tdeg.
in the indices of the inlet stream(s).
out the indices of the exit stream(s).
t The fraction of each compound in the product
that goes into each stream, except that the
last stream need not be given. Each row should
correspond to one exit stream. If tmp and out
are scalars, t does not need to be given.
sepen returns the sum of the enthalpies of the
exit streams minus the sum of the enthalpies
of the inlet streams.

Example 7.22 in Reklaitis illustrates the use of this program.

The program start301 is used to create the data
file E7.22 with data for oxygen and benzene in it. After
choosing a New Session, use Energy & Mass Balances
in CENG 301's database, using Celsius as the
temperature unit.

If we had made a mistake and set the temperature as Kelvin,
we can easily change the value stored in Tdeg with the following
command line:

>> Tdeg='C';

Set the flow in feed stream 1 using one hour of flow as the
basis:

>> setne('v',1,25,100000,1)

Write a simple program to give the error from mixing the two
streams and separating them as in the heat exchanger:

function er=ex722(FB)
global mw
% The flow of benzene is FB kg/hr, it's temperature is 250C.
setne('v',2,250,FB*1000/mw(2),2)
% The benzene out of the exchanger is saturated at 5.5bar or 550 kPa.
t4=teql(550);
% Stream 3 is a vapor at 200C, stream 4 is a liquid at t4(2)
% All the O2 goes into stream 3, none of the benzene goes into that stream.
er=sepen('vl',[200, t4(2)],1:2,3:4,[1 0]);

find a range in which there is a sign change:

>> ex722(100)
ans =
4.7360e+05
>> ex722(2000)
ans =
-5.2541e+05

Use ssec2 to find the required amount of
benzene:

>> ssec2([100 2000],'ex722(x)')
ans =
1.0007e+03

That's close to the value of 1050 kg/hr found in the text. Here is
what all the streams look like:

Here is the data found by use of sepen with the
trial and error function: ssec2 shown on the flow
diagram for the example:

The flow direction of the benzene has been reversed in this
picture since it would certainly require counter current flow in the
exchanger to have heat transfer from the benzene to the oxygen at all
points.

Note that sepen can be used with any number of inlet
and exit streams, it is not limited to just two of each as in this
example.

The Splitter Function: splite

The function splite can be used in two ways. The
simple splitting operation requires no energy balance since each
outlet from the splitter has the same state, temperature, and
mass/mole fractions as the feed. For this case
splite does the same thing as
split, except the state and temperature in
ne are kept.

>> help splite
splite: energy-balance splitter module
function hdif=splite(t,in,out,s,tmp)
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.
s the states of the exit streams.
tmp the temperatures of the exit streams.
The last two arguments are optional. Without them this works as a
normal splitter. With them splite can be used as a sort of heat
exchanger on the exit streams.
Ex: splite([.2 .2 .2 .2 .2],1,2:6)
would split stream 1 into 5 equal parts in streams 2 through 6,
all with the same state and temperature as stream 1.
Ex: splite([.2 .3 .5],1,2:4,'vvl',[400 300 200])
would split stream 1 into streams 2, 3 and 4.
Stream 2 would get 20% of the flow, as a vapor at 400 Tdeg,
stream 3 would get 30% as vapor at 300 Tdeg,
and stream 4 would get the remaining 50% as liquid at 200 Tdeg.
Splite returns the enthalpy difference between the inlet and outlet
streams, which should be zero unless the last two arguments are given.
For additional help and picture of Ex. #2 , see PICSPLITE
JWD, TYLC

The Reactor Functions: reacte, reacten

The function reacte simulates the behavior of a
reactor and computes material and energy balances for the process.
Before executing reacte, the arrays ne,
Tdeg, cnms as well as the stoic array for
the reactions must be set. A listing of reacte is
shown below:

The first three lines of code sums the inlet flows (if there is
more than one inlet stream) and puts the result into NS . It
then uses a matrix multiply to find the effect of the reactions on
these flows to produce the outlet flow rates. The vector, j,
indicates the indices of the non-zero flow compounds in the exit
stream. The function setne is then called to set the
outlet flows and other data and the difference between the exit and
inlet enthalpies returned in hdif.

Note that our answer is returned by reacte as a
negative 94.88 kJ per mol of NH3 added to the reactor.
This is the same as 22.68 kcal/mol NH3 removed from the
reactor and may be compared with 22.53 kcal/mol NH3 found
in the text.

From convu: 94.88000 kJ/(mol) = 22.67727 kcal/(mol)

Note that even reacte forces you
to have a single exit stream. If your reactor has two or more product
streams, you must use a combination of reacte
followed by one or more uses of sepe. This is what
reacten does. Since the sepe module
can handle two exit streams with different states, this makes the
modules capable of handling all the common cases that you want.
Again, the help explains how reacten is different
from the other reactors.

>> help reacten
function hdif=reacten(s,tmp,in,out,rs,t)
General purpose reactor module:
The number of inlet and exit streams can be any integer >0.
Argument List:
Argument Gives
s vector of states of the exit stream(s).
('v', 'l', or 's')
tmp temperatures of exit streams in Tdeg.
in the indices of the inlet stream(s).
out the indices of the exit stream(s).
rs the reaction rates.
t The fraction of each compound in the product
that goes into each stream, except that the
last stream need not be given. Each row should
correspond to one exit stream. If tmp and out
are scalars, t does not need to be given.
reacten returns the sum of the enthalpies of the
exit streams minus the sum of the enthalpies
of the inlet streams.
Ex: reacten('vs',[312 25],1:2,3:4,[.94 0.21],[1 1 0]);
JWD, SHD & OKB, TYLC

Example 8.4 in the Reklaitis text illustrates both the use of
reacten and the way in which data for missing compounds may be
inserted into the user's data bank with the program addcomp.
The compound benzaldehyde is not among the compounds currently stored
in the ceng301 data bank so we need to add information about it.

>> stdat2=addcomp
Choose a database to edit <-- brings up the menu

We
choose 301 Mass & Energy Balance and see next the very long
menu

<-- Our choice from the first menu is 301 Mass &
Energy Balance

We
can enter as much data as we need into this the new data bank from
this menu. From the statement of the example problem we know or can
find by changing units the following:

Information

Array name

Units

Data

Name

cnms

benzaldehyde

Formula

form

C6H5CHO

Molecular Weight

mw

106.124

Latent Heat of Vaporization at normal boiling point

LhlvkJ

kJ/mol

38.39

Normal Boiling Point

TbpK

K

452.15

State of compound used in setting its "Standard" Heat of
Formation

Ststdh

1 meaning liquid

"Standard" Heat of Formation

StdhkJ

kJ/mol

0 assumed and to be found

Coefficients in polynomial giving the Specific Heat of
Liquid

cpl

J/mol/K

[189.86 0 0 0]

Coefficients in polynomial giving the Specific Heat of
Vapor

cpv

J/mol/K

[129.7 0 0 0 0]

To input each type of data, we click on the button with the array
name we want. If we start with: For example to enter the compound
name, we click on the cnms button and get the following
message and give the name:

cnms= ? benzaldehyde

Then follow it by clicking on the appropriate buttons and entering
all the data in the table as follows:

>> save ex84
>> start301
Then choose from the next menu: New Session
and then: Energy & Mass Balances
and then: Your own
Enter the name of your database: ex84
Which units do you want to use for temperature?
Choose the temperature unit: Celcius
Input the name for a new file or just hit a return:
Input the number of compounds: 5
The number of compounds is: 5
Enter the name of compound # 1:C6H5CHO <-- This data base knows about benzaldehyde.

We can continue with a normal 301 session to set the other four
compounds and the reactions until we see:

Here are your compounds' formulae and names:
No. Formula Name
----------------------------------------
1 C6H5CHO benzaldehyde
2 C6H5CH3 toluene
3 O2 oxygen
4 H2O water
5 CO2 carbon dioxide
Here are your reactions:
----------------------------------------
1) C6H5CH3 + O2 --> C6H5CHO + H2O <-- reaction we want the dH for
2) C6H5CHO + 8O2 --> 3H2O + 7CO2 <-- reaction we know the heat ofcombustion for
>> intcp<-- we need to use this to set up icpl and icpv
>> sethcp<-- this then sets the hcpl and hcpv vectors
>> StdhkJ
StdhkJ =
0 <-- The value for this is what we need to find first using the given
50.0000 heat of combustion for the compound at 18C
0
-241.8300
-393.5000

The heat of combustion for benzaldehyde is given at 18°C.
This is the difference between the enthalpies of the products and the
enthalpies of the feed to a reactor. We have to be careful to specify
the state of the compounds as seen in the stoichiometric equation
that defines the heat of reaction. In Example 8.4 this reaction is
given as:

C6H5CHO(l) +
8O2(g) --> 3H2O(l) +
7CO2(g)

Thus we will set one mol of benzaldehyde as a liquid in stream 1
and 8 mols of oxygen in stream 2 as a gas. Then if we react all of
them by a unit amount of reaction 2 to produce one stream with liquid
water and one with vapor carbon dioxide, we will be carrying out the
reaction as specified.

Note that while reacten could be used with any
separation, normally the separation will just be used to separate
compounds with different states into separate streams. Here is an
example of solving problem 8.28 in Reklaitis.

a) in the first line the flows of C and CaCO3 are set
as shown in the table.
b) in the second line the reactions are carried out after streams 1
& 2 are mixed and followed by a separation of the product into
the vapor stream (3) at 600C with N2 and CO2 in
it and the solid stream (4) at 950C.