This document describes two algorithms for calculating ideal solution chemical equilibrium in multiphase systems. Both algorithms utilize a duality transformation of the Gibbs energy function to formulate the problem. The Lagrange-Newton method finds a stationary point of the Lagrangian using Newton's method. The multiplier penalty method replaces the constrained optimization with sequential unconstrained optimizations. Both methods were tested on a system with 10 gaseous compounds and up to 6 solid phases, and were able to reliably calculate the phase equilibria over a range of pressures.
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
1 s2.0-0378381289800731-main
1. Fluid Phase Equilibria, 53 ( 1989) 73-80
Elsevier Science Publishers B.V., Amsterdam - Printed in The Netherlands
73
Calculation of Multiphase Ideal Solution Chemical Equilibrium
Michael L. Michelsen
Instituttet for Kemiteknik
Bygning 229, DTH, 2800 Lyngby, Denmark
Abstract
Two algorithms for calculation of ideal solution chemical equilibrium in
multiphase systems are described. Both utilize a duality transformation of the
objective function, and for minimization of the transformed problem the
Lagrange-Newton method and the multiplier penalty method, respectively, are
used.
Introduction
Traditionally, algorithms based on the assumption of ideal solutions have
been of importance in the calculation of non-ideal phase equilibrium in the
abscence of chemical reactions. The ideal solution calculation is simple,
involving a number of independent variables corresponding to the number of
phases present. Deviations from ideality are accounted for by repeated
calculations, based on properties evaluated at the last iteration. Such
algorithms have proved reliable and, except for near-critical mixtures,
comparable to second order methods in efficiency, in particular when combined
with acceleration methods (Boston and Britt, 1979; Mehra et al., 1981;
Michelsen, 1982).
Calculation of phase equilibrium with chemical reactions is not extensive-
ly investigated for nonideal mixtures. A natural procedure to apply is the
assumption of ideality for the current iteration, followed by a reevaluation of
physical properties, in analogy with the physical equilibrium calculation.
Calculation of ideal multiphase chemical equilibrium is however more complex,
involving a larger number of independent variables. The basic procedures were
developed 40 years ago, but a variety of approaches are available, each with
their advantages and disadvantages.
Smith and Missen (1982) have in a recent monograph reviewed algorithms for
calculation of chemical equilibrium. They classify current algorithms as
stoichiometric or nonstoichiometric, depending on the manner in which material
balance constraints are handled. Extents of reactions are used as the
independent variables in the stoichiometric methods, whereas the nonstoichio-
metric methods incorporate the element abundance relations as constraints.
Smith and Missen advocate a stoichiometric method, the VCR algorithm. This
method, however, is only linearly convergent and is particularly slow when the
amount of one phase is small; it therefore appears unattractive for general
multiphase calculations.
In this work alternative procedures for calculation of ideal multiphase
chemical equilibrium are investigated, with emphasis on reliability and speed.
0378-38 12/89/$03.50 0 1989 Elsevier Science Publishers B.V.
2. 14
Computational methods
Let nik denote the number of moles of component i in phase k. The
distribution at equilibrium at specified T and P minimizes the Gibbs energy
G
C F
_=z zn.a
RT
i=l k=l
lk ik
(1)
with a
ik
= Clik/RT, where I_I,
lk
is the chemical potential of component i in
phase k.
The Gibbs energy must be minimized, subject to a set of equality
constraints of the form
C
6
i=l
AjiNi = bj ; j = l,Z,...M (2)
F
where Ni is the total amount of component i present, Ni = X nik. The co-
efficient matrix A could represent the formula matrix for the k=&dividual com-
ponents, in whic=h case the material balance constraints, eq. (2), express
conservation of elements, but it is also possible to derive A from a specifiedz
set of independent reactions.
In addition, all mole numbers must be non-negative, yielding the
inequality constraints
n. ' 0,lk -
i = 1,2,....C; k = 1,2,...F (3)
For ideal mixtures the reduced chemical potentials are given by
a a0
ik = ik
+ an x.
lk (4)
with a?
lk = '"Pk/RT> where I?
lk
is the chemical potential for the pure component,
ar:d x.
lk
its mole fraction. In the case of ideal mixtures the Gibbs function
is convex and has a unique minimum.
The component distribution minimizing the Gibbs energy subject to the
constraints, eqns. (2,3), can be obtained from the corresponding Lagrangian
function (Fletcher, 1981, Ch. 9)
F M C C F
(5)
i=l
Z nik aik - 6
k=l j=l
Xj ( c A..N.-bj) - z
i=l J1 1 i=l
x nik vik
k=l
where the solution must satisfy
( -as1 = 0 , i = 1,2,...C ; k= 1,2,...F ;
lk
j = l,Z,...M
j
and
TI n.
ik lk
= 0, nik 2 0, Tlik ' 0, i = 1.2,. ..C ; k = 1,2,...F ;
(6a)
(6b)
(6~)
3. 75
The working equations for the classical Rand algoritm are based on eqns.
(5,6). Substituting the expressions for the ideal solution chemical potentials,
the size of the set of equations to be solved can be reduced to (M+F).
The main advantage of the Rand algorithm is that the reduced equations can
be organized such that the equality constraints, eqn. (2), are satisfied at
each iteration. The Gibbs function can therefore be used to monitor the
progress of iterations, and convergence is virtually assured. Its main
drawbacks are that components present in small amount can hamper convergence,
and, due to the presence of the logarithmic terms, all concentrations in mixed
phases must be initialized with nonzero amounts. In addition, treatment of
phases that vanish or appear during the calculation is cumbersome (Ma and
Shipman, 1972; Smith and Missen, 1982).
As an alternative to the Rand method and its variants we may utilize that
the Gibbs function is convex and use the duality transformation, resulting in a
formulation where the Lagrange multipliers of the original problem become the
independent variables of the transformed problem.
The duality transformation yields the following function to be minimized,
M
Qz- x hj bj (7)
j=l
subject to the inequality constraints
1-Sk- ' 0,
where
k = 1,2,...F ; (8)
C M
'k =
z x.
lk ’
andcnx.
lk
= C AjiAj - vyk (9)
i=l j=l
The objective function is deceptively simple, but the presence of
nonlinear inequality constraints is a serious complication.
The Lagrangian function corresponding to eqn. (7) is
F
ijbj- X
k=l Bk Sk
and the optimality conditions are
j = 1,2,...M
and
6k,O, Sk=0
Or
k = 1,2,...F
Bk=o, Sk,0
(10)
(lla)
(lib)
The Lagrange multipliers @$, of the transformed problem can be identified
as the phase amounts at the solu Ion. Thus, condition (lla) yields
F C
z Bk ( X Ajixik) - bj = 0 (12)
k=l i=l
4. 76
C F C
C Aji ( I: Bkxik) =
’ AjiNi = b’
(13)
i=l k=l i=l J
Any vector A that satisfies eqn. (lla) therefore yields a component
distribution satisfying the material balance constraints, eqn. (2).
The condition (lib) is the familiar summation of mole fractions relation,
with s
k
< 1 for a phase absent at equilibrium.
Like the Rand method, minimization of the transformed problem involves
(M+F) variables, but components present in small amounts present no problems.
In the following we shall consider two procedures for minimizing Q. In the
Lagrange-Newton method a stationary point of the Lagrange function is found
using Newton's method, and in the multiplier penalty function method the
constrained optimization is replaced by sequential unconstrained optlmizations.
Initialization
Minimization procedures have the important advantage over 'equation
solvers' that they are far better able to tolerate initial estimates of low
quality. Good initial estimates, however, reduce the computational effort.
Initial estimates are here, as suggested by Smith and Missen (1982),
generated by means of Linear Programming. Neglecting the logarithmic terms in
the Gibbs function, eqn. (1) can be written
C F
Minimize Z z n. a?
i=l k=l lk lk
subject to the constraints, eqn. (2,3), i.e. an LP problem in standard form.
Solving this results in an approximate n-vector with (at most) M nonzero
elements. For convenience these M key components are assumed to be the first M
components. The material balance constraints are now multiplied by a
nonsingular MxM matrix, to yield a modified set of constraints
with the property that the leading MxM block of A is the identity matrix. The
associated Lagrange multipliers X. correspondillg to this formulation are the
reduced chemical potentials of theJM key components. Initial estimates for the
phase amounts Bk are found from the LP-solution as
C
Ok = C n';:
i=l
Improving the estimate
The LP-approximation usually gives adequate estimates for the components
present in large amounts and thus provides a fair approximation for the phase
amounts. Further refinement is possible by solving the modified material
balance constraints
c ^
z
i=l
Aji Ni - bj = 0
for 1, using the A-estimates obtained from the LP-approximation.
5. To solve for A, these constraints are reorganized, collecting terms with
positive A..-coefficients on the left-hand side and
coefficientdlon the right hand side,
terms with negative
to yield
C C
z Atl.NidTj_
i=l J1
x iJi Ni , j = l,Z,...M (15)
i=l
which can be written
en(q4) - fin(qt;)= 0 , j = 1,2,...M (16)
where qJ" and q; are the left- and the right hand sides of eqn. (15).
The set of equations (15) is solved for h using Newton's method. Keeping
leading block of A equals the identity matrix, it is easilyin mind that the
shown that the
identity matrix,
the mixture. One
for the solution
Jacobian matrix f& the set of equations is close to the
provided the key components constitute the dominant part of
to 4 iterations are usually adequate and result in an estimate
vector, for which the error in X as well as in f3 is small.- -
Converging the estimate
In the Lagrange-Newton method (Fletcher, 1981, Ch. 12) the stationarity
conditions for the Lagrangian are solved by Newton's method. The working
equations are
at F C
axj
=-gj+ z Bk(,C AjiXik) = 0 , j = 1,2,...M (17)
k=l 1=1
and
ad5-_=s
aBk k
-l= 0
for all phases present. "Inactive" phases, i.e. phases not present at
equilibrium must satisfy Sk< 1.
fraction of the solid component.
For a solid phase, sk is just the mole
Second derivatives are readily derived,
a’s? C F
- =
ax.iax
I: i..i .N.
m i=l
Jl”,ll ’
Ni =
' *kXik
k=l
a*d
C
- =
axjask
x .i..x.
i=l
Jl lk
and
A_%-=,
askas&
(18a)
(18b)
(18~)
The initialization provides initial B-values, among which some may equal
zero for multiphase systems. Only positive @-values are included in the set
of equations, and after each Newton step the effect of adding the
correction (Ax,As) is analyzed. The full Newton correction is used, provided
6. ‘78
a) All currently positive ~-values remain positive
b) The new X-values do not result in previously 'inactive' (~1) phases
becoming 'active'.
If one of these conditions are violated, a change in status for the phases
is required, a) requiring removal of a phase and b) introduction of a phase.
In such situations the correction vector is multiplied by a factor Q 1,
chosen to affect the status of only one phase, and iterations continue with a
modified number of phases.
When both the initialization procedures described above are used,
convergence has been unproblematic for all cases investigated. The iteration
count is usually in the range 2-10, with single phase calculations converging
more rapidly.
It is important to realize that the material balance constraints are not
satisfied at each iteration, and the value of the underlying objective
function
of conver~~~~e,(7~~d
therefore provides no guidance. We have thus no guarantee
divergence has occasionally occured when only the LP
initial estimate is used.
A more stable interation can be obtained by means of penalty functions. In
particular, multiplier penalty functions are attractive, being based (Fletcher,
1981, Ch. 12) on unconstrained optimization of an augmented Lagrangian,
F F
Xjbj + I: 5 (s -1) + ; 0 1
k=l k k
(Sk-l)* (19)
k=l
Eqn. (11) is minimized for fixed values of 5 and the parameter 0, and a
Newton correction to f3 is obtained from the converged solution. Nested loops
are thus required, with a simpler (M independent variables) subproblem in the
inner loop.
The disadvantage of nested loop is minor as the major effort is spent in
the first iteration. The outer loop in all cases has converged after 3
iterations, with corresponding iteration counts for the inner loop of 6-12,
2-3. and 1-2.
The multiplier penalty method accounts for the inequality constraints as
suggested by Fletcher and is more robust than the Lagrange-Newton method. Thus,
the intermediate correction of the X-values is not required. Suitable values
for the penalty parameter is 0 = 1-5 x c B
k k(LP).
Examples
To illustrate the stability to handle multiphase systems we analyze
a problem presented by Madeley and Toguri (1973) and by Smith and Missen
(1982). They consider a reaction mixture containing 10 gaseous compounds (0
H 0, CH co, co
C&O ,Cf: With "
H2, CHO, CH20,, PH and N2) and 6 solids (Fe, FeO, Fe 0
3.4.' Ca
8'
’
?I
overall composltlon and standard potentials as speclfled in
Smit and Missen, p. 210, calculations are performed at varying pressures,
assuming ideal behaviour of the gas phase. It is evident that at least 2 solid
phases form, but, depending on pressure, up to 4 solid phases can coexist, as
shown in table 1.
7. 79
Table 1. Formation of solid phases in dependence of pressure
Pressure (Atm) C cao C&O3 Fe Fe0
Fe?04
o-1.29 + +
1.29-3.14 + + +
3.14-3.18 + + + + _
3.18-23.9 + + +
23.9-39.7 + + + +
39.7-542 + + +
542-748 + _ + + +
74% + + +
Both approaches have been extensively tested for this system in the
pressure range 1< P < 1000 atm. A typical computation time for a single
calculation on an Olivetti M380 PC (16 MHz Intel 80386/387, Lahey F77L FORTRAN
compiler, v. 3.0) is 0.5 sec.
There is a narrow pressure interval, 3.14 < P < 3.18, where 2 Ca-contain-
ing solid phases are found, and it is illustrative to look at the phase
distribution for the two methods for a pressure in this range, during the
iterative solution. These intermediate results are shown in Table 2 for the
Lagrange-Newton method and in Table 3 for the penalty function method.
Table 2. Phase disposition in the Lagrange-Newton Method,
P = 3.15 atm.
Iteration no.
1
-----I2
3-4
5-7
Solid phases assumed present
Fe, FeO, CaC03
Fe, CaC03
Fe, C&03, C
Fe, CaCO,, CaO, C
Table 3. Phase distribution in multiplier penalty function method,
P = 3.15 atm
Solid phases assumed present
Conclusion
Two methods based on duality transformation of the Gibbs energy function
are suggested for calculation of ideal solution multiphase chemical equilibri-
um. Both methods are compact, and efficient, the multiplier penalty method
having the advantage of robustness, whereas the Lagrange-Newton method is less
complex and slightly faster.
For stand-alone calculations the robustness of the multiplier penalty
function method makes it the preferred approach. For use in connection with
nonideal eqilibrium calculations, however, excellent initial estimates are
available from the previous iteration, and the Lagrange-Newton method may well
be a superior choice.
8. 80
Nomenclature
A
=
b-
C
F
G
i
z
M
n.
lk
Ni
P
'j
Q
R
'k
T
x.
rk
a.
lk
'k
x
'ik
TI.
lk
0
Q
Coefficient matrix (formula matrix) of material balance constraints
RHS-vector of material balance constraints
Number of components in mixture
Number of phases
Gibbs energy
Component index
Index for material balance constraint
Lagrangian function
NO. of material balance constraints
Moles of component i in phase k
Total moles, component i
Pressure
Defined in eq. (16)
Transformed objective function
Gas constant
Sum of mole fractions, eq. (6)
Temperature
Mole fraction of component i in phase k
Reduced chemical potential, vik/(RT)
Phase amount, of phase k
Lagrange multiplier, primary objective function
Chemical potential, component i in phase k
Lagrange multiplier
Penalty factor
Step length multiplier
References
Boston, J.F. and Britt, H.I., 1978. A Radically Different Formulation and
Solution of the Single Stage Flash. Comput.Chem.Eng., 2, p. 109-122.
Fletcher, R., 1981. Practical Methods of Optimization. Vol. 2. Constrained
Optimization. John Wiley, New York.
Ma, Y.H. and Shipman, C.W., 1972. On the Computation of Complex Equilibria.
AIChE J., 18, p. 299-304.
Madely, W.D. and Toguri, J.M., 1973. Computing Chemical Equilibrium
Compositions in Multiphase Systems. Ind.Eng.Chem.Fundam., 12, p. 211-262.
Mehra, R.K., Heidemann, R.A. and Aziz, K., 1983. An Accelerated Successive
Substitution Algorithm. Can.J.Chem.Eng., 61, p. 590-596.
Michelsen, M.L., 1982. The Isothermal Flash Problem. Part II. Phase-Split
Calculation. Fluid Phase Equilibria, 8, p. 21-40.
Smith, R.S., Missen, R.W., 1982. Chemical Reaction Equilibrium Analysis:
Theory and Algorithms. John Wiley, New York.