Convex optimization problems possess very desirable mathe- ...... P. E. Gill, W. Murray and M. H. Wright, Practical Optimization. Academic Press, New York ...
Math1 Compu~. Modelling, Vol. 10, No. 7, pp. Printed in Great Britain. All rights reserved
529-550,
1988
0895-7177/88 $3.00+ 0.00 Copyright 0 1988Pergamon Press plc
COMPUTING COMPLEX CHEMICAL EQUILIBRIA BY GENERALIZED LINEAR PROGRAMMING H. GREINER Philips GmbH Forschungslaboratorium (Received
Aachen, 5100 Aachen, F.R.G.
December
1987)
Communicated by E. Y. Rodin Abstract-We show that the heterogeneous chemical equilibrium problem can be considered as a generalized linear program. An improved version of this minimization method and its application to the calculation of complex multiphase chemical equilibria are presented. An efficient numerical implementation is introduced and computational experience is reported. It is demonstrated that, compared with other methods, the scheme offers a number of distinct computational advantages. Finally, further possible improvements and extensions are discussed.
1. INTRODUCTION The determination of heterogeneous chemical equilibria is of paramount importance in many problems arising in science and technology. With the advent of digital computers after the Second World War many algorithms for their computation have been developed and tested. For the present state-of-the-art and the history of the subject we recommend Refs [l-4]. Complex systems are characterized by a large number of species and phases potentially present at equilibrium. Typical systems may involve hundreds of species and possible phases. Many natural and man-made systems can be described as complex chemical equilibria and the following list is certainly not exhaustive:
1. Geochemistry (see Refs [5, 61). 2. Biology (see Refs [7-lo]). 3. High-temperature systems: light sources [ 111, metallurgy, ceramics, combustion processes [ 121, chemical vapour deposition [ 131. 4. Chemical process design. To model and optimize such systems, complex equilibria have to be computed as efficiently as possible. The ideal algorithm for such calculations should fulfil the following requirements: (i) Reliability of convergence: the iterative procedure should converge independently of the initial estimate. (ii) Generality: the method should be able to handle any number of species and phases in an efficient manner and should not depend on particular thermodynamic models for the solution phases (robustness). (iii) Speed and accuracy: an accurate solution should be obtained as quickly as possible. The application of existing algorithms [l-4, 14-201 to the calculation of complex multiphase chemical equilibria encounters difficulties concerning reliability, speed of convergence and the general applicability of the method. They are related to: (i) The large number of variables (this applies in particular to the so-called stoichiometric algorithms; see Refs [3; 4, Chap. 6.41). (ii) The problem of determining the most stable phase set out of a multitude of possible phase combinations (see Refs [16, 18,201). (iii) The problem of determining the absolute minimum in the presence of miscibility gaps (see Refs [16,20]). M.C M.,0,7--D*
529
530
H. Grumm
(iv) The non-ideal nature of the solution phases; see Ref. [4, Chap. 71.
(v) Numerical singularities of certain coefficient matrices, see Ref. [4, Chap. 91. For a synoptic discussion of these matters, see Refs [2-4,201. The need for the development of a robust and reliable algorithm dealing with complex equilibria is thus strongly felt and much of the current research in the field is directed towards this goal [3, 151. For complex systems involving a gas phase and pure condensed species (“gas-solids problem”) efficient and reliable codes have been described in Refs. [4, Chap. 6.4; 21,221. The purpose $f this contribution is to show that the general chemical equilibrium problem involving arbitrary solution phases can be formulated as a generalized linear program and that this formulation can be used with great advantage for the computation of complex equilibria. To our knowledge generalized linear programming was invented by G. Dantzig and P. Wolfe. The reader will find a well-written and comprehensible introduction in Dantzig’s classic book Linear Programming and Extensions [23]. Dantzig published a number of investigations on the computation of chemical equilibria [24-261. In his book he treats the chemical equilibrium problem for an ideal gas as a generalized linear program [23, Chap. 24-21. We show that this approach can be extended to multiphase problems: generalized linear programming is particularly suited for the solution of complex multiphase problems as it “decomposes” the problem into smaller non-linear subproblems (one for each possible phase and solvable by standard algorithms), which are coordinated by a linear “master” program. The advantages of this scheme are: (i) The computational burden is reduced to the repeated solution of small non-linear subproblems, which depend on a linear “master” program. (ii) The global convergence towards the absolute minimum of the free energy of the system can be proved. Thus, miscibility gaps can readily be calculated. (iii) The scheme is general and applies to ideal and non-ideal phases alike. (iv) If generalized linear programming is used in conjunction with a local Newtontype method to improve the accuracy of the solution, the speed of convergence is very good. Our presentation is organized as follows. We start with a discussion of the mathematical structure of the heterogeneous chemical equilibrium problem and its special mathematical features. We then give a short introduction to linear programming and establish some terminology and notation. After introducing the notion of a generalized linear program, we present an improved version of Dantzig’s classic algorithm for their solution. Having prepared the ground, we formulate the chemical equilibrium problem as a generalized linear program and show how the general scheme can be adapted to various special cases. The following section describes the numerical implementation of the scheme in the computer code CALMIX. Preliminary computational experience with CALMIX is reported. To conclude we discuss the merits of the generalized linear programming approach to the calculation of complex equilibria in comparison with other methods. Finally, a mathematical appendix completes the article. 2. THE
MATHEMATICAL
FORMULATION
OF
THE
EQUILIBRIUM
PROBLEM
In this section the mathematical formulation of the constrained minimization problem describing chemical equilibrium in multiphase systems is established. We begin with the mathematical definition of a chemical reaction system. We then formulate the equilibrium problem as a convex program, whose solution is characterized by a special form of the Kuhn-Tucker conditions. 2.1. Mathematical Dejinition of a Chemical Reaction System In our terminology and notation we follow Ref. [4], which can be consulted for more details and explanation. We first consider a closed chemical system consisting of one homogeneous phase and then discuss heterogeneous systems. There are s chemical species, whose non-negative mole numbers ni are the components of the s-dimensional species abundance vector: n= (4, . . . ,
4)‘.
531
Calculation of complex chemical equilibria
The species are built from m different atoms or elements, whose mole numbers or “elemental abundancies” bi, i = 1, . . . , m, are the components of the m-dimensional element abundance vector: b = (b,, . . . ,6,,,)‘.
If one mole of the jth species contains R, moles of the ith element, we write Ri = (R,i, . . . , R,,,j)’ for its formula vector. The matrix R=(R,,...,R,) whose columns are the species formula vectors is called the system’s formula matrix. As the system is closed, the species abundance vector n has to satisfy the mass-balance equations Rn=b
and the obvious non-negativity
constraints ni 2 O, i=l,...,s.
The system is called feasible for a given elemental abundance vector b if there is at least one species abundance vector n satisfying the systems constraints. The system’s Gibbs free energy at constant temperature and pressure is defined by
G(T, P, n) = i
Pini,
i=l
where p, denotes the chemical potential of the ith species. Pure phases consist of one single species (s = 1) with a constant chemical potential p”(7’, P). Solution phases consist of several species (s > 1) and if xi denotes the mole fraction of the ith species and x=(x,,...,x,) the composition
vector, the chemical potential of the ith species takes the form
L4(T7
P,
X>
=
PP(T,
P)
+
In
(ai(T3
P,
X))
=
PLp(T,
P>
+
In
(Yi(T9
P,
X)4>.
Here py(T, P) is the standard chemical potential, a,(T, P, x) the activity and y,(T, P, x) the activity coefficient of the ith species. It is furthermore assumed that the activities and activity coefficients are continuous functions defined for all compositions and species. This entails that the Gibbs free energy is a continuous function of the species mole numbers ni defined for all ni 2 0. Molar free energies will be indicated by a bar, e.g. C(T,P,x) denotes the molar free Gibbs energy as a function of composition. Closed chemical systems comprising several phases (numbered from 1 to p) are described as follows. Chemical species are designated by an index pair (j, k), where j refers to the jth phase and s(j) (number of species in the jth phase) to the kth species occurring in that phase. k=l,..., Generally j is written as a superscript and k as a subscript. The following notations apply to the jth phase: species abundance vector, composition
vector,
nj =
(nj , , . . , nh);
xJ = (x’;, . . . , xl&,); s(i)
total mole number,
Nj = c n{; i=
formula matrix,
I
IV = (RiI,“‘,
Rijj);
H. GREINER
532 and $A
Gibbs energy,
= c pin{.
G’(d)
i=l
The following notations then specify the entire system: species abundance vector, n = (n’, . . . , n”); composition
vector,
total mole number, formula matrix,
x = (x’, . . . , xp); N = 2 Nj;
R = (,I:YI.,
IV);
and Gibbs energy,
G(n) = f: G’(d). j=l
The system’s constraints take the form Rn= i
Rjnj=h
and
n{>O
for
i=l,..,,
p
and
i=l,...,
s(i).
j=l
If there are further stoichiometric constraints, which cannot be expressed by the mass-balance constraints, the mass-balance constraints have to be augmented. As the mathematical form of the constraints remains unchanged, we do not especially consider this case (see Ref. [4]). If we are dealing with a multiphase system at constant temperature and volume, we employ a notation similar to the case of constant temperature and pressure: Fj( T, Vj, nj) denotes the Helmholtz free energy of the jth phase occupying a volume I”. The molar free Helmholtz energy is defined by Fj( r, Pi, x’), where Pj is the molar volume of the jth phase. The system’s constraints have to be augmented by the additional relation i
NjPj=
v,
j=l
where V is the total volume of the system. According to equilibrium thermodynamics, the system’s equilibrium is defined by the minimum of its Gibbs energy subject to the constraints. For a given chemical reaction system with formula matrix R = (R,, . . . , R,) and element abundance vector b, a priori bounds on the feasible species abundance vector n = (n, , . . . , n,) can easily be established.
Lemma 2.1
If n = (n, , . . . , n,) satisfies the constraints Rn = 1 R,n, = b,
i=l
the following inequalities hold: (i) 0 < ni < min
R,>O,j=I,...,m
i=l,...,s;
Calculation of complex chemical equilibria
533
and
ItIbj
j=l
(ii) 0 < i ni < i='
min{~,RU/i=l,...,s}’
TheprooffollowsfromR~>Ofori=l,...,sandj=l,..., is a j with R, > 0.
m and the fact that for each i there
2.2. The Equilibrium Problem as a Convex Program As a consequence of the maximum entropy principle of statistical mechanics, the entropy function of an internally unconstrained system in equilibrium is a convex function of its extensive variables like mole numbers and volume. More generally thermodynamic functions are concave in their intensive and convex in their extensive variables (for further discussion see Refs [27,28]). Therefore the free energy functions are convex functions of their extensive variables. As a consequence, the constrained minimization problems describing chemical equilibrium G(T, P, n) = ‘f Gj(T, P, nj) = min,
(la)
j=l
subject to Rn = b and non-negativity
constraints,
(lb)
F( T, V, n) = ‘f Fj(T, Vj, nj) = min,
(2a)
j=l
subject to Rn=b,
f: NjV’=
V and non-negativity
constraints,
(2b)
j=l
are convex optimization problems. Convex optimization problems possess very desirable mathematical properties (as a general reference we recommend Ref. [29]): the minimum value assumed by the objective function is uniquely determined (there may be more than one optimal point realizing it). Furthermore, the optimal points can be characterized by the so-called Kuhn-Tucker conditions, whose formulation for the chemical equilibrium problem will now be stated for the case of assigned temperature and pressure. For the Helmholtz free energy a similar formulation can be obtained by replacing the variables n by (V, n) and the variables x by (V, x). We shall use the following relationships between the species abundance vector nj of a phase and its total mole number Ni and composition vector xi: nj(Nj, xj) = (Njx’, , . . . , Njx’,,)
E Iw”“’
j=l,...,p,
and n = (n’(N’, x1), . . . , n”(NP, xp)) E Iwd’)x
. . . x lRNp).
Proposition 2.1
ii = n(P, 9, , . . , flJ’, 3’) is an optimal point for the minimization problem (1 a,b) if the following holds: (i) ii satisfies the constraints. (ii) There are multipliers 4 = (al, . . . , li,) such that
P(9) + ii
= I-II? {W(d) + ii(
2 0
(W
534
H. GREINER
holds for all phases (j = 1, . . . ,p). For the phases actually partaking in the equilibrium the following equalities must be true: xnJn (W(d) + ii(
=
(3b)
0
The proof is given in Ref. [28]. The solution of the multiphase chemical equilibrium problem thus amounts to finding a feasible species vector satisfying equations (3a) and (3b). For systems involving phases which have to be described by non-convex molar free energy functions, the chemical equilibrium problem can be formulated and solved in terms of an associated convex optimization problem. This can be accomplished by taking the convex hull of the non-convex free energy functions. It can be shown that this geometrical construction is equivalent to the application of the so-called lever rule of thermodynamics. For further details on this approach the reader is referred to Ref. [28] (see also Sections 4.1 and 5.1.3 of this article).
3.
LINEAR
AND
GENERALIZED
LINEAR
PROGRAMMING
We start this section by recalling some facts and terminology from linear programming. We then explain how a general class of convex programming problems can be solved by methods of linear programming (generalized linear programming). The standard references on linear and convex programming are Refs [23,30]. 3.1. A Short Introduction to Linear Programming We begin with the definition of a linear program. 3.1.1. Dejkition of a linear program A linear program is a constrained minimization problem of the following form: minimize the linear form $, cini = min,
(44
where the variables n = (n,, . . . , n,) E R” are subject to the following constraints: i=s
Rn=
xRini=b
and
ni>O
for
i=l,...,s.
i=l
(4b)
I? = (R, , . . . , R,) denotes a real (m, s) matrix with column vectors Rig R” and . . , b,) E [w” the r.h.s. vector of the restrictions. Thus the linear programming problem is specified by a set of column vectors and a r.h.s. vector
Here
b=(b,,.
C=((c,,Ri)ERm+‘)i=l
,...,
s>
and
be(W”‘.
We refer to the data of the linear programming problem with abbreviation (C, b). In the following we shall always assume that the set of vectors n satisfying the constraints form a bounded subset of UP.This clearly guarantees the existence of a bounded optimal solution of the linear program. To explain the revised simplex algorithm for finding the optimal solution of the linear program (4), we have to introduce some more terminology. 3.1.2. Terminology A set of m linearly independent column vectors of the restriction matrix R B=(B,,
. . ..B.)=(Rwu,...,
RR,,,)) with
B:{l,. . . ,m} + (1,. . . ,s}
is called a basis of the linear program. We refer to the indices B(j) j = 1, . . . , m as the basic indices and to all other indices as the non-basic indices.
Calculation of complex chemical equilibria
535
For a given basis B, we define the following quantities: n,=(n~,),...,n~(,))=B-‘b
(54
CB =
WI
b(,,,
. . . 3 C&n))
A basis B is called feasible if all components of the vector ns are non-negative. If all components are strictly positive, the basis is called non-degenerate. A feasible basis B=(B,,...,B,)
is called optimal if there exist multipliers u=(u,,...,u,) satisfying ci-uRi20
i= l,...,s
for
with equality holding for the basic indices 0
c&J)- uR,,=
for
1,. . .,m.
j=
It is not difficult to see that the multipliers u defined by an optimal basis are the negative Kuhn-Tucker multipliers of the optimization problem and that the conditions are the corresponding Kuhn-Tucker conditions for an optimal solution. As a sequence of this observation, we note that an optimal solution ii = (E, ) . . . ) ri,) of the linear program is characterized fiBcJl=(B-‘b)i
by an optimal feasible basis B with
j=l,...,m,
fii = 0
if i is not a basic index.
The minimal value of the linear program is given by the number zn defined in equation (5~). To find an optimal solution of the linear program, we must identify an optimal basis. The revised simplex method is an algorithm for identifying an optimal basis in a finite number of steps if the problem possesses an initial feasible basis. Starting with the feasible basis B” the algorithm constructs a sequence of feasible bases B’, which terminates after a finite number of steps with the optimal basis (provided the problem has a bounded solution). 3.1.3. Description of the revised simplex algorithm
We indicate how Bk+ ’ is constructed
from Bk. Determine multipliers uk from the equation Cgk
=
ukBk.
If the optimality conditions ci-ukRi>O
i=l,...,s
are satisfied, Bk is obviously an optimal basis. Otherwise find an index m with c,,,-ukR, 0
for
j =
1,. . . ,p,
(64
j = 1, . . . ,p (non-negativity).
To ensure that the problem possesses a solution, we assume furthermore G’
(64 that the sets
j = 1,. . . ,p
(he)
are bounded and that the variables nj are bounded from above: inj 0 we shall formulate an algorithm for calculating an c-minimum of a generalized linear program. It is based on the idea that problem (6) can be approximated by a linear program with a finite number of columns.
Calculation of complex chemical equilibria
537
3.2.4. Notation
In the following, the vector norm ,1x,1}
Ix(=max{(x,I,...
for
x=(x ,,...,
x,)ElR”
will always be used For a matrix B, 1BI will denote the corresponding matrix norm. Let C c Iw”be an arbitrary bounded set and n > 0. Let F,(C) denote a finite subset of C such that for each c E C there exists an f E F,(C) with (c - fl < IO-“. Let Go = (g, , . . ., grn)cG =A
G’
be vectors such that B” = (p, , . . ., P,) =
P(GO) = (IQ,), . . ., p&n))
form a non-degenerate basis for the generalized linear program (6). Define the linear programs P(n) = P(n, G, Go) = P(n, G’, . . . , GP, Go) = F,(G’) by their column sets. In the following we shall prove (see Proposition
U . . . U F,(GP)UG’
3.1 below)
lim min P(n) = min P
n-m
and show how for each E > 0 an n,(t) can be explicitly constructed (minP(n)-minPJ 0 be given. Determine
a feasible non-degenerate Go with
basis
B” = p(GO)
of the program (6) and let u” denote the multipliers associated with this basis. Let C denote an a priori bound (6f) for C{, , ni. Define the following quantities: d’ = min (min {c - u’p)(c, p) E G’}). j
D = D(B’,
b) =
C
Id’1
min{nH(,lli=l,...,m}’
E(B”, b) = ju”l +
J(BO)-‘ID + 1.
Define 6
61 =rc
and
cz =T 2E’
Determine the smallest n with lo-” < c2. (2) Solve the linear program P(n) = P(n, G, Go) by the revised simplex method described above. To obtain a new column at the kth step of the revised simplex method define d; = Ej-
uklj=
min {c - ukp((c, p)~ Gj}
j=l,...,p
and calculate (C’, @‘)E F,(G’)
with
(Fj-Ej/$;
and
($j-pjI -cl and there exists a column from the initial basis (c, p) E Go with c -dp -cl and
(c)
c - ukp 2 0,
V(c, p) E Go
(i.e. the optimality conditions for the linear program P(n) are satisfied up to c,), construct the approximate solution (n,(e), c,(c), pi(c)), j = 1, . . . , p, as follows. Let (ci, pi) E G””
i=l,...,m
denote the columns of the last basis of the program P(n) with coefficients ni, i = 1,. . . , m. Define nk(c)=x{nilj(i)=k
i=l,...,m)
k=l,...,p.
If &(c) > 0 define (c&), p,&)) E Gk by (ck(c),
Pk@))
=
1
--&(c’,p’)lj(i)=k
i=l,...,
m . 1
As (c,(c), pk(c)) is a convex linear combination of elements belonging to Gk, it belongs also to Gk. If nk(t) = 0 define (c,(E), pk(c)) E Gk arbitrarily. The following statements about the algorithm are established in the Appendix. Proposition 3.1
(i) The algorithm terminates in a finite number of steps. (ii) The data {(nj(c), cj(c),pj(c)) j = 1, . . . , p} define an c-optimum program (6).
of the generalized linear
The proof is given in the Appendix. 3.2.6. Remark Our method for calculating the minimum of a generalized linear program has the advantage that during the calculation only the current basis of the approximating linear program has to be kept. In the original formulation by Dantzig [23], the solution of the generalized linear program is approximated by a sequence of linear programs L’ with an increasing number of columns m + i. They are constructed as follows: Initialization: set Lo = {GO,b). Li-,
Li+l:
Solve the linear program Li to obtain optimal multipliers ui. Determine
a column (E,@)EG’U,...,UG~
Calculationof complexchemicalequilibria
539
with c”-u’@=min{c-u’pJ(c,p)EG’U,...,UGP) and add this column to the columns of L’. Under the assumption that the initial basis B” = p(GO) is non-degenerate the following statements are proved in Ref. [23, Chap. 241: 6)
lim min L’ = min P.
i-m
(ii) There is a subsequence i(j) such that the solutions of the linear programs L”J converge to a solution of the generalized linear program. It is one of the advantages of the generalized linear programming method that it furnishes explicit a priori error bounds on the value of the computed minimum.
4. THE EQUILIBRIUM
PROBLEM
AS A GENERALIZED
LINEAR
PROGRAM
In this section we will show how the chemical equilibrium problem in a multiphase system can be formulated as a generalized linear program. We then give details of the formulation for problems at constant temperature and pressure/volume. Finally, the case of phases that are described by models with internal parameters is discussed. 4.1. The General Case In general, the molar free energy of a phase is defined by a function (not necessarily convex) G:Q + !R, where Q is a bounded and convex subset of some Euclidean space Iw”. The equilibrium problem for a system with p phases (j = 1, . . . , p) is specified by their molar free energies
and restriction matrices
Let G{: Qi + [wdenote the convex envelope of the function Gj. The system’s equilibrium (N’, q’, * . . 9NP, qP) is then obtained as the solution of the convex minimization problem f: NjC G{(qj) and p = Rjqj). The convexity of these sets is implied by the convexity of the functions G;C . It is now easy to verify that problem (7) and the generalized linear program (@, . . . , @, b)
(8)
540
H. GREINER
are equivalent. The boundedness assumptions (6e) and (6f) (see Lemma 2.1) are clearly fulfilled for this program. If we solve the generalized linear program (8) by the algorithm described in Section 3.25, we have to deal for each phase with a minimization problem of the form min {(c - u(Rjqj))jc
>, Gf(qj), qjE Qj}
(9)
for given multipliers u. But clearly problem (9) is equivalent to the problem min {(@(qj) - u(F?jqj))Iqje Qj}.
(10)
Problem (10) is a standard non-linear minimization problem and can be computed by a variety of standard algorithms (see Section 5.1.). The algorithm described for computing an c-optimum of a generalized linear program can now be formulated for the equilibrium problem. To find an c-optimum for problem (7) proceed as follows: (1) Find q”‘l E Qflo, i = 1,*..1 m, such that the vectors RAl)qj(l) ,**-,
form a feasible and non-degenerate (2) Set
RAmIqj@O
basis B” (see Section 5.2.2).
GO= {(y;:;:;;)),
. . . ) (;;$I’)]
and determine the constants C, E, t,, cz and n described in Section 3.2.5. (3) Solve the linear program P(n) = (F,,(G”‘) U . . . U F,(@)
U Go, b),
where F”(&) = {(c, p) E R s(“+‘J there is a ge Gj with I(c,p) - gJ < lo-“}. At the kth iteration let dk = minmin {(@(qj)
- uk(R’q’))lq’E
Qj>.
Determine (c”,3) E F”(@) u . . . u &(G”P), satisfying dk < E - ~“$6 dk + cl.
Then proceed as described in Section 3.2.5. We remark that if a function GJ is not convex, the algorithm does not require the explicit construction of its convex envelope. As the relation
min{f(q>lqEQ)=min(f,(q)lqEQ} holds for any functionf:
Q --, lF!and its convex envelopef, : Q + R, one just has to make sure that dk = rnjn min {(Gj(qj)
- uk(Rjqj))lqjE
Qj}
actually represents an absolute minimum and not just a local one (for convex functions local and global minima coincide). In Section 5.1.3 we describe an efficient way of calculating the global minima of G’(q) - u( R’q’)
for a given u, which is based on the particular structure of problem (11).
(11)
Calculation of complex chemical equilibria
If the optimal solution is constructed
541
from the final basis
RX’)@, . . . , Rh)qAm) one has to account for the fact that the phases with non-convex free energy functions can “split” or “separate” into various phases. This means that vectors q belonging to different “regions of convexity” of the same phase represent different “split” phases.
4.2. Equilibrium at Constant Pressure In this case the free energy of a phase depends only on its composition x = (x, , . . . , x,). Thus, Qi = Q”” = ((x1,. . , , x,) ,$, xi = 1 and xi > O}.
4.3. Equilibrium at Constant Volume Here the molar free energy of a phase depends on its composition x and molar volume v. For condensed phases this causes no problem, as the molar volume will certainly be bounded by a well-defined constant. However, for a gaseous phase the molar volume is not bounded a priori. If the total volume of the system is denoted by V,,, and the total mole number in the gaseous phase by NB, we clearly have NBVg< V,,, . If N, is a mole number which may be considered as negligible for practical purposes, V,,,/N, gives an upper bound for P. The corresponding column set is given by G = {(c, Rx, P)E IWrn+2 Ix E Qmm,0 < P < V,,,/N,, c 2 F(x, p)}. Another approach is to consider the free energy F of the gas phase as a function of the species mole numbers n and the gas volume V. As n and V are bounded apriori, F has only to be considered on a bounded box. Now if the linear constraints are augmented by the additional equation N, = 1, the resulting linearly constrained optimization problem can again be solved as a generalized linear program. The corresponding column set is given by (7 = ((c, Rn, V, 1) E Rm+3[0Gj(qj)
j=l,...,p.
If C is large enough and if the original system is feasible, the extended and the original program have the same solution. In general, a value of C much larger than max(c(g)]gEG’U...U@} is sufficient.
5.2.3. Updating of the basis inverse During the revised simplex algorithm the basis B’ is changed at each step to the basis B'+ ’ by introduction of a new column into B’. After this modification the inverse of B’+’ and the multipliers “‘+I = c~,+I(B’+‘)~’ have to be recomputed.
This can be achieved by a pivot operation on the tableau Ti=
(W’ -c,,(B’)-’
0 1 ’
leading to the tableau T'+ ’ for the basis B'+ ‘. In our implementation we have chosen this “explicit” method of updating. The various methods for updating and their numerical problems are discussed by Murty [30, Chap. 51. 5.3. Control of the Numerical Accuracy We consider the question of how an c-optimum can be calculated as efficiently as possible. As most of the computational effort is invested in the solution of the subproblems, they should only be solved as accurately as necessary. Theoretically this accuracy is controlled by
where E = E(B’, b) is an a priori bound on the optimal multipliers of the programs P(n) (see Section 3.2.5 and Lemma A.5 in the Appendix). Experience has shown that this bound may be far too large, thus leading to unnecessary accuracy in the solution of the subproblems and to increased computing time. The following strategy for obtaining a better bound on the optimal multipliers has proved very efficient: In the first stage an approximate optimum is computed with a moderate accuracy. As a result of this calculation a good estimate and hence a close upper bound for the optimal multipliers is obtained. This bound determines the accuracy of the solution of the subproblems during the calculation of the c-optimum in the second stage. Here the optimal basis of the first stage is used as the initial basis for the second stage (F, c F,,, for n < m !), so the effort of the first stage is not wasted.
546
H. GREINER
Finally, we comment on the degree of accuracy to which a computed c-minimum, characterized by numbers (n’(c), q’(t)) (j = 1, . . . ,p) and multipliers u(c), approximates
the true minimum (fi’, ii’) (j = 1, . . . ,p) and multipliers ti
of problem (7). The approximation certainly depends on the “condition” of the minimum, i.e. for a “steep” minimum a given c-optimal point furnishes a better approximation than for a “shallow” minimum. The choice of E also determines the accuracy to which the necessary optimality conditions f
NjRjxj=b
(15)
j=l
and aG’
s
= pp’ + log a{(nj) = uR_l for i = 1, , . . , s(j)
I
if Nj > 0
(16)
are fulfilled. Here the 1.h.s. of equations (16) represents the activities of the chemical species in the system. 5.4. Miscellaneous 5.4. I. Scaling Experience has shown that the accuracy of the calculations can be improved if the system is scaled such that the sum of the elemental abundancies expressed in moles becomes unity. This can be achieved by scaling the system’s volume. 5.4.2. Degenerate initial basis If the algorithm is started with an initial degenerate basis it will in general converge, although convergence may take longer than for the non-degenerate case. Although we have not offered a formal proof for this fact, it may be explained by the observation that degeneracy is lifted by arbitrarily small perturbations of the r.h.s. vector b.
6. DISCUSSION
AND CONCLUSION
The generalized linear programming algorithm for the calculation of complex chemical equilibria has been implemented as the computer program CALMIX (“calculate mixtures”). Computational experience with CALMIX has so far vindicated the theoretical claims: we have computed complex “real-life” systems consisting of a large gas phase (up to several hundred species), many pure condensed species (up to several hundred) and several solution phases (ideal and non-ideal with up to 10 component species). In all cases the algorithm converged with a reasonable number of iterations of the revised simplex algorithm for the approximating linear program. Of course the number of iterations depends on the system size (number of elements, number of chemical species) and the required accuracy. It was found that the presence of condensed phases at equilibrium can speed up the convergence considerably (this applies particularly to the presence of pure condensed species). In most cases a moderate accuracy (say c = 10d3) requiring only relatively few iterations already gives a good approximation to the exact solution (convergence of the major species is more rapid than convergence of the minor species, i.e. it’s the dog that wags the tail and not vice versa). As the convergence rate of the algorithm is linear, the computational effort for improving the numerical accuracy of the approximation is relatively important. As a remedy in cases where rapid convergence is essential, we advocate the combination of the generalized linear programming algorithm (to produce a good estimate of the solution) with a local Newton-type method (to improve the accuracy of the solution); see Ref. [4, Chaps_ 671._ This
Calculation of complex chemical equilibria
547
approach combines the advantages of both methods, namely efficient and reliable calculation of a good estimate and rapid local convergence. Similar remarks apply to problems in which a series of equilibria is calculated by varying the system parameters in small steps. Here the equilibrium calculated at step n is taken as an initial estimate for step n + 1: in general this estimate gives a good starting point for a Newton method. But if the system changes drastically (for instance if there is a change in the phases present), this may no longer hold and the use of a program like CALMIX is recommended. To conclude, we sum up the main advantages of calculating complex multiphase chemical equilibria by generalized linear programming:
(1) Guaranteed and efficient convergence to a close estimate of the solution without any initial estimate for complex systems with many phases. In our experience generalized linear programming is definitely superior to Newton-type algorithms. The computational efficiency is achieved by decomposition into subproblems (one for each phase), which can be solved efficiently. In particular there is no need to solve large systems of linear equations to compute descent directions as in the Newton methods. (2) As the problem can be decomposed into subproblems which can be solved explicitly (ideal case) or numerically (non-ideal case) by quasi-Newton methods, the second derivatives of the molar free energies of the phases do not have to be provided (if the exact derivatives are approximated by finite differences even the first derivatives are not necessary. In our experience finite differences work perfectly well in most cases). The decomposition procedure allows the handling of systems consisting of many chemical elements forming a virtually unlimited number of chemical species and phases. (3) The algorithm does not depend on the thermodynamic models used to represent the molar free energies of the phases. The incorporation of a new model only requires the specification of the free energy as a function of the compositional and internal variables and the equations relating these variables. Thus each model can be programmed in a separate application module or library. The algorithm can calculate miscibility gaps for phases with any number of component species (4) in a reliable and efficient way. Acknowledgement-The
author wishes to thank Bemd Riiber for helpful discussions and suggestions. REFERENCES
1. F. Van Zeggeren and S. H. Storey, The Computation of Chemical Equilibrium. Cambridge Univ. Press, Cambs. (1970). 2. W. R. Smith, Computational aspects of chemical equilibrium in complex systems. In Theoretical Chemistry: Advances and Perspectives, Vol. 5 (Edited by H. Eyring and D. Henderson). Academic Press, New York (1980). 3. W. R. Smith, The computation of chemical equilibria in complex systems. Ind. Engng Chem. Fun&m. 19, I-10 (1980). 4. W. R. Smith and R. W. Missen, Chemical Reaction Equilibrium Analysis. Wiley, New York (1982). 5. D. K. Nordstrom and J. L. Munoz, Geochemical Thermodynamics. Benjamin/Cummings, Menlo, Calif. (1985). 6. H. Reed, Calculation of multicomponent chemical equilibria and reaction processes in systems involving minerals, gases and an aqueous phase. Geochim. Cosmochim. Acta 46, 513-528 (1982). 7. R. V. Eck, E. R. Lippincott, M. 0. Dayhoff and Y. T. Pratt, Thermodynamic equilibrium and the inorganic origin of organic compounds. Science 153, 628-633 (1966). 8. G. B. Dantzig and J. C. DeHaven, On the reduction of certain multiplicative chemical equilibrium systems to mathematically equivalent additive systems. .I. them. Phys, 36, 262&2627 (1962). 9. J. C. DeHaven and E. C. DeLand, Reactions of hemoglobin and steady states in the human respiratory system: an investigation using mathematical models and an electronic computer. Memorandum RM-3212-PR, The RAND Corp., Santa Monica, Calif. (1962). 10. J. V. Maloney, J. C. DeHaven, E. C. DeLand and G. B. Bradham, Analysis of chemical constituents of blood by digital computer. Memorandum RM-3541-PR, The RAND Corp., Santa Monica, Calif. (1963). 11. E. Schnedler, Computer modelling of high temperature lamp chemistry. In High Temperature Lamp Chemistry (Edited by E. Zubler). The Electrochemical Society, Toronto, Canada (1985). 12. Y. K. Rao, Stoichiometry and Thermodynamics of Metallurgical Processes. Cambridge Univ. Press, Cambs. (1985). 13. J. M. Blocher, Chemical vapour deposition. In Deposition Technologies for Films and Coatings (Edited by R. F. Bunshah). Noyes Publications, Park Ridge, N.J. (1982). 14. G. Eriksson, SOLGASMIX, a computer program for calculation of equilibrium compositions in multiphase systems. Chem. Scripta 8, 100-103 (1975). 15. M. Hillert, Some viewpoints on the use of a computer for calculating phase diagrams. Physica 103B, 31-40 (1981). 16. J. Castillo and I. E. Grossmann, Computation of phase and chemical equilibria. Comput. them. Engng 5,99-108 (1981). 17. B. Jansson, A general method for calculating phase equilibria under different types of conditions. Preprint Materials Center, Royal Institute of Technology, Stockholm (1984).
H. GREINER
548
18. M. Uchida, MPEC2: a code for multiphase chemical equilibria. Cornput. Chem. 11, 19-24 (1987). 19. R. Gautam and W. D. Seider. Computation of phase and chemical equilibrium. Part I: bounded minima in Gibbs free energy. Part II: phase splitting. AlehE JI 25, 991-1006 (1979). _ 20. W. D. Seider, R. Gautam and C. W. White III, Computation of phase and chemical equilibrium: a review. Computer applications to chemical engineering. ACS Symp. Ser., No. 124 (1980). 21. E. Schnedler, The calculation of complex chemical equilibria. CALPHAD 8, 265-279 (1984). 22. H. Greiner, An algorithm for the solution of linearly constrained programs with a partly linear objective function (in preparation). 23. G. B. Dantzig, Linear Programming and Extensions. Princeton Univ. Press, Princeton, N.J. (1963). 24. G. B. Dantzig and M. B. Shapiro, Solving the chemical equilibrium problem using the decomposition principle. P-2056, The Rand Corp. (Aug. 1960). 25. W. B. White, S. M. Johnson and G. B. Dantzig, Chemical equilibrium in complex mixtures. J. them. Phys. 28,751-755 (1958). 26. G. B..Dantzig, S. M. Johnson and W. B. White, A linear programming approach to chemical equilibrium. Mgmr Sci.
5, 3843 (1958). 27. N. Straumann, Thermodynamik. Springer Lecture Notes in Physics, No. 256 (1987). 28. H. Greiner, The chemical equilibrium problem for a multiphase system formulated as a convex program. CALPHAD 12, 133-145 (1988). 29. H. P. Kiinzi, W. Krelle and R. von Randow, Nichtlineare Programmierung. 30. K. G. Murty, Linear Programming. Wiley, New York (1983).
Springer Hochschultext,
Berlin (1979).
31. B. Sundman and J. Agren, A regular solution model for phases with several components and sublattices, suitable for computer applications. J. Phys. Chem. Solids 42, 297-301 (1981). 32. M. Minoux, Mathematical Programming: Theory and Algorithms. Wiley, New York (1986). 33. L. E. Scales, Introduction to Non-linear Optimization. Macmillan, New York (1985). 34. P. E. Gill, W. Murray and M. H. Wright, Practical Optimization. Academic Press, New York (1981). 35. J. Folkman and N. Shapiro, Approximating a convex function by another. SIAM JI appl. Math. 16,993997 (1968).
APPENDIX To prove the assertions of Proposition 3.1, we first have to establish a number of technical lemmas. The proof of the proposition is given at the end of the Appendix. Lemma A.1
Let B” be a non-degenerate basis. Let uk denote the multipliers associated with the bases B’ generated by the revised simplex algorithm starting with B”. Define r~;r~~(~-u~B~
fori=l,...,m.
Assume that the rf are non-negative. Then the following inequalities hold: ZIP-%
for i=l,...,m.
O&=fcCgOpkB: 0 for i = 1, . . , m (B” is assumed to be non-degenerate!) the yf are non-negative.
and the assumption that
Lemma A.2
Consider a generalized linear program (G’, . . , G*, b). Let H be a finite subset of G with h E G A’) for b E H. Assume that the linear program (H, b) is feasible. Then min(H,b)>min(G’,..., Proof.
GP,b).
Let ii& EH) denote an optimal solution of the linear program (H, b). Define ii,=C{ti,lh~H
and
j(h)=k}
k = 1,.
,p.
If A, z 0, define 9” E G’ by
As 9’ is a convex linear combination of elements belonging to G k, it is clearly contained in the set G’. If fia = 0, choose any element from G’ as g’. Now, evidently, min (H, b) = c {ii,c(h)(b E H} = f: fijc(gJ) 3 min (G, b). j=l
Calculation of complex chemical equilibria
549
Lemma A.3 Consider the linear program with generalized columns L = ({(c,, R,), .
, Cc,,RI}, b)
with an initial feasible basis B”. Let B”r’ denote an optimal basis. The following inequalities are valid for 0 < k < opt: s)+zk ProoJ The second inequality is obvious. The first one follows from
Here the equality zk =
ukb
has been used.
Lemma A.4 Let (5, Z,, &), j = 1, . ,p, denote the solution of the generalized linear program (6) and u)I (0 < k < opt) the multipliers of the hnear program P(n). Then the following inequalities hold: i li, min {c -
uqpl(c,
,=I
In particular, we have
p) E GJ} + zk Q min P Q zk,
P 1 fi, min {c - u,Op’pl(c,p) E G’} + min P(n) < min P < min P(n).
,=I Proof: The validity of the second inequality has already been shown in Lemma A.2. To prove the first inequality we write i
ri,min{c-utpl(c,p)eG’]+zk.
,=I
Here we have used the equality zk = uib. Lemma A.5 Let ttip’ denote the approximate optimal multipliers for the program P(n) as defined by the termination criteria for the algorithm described in Section 3.2.5. Then the set {u;rlJn > 1) is bounded by the constant E(B”, b) defined in Section 3.2.5. Proof. Let C be an upper bound for X+‘=,n, and define d’ = min (min {c - u”pl(c,
p) E G’}).
I
Then d’ < 0 [otherwise the basis B” would be optimal for P(n)]. From Lemma A.4 we deduce the inequalities Cd’+z’dmin(P)