Page 212 - Separation process engineering
P. 212

If there is any possibility that the equation can be misread, use () to make the equation clear. For example,
                    the equations y = a/(b+x) and y = (a/b) + x are not the same. For every left parenthesis, (, there needs to
                    be a corresponding right parenthesis,), to close the equation. The VBA editor will tell you if this rule is
                    violated.

                    VBA does loops in two different ways. “For....Next” loops do a set number of iterations of the loop
                    (typically from i = 1 to a higher number [N in loop below] or a variable that is equal to a higher number).
                    A simple loop to write values on the spreadsheet is,

                         For i = 1 To N
                             Cells(7 + i, 7).Value = x
                               x = x + deltax
                         Next i


                    We can also write “For....Next” loops with a logic expression (e.g., “If eqn0 > 0, Then Exit For”) to exit
                    the loop.
                    The other type of loops, Do loops, are discussed after a few introductory comments on the distillation
                    program and in more detail by McFedries (2004). To essentially do a McCabe-Thiele diagram with a
                    spreadsheet program, we need to have an equation for the binary VLE (see Chapter 2, Appendix 2.B.1.
                    Regression of Binary VLE with Excel). We also need operating equations such as Eqs. (4-21) and (4-22).
                    In addition, we need to be able to decide when to switch from one operating line to the other. This can be

                    done based on either the specified feed stage or a test for the optimum feed stage based on passing the
                    intersection points for x  given by Eq. (4-38a) or for y  given by Eq. (4-38b). If stepping off stages up the
                                               I
                                                                                 I
                    column, a convenient test is that the stage where y     MVC   first becomes greater than y  is the optimum feed
                                                                                                                 I
                    stage. Finally, we need a test for when the calculation if finished. Stepping off stages up the column, the
                    number of stages is sufficient when y > x  (or y > y  with a partial condenser) and stepping off stages
                                                                  D
                                                                              D
                    down the column the number of stages is sufficient when x < x .
                                                                                          B
                    The use of a Do loop is illustrated for the case with a specified feed stage, and we are stepping off stages
                    from the bottom up (partial reboiler is stage 1). After initializing i = 1 and x = x , we can set up a loop to
                                                                                                              B
                    step off stages in the stripping section,

                         Do
                            y = a6 * x ^ 6 + a5 * x ^ 5 + a4 * x ^ 4 + a3 * x ^ 3 + a2 *
                         x ^ 2 + a1 * x + a0
                             i = i + 1
                             x = (y / LbaroverVbar) + (LbaroverVbar - 1) * xb /
                         LbaroverVbar
                         Loop While i < feedstage

                    This loop starts with the word “Do” and then calculates y  from the equilibrium expression (fit to a 6th-
                                                                                     1
                    order polynomial) at the known value of x , then calculates x  from the operating equation (Eq. (4-22)
                                                                    1
                                                                                         2
                    solved for x) with the known value of y . This process is repeated to calculate y  and x , and so forth as
                                                                                                                       3
                                                                 1
                                                                                                               2
                    long as i < the specified feed stage. When i = the feed stage, we skip the loop and calculate the steps in
                    the enriching section using another loop. Note that Do loops always end with the word “Loop” either by
                    itself (see next example) or with a logic statement, as shown in first Do loop example.

                         Do While y < xd
                             y = a6 * x ^ 6 + a5 * x ^ 5 + a4 * x ^ 4 + a3 * x ^ 3 + a2
   207   208   209   210   211   212   213   214   215   216   217