Sunteți pe pagina 1din 12

Isenthalpic Expansion for Fluids - SRK_EOS

September 11, 2017

In [1]: """ISENTHALPIC EXPANSION"""

print("Program calculates P-T for isenthalpic expansion of fluids.\n ")

def TDProperty(Pc,Tc,w,T,P):
Pc=float(Pc)
Tc=float(Tc)
w=float(w)
T=float(T)
P=float(P)
T_ref=298
P_ref=101234
T_ref=float(T_ref)
P_ref=float(P_ref)

"""Constants"""

R= 8.314

"""Calculated quantities"""

Tr = T/Tc
Pr = P/Pc

Om=0.48+2.574*w - 0.176*w**2
a=(0.42748*(R**2)*Tc**2*(1+Om*(1-Tr**0.5))**2)/Pc
b=0.08664*R*Tc/Pc

A1= a*P/(R*T)**2
B1= b*P/(R*T)
Diff_a= (-0.42748*R**2*Tc*(1+Om*(1-Tr**0.5))*Om)/(Pc*Tr**0.5)

"""Calculation saturation pressure"""

1
def Saturation (Pc,Tc,w,T):

"""Constants"""

"""Calculated quantities"""
P=1000
P=float(P)
list=[]
Pr_list=[]
while P<Pc :

Tr = T/Tc
Pr = P/Pc

Om=0.48+2.574*w - 0.176*w**2
a=(0.42748*(R**2)*Tc**2*(1+Om*(1-Tr**0.5))**2)/Pc
b=0.08664*R*Tc/Pc

A1= a*P/(R*T)**2
B1= b*P/(R*T)
Diff_a= (-0.42748*R**2*Tc*(1+Om*(1-Tr**0.5))*Om)/(Pc*Tr**0.5)

"""Compressibility factor takes form Z**3 + C1*Z**2 + C2*Z + C3 """


C1=-1
C2= A1 - B1 - B1**2
C3= -A1*B1

"""Find root for compressibility factor"""

def Roots(C1,C2,C3):

C1=float(C1)
C2=float(C2)
C3=float(C3)
Q=((C1**2)-3*C2)/9
R=(2*(C1**3)-(9*C1*C2)+(27*C3))/54

if R>0:
Sign=-1.0
else:
Sign=1.0

2
Value=(R**2)-(Q**3)
if Value>0:
"""
print(Value,"is greater that zero, only one real root exists")
"""
A11=Sign*(abs(R)+(Value**0.5))**0.3333
if A11==0:
B11=0
else:
B11=Q/A11
Root_1=(A11+B11)-(C1/3)
Root_2=10
Root_3=0.0
Root=(Root_1,Root_2)

else:
"""
print(Value,"is less than zero, Three roots exist")
"""

import math
Theta=math.acos(R/Q**1.5)
m1=math.cos(Theta/3)
m2=math.cos((Theta+6.28)/3)
m3=math.cos((Theta-6.28)/3)

y1=(-2*(Q**0.5)*m1)-C1/3
y2=(-2*(Q**0.5)*m2)-C1/3
y3=(-2*(Q**0.5)*m3)-C1/3

Llist=[y1,y2,y3]
Root_l=min(Llist)
Root_g=max(Llist)
Root=(Root_l,Root_g)

return Root

Value=Roots(C1,C2,C3)

