You are on page 1of 43

Solving simultaneous nonlinear VLE

and LLE equations without NewtonRaphson


Jacob H. Lashover
November 12, 2012
Baton Rouge, Louisiana
ABSTRACT
Flash vaporization or single-stage-equilibrium separation of multicomponent
mixtures into vapor and liquid phases is frequently encountered in petrochemical
complexes, petroleum refineries, and gas processing plants. Design of distillation
columns, two phase flow pipelines, and pressure relief systems are the most common
operations which require determination of both the amount and composition of the
vapor and liquid phases formed (Henley, 1998).
The computation procedure does not have an exact analytical solution as the
equations are nonlinear in the unknowns. The most common solutions are in terms of
the vapor fraction represented by the Rachford-Rice objective function (Rice, 1952)
which is solved using an iterative Newton-Raphson method (Newton, 1685) or
modification thereof. For success, the data representations must have well behaved,
continuous derivatives and accurate initial estimates of the answers. These accurate
initial estimates are especially important when the bubble point or dew point region
of multicomponent mixtures is approached.
The Monte Carlo Marching (MCM) method presented here provides robust
convergence performance without derivatives and is insensitive to initial estimates of
the variables. Details of the flash of a Methanol-Isopropanol-Water (al, 1976) feed to
a distillation column under atmospheric pressure are presented. Application of MCM
is also demonstrated on solving the Rachford-Rice flash equation, and on Isaac
Newtons cubic polynomial, y^3 2y -5 = 0, (Cajori, 1911) which Newton used to
first demonstrate his Newton-Raphson procedure. There have been no convergence
failures even when the fraction of vapor flashed is near the system bubble or dew
point.
Keywords: flash vaporization, convergence, multicomponent, non-ideal, cubic EOS
P a g e 1 | 43

1.1 INTRODUCTION
Previous work by the author developed computer programs for the correlation of
binary VLE (vapor-liquid-equilibria) , primarily pressure vs. composition data, which
was used for design of the distillation columns in Union Carbides Sevin process. The
isothermal flash vaporization problem was also solved using Taylor series expansions, a
form of Newton-Raphson. The computer algebra code for the multicomponent
Margules/Redlich-Kister (Redlich O. a., 1948) equations and its derivatives was
developed for this earlier flash vaporization work1. The method presented in this paper
was motivated by the desire to avoid the tedious algebraic and calculus manipulations
required to program these partial derivatives for multi-component mixtures, and to insure
more reliable convergence.
This paper primarily demonstrates the successful solution of the isothermal flash feed
problem using MCM. Details of the flash of a Methanol-Isopropanol-Water (al, 1976)
feed to a distillation column under atmospheric pressure are presented. Also solved were
Rachford-Rice equations for hydrocarbons at two atmospheres with ideal liquid phases,
and Isaac Newtons polynomial, y^3 2y -5 = 0, (Cajori, 1911) which Newton used to
demonstrate his Newton-Raphson procedure.

LLE (liquid-liquid extraction) feed

1 The three suffix versions of the Margules and Redlich-Kister equations are
equivalent.

P a g e 2 | 43

streams were also flashed. Non-ideality of the liquid phases was represented by the
Redlich-Kister, Wilson (Wilson, 1964), and van Laar (Peng, 2010) models.
1.2 LITERATURE REVIEW
Monte Carlo Marching is a procedure that takes full advantage of the speed of todays
computers. The Monte Carlo method was invented by the mathematician Stanislaw Ulam
(Eckhardt, 1987), who in 1946 used the method in the design of atomic weapons at Los
Alamos.2 In 1984, William C. Conley, a mathematician on the faculty of the University
of Wisconsin-Green Bay, published Computer Optimization Techniques. (Conley,
Computer Optimization Techniques (Revised Edition), 1985) Conley called his
technique multi-stage Monte Carlo optimization, or MSMCO. His book demonstrated
the technique on the classical Simplex profit and resource allocation problems of
Operations Research. Richard P. Brent, a mathematician at the Australian National
University in Canberra, Australia published Algorithms for Minimization Without
Derivatives (Brent, 1973, rev. in 2002, 2013)

Brents algorithms rely solely on

sequential function evaluations which are essentially numerical methods. While his
books bibliography contains over 300 references, Conleys book and Monte Carlo
2

Stanislaw Ulam: The first thoughts and attempts I made to practice [the Monte Carlo Method] were
suggested by a question which occurred to me in 1946 as I was convalescing from an illness and playing
solitaires. The question was what are the chances that a Canfield solitaire laid out with 52 cards will come
out successfully? After spending a lot of time trying to estimate them by pure combinatorial calculations, I
wondered whether a more practical method than abstract thinking might not be to lay it out say one
hundred times and simply observe and count the number of successful plays. This was already possible to
envisage with the beginning of the new era of fast computers, and I immediately thought of problems of
neutron diffusion and other questions of mathematical physics, and more generally how to change
processes described by certain differential equations into an equivalent form interpretable as a succession
of random operations. Later [in 1946, I] described the idea to John von Neumann, and we began to plan
actual calculations.(Eckhardt, 1987)

