monte carlo marching

54
Solving simultaneous nonlinear VLE and LLE equations without Newton-Raphson 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 Page 1 | 54

Upload: jacob-h-jack-lashover

Post on 06-Dec-2015

11 views

Category:

Documents


3 download

DESCRIPTION

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 Newton’s 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.

TRANSCRIPT

Page 1: Monte Carlo Marching

Solving simultaneous nonlinear VLE and LLE equations without Newton-Raphson

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 Newton’s 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 | 40

Page 2: Monte Carlo Marching

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 Carbide’s 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 Newton’s polynomial, y^3 – 2y -5 = 0, (Cajori, 1911) which Newton used to

demonstrate his Newton-Raphson procedure. LLE (liquid-liquid extraction) feed

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 The three suffix versions of the Margules and Redlich-Kister equations are equivalent. P a g e 2 | 40

Page 3: Monte Carlo Marching

1.2 LITERATURE REVIEW

Monte Carlo Marching is a procedure that takes full advantage of the speed of today’s

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) Brent’s algorithms rely solely

on sequential function evaluations which are essentially numerical methods. While his

book’s bibliography contains over 300 references, Conley’s book and Monte Carlo

methods are not mentioned. No similar algorithms were found after reading Tamara G.

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 | 40

Page 4: Monte Carlo Marching

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 today’s

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,

Facebook CEO Mark Zuckerberg, and Twitter creator Jack Dorsey are among the tech

P a g e 4 | 40

Page 5: Monte Carlo Marching

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 Newton’s 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

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

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 | 40

Page 6: Monte Carlo Marching

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 n-

dimensional 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 | 40

Page 7: Monte Carlo Marching

1.4 PROBLEM DEFINITION

GIVEN CALCULATED

1. Vapor composition and total system Dew point and composition of resulting

pressure of multicomponent system. liquid phase.

2. Composition and temperature of feed Fraction of feed stream flashed and

stream to flash unit and pressure of composition of resulting liquid and flash unit.

flash unit. vapor phases.

3. Composition and temperature of feed Required pressure of flash unit and

stream to flash unit and fraction of composition of resulting liquid and

feed stream to be flashed. vapor phases.

4. Composition of feed stream to flash Required temperature of feed stream

unit, pressure of flash unit, and and composition of resulting liquid

fraction of feed stream to be flashed. and vapor phases.

Definition of calculation model:

When one mole of a solution containing Z(i) mole fraction of component i is partially vaporized at temperature T and pressure P to form V moles of vapor and (1 – V) moles of at

at temperature T and pressure P to form V moles of vapor and (1 – V) moles of liquid, as indicated in Figure 1. The over-all material balance on component I is

in Figure 1,

P a g e 7 | 40

Page 8: Monte Carlo Marching

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) = Raoult’s Law vapor-liquid equilibrium constant for

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.

FLASH VAPORIZATION

Given Unknown

A. Z(i), T, P V, X(i), Y(i)

B. Z(i), T, V P, X(i), Y(i)

P a g e 8 | 40

Page 9: Monte Carlo Marching

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.

DEW POINT

Given Unknown

A. Y(i), P T, X(i)

LIQUID-LIQUID EXTRACTION

Given Unknown

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 9 | 40

Page 10: Monte Carlo Marching

P a g e 10 | 40

Page 11: Monte Carlo Marching

1.5 Solving for V Using MCMComputer OutputIteration 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

COUNTI= 1 COUNTJ= 1

P a g e 11 | 40

Page 12: Monte Carlo Marching

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.326568432915565D-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.5072167416216

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

Table 1 Calculation of V, fraction of vapor flashed, for a 50, 15, 35 mole % mixtureof MeOH, IPA, & H2O, respectively, at 78 C and 101.325 kPa.

P a g e 12 | 40

Page 13: Monte Carlo Marching

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.∑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.

Iteration I 1 2 32 1034 1408 1638 1680 6224Iteration J 1 1 1 3 3 4 4 13

LL(1) 1 1 1 22.02 22.18 25.61 20.93 25.45LL(2) 1 1 3.804 1 1 4.79 1.1775 6.175LL(3) 1 1 1 34.15 33.43 44.16 56.58 68.25LL(4) 1 1 18.08 24.33 1 66.47 76.95 94.5R(1) 49 71.81 68.7 25 25 12.5 1.25E+01 2.44E-02R(2) 49 87.64 96.2 20.61 24.07 12.5 1.25E+01 2.44E-02R(3) 49 75.28 81.72 25 25 12.5 1.25E+01 2.44E-02R(4) 49 77.37 12.5 25 25 12.5 1.25E+01 2.44E-02OPT 1.00E+30 85.29 77.93 25.37 15.58 10.87 6.62E+00 8.87E-02

G 85.29 77.93 29.86 19.04 11.82 10.29 6.33E+00 8.75E-02