"""Fugacity calculation"""
if Value[1] < 1 :
if Value[1] > 0.001:
if Value [0] > 0.001:
import math
aaa= (Value[0]-1-math.log(Value[0]-B1)-(A1/B1)*math.log((Valu
bbb= (Value[1]-1-math.log(Value[1]-B1)-(A1/B1)*math.log((Valu

3
phi_vapour=math.exp(aaa)
phi_liquid=math.exp(bbb)

fugacity_vap=phi_vapour*P
fugacity_lqd=phi_liquid*P
Delta=fugacity_vap - fugacity_lqd

"""print( P, Delta )"""


list.append(Delta)
Pr_list.append(P)

P=P+3000
"""
print(Pr_list)
"""
abs_list=[abs(x) for x in list]
"""
print(abs_list)
"""
aa=abs_list.index(min(abs_list))
"""
print(aa)
"""
Saturation_Pressure=Pr_list[aa]

return (Saturation_Pressure)

Sat_Pr = Saturation(Pc,Tc,w,T)

if (P>Sat_Pr):

switch=0
else:

switch=1

"""Compressibility factor takes form Z**3 + C1*Z**2 + C2*Z + C3 """


C1=-1
C2= A1 - B1 - B1**2
C3= -A1*B1

"""Find root for compressibility factor"""

4
def Roots(C1,C2,C3):

C1=float(C1)
C2=float(C2)
C3=float(C3)
Q=((C1**2)-3*C2)/9
R=(2*(C1**3)-(9*C1*C2)+(27*C3))/54

if R>0:
Sign=-1.0
else:
Sign=1.0

Value=(R**2)-(Q**3)
if Value>0:
"""
print(Value,"is greater that zero, only one real root exists")
"""
A11=Sign*(abs(R)+(Value**0.5))**0.3333
if A11==0:
B11=0
else:
B11=Q/A11
Root=(A11+B11)-(C1/3)
"""
print("Single root= ",Root)
"""
else:
"""
print(Value,"is less than zero, Three roots exist")
"""
import math
Theta=math.acos(R/Q**1.5)
m1=math.cos(Theta/3)
m2=math.cos((Theta+6.28)/3)
m3=math.cos((Theta-6.28)/3)

y1=(-2*(Q**0.5)*m1)-C1/3
y2=(-2*(Q**0.5)*m2)-C1/3
y3=(-2*(Q**0.5)*m3)-C1/3

"""
print(y1,y2,y3)
"""

Set=[y1,y2,y3]
if switch==0:
Root=min(Set)

5
else:
Root=max(Set)
return Root
"""Smaller root for liquid and larger root for vapour"""

ZL=Roots(C1,C2,C3)

Molar_Volume_Liquid= (ZL*R*T/P)

"""Residual Thermodynamic Properties - Residual Enthalpy"""

import math
H_res = R*T*(ZL-1) + ((T*Diff_a - a)/b)*math.log((ZL+B1)/ZL)
"""
print("Residual Enthalpy = ", H_res, "J/mol")
"""

"""Residual Thermodynamic Properties - Residual Entropy"""

S_res= R*math.log(ZL-B1) + (Diff_a/b)*math.log((ZL+B1)/ZL)


"""
print("Residual Entropy = ",S_res)

"""

"""Ideal Thermodynamic Properties - Enthalpy"""

"""For Specific heat capacity in form, Cp/R = (A + B*T + C*T2 + D*T3 + E*T

A= 4.221
B= -0.008782
C= 0.00005795
D= -6.729*(10**-8)
E= 2.511*(10**-11)

from scipy.integrate import quad


def Integral(T):
return (A + B*T + C*T**2 + D*T**3 + E*T**4)*8.314

Answer = quad(Integral, T_ref , T )

"""Answer gives two values, first is the integral and second is the integr
Integration from reference state of 25C ( 298K) to desired Temperature.
"""

6
Enthalpy_Ideal= Answer[0]
"""
print("Ideal Enthalpy = ", Enthalpy_Ideal, "J/mol")
"""
"""Ideal Thermodynamic Properties - Enthalpy"""

Enthalpy= Enthalpy_Ideal + H_res

"""Ideal Entropy"""

import math

from scipy.integrate import quad


def Integral_2(T):
return (A/T + B + C*T + D*T**2 + E*T**3)*R

Answer = quad(Integral_2, T_ref, T )

"""Answer gives two values, first is the integral and second is the integr

Entropy_Ideal= Answer[0]- R*math.log(P/P_ref)


"""
print("Ideal Entropy = ", Entropy_Ideal)
"""

Entropy= Entropy_Ideal + S_res

"""Calculate Internal Energy"""

U = Enthalpy - ZL*R*T

"""Calculate Gibbs Free Energy"""

G = Enthalpy - T * Entropy

"""Calculate Fugacity"""

fug= (ZL-1-math.log(ZL-B1)-(A1/B1)*math.log((ZL+B1)/ZL))
phi=math.exp(fug)

7
fugacity=phi*P

return(Sat_Pr,ZL,Molar_Volume_Liquid,Enthalpy,Entropy)

"""pending specific heat A,B,C,D,E"""

Program calculates P-T for isenthalpic expansion of fluids.

In [6]: print("Program calculates P-T for isenthalpic expansion of fluids.\n ")


Fluid=input("Enter Fluid :")
P1=input ("Enter initial Pressure, Pa = ")
T1=input ("Enter initial Temperature, K = ")
P2=input ("Enter final Pressure, Pa = ")
print("Enter Fluid critical properties")
Tc=input ("Enter Critical Temperature, K = ")
Pc=input ("Enter Critical Pressure, Pa = ")
w=input("Enter accentric factor = ")
print("\n")
print("Calculation Summary")

Tc=float(Tc)
Pc=float(Pc)
w=float(w)

P1=float(P1)
P2=float(P2)
T1=int(T1)

"""To find T2 at same esnthalpy as P1,T1"""


delta_list=[]
T2_list=[]
Enthalpy_list=[]

alpha= TDProperty(Pc,Tc,w,T1,P1)
Enthalpy = alpha[3]
print("Saturation Pressure at initial condition = ",alpha[0], "Pa")
print("Enthalpy (J/mol) = ", Enthalpy)
if P2<P1 :
for Temperature in range (50,T1-2,2):
beta= TDProperty(Pc,Tc,w,Temperature,P2)
Enthalpy2=beta[3]
delta=Enthalpy-Enthalpy2
delta=float(delta)

8
delta_list.append(delta)
T2_list.append(Temperature)
Enthalpy_list.append(Enthalpy2)

"""Get Minimum of delta, check if minimum is less than abs(1).If yes, provi

ab_list=[abs(x) for x in delta_list]


aa=ab_list.index(min(ab_list))
bb=min(ab_list)
"""
print(Enthalpy_list)
"""
print("Convergence =" , bb)
if bb>500.0:
print("Isentropy calculation did not converge. Check for phase boundary
"""Comparing adj items in list"""
a=len(Enthalpy_list)
fff=[]
for i in range(a-1) :
diff=Enthalpy_list[i+1]-Enthalpy_list[i]
diff=float(diff)
fff.append(diff)
b=len(fff)
Difference=max(fff)
"""
print("Difference list",fff)
print("Maximum change in Enthalpy", Difference )
"""
position=fff.index(Difference)
print("Bounds of two phase enthalpy")
print(Enthalpy_list[position] , "J/mol")
print (Enthalpy_list[position+1], "J/mol")

"""position of difference in fff, get two elements causing diff, """


T2=T2_list[aa]
print("Two phase region., Proceed to Flash calculation ")
print("T2, Temperature after Isenthalpic Expansion = ", T2 , "K\n")
Diff_1= Enthalpy - Enthalpy_list[position]
Diff_2= Enthalpy_list[position+1] - Enthalpy
Flash_fraction =Diff_2/(Diff_2+Diff_1)
print("Flash fraction = ", 1.0-Flash_fraction)

else:
T2=T2_list[aa]
print("Isenthalpy calculation has converged")

9
print("T2, Temperature after Isenthalpy Expansion = ", T2 , "K\n")

print("\n")
print("Enthalpy-Pressure plot - Zoomed into Operating zone")

%pylab inline
pylab.rcParams['figure.figsize']=(14,10)
import pylab as plt

Temp = T2
Temp=float(Temp)
Enth_list=[]
Pr_list=[]
while Temp < T1+1 :

Pressure=P2
Pressure=float(Pressure)
while Pressure<P1+200000 :
alpha= TDProperty(Pc,Tc,w,Temp,Pressure)
Enthalpy=alpha[3]

Enthalpy=float(Enthalpy)
Enth_list.append(Enthalpy)
Pr_list.append(Pressure)

Pressure=Pressure+100000

Temp= Temp + 5
plt.plot(Enth_list, Pr_list, 'b.')
plt.xlabel('Enthalpy (J/mol)')
plt.ylabel('Pressure (Pa)')
plt.title('Enthalpy-pressure Plot (Isotherms from T2 to T1 .,step 5 K)'

plt.show()
print("Note on the Plot: Temperature drop corresponds to number of isotherm
print("T2 isotherm to the left extreme and T1 isotherm is to the right extr

""" Note: Update Specific heat capacity constants in Program fo Eqn: A + B*

Program calculates P-T for isenthalpic expansion of fluids.

Enter Fluid :2-MethylPropene


Enter initial Pressure, Pa = 3000000
Enter initial Temperature, K = 410

10
Enter final Pressure, Pa = 110000
Enter Fluid critical properties
Enter Critical Temperature, K = 418
Enter Critical Pressure, Pa = 4000000
Enter accentric factor = 0.194

Calculation Summary
Saturation Pressure at initial condition = 3487000.0 Pa
Enthalpy (J/mol) = 713.8328466960693
Convergence = 19.407001328746333
Isenthalpy calculation has converged
T2, Temperature after Isenthalpy Expansion = 318 K

Enthalpy-Pressure plot - Zoomed into Operating zone


Populating the interactive namespace from numpy and matplotlib

WARNING: pylab import has clobbered these variables: ['plt', 'beta']


`%matplotlib` prevents importing * from pylab and numpy

11
Note on the Plot: Temperature drop corresponds to number of isotherms crossing the
T2 isotherm to the left extreme and T1 isotherm is to the right extreme. isotherm p

Out[6]: ' Note: Update Specific heat capacity constants in Program fo Eqn: A + B*T

12

S-ar putea să vă placă și