import math
# Variables
Tc = 647.1; #[K] - Critical temperature
Pc = 220.55; #[bar] - Critical pressure
Tr = 0.7; # Reduced temperature
# Calculations
T = Tr*Tc; #[K]
#From steam table%vapour pressure of H2O at T is 10.02 [bar]% as reported in the book
P = 10.02; #[bar]
w = -1-math.log10((P/Pc))
# Results
print " The acentric factor (w) of water at given condition is %f "%w
# Variables
#math.log10(Psat)=8.1122-(1592.864/(t+226.184)) # 'Psat' in [mm Hg] and 't' in [c]
Tc = 513.9; #[K] - Critical temperature
Pc = 61.48; #[bar] - Critical pressure
Pc = Pc*10**(5) #[N/m**(2)]
Tr = 0.7; # Reduced temperature
# Calculations
T = Tr*Tc; #[K] - Temperature
T = T - 273.15; #[C]
P_sat = 10**(8.1122 - (1592.864/(T + 226.184))) #[mm Hg]
P_sat = (P_sat/760)*101325; #[N/m**(2)]
Pr_sat = P_sat/Pc;
w = -1-math.log10(Pr_sat) # Acentric factor
# Results
print " The acentric factor (w) for ethanol at given condition is %f"%w
# Variables
T = 380; #[K] - Temperature
Tc = 562.1; #[K] - Critical temperature
P = 7; #[atm] - Pressure
P = P*101325; #[N/m**(2)]
Pc = 48.3; #[atm] - Critical pressure
Pc = Pc*101325; #[N/m**(2)]
R = 8.314; #[J/mol*K] - Universal gas constant
w = 0.212; # acentric factor
Tr = T/Tc; # Reduced temperature
# Calculations and Results
B_0 = 0.083-(0.422/(Tr)**(1.6))
B_1 = 0.139-(0.172/(Tr)**(4.2))
#We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)
B = ((B_0+(w*B_1))*(R*Tc))/Pc; #[m**(3)/mol]
print " The second virial coefficient for benzene is %e m**(3)/mol"%B
#Compressibility factor is given by
Z = 1 + ((B*P)/(R*T))
print " The compressibility factor at 380 K is %f"%Z
#We know thar Z=(P*V)/(R/*T)%therfore
V = (Z*R*T)/P; #[m**(3)/mol]
print " The molar volume is %e m**(3)/mol"%V
# Variables
V_1 = 0.3; #[m**(3)] #volume of cylinder
T = 60+273.15; #[K] - Temperature
P = 130*10**(5) #[N/m**(2)] - Pressure
Tc = 305.3; #[K] - Critical temperature
Pc = 48.72*10**(5) #[N/m**(2)] - Critical pressure
w = 0.100; #acentric factor
M = 30.07; #molecular weight of ethane
Tr = T/Tc; # Reduced temperature
R = 8.314; #[J/mol*K] - Universal gas constant
# Calculations and Results
B_0 = 0.083-(0.422/(Tr)**(1.6))
B_1 = 0.139-(0.172/(Tr)**(4.2))
#We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)
B = ((B_0 + (w*B_1))*(R*Tc))/Pc; #[m**(3)/mol] - Second virial coefficient
Z = 1 + ((B*P)/(R*T)) #Compressibility factor
V = (Z*R*T)/P; #[m**(3)/mol] - Molar volume
#No.of moles in 0.3 m**(3) cylinder is given by
n1 = V_1/V; #[mol]
#Mass of gas in cylinder is given by
m1 = (n1*M)/1000.; #[kg]
print " Under actual conditions, the mass of ethane is, %f kg"%m1
#Under ideal condition% taking Z = 1%
V_ideal = (R*T)/P; #[m**(3)/mol]
n2 = V_1/V_ideal; #[mol]
m2 = (n2*M)/1000; #[kg]
print " Under ideal conditions,the mass of ethane is, %f kg"%m2
# Variables
T = 373.15; #[K] - Temperature
P = 101325; #[N/m**(2)] - Pressure
Tc = 647.1; #[K] - Critical temperature
Pc = 220.55*10**(5) #[N/m**(2)] - Critical pressure
w = 0.345; #acentric factor
Tr = T/Tc; # Reduced temperature
R = 8.314; #[J/mol*K] - UNiversal gas constant
# Calculations
B_0 = 0.083-(0.422/(Tr)**(1.6))
B_1 = 0.139-(0.172/(Tr)**(4.2))
#We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)
B = ((B_0+(w*B_1))*(R*Tc))/Pc; #[m**(3)/mol] - Second virial coefficient
#We have% Z = 1+(B/V) and Z = (P*V)/(R*T). Substituting the value of Z%we get
# V**(2)-((R*T)/P)*V-((B*R*T)/P)=0 .Solving the quadratic equation by shreedharcharya rule
V1 = (((R*T)/P) + (((R*T)/P)**(2) + 4*1*((B*R*T)/P))**(1./2))/2*1;
# Results
print " The molar volume of water vapour is %f m**(3)/mol"%V1
#The roots are%V1 = 0.0003670 [m**(3)/mol] and V2 = 0.0302510 [m**(3)/mol].
#As 'V2' is near to ideal volume (0.030618 [m**(3)/mol])%it is taken as the molar volume
#The other root 'V1' hss no physical significance
# Variables
T = 50+273.15; #[K] - Temperature
P = 15*10**(5) #[N/m**(2)] - Pressure
Tc = 305.3; #[K] - Critical temperature
Pc = 48.72*10**(5) #[N/m**(2)] - Critical pressure
w = 0.100; # Acentric factor
B = -157.31; #[cm**(3)/mol] - second virial coefficient
B = B*10**(-6) #[m**(3)/mol]
C = 9650; #[cm**(6)/mol**(2)] - third virial coefficient
C = C*10**(-12) #[cm**(6)/mol**(2)]
R = 8.314; #[J/mol*K] - Universal gas constant
# Calculations and Results
# (1)
V_1 = (R*T)/P; #[m**(3)/mol] - Molar volume
print " (1).The molar volume for ideal equation of state is %e m**(3)/mol"%V_1
# (2)
Tr = T/Tc; # Reduced temperature
# At this temperature
B_0 = 0.083-(0.422/(Tr)**(1.6))
B_1 = 0.139-(0.172/(Tr)**(4.2))
# We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)
B_2 = ((B_0 + (w*B_1))*(R*Tc))/Pc; #[m**(3)/mol] #second virial coefficient
print " (2).The second virial coefficent using Pitzer correlation is \
found to be %e m**(3)/mol which is same as given value"%B_2
# (3)
# Given (virial equation)%Z=1+(B/V)
V_3 = B + (R*T)/P; #[m**(3)/mol] - Molar volume
print " (3).The molar volume using virial equation of state is %e m**(3)/mol"%V_3
# (4)
# Given (virial equation)%Z = 1 + ((B*P)/(R*T)) + ((C - B**(2))/(R*T)**(2))*P**(2)
V_4 = B + (R*T)/P + ((C - B**(2))/(R*T))*P; # [m**(3)/mol]
print " (4).The molar volume using given virial equation of state is %e m**(3)/mol"%V_4
# (5)
# Given%Z = 1 + (B/V)
# Also%Z = (P*V)/(R*T). Substituting the value of Z%we get
# V**(2)-((R*T)/P)*V-((B*R*T)/P)=0.Solving the quadratic equation
from scipy.optimize import fsolve
def f(V):
global R,T,P,B
return V**(2)-((R*T)/P)*V-((B*R*T)/P)
V_5_1 = fsolve(f,0)
V_5_2 = fsolve(f,1)
print " (5).The molar volume using given virial equation of state is %e m**(3)/mol"%V_5_2
# The roots are%V_5_1=0.0001743 [m**(3)/mol] and V_5_2=0.0016168 [m**(3)/mol].
# As 'V_2' is near to ideal volume (0.0017911 [m**(3)/mol])%it is taken as the molar volume
# (6)
# Given%Z = 1 + (B/V) + (C/V**(2))
# Also%Z = (P*V)/(R*T). Substituting the value of Z%we get
# V**(3)-((R*T)/P)*V**(2)-((B*R*T)/P)*V-((C*R*T)/P)=0. Solving the cubic equation
def f1(V):
global P,R,T,B,C
return V**(3)-((R*T)/P)*V**(2)-((B*R*T)/P)*V-((C*R*T)/P)
V_6_3=fsolve(f1,-1)
V_6_4=fsolve(f1,0)
V_6_5=fsolve(f1,1)
#The above equation has 1 real and 2 imaginary roots. We consider only real root.
print " (6).The molar volume using given virial equation of state is %e m**(3)/mol"%V_6_5
T = 0 + 273.15; #[K] - Temperature
R = 8.314; #[J/mol*K] - Universal gas constant
from numpy import linalg,array
from scipy.stats import linregress
#Virial equation of state% Z=1+(B/V)+(C/V**(2))
#From above equation we get (Z-1)*V=B+(C/V)
P=[50,100,200,400,600,1000];
Z=[0.9846,1.0000,1.0365,1.2557,1.7559,2.0645];
V=[0,0,0,0,0,0]
k= []
t=array([0,0,0,0,0,0])
# Calculations
for i in range(6):
V[i]=(Z[i]*R*T)/(P[i]*101325.) #[m**(3)/mol]
k.append((Z[i]-1.)*V[i])
t[i]=1./V[i]
k = array(k)
#w = linalg.lstsq(t.T,k.T)
#[C,B,sig]=reglin(t',k')
C,B,c,d,e = linregress(t.T,k.T)
# Results
#From the regression% we get intercept=B and slope=C%and thus%
print " The value of second virial coefficient (B) is %e m**(3)/mol"%B
print " The value of third virial coefficient (C) is %e m**(6)/mol**(2)"%C
T = 444.3; #[K] - Temperature
R = 8.314; #[J/mol*K] - Universal gas constant
B_11 = -8.1; #[cm**(3)/mol]
B_11 = -8.1*10**(-6) #[m**(3)/mol]
B_22 = -293.4*10**(-6) #[m**(3)/mol]
y1 = 0.5; # mole fraction # equimolar mixture
y2 = 0.5;
# For component 1 (methane)
Tc_1 = 190.6; #[K] - cricitical temperature
Vc_1 = 99.2; #[cm**(3)/mol] - cricitical molar volume
Zc_1 = 0.288; # critical compressibility factor
w_1 = 0.012; # acentric factor
# For component 2 (n-butane)
Tc_2 = 425.2; #[K]
Vc_2 = 255.0; #[cm**(3)/mol]
Zc_2 = 0.274;
w_2 = 0.199;
# Calculations
#Using virial mixing rule%we get
Tc_12 = (Tc_1*Tc_2)**(1./2) #[K]
w_12 = (w_1 + w_2)/2.;
Zc_12 = (Zc_1+Zc_2)/2.;
Vc_12 = (((Vc_1)**(1./3) + (Vc_2)**(1./3))/2.)**(3) #[cm**(3)/mol]
Vc_12 = Vc_12*10**(-6) #[cm**(3)/mol]
Pc_12 = (Zc_12*R*Tc_12)/Vc_12; #[N/m**(2)]
Tr_12 = T/Tc_12; #Reduced temperature
B_0 = 0.083 - (0.422/(Tr_12)**(1.6))
B_1 = 0.139 - (0.172/(Tr_12)**(4.2))
#We know%(B_12*Pc_12)/(R*Tc_12) = B_0 + (w_12*B_1)
B_12 = ((B_0+(w_12*B_1))*(R*Tc_12))/Pc_12; #[m**(3)/mol] - Cross coefficient
B = y1**(2)*B_11+2*y1*y2*B_12+y2**(2)*B_22; #[m**(3)/mol] - Second virial coefficient for mixture
B = B*10**(6) #[cm**(3)/mol]
# Results
print " The second virial coefficient,(B) for the mixture of gas is %f cm**(3)/mol"%B
T = 71+273.15; #[K] - Temperature
P = 69*10**(5) #[N/m**(2)] - Pressure
y1 = 0.5; #[mol] - mole fraction of equimolar mixture
y2 = 0.5;
R = 8.314; #[J/mol*K] - Universal gas constant
#For component 1 (methane)
Tc_1 =190.6; #[K] - Critical temperature
Pc_1 = 45.99*10**(5) #[N/m**(2)] - Critical pressure
Vc_1 = 98.6; #[cm**(3)/mol] - Critical volume
Zc_1 = 0.286; # Critical compressibility factor
w_1 = 0.012; # acentric factor
#For component 2 (hydrogen sulphide)
Tc_2 = 373.5; #[K]
Pc_2 = 89.63*10**(5) #[N/m**(2)]
Vc_2 = 98.5; #[cm**(3)/mol]
Zc_2 = 0.284;
w_2 = 0.094;
# Calculations
#For component 1
Tr_1 = T/Tc_1; #Reduced temperature
#At reduced temperature
B1_0 = 0.083-(0.422/(Tr_1)**(1.6))
B1_1 = 0.139-(0.172/(Tr_1)**(4.2))
#We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)
B_11 = ((B1_0+(w_1*B1_1))*(R*Tc_1))/Pc_1; #[m**(3)/mol]
#Similarly for component 2
Tr_2 = T/Tc_2; #Reduced temperature
#At reduced temperature Tr_2%
B2_0 = 0.083 - (0.422/(Tr_2)**(1.6))
B2_1 = 0.139 - (0.172/(Tr_2)**(4.2))
B_22 = ((B2_0+(w_2*B2_1))*(R*Tc_2))/Pc_2; #[m**(3)/mol]
#For cross coeffcient
Tc_12 = (Tc_1*Tc_2)**(1./2) #[K]
w_12 = (w_1 + w_2)/2;
Zc_12 = (Zc_1 + Zc_2)/2;
Vc_12 = (((Vc_1)**(1./3) + (Vc_2)**(1./3))/2)**(3) #[cm**(3)/mol]
Vc_12 = Vc_12*10**(-6) #[m**(3)/mol]
Pc_12 = (Zc_12*R*Tc_12)/Vc_12; #[N/m**(2)]
#Now we have%(B_12*Pc_12)/(R*Tc_12) = B_0+(w_12*B_1)
#where B_0 and B_1 are to be evaluated at Tr_12
Tr_12 = T/Tc_12;
#At reduced temperature Tr_12
B_0 = 0.083 - (0.422/(Tr_12)**(1.6))
B_1 = 0.139 - (0.172/(Tr_12)**(4.2))
B_12=((B_0 + (w_12*B_1))*R*Tc_12)/Pc_12; #[m**(3)/mol]
#For the mixture
B = y1**(2)*B_11+2*y1*y2*B_12 + y2**(2)*B_22; #[m**(3)/mol]
#Now given virial equation is% Z=1+(B*P)/(R*T)
Z = 1 + (B*P)/(R*T)
#Also Z = (P*V)/(R*T).Therefore%
V = (Z*R*T)/P; #[m**(3)/mol]
# Results
print " The molar volume of the mixture is %e m**(3)/mol"%V
#The value obtained is near the math.experimental value of V_math.exp = 3.38*10**(-4) m**(3)/mol
P = 6.*10**(6) # [Pa] - Pressure
P_max = 12.*10**(6) # [Pa] - Max pressure to which cylinder may be math.exposed
T = 280.; #[K] - Temperature
R = 8.314; #[J/mol*K] - Universal gas constant
# Calculations and Results
#(1).Assuming ideal gas behaviour%
V_ideal = (R*T)/P; #[m**(3)/mol]
#Now when temperature and pressure are increased%the molar volume remains same%as total volume and number of moles are same.
#For max pressure of 12 MPa%temperature is
T_max_ideal = (P_max*V_ideal)/R;
print " (1).The maximum temperature assuming ideal behaviour is %f K"%T_max_ideal
# (2).Assuming virial equation of state
# For component 1 (methane)%at 280 K
Tc_1 = 190.6; #[K]
Pc_1 = 45.99*10**(5) #[N/m**(2)]
Vc_1 = 98.6; #[cm**(3)/mol]
Zc_1 = 0.286;
w_1 = 0.012;
Tr_1 = T/Tc_1; #Reduced temperature
B1_0 = 0.083 - (0.422/(Tr_1)**(1.6))
B1_1 = 0.139 - (0.172/(Tr_1)**(4.2))
#We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)
B_11 = ((B1_0 + (w_1*B1_1))*(R*Tc_1))/Pc_1; #[m**(3)/mol]
#For component 2 (Propane)
Tc_2 = 369.8; #[K]
Pc_2 = 42.48*10**(5) #[N/m**(2)]
Vc_2 = 200; #[cm**(3)/mol]
Zc_2 = 0.276;
w_2 = 0.152;
Tr_2 = T/Tc_2; # Reduced temperature
B2_0 = 0.083 - (0.422/(Tr_2)**(1.6))
B2_1 = 0.139 - (0.172/(Tr_2)**(4.2))
B_22 = ((B2_0 + (w_2*B2_1))*(R*Tc_2))/Pc_2; #[m**(3)/mol]
#For cross coeffcient
y1 = 0.8; #mole fraction of component 1
y2 = 0.2; #mole fraction of component 2
Tc_12 = (Tc_1*Tc_2)**(1/2.) #[K]
w_12 = (w_1 + w_2)/2;
Zc_12 = (Zc_1 + Zc_2)/2;
Vc_12 = (((Vc_1)**(1./3) + (Vc_2)**(1./3))/2)**(3) #[cm**(3)/mol]
Vc_12 = Vc_12*10**(-6) #[m**(3)/mol]
Pc_12 = (Zc_12*R*Tc_12)/Vc_12; #[N/m**(2)]
Tr_12 = T/Tc_12;
#At reduced temperature%Tr_12%
B_0 = 0.083 - (0.422/(Tr_12)**(1.6))
B_1 = 0.139 - (0.172/(Tr_12)**(4.2))
B_12 = ((B_0 + (w_12*B_1))*R*Tc_12)/Pc_12; #[m**(3)/mol]
#For the mixture
B = y1**(2)*B_11+2*y1*y2*B_12 + y2**(2)*B_22; #[m**(3)/mol]
#Now given virial equation is% Z=1+(B*P)/(R*T)
Z = 1 + (B*P)/(R*T)
#Also Z = (P*V)/(R*T).Therefore%
V_real = (Z*R*T)/P; #[m**(3)/mol]
T_prime = 560.; #[K]
fault = 10.;
while(fault > 1):
T_prime_r1 = T_prime/Tc_1;
B_prime1_0 = 7.7674*10**(-3)
B_prime1_1 = 0.13714;
B_prime_11 = ((B_prime1_0 + (w_1*B_prime1_1))*(R*Tc_1))/Pc_1; #[m**(3)/mol]
#Similarly for component 2%
T_prime_r2 = T_prime/Tc_2;
B_prime2_0 = -0.1343;
B_prime2_1 = 0.10887;
B_prime_22 = ((B_prime2_0 + (w_2*B_prime2_1))*(R*Tc_2))/Pc_2; #[m**(3)/mol]
#For cross coefficient (assuming k12=0)
#Tc_12 % w_12 % Zc_12 % Vc_12 and Pc_12 have already been calculated above%now
T_prime_r12 = T_prime/Tc_12; #
#At reduced temperature%T_prime_r12%
B_prime_0 = 0.083 - (0.422/(T_prime_r12)**(1.6))
B_prime_1 = 0.139 - (0.172/(T_prime_r12)**(4.2))
B_prime_12 = ((B_prime_0+(w_12*B_prime_1))*R*Tc_12)/Pc_12; #[m**(3)/mol]
#For the mixture
B_prime = y1**(2)*B_prime_11 + 2*y1*y2*B_prime_12 + y2**(2)*B_prime_22; #[m**(3)/mol]
Z_prime = 1 + (B_prime*P_max)/(R*T_prime)
T_new = (P_max*V_real)/(Z_prime*R)
fault = abs(T_prime - T_new)
T_prime = T_new;
print " (2).The maximum temperature assuming the gas to follow virial equation of state is %f K"%T_new
# Note : Answers varies because of rounding error. Please check it manually.
V_vessel = 0.1; #[m**(3)] # Volume of vessel
T = 25 + 273.15; #[K] - Temperature
R = 8.314; #[J/mol*K] - Universal gas constant
m = 25*1000; #[g] # Mass of ethylene
Tc = 282.3; #[K] - Critical temperature
Pc = 50.40; #[bar] - Critical pressure
Pc = Pc*10**(5) #[N/m**(2)]
Zc = 0.281; # Critical compressibility factor
Vc = 131; #[cm**(3)/mol] - Critical volume
Vc = Vc*10**(-6) #[m**(3)/mol]
w = 0.087; # Acentric factor
M = 28.054; # Molecular weight of ethylene
# Calculations
n = m/M; #[mole] - No. of moles of ethylene
V = V_vessel/n; #[m**(3)/mol] - Molar volume
#Under Redlich Kwong equation of state% we have
a = (0.42748*(R**(2))*(Tc**(2.5)))/Pc; #[Pa*m**(6)*K**(1/2)/mol]
b = (0.08664*R*Tc)/Pc; #[m**(3)/mol]
P = ((R*T)/(V-b))-(a/(T**(1./2)*V*(V+b))) #[N/m**(2)]
# Results
print " The required pressure using Redlich Kwong equation of state is %e N/m**(2)"%P
#For ideal gas equation of state%
P_ideal = (R*T)/V; #[N/m**(2)]
print " For ideal gas equation of state,the required pressure is %e N/m**(2)"%P_ideal
V_vessel = 360*10**(-3) #[m**(3)] - volume of vessel
T = 62+273.15; #[K] - Temperature
R = 8.314; #[J/mol*K] - Universal gas constant
m = 70.*1000; #[g]/ - Mass of carbon dioxide
#For carbon dioxide
Tc = 304.2; #[K] - Cricitical temperature
Pc = 73.83; #[bar] - Cricitical pressure
Pc = Pc*10**(5) # [N/m**(2)]
Zc = 0.274; # Critical compressibility factor
Vc = 94.0; #[cm**(3)/mol]
Vc = Vc*10**(-6) #[m**(3)/mol]
w = 0.224; # Acentric factor
M = 44.01; # Molecular weight of carbon dioxide
# Calculations and Results
n = m/M; #[mol] - No. of moles
V = V_vessel/n; #[m**(3)/mol] #molar volume
# (1)
# Ideal gas behaviour
P_1 = (R*T)/V; #[N/m**(2)]
print " (1).The required pressure using ideal equation of state is %e N/m**(2)"%P_1
# (2)
# Virial equation of state% Z = 1 + (B*P)/(R*T)
# (P*V)/(R*T) = 1 + (B*P)/(R*T)% and thus P = (R*T)/(V - B). Now
Tr = T/Tc; #Reduced temperature
# At reduced temperature Tr%
B_0 = 0.083 - (0.422/(Tr)**(1.6))
B_1 = 0.139 - (0.172/(Tr)**(4.2))
B = ((B_0 + (w*B_1))*(R*Tc))/Pc; #[m**(3)/mol]
P_2 = (R*T)/(V - B) #[N/m**(2)]
print " (2).The required pressure using given virial equation of state is %e N/m**(2)"%P_2
# (3)
# Virial equation of state% Z = 1 + (B/V)
# (P*V)/(R*T) = 1 + (B/V)
P_3 = ((R*T)/V) + (B*R*T)/(V**(2)) #[N/m**(2)]
print " (3).The required pressure using given virial equation of state is %e N/m**(2)"%P_3
# (4)
# Van der Walls equation of state%P = ((R*T)/(V-b)) - a/(V**(2))
a = (27*(R**(2))*(Tc**(2)))/(64*Pc) #[Pa*m**(6)/mol**(2)]
b = (R*Tc)/(8*Pc) #[m**(3)/mol]
P_4 = ((R*T)/(V-b)) - a/(V**(2)) #[N/m**(2)]
print " (4).The required pressure using van der Walls equation of state is %e N/m**(2)"%P_4
#(5)
# Redlich Kwong equation of state%
a_1 = (0.42748*(R**(2))*(Tc**(2.5)))/Pc; #[Pa*m**(6)*K**(1/2)/mol]
b_1 = (0.08664*R*Tc)/Pc; #[m**(3)/mol]
P_5 = ((R*T)/(V - b_1)) - (a_1/(T**(1./2)*V*(V + b_1))) #[N/m**(2)]
print " (5).The required pressure using Redlich Kwong equation of state is %e N/m**(2)"%P_5
T = 500+273.15; #[K] - Temperature
R = 8.314; #[J/mol*K] - Universal gas constant
P = 325*1000; #[Pa] - Pressure
Tc = 647.1; #[K] - Cricitical temperature
Pc = 220.55; #[bar] - Cricitical pressure
Pc = Pc*10**(5) #[N/m**(2)]
# Calculations and Results
#(1)
# Van der Walls equation of state%
a = (27*(R**(2))*(Tc**(2)))/(64*Pc) #[Pa*m**(6)/mol**(2)]
b = (R*Tc)/(8*Pc) #[m**(3)/mol]
# The cubic form of van der Walls equation of state is given by%
# V**(3)-(b+(R*T)/P)*V**(2)+(a/P)*V-(a*b)/P=0
# Solving the cubic equation
def f(V):
global b,R,T,P,a
return V**(3)-(b+(R*T)/P)*V**(2)+(a/P)*V-(a*b)/P
from scipy.optimize import fsolve
V_1 = fsolve(f,1)
V_2 = fsolve(f,10)
V_3 = fsolve(f,100)
# The above equation has 1 real and 2 imaginary roots. We consider only real root%
Z_1 = (P*V_1)/(R*T) #compressibility factor
print " (1).The compressibility factor of steam using van der Walls equation of state is %f"%Z_1
#(2)
#Redlich Kwong equation of state%
a_1 = (0.42748*(R**(2))*(Tc**(2.5)))/Pc; #[Pa*m**(6)*K**(1/2)/mol]
b_1 = (0.08664*R*Tc)/Pc; #[m**(3)/mol]
# The cubic form of Redlich Kwong equation of state is given by%
# V**(3)-((R*T)/P)*V**(2)-((b_1**(2))+((b_1*R*T)/P)-(a/(T**(1/2)*P))*V-(a*b)/(T**(1/2)*P)=0
#Solving the cubic equation
def f1(V):
return V**(3)-((R*T)/P)*V**(2)-((b_1**(2))+((b_1*R*T)/P)-(a_1/(T**(1./2)*P)))*V-(a_1*b_1)/(T**(1./2)*P)
V_4=fsolve(f1,1)
V_5=fsolve(f1,10)
V_6=fsolve(f1,100)
# The above equation has 1 real and 2 imaginary roots. We consider only real root%
# Thus compressibility factor is
Z_2 = (P*V_4)/(R*T) #compressibility factor
print " (2).The compressibility factor of steam using Redlich Kwong equation of state is %f"%Z_2
from scipy.optimize import fsolve
# Variables
T = 250+273.15; #[K]
R = 8.314; #[J/mol*K]
P = 39.76; #[bar] Vapour pressure of water at T
P = P*10**(5) #[N/m**(2)]
Tc = 647.1; #[K] - Cricitical temperature
Pc = 220.55*10**(5) #[N/m**(2)] - Cricitical pressure
w = 0.345; #Acentric factor
M = 18.015; # Molecular weight of water
# Calculations and Results
# Using peng-Robinson equation of stste
m = 0.37464 + 1.54226*w - 0.26992*w**(2)
Tr = T/Tc;
alpha = (1 + m*(1 - Tr**(1./2)))**(2)
a = ((0.45724*(R*Tc)**(2))/Pc)*alpha; #[Pa*m**(6)/mol**(2)]
b = (0.07780*R*Tc)/Pc; #[m**(3)/mol]
# Cubuc form of Peng-Robinson equation of stste is given by
# V**(3) + (b-(R*T)/P)*V**(2) - ((3*b**(2)) + ((2*R*T*b)/P) - (a/P))*V+b**(3) + ((R*T*(b**(2))/P) - ((a*b)/P) = 0;
# Solving the cubic equation
def f(V):
global b,R,T,P,a
return V**(3)+(b-(R*T)/P)*V**(2)-((3*b**(2))+((2*R*T*b)/P)-(a/P))*V+b**(3)+((R*T*(b**(2)))/P)-((a*b)/P)
V_1 = fsolve(f,-1)
V_2 = fsolve(f,0)
V_3 = fsolve(f,1)
#The largest root is for vapour phase%
V_vap = V_3; #[m**(3)/mol] - Molar volume (saturated vapour)
V_vap = V_vap*10**(6)/M; #[cm**(3)/g]
print " The moar volume of saturated water in the vapour phase (V_vap) is %f cm**(3)/g"%V_vap
#The smallest root is for liquid phase%
V_liq = V_1; #[m**(3)/mol] - molar volume (saturated liquid)
V_liq = V_liq*10**(6)/M; #[cm**(3)/g]
print " The moar volume of saturated water in the liquid phase (V_liq) is %f cm**(3)/g"%V_liq
#From steam table at 250 C% V_vap = 50.13 [cm**(3)/g] and V_liq = 1.251 [cm**(3)/g].
print " From steam table at 250 C, V_vap = 50.13 [cm**(3)/g] and V_liq = 1.251 [cm**(3)/g]"
# Variables
T = 500+273.15; #[K] - Temperature
P = 15.; #[atm] - Pressure
P = P*101325; #[N/m**(2)]
R = 8.314; #[J/mol*K] - Universal gas constant
Tc = 190.6; #[K] - Cricitical temperature
Pc = 45.99*10**(5) #[N/m**(2)] - Cricitical pressure
Vc = 98.6; #[cm**(3)/mol] - Cricitical molar volume
Zc = 0.286; # Critical compressibility factor
w = 0.012; # Acentric factor
# Calculations and Results
#(1)
#Virial equation of state%Z = 1 + (B*P)/(R*T)
Tr_1 = T/Tc; #Reduced temperature
B_0 = 0.083-(0.422/(Tr_1)**(1.6))
B_1 = 0.139-(0.172/(Tr_1)**(4.2)) # We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)
B = ((B_0+(w*B_1))*(R*Tc))/Pc; #[m**(3)/mol] #second virial coefficient
Z = 1 + (B*P)/(R*T) #compressibility factor
#(P*V)/(R*T)=1+(B*P)/(R*T)%and thus%
V_1 = (Z*R*T)/P; #[m**(3)/mol]
print " (1).The molar volume of methane using given virial equation is %e m**(3)/mol"%V_1
#(2).
#Virial equation of state%Z = 1 + (B/V)
#Also%Z = (P*V)/(R*T). Substituting the value of Z%we get
# V**(2) - ((R*T)/P)*V - ((B*R*T)/P) = 0.Solving the quadratic equation
def f(V):
global R,T,P,B
return V**(2)-((R*T)/P)*V-((B*R*T)/P)
V2_1=fsolve(f,0)
V2_2=fsolve(f,1)
# Out of two roots%we will consider only positive root
print " (2).The molar volume of methane using given virial equation is %e m**(3)/mol"%V2_2
# (3)
# Van der Walls equation of state%
# (P + (a/V**(2)))*(V - b) = R*T
a_3 = (27*(R**(2))*(Tc**(2)))/(64*Pc) #[Pa*m**(6)/mol**(2)]
b_3 = (R*Tc)/(8*Pc) #[m**(3)/mol]
# The cubic form of van der Walls equation of state is given by%
# V**(3) - (b + (R*T)/P)*V**(2) + (a/P)*V - (a*b)/P = 0
# Solving the cubic equation
def f1(V):
global b,R,T,P,a_3
return V**(3)-(b_3+(R*T)/P)*V**(2)+(a_3/P)*V-(a_3*b_3)/P
V3_1=fsolve(f1,1)
V3_2=fsolve(f1,10)
V3_3=fsolve(f1,100)
# The above equation has 1 real and 2 imaginary roots. We consider only real root.
print " (3).The molar volume of methane using van der Walls equation of state is %e m**(3)/mol"%V3_1
# (4)
# Redlich Kwong equation of state
a_4 = (0.42748*(R**(2))*(Tc**(2.5)))/Pc; #[Pa*m**(6)*K**(1/2)/mol]
b_4 = (0.08664*R*Tc)/Pc; #[m**(3)/mol]
# The cubic form of Redlich Kwong equation of state is given by%
# V**(3) - ((R*T)/P)*V**(2) - ((b_1**(2)) + ((b_1*R*T)/P) - (a/(T**(1/2)*P))*V - (a*b)/(T**(1/2)*P) = 0
# Solving the cubic equation
def f2(V):
global R,T,P,b_4,a_4
return V**(3)-((R*T)/P)*V**(2)-((b_4**(2))+((b_4*R*T)/P)-(a_4/(T**(1./2)*P)))*V-(a_4*b_4)/(T**(1./2)*P)
V4_1=fsolve(f2,1)
V4_2=fsolve(f2,10)
V4_3=fsolve(f2,100)
#The above equation has 1 real and 2 imaginary roots. We consider only real root.
print " (4).The molar volume of methane using Redlich Kwong equation of state is %e m**(3)/mol"%V4_1
# (5)
# Using Peng-Robinson equation of state
m = 0.37464 + 1.54226*w - 0.26992*w**(2)
Tr_5 = T/Tc;
alpha = (1 + m*(1 - Tr_5**(1./2)))**(2)
a = ((0.45724*(R*Tc)**(2))/Pc)*alpha; #[Pa*m**(6)/mol**(2)]
b = (0.07780*R*Tc)/Pc; #[m**(3)/mol]
# Cubic form of Peng-Robinson equation of stste is given by
# V**(3)+(b-(R*T)/P)*V**(2)-((3*b**(2))+((2*R*T*b)/P)-(a/P))*V+b**(3)+((R*T*(b**(2))/P)-((a*b)/P)=0;
# Solving the cubic equation
def f3(V):
global b,R,T,P,a
return V**(3)+(b-(R*T)/P)*V**(2)-((3*b**(2))+((2*R*T*b)/P)-(a/P))*V+b**(3)+((R*T*(b**(2)))/P)-((a*b)/P)
V5_1=fsolve(f3,-1)
V5_2=fsolve(f3,0)
V5_3=fsolve(f3,1)
#The largest root is for vapour phase%
#The largest root is only considered as the systemis gas
print " (5).The molar volume of methane using Peng-Robinson equation of state is %e m**(3)/mol"%V5_3
# Variables
T = 310.93; #[K] - Temperature
P = 2.76*10**(6) #[N/m**(2)] - Pressure
R = 8.314; #[J/mol*K] - Universal gas constant
y1 = 0.8942; # Mole fraction of component 1 (methane)
y2 = 1-y1; # Mole fraction of component 2 (n-butane)
#For component 1 (methane)
Tc_1 = 190.58; #[K] - Cricitical temperature
Pc_1 = 46.05; #[bar] - Cricitical pressure
Pc_1 = Pc_1*10**(5) #[N/m**(2)]
Zc_1 = 0.288; # Critical compressibility factor
Vc_1 = 99.1; #[cm**(3)/mol]
Vc_1 = Vc_1*10**(-6) #[m**(3)/mol]
w_1 = 0.011; # Acentric factor
#For component 2 (n-butane)
Tc_2 = 425.18; #[K] - Cricitical temperature
Pc_2 = 37.97; #[bar] - Cricitical pressure
Pc_2 = Pc_2*10**(5) # [N/m**(2)]
Zc_2 = 0.274; # Critical compressibility factor
Vc_2 = 255.1; # [cm**(3)/mol]
Vc_2 = Vc_2*10**(-6) # [m**(3)/mol]
w_2 = 0.193; # Acentric factor
# Calculations and Results
# (1)
# Virial equation of state% Z = 1 + (B*P)/(R*T)
# For component 1 (methane)
Tr_1 = T/Tc_1; #Reduced temperature
# At reduced temperature
B1_0 = 0.083 - (0.422/(Tr_1)**(1.6))
B1_1 = 0.139 - (0.172/(Tr_1)**(4.2))
# We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)
B_11 = ((B1_0+(w_1*B1_1))*(R*Tc_1))/Pc_1; #[m**(3)/mol]
#Similarly for component 2
Tr_2 = T/Tc_2; #Reduced temperature
#At reduced temperature Tr_2%
B2_0 = 0.083 - (0.422/(Tr_2)**(1.6))
B2_1 = 0.139 - (0.172/(Tr_2)**(4.2))
B_22 = ((B2_0 + (w_2*B2_1))*(R*Tc_2))/Pc_2; #[m**(3)/mol]
#For cross coeffcient
Tc_12 = (Tc_1*Tc_2)**(1./2) #[K]
w_12 = (w_1 + w_2)/2;
Zc_12 = (Zc_1 + Zc_2)/2;
Vc_12 = (((Vc_1)**(1./3)+(Vc_2)**(1./3))/2)**(3) #[m**(3)/mol]
Pc_12 =(Zc_12*R*Tc_12)/Vc_12; #[N/m**(2)]
#Now we have%(B_12*Pc_12)/(R*Tc_12) = B_0+(w_12*B_1)
#where B_0 and B_1 are to be evaluated at Tr_12
Tr_12 = T/Tc_12;
#At reduced temperature Tr_12
B_0 = 0.083 - (0.422/(Tr_12)**(1.6))
B_1 = 0.139 - (0.172/(Tr_12)**(4.2))
B_12 = ((B_0+(w_12*B_1))*R*Tc_12)/Pc_12; #[m**(3)/mol]
#For the mixture
B = y1**(2)*B_11+2*y1*y2*B_12+y2**(2)*B_22; #[m**(3)/mol]
Z_1 = 1+(B*P)/(R*T) #compressibility factor
print " (1).The compressibility factor of mixture using Virial equation of state is %f"%Z_1
# (2)
# Pseudo reduced method.
T_pc = (y1*Tc_1)+(y2*Tc_2) #[K] - Cricitical temperature
P_pc = (y1*Pc_1)+(y2*Pc_2) #[N/m**(2)] - Cricitical pressure
w = (y1*w_1)+(y2*w_2) # Acentric factor
T_pr = T/T_pc; # Reduced temperature
P_pr = P/P_pc; # Reduced pressure
#At this value of Tpr%
B0 = 0.083 - (0.422/(T_pr)**(1.6))
B1 = 0.139 - (0.172/(T_pr)**(4.2))
Z0 = 1 + B0*(P_pr/T_pr)
Z1 = B1*(P_pr/T_pr)
Z = Z0 + w*Z1;
print " (2).The compressibility factor of mixture using pseudo reduced method is %f"%Z
# (3)
# Redlich Kwong equation of state is given by
# P = ((R*T)/(V-b)) - (a/(T**(1/2)*V*(V+b)))
# For methane%component 1
a_1 = (0.42748*(R**(2))*(Tc_1**(2.5)))/Pc_1; #[Pa*m**(6)*K**(1/2)/mol]
b_1 = (0.08664*R*Tc_1)/Pc_1; #[m**(3)/mol]
#For n-butane%component 2
a_2 = (0.42748*(R**(2))*(Tc_2**(2.5)))/Pc_2; #[Pa*m**(6)*K**(1/2)/mol]
b_2 = (0.08664*R*Tc_2)/Pc_2; #[m**(3)/mol]
#For the mixture
a_12 = (a_1*a_2)**(1./2) #[Pa*m**(6)*K**(1/2)/mol]
a = y1**(2)*a_1 + 2*y1*y2*a_12 + y2**(2)*a_2; #[Pa*m**(6)*K**(1/2)/mol]
b = (y1*b_1) + (y2*b_2) #[m**(3)/mol]
# The cubic form of Redlich Kwong equation of state is given by%
# V**(3) - ((R*T)/P)*V**(2) - ((b_1**(2)) + ((b_1*R*T)/P) - (a/(T**(1/2)*P))*V - (a*b)/(T**(1/2)*P) = 0
# Solving the cubic equation
def f(V):
global R,T,P,b,a
return V**(3)-((R*T)/P)*V**(2)-((b**(2))+((b*R*T)/P)-(a/(T**(1./2)*P)))*V-(a*b)/(T**(1./2)*P)
V_1=fsolve(f,1)
V_2=fsolve(f,10)
V_3=fsolve(f,100)
# Thus compressibility factor is
Z_3 = (P*V_1)/(R*T) #compressibility factor
print " (3).The compressibility factor of mixture using Redlich Kwong equation of state is %f"%Z_3