V 28.37 68.08 37.54 46.69 67.27 78.16 8.86E+019.45E+0

1X(1) 0.2281 0.197 0.3865 0.3327 0.326 0.3074 2.64E-01 2.55E-01X(2) 0.3864 0.538 0.1309 0.148 0.1111 0.08579 8.26E-02 6.18E-02X(3) 0.2628 0.3272 0.3112 0.4206 0.4865 0.5548 6.34E-01 6.83E-01ƩX"S 0.8773 1.0622 0.8285 0.9012 0.9236 0.9421 9.81E-01 9.99E-01Y(1) 0.3563 0.2928 0.6558 0.5656 0.5769 0.5687 5.06E-01 5.14E-01Y(2) 0.3508 0.4568 0.1432 0.1867 0.1644 0.1499 1.76E-01 1.55E-01Y(3) 0.2104 0.304 0.1926 0.2521 0.2712 0.2887 3.19E-01 3.31E-01

ƩY'S 0.9175 1.0536 0.9916 1.0044 1.0126 1.0073 1.00E+001.00E+0

0

ƩkPa 92.96 106.76 100.47 101.77 102.6 102.07 1.01E+021.01E+0

2

Ʃmoles 99.91 98.94 99.11 99.05 99.01 99 9.90E+011.00E+0

2

P a g e 13 | 40

Page 14: Monte Carlo Marching

Redlich-Kister model for activity coefficients; Raoult's Law for vapor phase

Table 2. Compare MCM Results with Calculations Using DerivativesV X1 X2 X3 Y1 Y2 Y3

Derivative 94.34 0.2579 0.06269 0.6794 0.5145 0.1552 0.3302MCM 94.56 0.2545 0.06175 0.6831 0.5141 0.1551 0.3308

Δ -0.22 0.0034 0.00094 -0.0037 0.0004 0.0001 -0.0006 V = percent of feed vaporized. 100 - V = percent of liquid remaining.

P a g e 14 | 40

Page 15: Monte Carlo Marching

INTENTIONALLY BLANK

P a g e 15 | 40

Page 16: Monte Carlo Marching

Figure 2.

P a g e 16 | 40

Page 17: Monte Carlo Marching

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 author’s 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, Σ X’s, that was less than 1.0, then VL was set equal to V. If the ΣX’s 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 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 P a g e 17 | 40

Page 18: Monte Carlo Marching

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

be the second, the total calculated pressure – atmospheric or other designated pressure

would be G3, and the sum of Z’s, feed compositions, times the molar feed, G4, would be

compared to the mass balance, Equation (1), for each component. Thus G, profit in

P a g e 18 | 40

Page 19: Monte Carlo Marching

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, ΣX’s = 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 X’s are considered unknown along with the fraction of vapor flashed,

V. Notice how the total pressure constraint mimics the ƩY’s 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

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

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 19 | 40

Page 20: Monte Carlo Marching

In each iteration a number of feasible solutions are calculated for the marching region

and the lowest G with its X’s 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 didn’t 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,

G’s, 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

Appendix A for the Rachford-Rice Example, and Appendix B for the solution of Isaac

Newton’s 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 Microsoft’s QB45 P a g e 20 | 40

Page 21: Monte Carlo Marching

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 21 | 40

Page 22: Monte Carlo Marching

P a g e 22 | 40

Page 23: Monte Carlo Marching

P a g e 23 | 40

Page 24: Monte Carlo Marching

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 Newton’s 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 24 | 40

Page 25: Monte Carlo Marching

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 25 | 40

Page 26: Monte Carlo Marching

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 26 | 40

Page 27: Monte Carlo Marching

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 27 | 40

Page 28: Monte Carlo Marching

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 28 | 40

Page 29: Monte Carlo Marching

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 29 | 40

Page 30: Monte Carlo Marching

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 30 | 40

Page 31: Monte Carlo Marching

P a g e 31 | 40

Page 32: Monte Carlo Marching

1.8 CONCLUSIONS

Testing on sample problems revealed that indeed two separate loops weren’t

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 Newton’s

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

[email protected] where I am an Engineering Consultant in Baton Rouge, LA.

P a g e 32 | 40

Page 33: Monte Carlo Marching

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, 29-32.

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.

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

P a g e 33 | 40

Page 34: Monte Carlo Marching

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 34 | 40

Page 35: Monte Carlo Marching

1.10 NOMENCLATURE

