Documente Academic
Documente Profesional
Documente Cultură
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)
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)
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
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
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)
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")
"""
"""
"""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)
"""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"""
"""Ideal Entropy"""
import math
"""Answer gives two values, first is the integral and second is the integr
U = Enthalpy - ZL*R*T
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)
Tc=float(Tc)
Pc=float(Pc)
w=float(w)
P1=float(P1)
P2=float(P2)
T1=int(T1)
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
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
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
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