CinChE Excel Functions for Vapor

CinChE Excel Functions for Vapor-Liquid Equilibrium
Chapter 6 (pp. 6-15 to 6-17) of The Companion in Chemical Engineering, the CinChE manual, presents a
mathematical model and three mathematical algorithms based on Raoult’s Law for multicomponent
vapor-liquid equilibrium (VLE). For a two-component or binary system, three Excel-based functions have
been developed to represent the three mathematical algorithms—vlet, vlevf, and vlep—as follows:
Value = vleT2( Vcode,
Value = vleVf2( Vcode,
Value = vleP2( Vcode,
P, Vf, z1, z2,
T, P, z1, z2,
T, Vf, z1, z2,
A1, B1, C1,
A1, B1, C1,
A1, B1, C1,
A2, B2, C2 )
A2, B2, C2 )
A2, B2, C2 )
where Value is the property value returned by a function as indicated by its first argument Vcode.
Character “2” in a function name implies a binary system. The other arguments are defined as follows:
T
P
Vf
z1
z2
A1, B1, C1
A2, B2, C2
is
is
is
is
is
the equilibrium temperature, °C.
the equilibrium pressure, mm Hg.
the equilibrium molar vapor fraction, range of 0.0 to 1.0.
the total composition for Component 1, mole fraction.
the total composition for Component 2, mole fraction.
Note that z1 + z2 should equal 1.0.
are
are
the Antoine constants for Component 1.
the Antoine constants for Component 2.
Antoine Equation is log P = A - B / (T + C)
where P is in mm Hg, T is in °C, and log is base 10.
See Table B.4 in Felder & Rousseau, 3rd Ed.
The character value of Argument Vcode must be enclosed by quote marks, and its value depends upon
the function as follows:
For function vleT2:
For function vleVf2:
For function vleP2:
where
is
is
is
Lf
xi
yi
“T” or
“Vf” or
“P” or
“Lf”
“Lf”
“Lf”
or
or
or
“x1”
“x1”
“x1”
or
or
or
“x2”
“x2”
“x2”
or
or
or
“y1”
“y1”
“y1”
or
or
or
“y2”
“y2”
“y2”
the equilibrium molar liquid fraction (i.e., Lf = 1.0 – Vf).
the saturated liquid mole fraction of the i-th component.
the saturated vapor mole fraction of the i-th component.
Since an Excel-based function can only return one value, multiple calls to a function must be made to
return each desired calculated variable, like “T”, “Lf”, “x1”, “x2”, “y1”, and “y2”.
How to use these VLE Excel-based functions with the CinChE “EZ Setup” utility is illustrated using the
binary system of n-pentane and n-hexane, which appears on Page 6-18 of the CinChE manual. Click here
to download and open the Excel file pentane-hexane for this binary system. Save this document as an
“.xls” file for Excel 2010 or “.xlsm” for Excel 2013. Worksheet “Raoult” is the mathematical model for
Raoult’s Law applied to the pentane-hexane system, and its numerical solution shows that the bubblepoint temperature is 51.64°C for P = 760 mm Hg, Vf = 0, and zPT = 0.4. To find other equilibrium
temperature values, you would change the Vf value and resolve the model using the Data/Solver.
Worksheet “vleT” is a mathematical algorithm that shows how to use the Excel “vleT2” function to find
three equilibrium temperatures concurrently —a bubble-point (bp) value, an equilibrium (eq) value, and
a dew-point (dp) value—at 760 mm Hg. The three Excel “vleT2” function calls are illustrated as follows:
Tbp
Teq
v15.02.28
=
=
vleT2("T",
vleT2("T",
P, 0.0, zPT, zHX,
P, 0.6, zPT, zHX,
A1,B1,C1, A2,B2,C2)
A1,B1,C1, A2,B2,C2)
© 2015, Michael E. Hanyak, Jr., All Rights Reserved
1 of 4
CinChE Excel Functions for Vapor-Liquid Equilibrium
Tdp
=
vleT2("T",
P, 1.0, zPT, zHX,
A1,B1,C1, A2,B2,C2)
The third argument in each “vleT2” call is the value for the vapor fraction. Worksheet “vleP” illustrates
the use of the Excel “vleP2” function to find three pressures for an equilibrium temperature of 55°C.
Note that Excel-based functions—vleT3, vleVf3, vleP3 and vleT4, vleVf4, vleP4—exists for a three- and
four-component equilibrium system. To use them, extra z’s and A, B, C’s must be added as arguments,
as show in this example of a three-component system for the “vleT3” function:
T
=
vleT3("T",
P, Vf, z1, z2, z3,
A1,B1,C1, A2,B2,C2, A3,B3,C3)
where the red text indicates the changes that must be made to the function call.
The remainder of this handout presents the Excel Visual Basic Application (VBA) code for the “vleT2”
algorithm. The VBA codes for other algorithms like “vleVf2”, “vleP2”, “vleT3”, “vleVf3”, etc. are similar.
Function vleT2(Prop As String, P As Double, Vf As Double, _
z1 As Double, z2 As Double, _
A1 As Double, B1 As Double, C1 As Double, _
A2 As Double, B2 As Double, C2 As Double) As Variant
'
'
This Excel macro function implements the vapor-liquid equilibriurm (vle)
'
mathematical algorithm "vleT" for a binary system and Raoult's Law.
'
'
Author: Dr. Michael E. Hanyak,
February 24, 2015.
'
'
P - the equilibrium pressure, mm Hg.
'
Vf - the equilibrium vapor fraction, range of 0.0 to 1.0.
'
'
z1 - the total composition for Component 1, mole fraction.
'
z2 - the total composition for Component 2, mole fraction.
'
'
A1, B1, C1 - Antoine constants for Component 1.
'
A2, B2, C2 - Antoine constants for Component 2.
'
'
Antoine Equation is
log P = A - B / (T + C)
'
where P is in mm Hg, T is in °C, and log is base 10.
'
'
Function "vleT2" does the iteration on temperature using the Bisection
'
Method. When the last two temperatures of the bisection interval are
'
within 0.000001°C of each other, the function returns a value based
'
on the character content of the first argument, as follows:
'
'
If Prop = "T",
then vleT2 = T
as equilibrium temperature in °C.
'
If Prop = "Lf", then vleT2 = Lf as equilibrium molar liquid fraction.
'
'
If Prop = "x1", then vleT2 = x1 as the sat'd liq mol frac of Comp 1.
'
If Prop = "x2", then vleT2 = x2 as the sat'd liq mol frac of Comp 2.
'
'
If Prop = "y1", then vleT2 = y1 as the sat'd vap mol frac of Comp 1.
'
If Prop = "y2", then vleT2 = y2 as the sat'd vap mol frac of Comp 2.
'
'
':
Declare static variables whose values remain from call to
':
to call of vleT2, until they are changed by this function.
'
Static s_P
As Double, s_Vf As Double
Static s_z1 As Double, s_z2 As Double
Static s_A1 As Double, s_B1 As Double, s_C1 As Double
Static s_A2 As Double, s_B2 As Double, s_C2 As Double
'
Static Tmid As Double, Lf
As Double
Static x1
As Double, x2
As Double
Static y1
As Double, y2
As Double
'
':
Local variables whose values disappear when function call ends.
'
Dim doCalc
As Boolean
' true to do the iterative calculations.
v15.02.28
© 2015, Michael E. Hanyak, Jr., All Rights Reserved
2 of 4
CinChE Excel Functions for Vapor-Liquid Equilibrium
'
'
'
'
'
'
'
':
'
'
'
':
'
'
'
'
'
'
'
'
':
':
'
'
':
'
'
':
'
'
':
':
'
'
Dim DONE
Dim I
Dim nMax
As Boolean
As Integer
As Integer
' true to stop the iteration process.
' index counter for the i-th iteration.
' maximum number of iterations.
Const eps
As Double = 0.000001 ' tolerance on temperature interval.
Dim T1
Dim T2
As Double
As Double
' boiling temperature of Component 1.
' boiling temperature of Component 2.
Dim Tright
Dim Tleft
As Double
As Double
' right-side temperature in the bisection.
' left-side temprature in the bisection.
Dim Psat1
Dim Psat2
As Double
As Double
' sat'n pressure of Component 1 at calc T.
' sat'n pressure of Component 2 at calc T.
Dim K1
Dim K2
As Double
As Double
' equil. coef. of Component 1 at calc T.
' equil. coef. of Component 2 at calc T.
Dim Fright
Dim Fleft
Dim Fmid
As Double
As Double
As Double
' right-side f(Tright) in the bisection.
' left-side f(Tleft) in the bisection.
'
middle f(Tmid)
in the bisection.
Check if the iterative calculations are to be done.
doCalc = True
If (P = s_P) And (Vf = s_Vf) And (z1 = s_z1) And (z2 = s_z2) And _
(A1 = s_A1) And (B1 = s_B1) And (C1 = s_C1) And _
(A2 = s_A2) And (B2 = s_B2) And (C2 = s_C2) Then doCalc = False
Proceed to do the iterative calculation on temperature.
If doCalc Then
On Error GoTo MATH_ERROR
' trap any math error.
First two estimates for the iteration on the equilibrium temperature.
They are the boiling temperatures of each pure compound at P in mm Hg.
T1 = B1 / (A1 - WorksheetFunction.Log10(P)) - C1
T2 = B2 / (A2 - WorksheetFunction.Log10(P)) - C2
' in °C for Component 1.
' in °C for Component 2.
Tleft = WorksheetFunction.Min(T1, T2)
Tright = WorksheetFunction.Max(T1, T2)
' lowest boiling point.
' highest boiling point.
Determine the number of iterations based on the first two estimates and
add a little cushion. See "Bisection Method" in www.wikipedia.org
nMax = (Log(Tright - Tleft) - Log(eps)) / Log(2) + 10
Start the mathematical algorithm for VLET based on Raoult's Law.
Lf = 1 - Vf
' molar liquid fraction.
Check for the special case of a mixture that is just a pure compound.
If (z1 = 1) And (z2 = 0) Then Tmid = T1: y1 = 1: x1 = 1: y2 = 0: x2 = 0: GoTo SET_RESULT
If (z1 = 0) And (z2 = 1) Then Tmid = T2: y1 = 0: x1 = 0: y2 = 1: x2 = 1: GoTo SET_RESULT
Iterate on temperature using the Bisection Method, until tolerance eps
on the interval bound is met or maximum number of iteration is reached.
DONE = False
For I = 1 To nMax
If (Abs(Tright - Tleft) <= eps) Or (I = nMax) Then DONE = True
'
v15.02.28
Select Case I
Case Is = 1:
Case Is = 2:
Case Else:
End Select
Tmid = Tleft
Tmid = Tright
Tmid = (Tleft + Tright) / 2
Psat1 = 10 ^ (A1 - B1 / (Tmid + C1))
' initial left estimate.
' initial right estimate.
' mid-value in an interval.
' for Component 1 in mm Hg.
© 2015, Michael E. Hanyak, Jr., All Rights Reserved
3 of 4
CinChE Excel Functions for Vapor-Liquid Equilibrium
'
'
'
'
'
'
'
'
':
':
':
'
Psat2 = 10 ^ (A2 - B2 / (Tmid + C2))
' for Component 2 in mm Hg.
K1 = Psat1 / P
K2 = Psat2 / P
' K-value for Component 1.
' K-value for Component 2.
x1 = z1 / (Vf * K1 + Lf)
x2 = z2 / (Vf * K2 + Lf)
' sat'd liq mol frac for 1.
' sat'd liq mol frac for 2.
y1 = K1 * x1
y2 = K2 * x2
' sat'd vap mol frac for 1.
' sat'd vap mol frac for 2.
Fmid = (x1 + x2) - (y1 + y2)
' f(T) value at mid-point.
Select Case I
Case Is = 1:
Case Is = 2:
End Select
' f(T) for first estimate.
' f(T) for second estimate.
Fleft = Fmid
Fright = Fmid
If DONE Then Exit For
' stop since all x's and y's are at value Tmid.
If I > 2 Then
If (Fleft * Fmid > 0) Then
Tleft = Tmid
Fleft = Fmid
Else
Tright = Tmid
Fright = Fmid
End If
End If
Next I
' throw away left half.
' throw away right half.
Save the arguments in the static variables for the new results.
For the next call to this function, no calculations are done
if the argument values have not changed from the previous call.
s_P = P:
s_Vf = Vf:
s_A1 = A1:
s_A2 = A2:
s_z1 = z1:
s_B1 = B1:
s_B2 = B2:
s_z2 = z2
s_C1 = C1
s_C2 = C2
End If
'
':
Return vleT2 result depending upon the value of Argument Prop.
'
SET_RESULT:
Select Case UCase(Prop)
Case Is = "T":
vleT2 = Tmid
Case Is = "LF": vleT2 = Lf
'
Case Is = "X1": vleT2 = x1
Case Is = "X2": vleT2 = x2
'
Case Is = "Y1": vleT2 = y1
Case Is = "Y2": vleT2 = y2
'
Case Else: vleT2 = CVErr(xlErrNA)
MsgBox "The first argument of """ & Prop & """ to function vleT2 is invalid." & _
vbNewLine & vbNewLine & _
"This argument can only be ""T"", ""Lf"", ""x1"", ""x2"", ""y1"", or ""y2""." & _
vbNewLine & vbNewLine & _
"Look for a cell with #N/A to make the necessary correction."
End Select
'
Exit Function
'
':
Force next call to function to redo the calculations.
'
MATH_ERROR:
'
s_z1 = 0:
s_z2 = 0
vleT2 = CVErr(xlErrNum)
'
On Error GoTo 0
'
End Function
v15.02.28
© 2015, Michael E. Hanyak, Jr., All Rights Reserved
4 of 4