P a g e 3 | 43

methods are not mentioned.

No similar algorithms were found after reading Tamara G.

Kolda et.al. Optimization by Direct Search: New Perspectives on some Classical and
Modern Methods. (Kolda, 2006)
There has been intense research on the flash vaporization problem, and a literature
search turned up numerous methods. Most of these methods use derivatives and stress
acceleration of convergence. These authors have not thought about the fact that todays
cell phones have the raw computing power of the 1970s-era supercomputers. According
to the current Top 10 Android Linpack results, a tweaked Motorola Droid is capable of 52
Mflop/s which is over 15 times faster than the 1979 Cray I CPU. (Croucher, 2010) Note
also that the Cray had to be cooled with liquid nitrogen. Today, the Chinese computer,
Tiahne-1A, is considered the fastest computer in the world with a computing speed of 2.5
petaflops. A petaflop is equivalent to 1,000 trillion calculations per second. Using
MCM, solution of a typical multicomponent VLE problem can be easily accomplished in
less than 0.1 seconds on a desk top computer. The significant problem reformulation of
the model equations, differentiating complex equations, and unreliable convergence can
be avoided by letting the computer do the heavy lifting.
Needless to say, computer speed is no longer an issue. In fact, The engineering and
computer science community is woefully behind in developing software that can exploit
these new multi-core hardware systems. (Committee on Sustaining Growth in
Computing Performance, 2011) Help is on the way as Microsoft Chairman Bill Gates,
P a g e 4 | 43

Facebook CEO Mark Zuckerberg, and Twitter creator Jack Dorsey are among the tech
luminaries who are promoting the teaching of computer coding starting in grade school
through Code.org., a nonprofit foundation created last year to help grow computer
programming education. (Ortutay, 2013)
1.3 DISCUSSION
Optimization by calculus with its derivatives3 and Jacobian procedures has been
shown to be difficult, tedious, and time consuming. While Newtons cubic equation and
Rachford-Rice can usually be solved using programs like Excel, Mathematica, or
Maple, etc., these programs are basically black boxes with code and the results of
each iteration unavailable to the user. These math packages also have limitations. Excel
Solver, for instance, has limitations on the number of variables and constraints that it can
process. To solve the popular SUDOKU puzzle, it was necessary to purchase the
Premium Solver Platform from Frontline Systems (Frontline Solvers, 2012), which
developed and maintains Solver for Excel. The solution required 243 variables and 34
lines of constraints which significantly exceeded the capacity of Excel 2010. 4 Then, the
Premium Solver had restrictions on the number of differing constraints that could be
placed on an Excel cell. This limitation required serious improvisation to finally solve

3 Newton called his derivatives fluxions.


4 Excel 2003-07 does not have the capability to solve this type of problem. A
reduced 4 X 4 Sudoku puzzle (9 X 9 by definition) was solved with Excel 2010.

P a g e 5 | 43

the problem. Spreadsheets with cell numbers and few visible variable names and
equations are also difficult to follow. Easily solving the Sudoku problem using Monte
Carlo methods with recursive backtracking led to the investigation of solution of
chemical engineering problems using the MCM method. The MCM solution of the flash
vaporization and solution of other nonlinear equations resulted, thus reminding the author
of the benefits of tackling problems outside of our fields to change our perspective and
open our minds to different ways of thinking.
Monte Carlo Marching makes use of constraints which insure that the solutions will
satisfy thermodynamics, energy balances, and mass balances. These constraints are
basically simultaneous linear and non-linear equations which model the system being
studied. The MCM objective functions are formed by designing the constraints to be
convex and adding them. The justification for the addition of these constraints is similar
to that used in Maximum Likelihood methods. (Banbura, "Maximum Likelihood
Estimation of Factor Models on Data Sets with Arbitrary) The objective function
becomes convex by being built of convex functions and can thus be minimized. The
feasible solutions are bounded so as to insure that they are part of the thermodynamic
model set. Further proof of the linearity (ability to add constraints) of the
simultaneous marching schema used in this work can be found in Analysis of the ndimensional quadtree decomposition for arbitrary hyper-rectangles by Christos Faloutsos
et.al. at http://drum.lib.umd.edu/bitstream/1903/678/2/CS-TR-3381.pdf. (Faloutsos,
1903)
P a g e 6 | 43

1.4 PROBLEM DEFINITION


GIVEN

CALCULATED

1. Vapor composition and total system


pressure of multicomponent system.
2. Composition and temperature of feed
stream to flash unit and pressure of

Dew point and composition of resulting


liquid phase.
Fraction of feed stream flashed and
composition of resulting liquid and

flash unit.
3. Composition and temperature of feed
stream to flash unit and fraction of
feed stream to be flashed.
4. Composition of feed stream to flash

vapor phases.
Required pressure of flash unit and
composition of resulting liquid and
vapor phases.
Required temperature of fe

unit, pressure of flash unit, and


fraction of feed stream to be flashed.

and composition of resulti


