[Go to previous section: 1.5| Go to next Chapter: 2.0]
[ Go to CENG301 Homepage | CENG301 Notes Table of Contents]


 

1.6: Analyzing the Flows and Reactions in a Plant - Page 2

Page 1

Page 2


1.6.3 The General Purpose Driver Program: drive


The drive program can be used to simulate multi-unit systems. The listing of it is quite long but most of the operations are simple and help shows us:

>> help drive

drive  - Provides an interactive mass balance analysis of a plant
  function drive
  DRIVE provides an interactive analysis of a plant
  Before running DRIVE  you must run start301.
  DRIVE  lets the user execute any of the four basic modules: 
        sep, split, mix, and react
  The user may also choose to use SSEC2 (trial and error option) or
        to evaluate a given Matlab function.
  The drive menu lists:
  Option                      Reply     for some additional help see:
  set rates in a feed stream   sf       ns, start301, cnms
  set stoichiometric coef      ss       setstc, stoic
  mixer                        mx       mix, picmix
  splitter                     sp       split, picsplit
  separator                    se       sep, picsep
  reactor                      re       react, picreact
  trial and  error             te       tecon1, tecon2, ssec2
  evaluate Matlab expression   ev       tecon1, tecon2, ssec2
  stop                         st
  OKB, additions by JWD, revised help by TYLC


The flow matrix ns (with known flow rates in it), the compound name arrays cnms, and the stoichiometric array stoic (if there are reactions) must be defined before using the drive program. After these three arrays have been set, start the drive program in motion by typing its name. The program will then ask for any balances you wish to perform using the modular programs. Needed data such as reaction rates, split ratios, and separator fraction must be given in reply to prompts from the computer.

Modular Approach to Problem 3.12 with drive

We will demonstrate the use of drive to solve Problem 3.12 in the text.

You will find it much easier to see what must be done by using the program in an interactive session than you will in just reading these notes. We set the compound names and define stoic for the one reaction in Problem 3.12. After executing start301 to name the eight compounds and specify the one reaction, using Mass Balances Only gives:

Input the name of your new file: chroms
The output file name is: chroms

Input the number of compounds: 7
The number of compounds is: 7

Enter the name of compound # 1: ethanol
Enter the name of compound # 2: sodium chromate
Enter the name of compound # 3: sulfuric acid
Enter the name of compound # 4: acetic acid
Enter the name of compound # 5: Cr2(SO4)3
Enter the name of compound # 6: Na2SO4
Enter the name of compound # 7: water
Enter the number of reactions: 1

Enter the coefficients for each compound in the same order that
the compounds are listed.  Coefficients for reactants should be
Negative, and coefficients for products should be positive
Enter the coefficients for each compound in reaction # 1
 C2H5OH  Na2Cr2O7  H2SO4  CH3COOH  Cr2(SO4)3  Na2SO4  H2O  
  -3       -2     -8     3         2       2   11
Here are your reactions:
3 C2H5OH  + 2 Na2Cr2O7  + 8 H2SO4  --> 3 CH3COOH  + 2 Cr2(SO4)3  + 
2 Na2SO4  + 11 H2O 
Enter the number of streams: 8


The single separator in Figure 3.12 must be replaced by a sequence of two separators since our sep function handles only two product streams. In the first separator we will split off the acetic acid product and in the second one we will separate into a waste stream and the recycle stream. The streams are numbered so that:

     Stream                  Connects
                   From                  To            
       1       Ethanol Feed             Mixer
       2   Acid and Chromate Feed       Mixer
       3          Mixer                Reactor
       4         Reactor             Separator 1
       5        Separator 1         Acid Product
       6        Separator 1          Separator 2
       7        Separator 2         Waste Product
       8        Separator 2            Recycle

Using 3 mols of ethanol as a basis in stream 1 with the information given for the feed rates in stream 2 and the recycle stream 8, we can use drive to set the flows in these streams by:

>> drive

Give the space for printing flows: 9