A(i),B(i),C(i) Constants in Antoine vapor pressure equation for pure comp.BASIC Basic computer languageC Celsius temperatureFORTRAN Engineering and scientific computer languageH2O WaterIPA 2-propanol, Isopropanol, or Isopropyl alcohol, C3H8OIvs All independent variables as a groupK(i) Raoult's Law equilibrium constant for component ikPa Pressure unit, kilopascalsLL Lower limit or boundary of any variable before calculationsOPT Current local optimumMCM Monte Carlo MarchingMeOH Methyl Alcohol or methanol, CH3OHMSMCO Multi-stage Monte Carlo OptimizationN or C Number of components in multi-component solutionG Profit or value of objective function to be optimizedP(i) Pure component vapor pressure in kPaG1, G2, …Gn Value of constraints, 1 to nPT Total system pressure in kPaQB64 Open source 64 bit version of BASICR Range of variable valuesT Total system temperature in degrees CentigradeUL Upper limit or boundary of any variable before calculationsV or Ψ Ratio of moles of vapor flashed to moles of feedVB Visual Basic computer languageVBA Visual Basic for Applications computer languageVL Current lower limit or boundary of VVLE Vapor-liquid-equilibriaVU Current upper limit or boundary of VX(i) Liquid composition of component iY(i) Vapor composition of component IZ(i) Feed composition of component iγ(i) Gamma, activity coefficient of component I in the liquid phase

P a g e 35 | 40

Page 36: Monte Carlo Marching

APPENDIX A. DEMONSTRATE USE OF MONTE CARLO METHOD TO SOLVE RACHFORD-RICE EXAMPLE PROBLEM

PROBLEM TAKEN FROM EXAMPLE 4.1 ON PAGE 180 OF 'SEPARATION PROCESS PRINCIPLES' BY J. D. SEADER AND E. J. HENLEY, JOHN WILEY & SONS, 1998.

A 100-KMOL/H FEED CONSISTING OF 10, 20, 30, AND 40 MOL % OF PROPANE(1), N-BUTANE(2), N-PENTANE(3), AND N-HEXANE(4), RESPECTIVELY, ENTERS A DISTILLATION COLUMN AT 100 PSIA (689.5 kPa) AND 200 F (366.5 K). ASSUMING EQUILIBRIUM, WHAT MOLE FRACTION OF THE FEED ENTERS AS VAPOR? THE SOLUTION IS 0.1219 = 12.19 KMOL/HR OF VAPOR AND 87.81 KMOL/HR OF LIQUID.

TAKEN FROM S.T. HADDEN AND H.G. GRAYSON VLE DATA FOR HYDROCARBONS, AT FLASH CONDITIONS, K (1) = 4.2, K (2) = 1.75, K (3) = 0.74, AND K (4) = 0.34, INDEPENDENT OF COMPOSITIONS.

FROM RACHFORD-RICE,

f (Ψ) = 1∑4 {[Z (I)*(1 – K (I)] / [(1 + Ψ*(K (I) - 1)] } = 0

WHERE Ψ = V/F AND Z(I) = THE FEED COMPOSITION IN MOLE FRACTION FOR THE ITH COMPONENT, 0.1, 0.2, 0.3, AND 0.4, RESPECTIVELY. f(0) WAS CALCULATED TO BE -0.128 AND f(1) WAS CALCULATED TO BE 0.720. SINCE f (0) < 0 THE MIXTURE IS ABOVE ITS BUBBLE POINT TEMPERATURE, AND SINCE f (1) > 0 THE MIXTURE IS BELOW ITS DEW POINT MEANING THAT TWO PHASES EXIST. THE CALCULATION OF Ψ USING MONTE CARLO INSTEAD OF NEWTON-RAPHSON FOLLOWS:

Iteration# 1 2 4 6 7 8 9 10LL(1) 0 0 5.92 10.62 11.41 11.8 11.99 12.09V 0 12.36 12.17 12.17 12.18 12.18 12.18 12.189Range 50 62.36 12.5 3.125 1.5625 0.78125 0.3906 0.19531

P a g e 36 | 40

Page 37: Monte Carlo Marching

3 3

OPT0.0767

7 0.0008270.00015

7 8.65E-5 1.77E-5 1.77E-51.8E-

051.63E-

06XP(1) 22.25 12.29 13.21 13.71 11.41 12.49 12 12.189

The liquid and vapor compositions are as follows:

Component Liquid Mole Fraction Vapor Mole FractionPropane 0.0719 0.3021n-Butane 0.1833 0.3207n-Pentane 0.3098 0.2293n-Hexane 0.4350 0.1479 1.0000 1.0000

TABLE 3. SOLVING RACHFORD-RICE

P a g e 37 | 40

Page 38: Monte Carlo Marching

Pct. Vapor

Iteration No.Figure 6.

P a g e 38 | 40

1 2 3 4 5 6 7 80

10

20

30

40

50

60

70

Solving Rachford-Rice

Iteration# LL(1) VRange OPT XP(1)

Page 39: Monte Carlo Marching

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 39 | 40

Page 40: Monte Carlo Marching

The real root = 2.09455129 and is calculated below:

Figure 7.

TABLE 4. SOLVING NEWTON’S CUBIC POLYNOMIAL

P a g e 40 | 40