and vapor phases.

Definition of calculation model:


When one mole of a solution containing Z(i) mole fraction of component i is partially vaporized a

at temperature T and pressure P to form V moles of vapor and (1 V) moles of liquid, as indicated
in Figure 1,
V Y (i) + (1 V) X (i) = (1) (Z (i),
(1)
where X(i) = mole fraction of component i in the liquid phase,
and
Y(i) = mole fraction of component i in the vapor phase.
For the moderate pressures under consideration one can define
Y( i) = K(i)(i)X(i) ,
K (i) = P (i)o / P ,
P (i)o = vapor pressure of pure component i to be calculated
by the Antoine equation,
K (i) = Raoults Law vapor-liquid equilibrium constant for
P a g e 7 | 43

component i,
(i) = liquid phase activity coefficient of component I; (i) = (i)(X1, X2, Xn) .
It is readily seen that n + 1 simultaneous equations arise when Equation (1) is written for an n
component system. These equations are to be solved for the following cases where i = 1, 2, 3,
n.

P a g e 8 | 43

FLASH VAPORIZATION
Given
Unknown
A. Z(i), T, P
V, X(i), Y(i)
B. Z(i), T, V
P, X(i), Y(i)
C. Z(i), P, V
T, X(i), Y(i)
and it will be shown that by setting Z(i) = Y(i) and V = 1, the same equation system can be solved
for the dew point temperature.

P a g e 9 | 43

DEW POINT

A.

Given
Y(i), P

Unknown
T, X(i)

LIQUID-LIQUID EXTRACTION
Given

Unknown

P a g e 10 | 43

B. Z(i), T, P

V, X(i), Y(i)

Where in this case, V = fraction of raffinate stream, X(i) = composition in raffinate, and Y(i)
composition in the extract phase.

P a g e 11 | 43

1.5 Solving for V Using MCM


Computer Output
Iteration 1
V= .283724138736725
OLD OPT= 1D+30 G= 85.29139956077
NEW OPT= 85.29139956077
SUMX= .8772386085987092
SUMY= .9174543451798476
SUMPT= 92.96106152534807
SUMZX= .9911135121617614
G1= 8.363938474651931 G2= 12.2761391401291 G3= 8.254565482015238 G4= 56.3967564639
7374 G= 85.29139956077
X(1)= .2280518072843552 X(2)= .3864084398746491 X(3)= .262778361439705
Y(1)= .3562745191479074 Y(2)= .3508095455125981 Y(3)= .2103702805193421
LL(1)= 1 LL(2)= 1 LL(3)= 1 LL(4)= 1
UL(1)= 100 UL(2)= 100 UL(3)= 100 UL(4)= 100
R(1)= 49 R(2)= 49 R(3)= 49 R(4)= 49
ZX(1)= .4973556831422566 ZX(2)= .146236918257682 ZX(3)= .3475209107618227
PP(1)= 36.09951565266172 PP(2)= 35.54577719906401 PP(3)= 21.31576867362234
P a g e 12 | 43

COUNTI= 1 COUNTJ= 1

Final Iteration
V= .9451196705718721
OLD OPT= .108056010212107 G= 8.869474744795088D-02
NEW OPT= 8.869474744795088D-02
SUMX= .9991877469223368
SUMY= .9999986734315671
SUMPT= 101.3248655854536
SUMZX= .990000458304824
G1= 1.344145464514668D-04 G2= .0812253077663172 G3= 1.3265684
32915565D-04 G4= 7.20236829189065D-03 G= 8.869474744795088D-02
X(1)= .254672596779671 X(2)= 6.184798915739828D-02 X(3)= .6826671609852676
Y(1)= .514203322045091 Y(2)= .1550985014029116 Y(3)= .3306968499835646

LL(1)= 25.43944087766766 LL(2)= 6.15487926417003 LL(3)= 68.2508029011053 LL(4)= 94.507


UL(1)= 100 UL(2)= 100 UL(3)= 100 UL(4)= 100
R(1)= .048828125 R(2)= .048828125 R(3)= .048828125 R(4)= .048828125
ZX(1)= .495000398096542 ZX(2)= .1485001911742847 ZX(3)= .3464998690339974
PP(1)= 52.10165160621884 PP(2)= 15.71535565465002 PP(3)= 33.50785832458468
COUNTI= 5505 COUNTJ= 12

P a g e 13 | 43

P a g e 14 | 43

Calculation of V, fraction of vapor flashed, for a 50, 15, 35 mole %


mixture
of MeOH, IPA, & H2O, respectively, at 78 C and
101.325 kPa. using MCM.
LL(1), LL(2), AND LL(3) are lower limits of liq. phase mole%, LL(4) is
lower limit of V.
R()'s are ranges of variables to be searched for feasible
solutions.
OPT is last optimum value of objective
function.
G is new optimum found during present
iteration.
X's and Y's are liquid and vapor compositions in mole fraction,
respectively.

Table 1

X's and Y's are sums of liquid and vapor


compositions.
kPa and moles are the sums of the vapor pressures and total
moles fed.
Total feed is 100 moles while total pressure is
101.325 kPa.
Iteratio
nI

32

1034

1408

1638

1680

6224

Iteration
J
LL(1)
LL(2)
LL(3)
LL(4)

1
1
1
1
1

1
1
1
1
1

1
1
3.804
1
18.08

3
22.02
1
34.15
24.33

3
22.18
1
33.43
1

4
25.61
4.79
44.16
66.47

R(1)

49

71.81

68.7

25

25

12.5

R(2)

49

87.64

96.2

20.61

24.07

12.5

R(3)

49

75.28

81.72

25

25

12.5

R(4)

77.37

12.5

25

25

12.5

OPT

49
1.00E+3
0

85.29

77.93

25.37

15.58

10.87

85.29

77.93

29.86

19.04

11.82

10.29

28.37

68.08

37.54

46.69
0.332

67.27

78.16

4
20.93
1.1775
56.58
76.95
1.25E+0
1
1.25E+0
1
1.25E+0
1
1.25E+0
1
6.62E+0
0
6.33E+0
0
8.86E+0
1
2.64E-

13
25.45
6.175
68.25
94.5
2.44E02
2.44E02
2.44E02
2.44E02
8.87E02
8.75E02
9.45E+
01
2.55E-

P a g e 15 | 43

V = percent of feed vaporized. 100 - V = percent of liquid remaining.

P a g e 16 | 43

INTENTIONALLY BLANK

P a g e 17 | 43

Figure 2.

P a g e 18 | 43

1.6 DEVELOPING THE COMPUTER ALGORITHMS


When writing a distillation simulation program, the column feed must first be
flashed to determine its state, composition, and enthalpy. The VLE equations are
highly non-linear when using a liquid phase activity coefficient model such as Wilson,
Redlich-Kister, etc. The authors earlier Taylor series solution consisted of an inner loop
where the liquid compositions were solved using derivatives and an outer loop which
used a procedure called Marching, Binary-chop, Interval-halving or Bi-section .
The Marching procedure was of much interest to the author as it guaranteed a solution
to the bounded variables in the systems studied, i.e., the fraction of vapor flashed, V,
varied from 0 to 100 % or from 0 to 1.0 as a fraction. Temperatures varied from the
boiling point of the low-boiler to the boiling point of the high-boiler. Compositions
varied from 0 to 1.0 when expressed as fractions. When solving for V, the lower limit,
VL was set to zero and the upper limit, VU, was set equal to 1.0. The initial value of V
was calculated as V = (VL + VU)/ 2 = 0.50. If the first iteration produced a sum of liquid
compositions, Xs, that was less than 1.0, then VL was set equal to V. If the Xs was
greater than 1.0, VU was set equal to V. The next value of V to be tried was again
calculated as V = (VL + VU)/2. So, if V was too low, the lower limit, VL, was raised to
V as no solution existed below V. Similarly, if V was too high, values above VU could be
P a g e 19 | 43

eliminated. This method always converged and eliminated one-half of the range of
feasible solutions after each iteration. This can be represented algebraically by the
function f(x) = R / (Xn) where R = the range of solutions, X = 2, and n = 1, 2, 3.n, the
number of the iteration. The limit of this function as n approaches infinity is 0 where the
entire feasible range of solutions has been examined.
The unknown variables are essentially improved from their lower boundary
values toward their higher boundary values by analyzing linear regions which are inverse
multiples of powers of two. This procedure emulates the guaranteed conversion
procedure of Marching and satisfies the mathematical theories of hyper-rectangles.
(Faloutsos, 1903)

Remember, after the first iteration of marching, the region left to

study has decreased by or 1/ (2^1). After the second iteration, the region left to study
has decreased to or 1/ (2^2), and so forth. The feasible region of solutions for V, after
being reduced to by searching either 0.5 to 1.0 or 0 to 0.5 is next reduced to by
searching either 0.75 to 1.0 or 0 to 0.25.

See the values of the variable ranges, R (i), in

Table 1 for an example of this procedure in use. By normalizing all independent


variables to 0 to 1 or 0 to 100, no one variable can overly influence the objective
function.
Finally, the objective function is the sum of the absolute differences of the convex
constraint values from the desired constraint values at each iteration, i.e., for the V
calculation, G1 = ABS( X 1.0) would be one constraint, G2 = ABS(Y 1.0) would
P a g e 20 | 43

be the second, the total calculated pressure atmospheric or other designated pressure
would be G3, and the sum of Zs, feed compositions, times the molar feed, G4, would be
compared to the mass balance, Equation (1), for each component. Thus G, profit in
most Simplex calculations, would equal to G1 + G2 + G3 + G4 and comprise the
convex objective function which would be minimized.
We apply the Gibbs phase rule, P + F = C + 2, where P is the number of phases, F is
the number of independently specifiable variables, and C is the number of components.
When P =2, liquid and vapor phases, and C = three components, F = 3 specifiable
variables for a ternary system. Since we are given the three compositions of the feed, and
when calculating V, we know both the temperature and pressure. Selecting the three
liquid phase compositions plus V as the independent variables leads to over-specification.
This is true because we could calculate X (3) by subtracting X (1) and X(2) from 1.0 to
obtain X(3). However, calculating X (3) this way leads to the satisfaction of the
constraint, Xs = 1.0, with incorrect X (1) and X (2) on the initial iteration effectively
removing this constraint as a convergence driving force with incorrect compositions. .
Therefore, all three Xs are considered unknown along with the fraction of vapor flashed,
V. Notice how the total pressure constraint mimics the Ys constraint in Figure 3.
Since the vapor composition, Y (i), of component i can be calculated by dividing the
partial pressure due to component i by the total pressure, these variables are covariant.
All four of these variables are set to zero initially as the method is not sensitive to the

P a g e 21 | 43

initial values of the variables as are most nonlinear solution algorithms. Zero is the
lower boundary for all four variables, and thus prevents infeasible solutions.5
In each iteration a number of feasible solutions are calculated for the marching region
and the lowest G with its Xs and V is stored as a local minimum, OPT. The number of
solutions checked can be determined by using statistics, similar to determining how many
samples which pass product specifications are needed to guarantee that the entire
shipment would pass at some confidence level, e.g., 95%, 97.5%, or 99%. Only a tiny
probability of an off-spec sample is thus assured and in this case we would be assured
that we didnt miss a local minimum. The number of solutions examined can easily be
increased to insure location of a global stationary point with little penalty in computing
time. The values of the variables used for each solution are obtained by random (Monte
Carlo) selection of values in the iteration ranges. A plot of the objective function values,
Gs, the constraint values, and all of the other independent variables, versus iteration
number is shown for the MCM V calculation in Figure 2. Table 1 shows the data.
Figure 3 shows the constraint values versus iteration number for the V calculation while
Figure 4 shows the solution variables versus iteration number when using derivatives.
Table 2 shows a comparison of results from the MCM solution with those for the
calculation with derivatives. Figure 5 is a block diagram of the MCM logic. See
5 During LLE flashes where the two liquid phases are almost totally
immiscible by design, and dilute solution activity coefficient values can be in
the thousands, the lower composition limits and V, fraction of raffinate, are
set realistically to real values to avoid significantly infeasible mass balances.

P a g e 22 | 43

Appendix A for the Rachford-Rice Example, and Appendix B for the solution of Isaac
Newtons polynomial.
With so many samples required, it is important to use a random number generator
which has a large capacity to avoid recycling random numbers. All of the test programs
were written using open source QB64 which is an improved version of Microsofts QB45
and QB71 which they no longer support. The random number generator used by QB64
proved to be adequate. To obtain a free copy of this program, go to www.qb64.net/
which is the official website. This program will run on both 32 and 64 bit computers.
The current version is V0.954 which was released on April 20, 2012. A
Linux/MacOSX/Windows version V0.953 was released on March 12, 2012. The code
language is very similar to VB / VBA.

P a g e 23 | 43

P a g e 24 | 43

P a g e 25 | 43

1.7 COMPUTER PROGRAM


The computer program written to test the Monte Carlo Marching algorithm includes
the subroutines shown below.
QBVLE35--09/11/12
ENTER A LETTER CORRESPONDING TO YOUR CHOICE
A. TEST FOR TWO PHASES

B. BUBBLE POINT

C. CUBIC EQUATION

D. DEW POINT

H. ENTHALPY

P. FLASH FOR P

T. FLASH FOR T

V. FLASH FOR V

R. RACHFORD-RICE

Q. QUIT

Z. TEST ANTOINE CONSTANTS

L. LLE FLASH

Property subroutines called ANTOINE, WILSON, VAN LAAR, and


REDLICH-KISTER are called by the executive routine to provide vapor pressure and
liquid phase activity coefficients. The Enthalpy subroutine calculates the Q or heat
added to maintain constant temperature during the flash. The CUBIC EQUATION
subroutine solves Newtons polynomial. Computing times are calculated for each
problem, but are increased due to the intermediate data printed to files for verifying the
calculations.
P a g e 26 | 43

1.7.1 SUBROUTINE: CALCULATE FRACTION OF VAPOR FLASHED


The computer code for the subroutine to calculate the fraction of a VLE stream
which flashes to vapor follows. Note that the multicomponent mixture must be between
its bubble point and dew point temperatures to exhibit two phases.
SUB VAPOR
CLS
PRINT: PRINT: PRINT " INPUT DATA FOR FLASH WITH UNKNOWN V"
DIM LL(10), UL(10), PP(10), Z(10), VP(10), Y(10), EK(10), ZX(10), R(10), XP(10)
101 INPUT " NUMBER OF COMPONENTS= ", N
INPUT " TOTAL SYSTEM PRESSURE IN kPa= ", PT
INPUT " TEMPERATURE IN DEG. C, T= ", T
PRINT: SUMZ = 0
FOR K = 1 TO N
PRINT COMPONENT$(K)
INPUT " MOLE FRACTION IN FEED= ", Z(K)
SUMZ = SUMZ + Z(K)
NEXT K
PRINT " SUMZ= "; SUMZ
OP1% = 0: INPUT " OP1=0 NO ERRORS CONTINUE, OP1=1 REDO, OP1= ", OP1%
IF OP1% = 1 THEN GOTO 101
REM SOLUTION BY MONTE CARLO
615 OP2% = 0: INPUT " ENTER '1' TO USE REDLICH-KISTER, ENTER '2' TO USE
WILSON, ENTER '3' TO USE VAN LAAR: OP2= ", OP2%
P a g e 27 | 43

IF OP2% = 0 OR OP2% > 3 THEN PRINT: PRINT " YOU MUST ENTER A 1, 2, OR 3:
REDO": GOTO 615
TS# = TIMER
FIL% = -1111: RANDOMIZE (FIL%) Any seed number can be used.
OPT = 1E+30
COUNT& = 0: COUNTI% = 0: COUNTJ% = 0
XP(1) = 0.0: XP(2) = 0.0: XP(3) = 0.0: XP(4) = 0.0 'INITIAL VALUES OF X AND V
UL(1) = 100.: UL(2) = 100.: UL(3) = 100.: UL(4) = 100. 'UPPER LIMITS OF X'S AND
V
LL(1) = 0: LL(2) = 0: LL(3) = 0: LL(4) = 0 'LOWER LIMITS OF X'S AND V
FOR J = 1 TO 30 Can be raised to search smaller grid size, i.e., more samples.
COUNTJ% = COUNTJ% + 1
FOR I = 1 TO 500 Can be raised to search smaller grid size, i.e., more samples.
COUNT& = COUNT& + 1: COUNTI% = COUNTI% + 1
FOR K = 1 TO 4
IF XP(K) - 100. / 2 ^ J < 1. THEN GOTO 350
GOTO 366
350 LL(K) = 1!
GOTO 365
366 LL(K) = XP(K) - UL(K) / 2 ^ J
365 IF XP(K) + UL(K) / 2 ^ J > UL(K) THEN GOTO 380
GOTO 390
380 R(K) = UL(K) - LL(K)
GOTO 391
390 R(K) = XP(K) + UL(K) / 2 ^ J - LL(K)
391 X(K) = LL(K) + RND * R(K)
P a g e 28 | 43

NEXT K
REM Convert liquid compositions to fractions for activity coefficient equations.
X(1) = X(1) / 100!: X(2) = X(2) / 100!: X(3) = X(3) / 100!: V = X(4) / 100!
'INPUT " PRESS ENTER TO CONTINUE", YES
IF OP2% = 1 THEN CALL RK: GOTO 1213 'USE RK ACTIVITY COEFFS.
IF OP2% = 2 THEN CALL WILSON: GOTO 1213 'USE WILSON ACTIVITY
COEFFS.
IF OP2% = 3 THEN CALL VANLAAR: GOTO 1213
1213 G1 = 0!: SUMPT = 0!
FOR II = 1 TO 3
VP(II) = 2.718282 ^ (A(II) - (B(II) / ((T) + C(II)))): 'PRINT #1, " VP(II)= ";
VP(II)
PP(II) = X(II) * G(II) * VP(II): 'PRINT #1, " PP= "; PP(II)
G1 = G1 + PP(II): SUMPT = SUMPT + PP(II)
111 NEXT II
G1 = ABS(G1 - 101.325)
'INPUT " PRESS ENTER TO CONTINUE", YES
G2 = 0!: SUMX = 0!
FOR II = 1 TO 3
X(II) = 100! * X(II) Convert liquid compositions back to 100 scale.
G2 = G2 + X(II): SUMX = SUMX + X(II)
NEXT II
G2 = ABS(G2 - 100!)
G3 = 0!: SUMY = 0!
FOR II = 1 TO 3
EK(II) = VP(II) / PT
P a g e 29 | 43

Y(II) = EK(II) * G(II) * X(II)


G3 = G3 + Y(II): SUMY = SUMY + Y(II)
NEXT II
G3 = ABS(G3 - 100!)
G4 = 0!: SUMZX = 0!
FOR II = 1 TO 3
ZX(II) = ABS(Z(II) * 100! - (V * X(II) * G(II) * EK(II)) - (1! - V) * X(II)) ':
PRINT " ZX(II)= "; ZX(II) Overall mass balance for model as shown in Figure 1.
G4 = G4 + ZX(II): SUMZX = SUMZX + ZX(II)
NEXT II
G = G1 + G2 + G3 + G4: 'PRINT: 'PRINT " G= "; G; " V= "; V; " OPT= "; OPT
'INPUT " PRESS ENTER TO CONTINUE", YES Will stop program for user.
IF G < OPT THEN GOTO 392
GOTO 393 Solution not as good as previous ones. Try another solution.
REM SAVE BEST SO FAR X'S AND V
392 XP(1) = X(1): XP(2) = X(2): XP(3) = X(3): XP(4) = V * 100!
PRINT " G < OPT, SAVE BEST AND SET NEW OPT = G"
PRINT " OLD OPT= "; OPT; " G= "; G
OPT = G: PRINT " NEW OPT= "; OPT
SUMX = 0: FOR II = 1 TO 3: X(II) = XP(II) / 100!: SUMX = SUMX + X(II):
NEXT II
IF OP2% = 1 THEN CALL RK: GOTO 776 'USE RK ACTIVITY COEFFS.
IF OP2% = 2 THEN CALL WILSON: GOTO 776 'USE WILSON ACTIVITY
COEFFS.
IF OP2% = 3 THEN CALL VANLAAR: GOTO 776
776 SUMY = 0!: SUMZX = 0
P a g e 30 | 43

FOR II = 1 TO 3
ZX(II) = ABS(Z(II) * 100! - (V * X(II) * G(II) * EK(II)) - (1! - V) * X(II)):
ZX(II) = ZX(II) / 100.
Y(II) = EK(II) * G(II) * X(II):
SUMY = SUMY + Y(II): SUMZX = SUMZX + ZX(II)
NEXT II
SUMPT = 0!
FOR II = 1 TO 3
PP(II) = X(II) * G(II) * VP(II)
SUMPT = SUMPT + PP(II)
NEXT II
PRINT: PRINT " COUNTI= "; COUNTI%; " COUNTJ= "; COUNTJ%
INPUT " PRESS ENTER TO CONTINUE", YES
393 NEXT I
777 NEXT J
CLS: PRINT: PRINT " FINAL RESULTS FOR FRACTION OF VAPOR FLASHED!"
REM Use best solution so far and recalculate activity coefficients, etc for this solution.
X(1) = XP(1) / 100!: X(2) = XP(2) / 100!: X(3) = XP(3) / 100!: V = XP(4) / 100!
SUMX = 0!
FOR II = 1 TO 3: SUMX = SUMX + X(II): NEXT II
IF OP2% = 1 THEN CALL RK: GOTO 297 'USE RK ACTIVITY COEFFS.
IF OP2% = 2 THEN CALL WILSON: GOTO 297 'USE WILSON ACTIVITY COEFFS.
IF OP2% = 3 THEN CALL VANLAAR: GOTO 297 'USE VAN LAAR ACTIVITY
COEFFS.
297 SUMY = 0!
FOR II = 1 TO 3: Y(II) = EK(II) * G(II) * X(II): SUMY = SUMY + Y(II): NEXT II
P a g e 31 | 43

PRINT " X(1)= "; X(1); " X(2)= "; X(2); " X(3)= "; X(3); " SUMX= "; SUMX
PRINT " Y(1)= "; Y(1); " Y(2)= "; Y(2); " Y(3)= "; Y(3); " SUMY= "; SUMY
PRINT " G1= "; G1; " G2= "; G2; " G3= "; G3; " G4= "; G4
PRINT: PRINT " SUMPT= "; SUMPT; " SUMZX= "; SUMZX
PRINT " COUNTJ= "; COUNTJ%; " TOTAL FEASIBLE SOLUTIONS EXAMINED=
"; COUNT&
PRINT " G= "; G; " OPT= "; OPT; " V= "; V
TF# = TIMER
PRINT: PRINT " START TIME= "; TS#; " FINISH TIME= "; TF#
ELAPSE# = (TF# - TS#): PRINT " ELAPSED TIME= "; ELAPSE#; " SECONDS"
INPUT " PRESS ENTER TO CONTINUE", YES Stops program for user to view
solution.
CLS
END SUB

P a g e 32 | 43

P a g e 33 | 43

1.8 CONCLUSIONS
Testing on sample problems revealed that indeed two separate loops werent necessary
to calculate both composition values and fraction flashed. All independent variables,
some of which are different types such as vapor fraction and composition variables, could
be solved simultaneously, with the objective function guaranteed to be minimized by the
Marching procedure. As expected, the tolerances in the mass balances achieved at
convergence varied with the convergence error(s) in the correlation of the VLE data for
the systems studied. When using the Redlich-Kister VLE model to calculate V, the
overall mass balance closed within 0. 1%. The results of calculations performed with
MCM nicely duplicate the results of the same problem calculated with derivatives. See
Table 3.
Sample calculations for V close to 0 and 1, where many flash procedures fail,
presented no problems.

Solution of Rachford-Rice (Appendix A) , and Newtons

polynomial (Appendix B) were very straight forward and indicate that other systems of
equations can also be solved using this method, including calculations at high pressures
or for other physical/chemical models. The QB64 code and sample program output can
be obtained by contacting the author. It is hoped that readers will give this method a try
and communicate what results that you can with me.

I can be reached at

jacklash@cox.net where I am an Engineering Consultant in Baton Rouge, LA.

P a g e 34 | 43

1.9 REFERENCES
Frontline Solvers. (2012). Retrieved September 17, 2012, from
www.solver.com
al, E.-Y. e. (1976). J. Chem. Thermodynamics 8, 1061.
Banbura, M. a. ("Maximum Likelihood Estimation of Factor Models on Data
Sets with Arbitrary, Pattern of Missing Data"). Social Science Research
Network . Retrieved September 1, 2012, from SSRN Electronic Library
(Working Paper Series No. 1189/May 2010,:
http://ssrn.com/abstract_id=1598302
Cajori, F. (1911). Historical Note on the Newton-Raphson Method of
Approximation. The American Mathematical Monthly, Vol. 18, No. 2, 2932.
Committee on Sustaining Growth in Computing Performance, N. (2011). "The
Future of Computing Performance: Game Over or Next Level?".
www.nap.edu/catalog.php?record_id=12980 (p. vii). The National
Academies Press, 2011.
Conley, W. C. (1983). BASIC II Advanced. New York: Petrocelli Books, Inc.
Conley, W. C. (1985). Computer Optimization Techniques (Revised Edition).
New York: Petrocelli Books, Inc.
Croucher, M. (2010, June 2). Walking Randomly. Retrieved September 18,
2012, from "Supercomputers vs. Mobile Phones":
www.walkingrandomly.com/?p=2684
Eckhardt, R. (1987). "Stan Ulam, John von Neumann, and the Monte Carlo
method". Los Alamos Science, Special Issue (15), pp. 131-137.
Faloutsos, C. (1903). Analysis of the n-dimensional quadtree decomposition
for arbitrary hyper-rectangles. Retrieved September 15, 2012, from
http://drum.lib.umd.edu/bitstream/1903/678/2/CS-TR-3381.pdf
Henley, J. D. (1998). Separation Process Principles. New York, N. Y.: John Wiley
& Sons.

P a g e 35 | 43

Lashover, J. H. (1961). A Computer Program for the Correlation of Binary


Vapor-Liquid Equilibria Data. South Charleston, W. Va.: Union Carbide
Chemicals Co., R & D Dept.
Lashover, J. H. (1962). Use of the Taylor Series as a Convergence Technique
for the Correlation of VLE and Solution of Multicomponent, Nonideal
Flash Vaporization Problems. New Orleans, LA: Unpublished Master's
Thesis at Tulane University, Chemical Engineering Dept.
Newton, S. I. (1685). "Methodus fluxionam et serierum infinitarum" in Wallis'
"Algebra" Chapter 94. London.
Peng, D.-Y. (2010). Extending the van Laar Model to Multicomponent Systems.
The Open Thermodynamics Journal, 41, 129-140.
Redlich, O. a. (1948). Ind. Eng. Chem., No. 2, 40, 345.
Redlich, O. a. (1949). On the Thermodynamics of Solutions. Chem. Rev. 44(1),
233-244.
Rice, R. H. (1952). Procedure for Use of Electrical Digital Computers in
Calculating Flash Vaporization Hydrocarbon Equilibrium. Journal of
Petroleum Technology 4(10), Section 1, p. 19, and Section 2, p. 3.
Wang, J. C. (1966). Tridiagonal Matrix for Distillation. Hydrocarbon Processing
45(8), 155-163.
Wilson, G. M. (1964). J. Am. Chem. Soc., 86, 127.

P a g e 36 | 43

P a g e 37 | 43

P a g e 38 | 43

P a g e 39 | 43

Solving Rachford-Rice
70
60
50
40
30
20
10
0

Iteration#

LL(1)

OPT

XP(1)

6
V

Range

Pct. Vapor

Iteration No.
Figure 6.

P a g e 40 | 43

APPENDIX B. DEMONSTRATE SOLVING CUBIC


EQUATIONS USING NEWTON'S EXAMPLE FROM
HIS ORIGINAL WORK
Isaac Newton's polynomial: Y^3 - 2Y - 5 = 0
THE TIME IS 11:09:18 AND THE DATE IS 10-10-2012
DISCRIMINANT= -643
IF THE DISCRIMINANT IS > 0 THEN THE EQUATION HAS
THREE DISTINCT REAL ROOTS.
IF THE DISCRIMINANT = 0 THEN THE EQUATION HAS A
MULTIPLE ROOT AND ALL ITS ROOTS ARE REAL.
IF THE DISCRIMINANT IS < 0 THEN THE EQUATION HAS ONE
REAL ROOT AND TWO NONREAL COMPLEX CONJUGATE
ROOTS.
IF THE DISCRIMINANT = 0 AT LEAST TWO ROOTS COINCIDE
AND THEY ARE ALL REAL.
IT MAY BE THAT THE EQUATION HAS A DOUBLE REAL ROOT
AND ANOTHER SINGLE REAL ROOT; ALTERNATIVELY, ALL_
THREE ROOTS COINCIDE YIELDING A TRIPLE REAL ROOT.
NEWTON'S CUBIC EQUATION HAS ONE REAL AND A
CONJUGATE PAIR OF COMPLEX ROOTS.

P a g e 41 | 43

The real root = 2.09455129 and is calculated below:

Figure 7.

TABLE 4. SOLVING NEWTONS CUBIC POLYNOMIAL

P a g e 42 | 42

You might also like