Give the number of decimals to print them: 3
Flow Matrix
row/col         1        2        3        4        5        6        7
   1         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   2         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   3         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   4         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   5         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   6         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   7         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   8         0.000    0.000    0.000    0.000    0.000    0.000    0.000
Option                      Reply
set rates in a feed stream   sf
set stoichiometric coef      ss
mixer                        mx
splitter                     sp
separator                    se
reactor                      re
trial and  error             te
evaluate Matlab expression   ev
stop                         st

 Enter your choice  sf  <-- to set a feed stream

Which stream do you want to set? 1

Enter the flow rate for each compound   [3,zeros(1,6)]

If you want to see all the flows in ns, reply: y  

       Option Lists

 Enter your choice  sf   <-- Set feed stream

Which stream do you want to set? 2

Enter the flow rate for each compound   [0 2.2 9.6 zeros(1,4)]

If you want to see all the flows in ns, reply: y  

       Option Lists

 Enter your choice  sf   <-- Set feed stream

Which stream do you want to set? 8

Enter the flow rate for each compound   [0.18 0 2.82 zeros(1,4)]

If you want to see all the flows in ns, reply: y  y
Flow Matrix
row/col         1        2        3        4        5        6        7
   1         3.000    0.000    0.000    0.000    0.000    0.000    0.000
   2         0.000    2.200    9.600    0.000    0.000    0.000    0.000
   3         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   4         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   5         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   6         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   7         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   8         0.180    0.000    2.820    0.000    0.000    0.000    0.000

       Option Lists  

  Enter your choice  mx            <-- Our response to get a mixer
 Give the indices of the feed streams  1 2 8 <-- We want to mix streams   
 Give the indices of the exit streams  3      <--  1,2 and 8 to get 3
 If you want to redo these indices, reply y n

 They were entered correctly so mix and display are executed and we see:

                   

Compound                Inlet                      | Outlet  
        Stream        1        2        8    Total |        5
ethanol           3.000    0.000    0.180    3.180 |    3.180
sodium chromate   0.000    2.200    0.000    2.200 |    2.200
sulfuric acid     0.000    9.600    2.820   12.420 |   12.420
Total             3.000   11.800    3.000   17.800 |   17.800
If you want to see all the flows in ns, reply y y  <-- We do this time.

Flow Matrix
row/col         1        2        3        4        5        6        7
   1         3.000    0.000    0.000    0.000    0.000    0.000    0.000 
   2         0.000    2.200    9.600    0.000    0.000    0.000    0.000 
   3         3.180    2.200   12.420    0.000    0.000    0.000    0.000 
   4         0.000    0.000    0.000    0.000    0.000    0.000    0.000 
   5         0.000    0.000    0.000    0.000    0.000    0.000    0.000
   6         0.000    0.000    0.000    0.000    0.000    0.000    0.000 
   7         0.000    0.000    0.000    0.000    0.000    0.000    0.000 
   8         0.180    0.000    2.820    0.000    0.000    0.000    0.000

       Option Lists  

  Enter your choice re                   <-- Next is our reactor.
 Give the indices of the feed streams  3 <-- Stream 3 is its feed.

 Give the indices of the exit streams  4 <-- Stream 4 is produced.

 If you want to redo these indices, reply y n 

 give the reaction rates    0.9     <-- with one reaction at rate 0.9. 
Compound                Inlet   | Outlet  
                Stream        3 |        4
ethanol                   3.180 |    0.480
sodium chromate           2.200 |    0.400
sulfuric acid            12.420 |    5.220
acetic acid               0.000 |    2.700
Cr2(SO4)3                 0.000 |    1.800
Na2SO4                    0.000 |    1.800
water                     0.000 |    9.900
Total                    17.800 |   22.300

 If you want to see all the flows in ns, reply: y  n 

       Option Lists  

  Enter your choice  se <-- Using a separator

 Give the indices of the feed streams  4 

 Give the indices of the exit streams  5 6 

 If you want to redo these indices, reply y n 
Give the fraction of each species that
goes to stream:    5
  0 0 0 1 0 0 0      <-- Only Acetic acid goes to stream 5.

Compound                Inlet   |          Outlet           
                Stream        4 |        5        6   Total 
ethanol                   0.480 |    0.000    0.480    0.480
sodium chromate           0.400 |    0.000    0.400    0.400
sulfuric acid             5.220 |    0.000    5.220    5.220
acetic acid               2.700 |    2.700    0.000    2.700
Cr2(SO4)3                 1.800 |    0.000    1.800    1.800
Na2SO4                    1.800 |    0.000    1.800    1.800
water                     9.900 |    0.000    9.900    9.900
Total                    22.300 |    2.700   19.600   22.300

 If you want to see all the flows in ns, reply: y  n 

       Option Lists

  Enter your choice  se <-- Another separator

 Give the indices of the feed streams  6 

 Give the indices of the exit streams  7 8 

 If you want to redo these indices, reply y n 
Give the fraction of each species that
goes to stream:    7
0.625 1 0.45977011 1 1 1 1  <-- These are the fractions that
                            meet the specs for the recycle.

Compound                Inlet   |          Outlet           
                Stream        6 |        7        8   Total 
ethanol                   0.480 |    0.300    0.180    0.480
sodium chromate           0.400 |    0.400    0.000    0.400
sulfuric acid             5.220 |    2.400    2.820    5.220
Cr2(SO4)3                 1.800 |    1.800    0.000    1.800
Na2SO4                    1.800 |    1.800    0.000    1.800
water                     9.900 |    9.900    0.000    9.900
Total                    19.600 |   16.600    3.000   19.600

 If you want to see all the flows in ns, reply: y  

       Option Lists

  Enter your choice  st <-- We are finished!

>>


1.6.4 Use of Specially Written Functions


Suppose we had a more common variation in the problem described in the last section in which we are given the separation ratios in both separators but do not know the recycle flows. Then we have no place to start our analysis in which we know all flow rates. If we assume values for the rates in the recycle stream, we can proceed as before around the loop. When we get back through the second separator, we will find a new set of flow rates in the recycle stream. These of course will not match our assumed values, but may be better values for starting a second time around. We could use the drive program to do this, but you will find this to be tedious. A special purpose program used just to simulate this one combination of units will be much easier to use for the trial and error solution.

 

 

The function p312 simply does the operations we showed:

  1. Mix streams 1, 2, and 8 to form 3.
  2. React stream 3 with rate .9 to form stream 4.
  3. Separate stream 4 into 5 with all the acetic acid in it and stream 6 with every thing else.
  4. Separate stream 6 with a given fraction of each compound going to the waste and the rest going to the recycle.

After the loop is complete, the function returns a listing of the rates of sulfuric acid and ethanol in the recycle stream. Here is a session using p312 that followed the last session:

>> ns(3:8,:)=zeros(6,7);   <-- Assuming no flow in the recycle.
>> p312
    C2H5OH     H2SO4   in Stream 8
    0.1125    1.2966          <-- We see the result after one loop.
>> p312
    C2H5OH     H2SO4   in Stream 8
    0.1547    1.9970          <-- Changing some more.
>> p312
    C2H5OH     H2SO4   in Stream 8
    0.1705    2.3754          <-- and more.
>> ns(8,[1 3])=[.18 2.82];
>> p312                      <-- If we had guessed right,
    C2H5OH     H2SO4   in Stream 8
    0.1800    2.8200          <-- there would be no change.


Example Problem: 5.33

A problem that requires more analysis before it can be solved with the module functions is Problem 5.33 in the text.

The number of streams in the problem must be increased to 17 to accommodate our modular restrictions of single inputs to reactors and separators. The function iter was developed in APL by Mr. Matthys, modified to shorten it and then rewritten in MATLAB. The streams are numbered so that:

     Stream                 Connects
                    From                 To
       1        Hydrogen Feed          Mixer 1
       2     Separator (recycle)       Mixer 1
       3          Mixer 1              Mixer 2
       4          Splitter             Mixer 2
       5          Mixer 2              Reactor
       6          Reactor              Condenser
       7          Condenser            Splitter
       8          Splitter             Purge
       9          Condenser            Mixer 3
      10          Mixer 3              Burner
      11          Burner               Mixer 4
      12          Mixer 4              Absorber
      13          Absorber             HNO3 Product
      14          Absorber             Separator
      15          Separator            Waste Gas
      16          Air Feed             Mixer 3
      17          Water Feed           Mixer 4

 

The function iter lists all the flows in a table using prntmx. The function iter has an argument that sets the number of times that the function loops through the calculation of all the balances.

 

 


We must first set the compound names and reactions, using (1) New Session, with Mass Balances Only.

Give the name of your data file:nitric

 
Here are your compounds' names:
 oxygen      
 nitrogen    
 hydrogen    
 ammonia     
 nitric oxide
 nitric acid 
 water       
Here are your reactions:
 N2    + 3 H2     --> 2 NH3   
2 O2    +  NH3    -->  HNO3  +  H2O   
2.5 O2    + 2 NH3    --> 2 NO    + 3 H2O 
Enter the number of streams: 17

Next we set the feed streams:

>> ns(1,3)=220; 
>> ns(16,1:2)=[357 1343]; 
>> ns(17,7)=110;

Here is the flow matrix that we start with:

>> prntmx('Flow matrix',ns,6,0) 
Flow matrix
row/col       1     2     3     4     5     6     7
   1          0     0   220     0     0     0     0
   2          0     0     0     0     0     0     0
   3          0     0     0     0     0     0     0
   4          0     0     0     0     0     0     0
   5          0     0     0     0     0     0     0
   6          0     0     0     0     0     0     0
   7          0     0     0     0     0     0     0
   8          0     0     0     0     0     0     0
   9          0     0     0     0     0     0     0
  10          0     0     0     0     0     0     0
  11          0     0     0     0     0     0     0
  12          0     0     0     0     0     0     0
  13          0     0     0     0     0     0     0
  14          0     0     0     0     0     0     0
  15          0     0     0     0     0     0     0
  16        357  1343     0     0     0     0     0
  17          0     0     0     0     0     0   110


If we iterate once around the loop, we find:

>> iter(1)
Flow matrix
row/col         1       2       3       4       5       6       7
   1         0.00    0.00  220.00    0.00    0.00    0.00    0.00
   2         0.00   94.01    0.00    0.00    0.00    0.00    0.00
   3         0.00   94.01  220.00    0.00    0.00    0.00    0.00
   4         0.00    0.00    0.00    0.00    0.00    0.00    0.00
   5         0.00   94.01  220.00    0.00    0.00    0.00    0.00
   6         0.00    0.00    0.00    0.00    0.00    0.00    0.00
   7         0.00    0.00    0.00    0.00    0.00    0.00    0.00
   8         0.00    0.00    0.00    0.00    0.00    0.00    0.00
   9         0.00    0.00    0.00    0.00    0.00    0.00    0.00
  10       357.00 1343.00    0.00    0.00    0.00    0.00    0.00
  11       357.00 1343.00    0.00    0.00    0.00    0.00    0.00
  12       357.00 1343.00    0.00    0.00    0.00    0.00  110.00
  13         0.00    0.00    0.00    0.00    0.00    0.00  110.00
  14       357.00 1343.00    0.00    0.00    0.00    0.00    0.00
  15       357.00 1248.99    0.00    0.00    0.00    0.00    0.00
  16       357.00 1343.00    0.00    0.00    0.00    0.00    0.00
  17         0.00    0.00    0.00    0.00    0.00    0.00  110.00 


Ten more iterations and:

>> iter(10)
Flow matrix
row/col         1       2       3       4       5       6       7
   1         0.00    0.00  220.00    0.00    0.00    0.00    0.00
   2         0.00   94.01    0.00    0.00    0.00    0.00    0.00
   3         0.00   94.01  220.00    0.00    0.00    0.00    0.00
   4         0.00  333.25  526.83    0.00    0.00    0.00    0.00
   5         0.00  427.26  746.83    0.00    0.00    0.00    0.00
   6         0.00  350.79  554.56  123.24    0.00    0.00    0.00
   7         0.00  350.79  554.56    0.00    0.00    0.00    0.00
   8         0.00   17.54   27.73    0.00    0.00    0.00    0.00
   9         0.00    0.00    0.00  123.24    0.00    0.00    0.00
  10       357.00 1343.00    0.00  123.24    0.00    0.00    0.00
  11       122.54 1343.00    0.00    0.00   16.02  107.22  131.25
  12       122.54 1343.00    0.00    0.00   16.02  107.22  241.25
  13         0.00    0.00    0.00    0.00    0.00  107.22  241.25
  14       122.54 1343.00    0.00    0.00   16.02    0.00    0.00
  15       122.54 1248.99    0.00    0.00   16.02    0.00    0.00
  16       357.00 1343.00    0.00    0.00    0.00    0.00    0.00
  17         0.00    0.00    0.00    0.00    0.00    0.00  110.00

 

Twenty more iterations show just how slowly the process converges:

>>   iter(20)

Flow matrix
row/col         1       2       3       4       5       6       7
   1         0.00    0.00  220.00    0.00    0.00    0.00    0.00
   2         0.00   94.01    0.00    0.00    0.00    0.00    0.00
   3         0.00   94.01  220.00    0.00    0.00    0.00    0.00
   4         0.00  490.27  545.20    0.00    0.00    0.00    0.00
   5         0.00  584.28  765.20    0.00    0.00    0.00    0.00
   6         0.00  516.07  573.89  127.53    0.00    0.00    0.00
   7         0.00  516.07  573.89    0.00    0.00    0.00    0.00
   8         0.00   25.80   28.69    0.00    0.00    0.00    0.00
   9         0.00    0.00    0.00  127.53    0.00    0.00    0.00
  10       357.00 1343.00    0.00  127.53    0.00    0.00    0.00
  11       114.37 1343.00    0.00    0.00   16.58  110.95  135.82
  12       114.37 1343.00    0.00    0.00   16.58  110.95  245.82
  13         0.00    0.00    0.00    0.00    0.00  110.95  245.82
  14       114.37 1343.00    0.00    0.00   16.58    0.00    0.00
  15       114.37 1248.99    0.00    0.00   16.58    0.00    0.00
  16       357.00 1343.00    0.00    0.00    0.00    0.00    0.00
  17         0.00    0.00    0.00    0.00    0.00    0.00  110.00

The Root Finding "Module": Vweg2

The procedure described in the section on individual modules for finding a scalar root of one equation is not easily generalized to multiple equations and vector roots. One way that does work in many problems is based on Wegstein's method described in the text starting on page 280. Two functions similar to ssec1 and ssec2 are named vweg1 and vweg2. A more general procedure for "solving" multiple simultaneous nonlinear equations may be found in MATLAB using the fsolve function. A comparison of the using the two approaches are:

  1. fsolve will work in many cases where vweg2 converges very slowly or not at all,
  2. fsolve requires writing a special function that gives the error for each problem to be solved,
  3. fsolve can be very time consuming in some problems where vweg2 is both easy and fast.

We will illustrate vweg2 with two examples. The inside function vweg1 makes a single "Wegstein" step. The function vweg2 gives the following information with help:

>> help vweg2

  vweg2: vector solution of n equations in n unknowns using Wegstein's method
  function x=vweg2(v1,g,tmin,tmax,nmax,erc)
  Vector solution of n equations in n unknowns using the Wegstein method
        of finding roots
  Use VWEG1 to do each Wegstein step
  Argument    Gives
     g     a character vector naming a function that tells how to 
           find a better value for the unknown 
           vector x given an approximate set: v1.
           The vector must be called x in g.
     v1    the initial guess for x.
    tmin   min allowed change in a step. 
    tmax   max allowed change in a step.
    nmax   max iterations allowed.
    erc    desired error.
  Typical (default) values are: nmax=10, erc=.001, 
    tmax=5 and tmin=-10
  You may give the function 2, 4 or 6 arguments.
  If you give it only two, the default values are used 
    for the rest.
  If you give it 4, the default values for nmax and erc 
    will be used.
  Example: >> vweg2(zeros(1,7),'g312(x)',-10,5,10,0.001)
  revised help by TYLC


Each Wegstein function is used with a character argument that tells how to compute a better estimate for a vector x given an initial value for that vector. Thus in using this method we must express the function we want in the form:

     x = g(x)


One example of this is Example Problem 5.16 in the text where we want to determine the values for x1 and x2 satisfying:

     x1 = 0.2x12  + 0.1x2 + 0.7
     x2 = 0.5 + 2/(x1+3x2)


Our g(x) is readily recognized as the vector found for the two lines of this pair of equations. In MATLAB this is given by:

function g=ex516(x)
g=(.2*x(1)^2)+.1*x(2)+.7;
g=[g,.5+2/(x(1)+3*x(2))];


The function vweg2 requires that we give an initial guess for the vector unknown in its left argument. Guessing .5 for both elements we find:

>> vweg2([.5 .5],'ex516(x)')
ans =
    0.9998    1.0000


If we want a higher accuracy, we can specify it by:

>> vweg2([.5 .5],'ex516(x)',-10,5,10,.0001) 
ans =
    1.0000    1.0000


Now we will see that this works very well in the case of some chemical system computations. The solution of Problem 3.12 that was solved by iteration is readily done with vweg2. We saved workspace ex312 for that purpose and just need to load it and zero out the recycle stream:

>> load ex312 
>> prntmx('Flow matrix',ns,6,2) 
Flow matrix
row/col       1     2     3     4     5     6     7
   1       3.00  0.00  0.00  0.00  0.00  0.00  0.00
   2       0.00  2.20  9.60  0.00  0.00  0.00  0.00
   3       0.00  0.00  0.00  0.00  0.00  0.00  0.00
   4       0.00  0.00  0.00  0.00  0.00  0.00  0.00
   5       0.00  0.00  0.00  0.00  0.00  0.00  0.00
   6       0.00  0.00  0.00  0.00  0.00  0.00  0.00
   7       0.00  0.00  0.00  0.00  0.00  0.00  0.00
   8       0.18  0.00  2.82  0.00  0.00  0.00  0.00
>> ns(8,:)=zeros(1,7);



The function g312 performs a single loop around the modules:

 

Note that in making the loop we start with a guessed vector of the flows of all compounds in stream 8. At the end of the loop we hope we have a better estimate for the flows in that stream. If we use 0 for all flow rates in the stream we get:

>> g312(zeros(1,7))
ans =
    0.1125         0    1.2966         0         0         0         0


exactly as we did before. A second iteration may also be done by hand with the function g312:

>> g312(ns(8,:)) 
ans =
    0.1547         0    1.9970         0         0         0         0


The function vweg2 may also be invoked to get the result we found before after many iterations.

>> vweg2(zeros(1,7),'g312(x)',-10,5,10,.001) 
Warning: Divide by zero
Warning: Divide by zero
ans =
    0.1800         0    2.8200         0         0         0         0


We see a couple of warnings about dividing by zero, but the desired solution is found within the 10 iterations. Thus many fewer iterations are required than by direct substitution.


Go back to Page 1


[Go to previous section: 1.5| Go to next Chapter: 2.0]
[ Go to CENG301 Homepage | CENG301 Notes Table of Contents]

Last modified July 28, 1998.