# Chapter 3 : PvT relations of fluids¶

### Example 3.1 Page No : 48¶

In [1]:
# Variables
X = 0.8;    			 #Quality of wet steam (no unit)
T = 150.;	    		 #Temperature of the wet steam in degree celsius
vf = 0.0010908;			 #molar volume of saturated liquid in m**3/kg
vg = 0.3924;			 #molar volume of saturated vapour in m**3/kg
uf = 631.63;			 #molar internal energy of the saturated liquid in kJ/kg
ug = 2558.6;			 #molar internal energy of the saturated vapour in kJ/kg

# Calculations
V = (X*vg)+((1-X)*vf);			 # Calculations of specific volume in m**3/kg using Eq.(3.3)
U = (X*ug)+((1-X)*uf);			 # Calculations of specific internal energy in kJ/kg using Eq.(3.6)

# Results
print 'The specific volume of wet steam =  %0.4f m**3/kg '%(V);
print 'The specific internal energy of wet steam =  %0.1f kJ/kg '%(U);

The specific volume of wet steam =  0.3141 m**3/kg
The specific internal energy of wet steam =  2173.2 kJ/kg


### Example 3.2 Page No : 49¶

In [2]:
# Variables
V = 1.42;			 #specific volume of wet steam in m**3/kg
T = 100.;			 #temperature of wet steam in degree celsius
vf = 0.0010437;		 #molar volume of saturated liquid in m**3/kg
vg = 1.673;			 #molar volume of saturated vapour in m**3/kg

# Calculations
X = (V-vf)/(vg-vf);			 # Calculations of the quality of wet steam using Eq.(3.3) (no unit)

# Results
print ' The quality of wet steam =  %0.4f '%(X);

 The quality of wet steam =  0.8487


### Example 3.3 Page No : 49¶

In [4]:
# Variables
T = 100.;			 #temperature inside the vessel in degree celsius
V = 0.00317;			 #specific volume of water at the critical point in m**3/kg
vf = 0.0010437;			 #molar volume of saturated liquid in m**3/kg
vg = 1.673;			 #molar volume of saturated vapour in m**3/kg

# Calculations
X = (V-vf)/(vg-vf);			          # Calculations of the quality of wet steam using Eq.(3.3) (no unit)
ratio = (X*vg)/((1-X)*vf);			 # Calculations of volume ratio of saturated vapour to the saturated liquid (no unit)

# Results
print ' The volume ratio of saturated vapour to the saturated liquid =  %0.2f '%(ratio);

 The volume ratio of saturated vapour to the saturated liquid =  2.04


### Example 3.4 Page No : 49¶

In [5]:
# Variables
U = 2000.			 #specific internal energy of liquid-vapour mixture in kJ/kg
uf = 850.6			 #specific internal energy of saturated liquid in kJ/kg
ug = 2593.2			 #specific internal energy of saturated vapour in kJ/kg

# Calculations
mass_ratio = (U-uf)/(ug-U);			 # Calculations of the mass ratio of vapour to liquid using the lever rule (no unit)

# Results
print ' The mass ratio of vapour to liquid =  %0.4f '%(mass_ratio);

 The mass ratio of vapour to liquid =  1.9376


### Example 3.5 Page No : 52¶

In [6]:
# Variables
n = 1.			 #number of moles of n-octane vapour in mol
T = 427.85;			 #tempearture of n-octane vapour in K
P = 0.215;			 #pressure n-octane vapour in MPa
R = 8.314;			 #universal gas constant in (kPa m**3)/(kmol K)

# Calculations
V = ((n*10**-3)*R*T)/(P*10**3);			 # Calculations of volume using ideal gas law-Eq.(3.9) in m**3

# Results
print ' The volume occupied by n-octane vapour =  %f m**3 '%(V);

 The volume occupied by n-octane vapour =  0.016545 m**3


### Example 3.6 Page No : 54¶

In [1]:
# Variables
n = 1.; 			 #number of moles occupied by n-octane vapour in mol
T = 427.85;			 #temperature in K
P = 0.215;			 #saturation pressure in MPa
a = 3.789;			 #van der Waals constant in Pa(m**3/mol)**2
b = 2.37*10**-4;	 #van der Waals constant in m**3/mol
R = 8.314;			 #universal gas constant in (Pa m**3)/(mol K)

# Calculations
Vguess = (n*R*T)/(P*10**6);
Vnew = (R*T)/((P*10**6)+(a/Vguess**2))+b
tolerance = 1e-6

while abs(Vguess-Vnew)>tolerance:
Vguess = Vnew;
Vnew = (R*T)/((P*10**6)+(a/Vguess**2))+b;			 #the iteration process to solve the system of equation

V = Vnew;			 #The volume calculated using the van der Waals equation in m**3/mol

# Results
print ' The volume occupied by n-octane vapour obtained by van der Waals equation =  %f m**3/mol'%(V);

 The volume occupied by n-octane vapour obtained by van der Waals equation =  0.015675 m**3/mol


### Example 3.7 Page No : 55¶

In [9]:
# Variables
n = 1.; 			 #number of moles occupied by n-octane liquid in mol
T = 427.85;			 #temperature in K
P = 0.215;			 #saturation pressure in MPa
a = 3.789;			 #van der Waals constant in Pa(m**3/mol)**2
b = 2.37*10**-4;			 #van der Waals constant in m**3/mol
R = 8.314;			 #universal gas constant in (Pa m**3)/(mol K)

# Calculations
Vguess = b
Vnew = (R*T)/((P*10**6)+(a/Vguess**2))+b
tolerance = 1e-6
while abs(Vguess-Vnew)>tolerance:
Vguess = Vnew;
Vnew = (R*T)/((P*10**6)+(a/Vguess**2))+b;			 #the iteration process to solve the system of equation

V = Vnew;			 #The volume calculated using the van der Waals equation in m**3/mol

# Results
print ' The volume occupied by n-octane liquid obtained by van der Waals equation =  %e m**3/mol'%(V);

 The volume occupied by n-octane liquid obtained by van der Waals equation =  3.517652e-04 m**3/mol


### Example 3.8 Page No : 57¶

In [2]:
import math

# Variables
T = 427.85; 		    	 #temperature in K
P = 0.215;	    		     #saturation pressure in MPa
a = 3.789;		    	     #van der Waals constant in Pa(m**3/mol)**2
b = 2.37*10**-4;			 #van der Waals constant in m**3/mol
R = 8.314;		        	 #universal gas constant in (Pa m**3)/(mol K)
Pcvc = 3
RTc = 8.
# Calculations
#The Cardan's method simplifies the equation of state into a cubic equation which can be solved easily
#The general form of the cubic equation is (Z**3)+(alpha*Z**2)+(beeta*Z)+gaamma = 0, where alpha,beeta and gaamma are determined using established relations

A = (a*P*10**6)/(R*T)**2;
B = (b*P*10**6)/(R*T);
alpha = -1-B;
beeta = A;
gaamma = -(A*B);
p = round(beeta-(alpha**2)/3,4)
q = round(((2*alpha**3)/27)-((alpha*beeta)/3)+gaamma,4)
D = (q**2/4)+(p**3/27);

if D>0 :
Z = ((-q/2)+(math.sqrt(D)))**(1./3)+((-q/2)-(math.sqrt(D)))**(1./3)-(alpha/3);
vf = ((Z)*R*T)/(P*10**6);
vg = ((Z)*R*T)/(P*10**6);
elif D == 0:
Z1 = ((-2*(q/2))**(1./3))-(alpha/3);
Z2 = ((q/2)**(1./3))-(alpha/3);
Z3 = ((q/2)**(1./3))-(alpha/3);
Z = [Z1 ,Z2, Z3];
vf = (min(Z)*R*T)/(P*10**6)
vg = (max(Z)*R*T)/(P*10**6)
else:
r = math.sqrt((-(p**3)/27));			 # Calculations of r using Eq.(3.38)
theta = math.cos((-(q)/2)*(1./r));			 # Calculations of theta in radians using Eq.(3.37)
Z1 = (2*(r**(1./3))*math.cos(theta/3))-(alpha/3);
Z2 = (2*(r**(1./3))*math.cos(((2*math.pi)+theta)/3))-(alpha/3);			 #Three unequal real roots given by Eqs.(3.34,3.35 and 3.36)
Z3 = (2*(r**(1./3))*math.cos(((4*math.pi)+theta)/3))-(alpha/3);
Z = [Z1, Z2, Z3];
vf = (min(Z)*R*T)/(P*10**6)
vg = (max(Z)*R*T)/(P*10**6)

crit = Pcvc/RTc

# Results
print ' The volume occupied by n-octane saturated liquid obtained by Cardans method =  %.3e m**3/mol'%(vf);
print ' The volume occupied by n-octane saturated vapour obtained by Cardans method =  %.2e m**3/mol'%(vg);
print " At the critical point, PcVc/RTc = %.3f"%crit

# Note: value of D is calculated wrongly in book. Please calculate manually.

 The volume occupied by n-octane saturated liquid obtained by Cardans method =  -9.345e-04 m**3/mol
The volume occupied by n-octane saturated vapour obtained by Cardans method =  1.55e-02 m**3/mol
At the critical point, PcVc/RTc = 0.375


### Example 3.9 Page No : 60¶

In [1]:
from numpy import *
import math

# Variables
T = 427.85;			 #temperature in K
P = 0.215;			 #saturation pressure in MPa
R = 8.314;			 #universal gas constant in (Pa m**3)/(mol K)
Pc = 24.97;			 #critical pressure of n-octane in bar
Tc = 569.4;			 #critical temperature of n-octane in K

# Calculations
a = (0.42748*R**2*Tc**2.5)/(Pc*100*10**3*math.sqrt(T));
b = (0.08664*R*Tc)/(Pc*100*10**3);

A = (a*P*10**6)/(R*T)**2;
B = (b*P*10**6)/(R*T);
alpha = -1.;
beeta = A-B-B**2.;
gaamma = -(A*B);
p = beeta-(alpha**2)/3.
q = ((2*alpha**3.)/27.)-((alpha*beeta)/3)+gaamma
D = (((q)**2)/4.)+(((p)**3)/27.);
#if D>0 then:
#       Z = ((-q/2)+(math.sqrt(D)))**(1./3)+((-q/2)-(math.sqrt(D)))**(1./3)-(alpha/3)
#      vf = ((Z)*R*T)/(P*10**6)
#     vg = ((Z)*R*T)/(P*10**6)
#elif D == 0:
#       Z1 = ((-2*(q/2))**(1./3))-(alpha/3);
#      Z2 = ((q/2)**(1./3))-(alpha/3);
#     Z3 = ((q/2)**(1./3))-(alpha/3);
#    Z = [Z1 ,Z2, Z3];
#   vf = (min(Z)*R*T)/(P*10**6);
#  vg = (max(Z)*R*T)/(P*10**6);
#else:

r = math.sqrt((-(p**3)/27));
theta = (math.acos((-(q)/2)*(1./r)));
Z1 = (2*(r**(1./3))*math.cos(theta/3))-(alpha/3);
Z2 = (2*(r**(1./3))*math.cos(((2*math.pi)+theta)/3))-(alpha/3);
Z3 = (2*(r**(1./3))*math.cos(((4*math.pi)+theta)/3))-(alpha/3);
Z = [Z1, Z2, Z3];
vf = (min(Z)*R*T)/(P*10**6);
vg = (max(Z)*R*T)/(P*10**6);

# Results
print ' The volume occupied by n-octane saturated vapour) using Redlich-Kwong equation of state =  %f m**3/mol'%(vg);
print ' The volume occupied by n-octane saturated liquid) using Redlich-Kwong equation of state =  %f m**3/mol'%(vf);

 The volume occupied by n-octane saturated vapour) using Redlich-Kwong equation of state =  0.015401 m**3/mol
The volume occupied by n-octane saturated liquid) using Redlich-Kwong equation of state =  0.000244 m**3/mol


### Example 3.10 Page No : 67¶

In [13]:
import math

# Variables
T = 180.;			 #temperature of water in degree celsius
P = 1.0027;			 #saturation pressure of water in MPa
Tc = 647.3;			 #critical temperature of water in K
Pc = 221.2;			 #critical pressure of water in bar
Tr = 0.7;			 #reduced temperature at which acentric factor was defined by Pitzer

# Calculations
T1 = Tr*Tc; 			 #calculating temperature  in K using reduced temperature value
T1 = T1-273.15;			 #conversion to degree celsius
Pr = (P*10)/Pc;			 # Calculations of reduced pressure (no unit) using saturation pressure at t1. In this case t1 equals t, therefore the given saturation pressure is taken
w = -math.log10(Pr)-1.0;			 # Calculations of acentric factor using Eq.(3.62)

# Results
print ' The acentric factor of water =  %f '%(w);

 The acentric factor of water =  0.343614


### Example 3.11 Page No : 72¶

In [15]:
# Variables
T = 409.41;			 #temperature of n-octane in degree celsius
P = 4.98;			 #pressure in bar
Tc = 569.4;			 #critical temperature of n-octane in K
Pc = 24.97;			 #critical pressure of n-octane in bar
w = 0.398;			 #acentric factor (no unit)
R = 8.314;			 #universal gas constant in (Pa m**3)/(mol K)

# Calculations
Tr = (T+273.15)/Tc;
Pr = P/Pc;
z0 = 0.96;
V1 = (z0*R*(T+273.15))/(P*10**5);
z1 = 0.01;
z = z0+(w*z1);
V2 = (z*R*(T+273.15))/(P*10**5)

# Results
print ' The volume occupied by n-octane obtained by the two parameter compressibilty \
factor correlation =  %f m**3/mol'%(V1);
print ' The volume occupied by n-octane obtained by the three parameter compressibility \
factor correlation =  %f m**3/mol'%(V2);

 The volume occupied by n-octane obtained by the two parameter compressibilty  factor correlation =  0.010939 m**3/mol
The volume occupied by n-octane obtained by the three parameter compressibility factor correlation =  0.010985 m**3/mol


### Example 3.12 Page No : 72¶

In [69]:
# Variables
V = 1.;	    		 #volume of the tank in m**3
m = 180.;			 #mass of carbon dioxide in kg
T = 91.8;			 #temperature of the tank in degree celsius after it is placed in the vicinity of a furnace
Tc = 304.2;			 #critical temperature of carbon dioxide in K
Pc = 73.87;			 #critical pressure of carbon dioxide in bar
R = 8.314;			 #universal gas constant in (Pa m**3)/(mol K)

# Calculations
mwt = 44.*10**-3	 #molecular weight of carbon dioxide in kg/mol
n = m/mwt;			 # Calculations of number of moles of carbon dioxide in the tank in moles
MV = V/n;			 # Calculations of molar volume in m**3/mol
slope = (MV*Pc*10**5)/(R*(T+273.15));			 #slope of the straight line formed when z0 is plotted against Pr formed by using the relation z0 = (V*Pc*Pr)/(R*T)
Tr = (T+273.15)/Tc;			 # Calculations of reduced temperature (no unit)

#At the given conditions, the state of CO2 must lie on the curve corresponding to the obtained value of Tr. To determine the state of CO2, a straight line passing through the origin, with the obtained value of slope is drawn on the z0 vs Pr plot of Fig.3.12 and the point of intersection of this straight line with the Tr curve is obtained to get the value of z0
z0 = 0.725;			 #value of compressibilty factor obtained by doing the above mentioned procedure
P = (z0*R*10**-6*(T+273.15))/(MV)			 # Calculations of pressure in MPa using Eq.(3.59)

# Results
print ' The pressure developed by carbon dioxide =  %.0f MPa'%(P);

 The pressure developed by carbon dioxide =  9 MPa


### Example 3.13 Page No : 73¶

In [4]:
# Variables
V = 1.;			 #volume of the tank in m**3
m = 180.;			 #mass of carbon dioxide in kg
T = 91.8;			 #temperature of the tank in degree celsius after it is placed in the vicinity of a furnace
Tc = 304.2;			 #critical temperature of carbon dioxide in K
Pc = 73.87;			 #critical pressure of carbon dioxide in bar
R = 8.314;			 #universal gas constant in (Pa m**3)/(mol K)
w = 0.239;			 #acentric factor (no unit)

# Calculations
mwt = 44.*10**-3
n = m/mwt
MV = V/n;
Tr = (T+273.15)/Tc
z0 = 0.725
z_init = z0;
slope = (MV*Pc*10**5)/(R*(T+273.15));
Prguess = z_init/slope;
z1guess = 0.1;
tolerance = 1e-6;

def solver_function(zi):
return zi-(z0+(w*z1guess))

z = fsolve(solver_function,z1guess)
Pr = z/slope;
P = ((Pc*10**5)*Pr)*10**-6

# Results
print ' The pressure developed by carbon dioxide =  %f MPa'%(P);

 The pressure developed by carbon dioxide =  9.295806 MPa


### Example 3.14 Page No : 75¶

In [2]:
from scipy.optimize import fsolve

# Variables
T = 427.85;			 #temperature of n-octane vapour in K
P = 0.215;			 #pressure of n-ocatne vapour in MPa
Tc = 569.4;			 #critical temperature of n-octane in K
Pc = 2.497;			 #critical pressure of n-octane in MPa
R = 8.314;			 #universal gas constant in (Pa m**3)/(mol K)

# Calculations
Tr = T/Tc
Pr = P/Pc
z_init = 1
h = (0.08664*Pr)/(z_init*Tr)
tolerance = 1e-6;

def solver_func(zi):
return zi-((1./(1-h))-((h/(1+h))*(4.93398/(Tr**(3./2)))))

z = fsolve(solver_func,h)
V = (z*R*T)/(P*10**6);

# Results
print ' The volume occupied by n-octane vapour obtained by the generalized form of \
\n Redlich-Kwong equation of state =  %.2e m**3/mol'%(V);

# Note : Answer may vary because of rouding off error.

 The volume occupied by n-octane vapour obtained by the generalized form of
Redlich-Kwong equation of state =  1.55e-02 m**3/mol


### Example 3.15 Page No : 77¶

In [74]:
import math
# Variables
T = 427.85;			 #temperature in K
P = 0.215;			 #saturation pressure in MPa
Tc = 569.4;			 #critical temperature of n-octane in K
Pc = 24.97;			 #critical pressure of n-octane in bar
w = 0.398;			 #acentric factor (no unit)
R = 8.314;			 #universal gas constant in (Pa m**3)/(mol K)

# Calculations
#The Cardan's method simplifies the equation of state into a cubic equation which can be solved easily
#The general form of the cubic equation is (Z**3)+(alpha*Z**2)+(beeta*Z)+gaamma = 0, where alpha,beeta and gaamma are determined using established relations

Tr = T/Tc
Pr = (P*10**6)/(Pc*10**5)
S = 0.48+(1.574*w)-(0.176*w**2)
alpha1 = (1+(S*(1-math.sqrt(Tr))))**2
a = (0.42748*R**2*Tc**2*alpha1)/(Pc*10**5)
b = (0.08664*R*Tc)/(Pc*10**5)
A = (a*P*10**6)/(R*T)**2
B = (b*P*10**6)/(R*T)
alpha = -1.
beeta = A-B-B**2
gaamma = -(A*B)
p = beeta-(alpha**2)/3
q = ((2*alpha**3)/27)-((alpha*beeta)/3)+gaamma
D = (((q)**2)/4.)+(((p)**3)/27.)

if D>0:
Z = ((-q/2)+(math.sqrt(D)))**(1./3)+((-q/2)-(math.sqrt(D)))**(1./3)-(alpha/3)
vf = ((Z)*R*T)/(P*10**6)
vg = ((Z)*R*T)/(P*10**6)
elif D == 0:
Z1 = ((-2*(q/2))**(1./3))-(alpha/3)
Z2 = ((q/2)**(1./3))-(alpha/3);
Z3 = ((q/2)**(1./3))-(alpha/3);
Z = [Z1, Z2, Z3];
vf = (min(Z)*R*T)/(P*10**6);
vg = (max(Z)*R*T)/(P*10**6);
else:
r = math.sqrt((-(p**3)/27));
theta = acos((-(q)/2)*(1./r));
Z1 = (2*(r**(1./3))*math.cos(theta/3))-(alpha/3);
Z2 = (2*(r**(1./3))*math.cos(((2*math.pi)+theta)/3))-(alpha/3)
Z3 = (2*(r**(1./3))*math.cos(((4*math.pi)+theta)/3))-(alpha/3);
Z = [Z1, Z2, Z3];
vf = (min(Z)*R*T)/(P*10**6)
vg = (max(Z)*R*T)/(P*10**6)

# Results
print ' The volume occupied by n-octane saturated vapour obtained by Soave-Redlich-Kwong \
equation of state =  %f m**3/mol'%(vg);
print ' The volume occupied by n-octane saturated liquid obtained by Soave-Redlich-Kwong \
equation of state =  %f m**3/mol'%(vf);

 The volume occupied by n-octane saturated vapour obtained by Soave-Redlich-Kwong  equation of state =  0.015207 m**3/mol
The volume occupied by n-octane saturated liquid obtained by Soave-Redlich-Kwong  equation of state =  0.000227 m**3/mol


### Example 3.16 Page No : 78¶

In [33]:
import math
# Variables
T = 427.85;			 #temperature in K
P = 0.215;			 #saturation pressure in MPa
Tc = 569.4;			 #critical temperature of n-octane in K
Pc = 24.97;			 #critical pressure of n-octane in bar
w = 0.398;			 #acentric factor (no unit)
R = 8.314;			 #universal gas constant in (Pa m**3)/(mol K)

# Calculations
Tr = T/Tc;
Pr = (P*10**6)/(Pc*10**5)
S = 0.37464+(1.54226*w)-(0.26992*w**2)
alpha1 = (1+(S*(1-math.sqrt(Tr))))**2
a = (0.45724*R**2*Tc**2*alpha1)/(Pc*10**5)
b = (0.07780*R*Tc)/(Pc*10**5)
A = (a*P*10**6)/(R*T)**2
B = (b*P*10**6)/(R*T)
alpha = -1+B;
beeta = A-(2*B)-(3*B**2)
gaamma = -(A*B)+(B**2)+(B**3)
p = beeta-(alpha**2)/3;
q = ((2*alpha**3)/27)-((alpha*beeta)/3)+gaamma
D = (((q)**2)/4)+(((p)**3)/27)

if D>0:
Z = ((-q/2)+(math.sqrt(D)))**(1./3)+((-q/2)-(math.sqrt(D)))**(1./3)-(alpha/3)
vf = ((Z)*R*t)/(P*10**6)
vg = ((Z)*R*t)/(P*10**6)
elif D == 0:
Z1 = ((-2*(q/2))**(1./3))-(alpha/3)
Z2 = ((q/2)**(1./3))-(alpha/3);
Z3 = ((q/2)**(1./3))-(alpha/3);
Z = [Z1 ,Z2, Z3];
vf = (min(Z)*R*T)/(P*10**6)
vg = (max(Z)*R*T)/(P*10**6)
else:
r = math.sqrt((-(p**3)/27))
theta = .1533
Z1 = (2*(r**(1./3))*math.cos(theta/3))-(alpha/3);
Z2 = (2*(r**(1./3))*math.cos(((2*math.pi)+theta)/3))-(alpha/3);
Z3 = (2*(r**(1./3))*math.cos(((4*math.pi)+theta)/3))-(alpha/3);
Z = [Z1, Z2, Z3];
vf = (min(Z)*R*T)/(P*10**6)
vg = (max(Z)*R*T)/(P*10**6)

# Results
print ' The volume occupied by n-octane saturated vapour, obtained by Peng\
-Robinson equation of state =  %.3e m**3/mol'%(vg);
print ' The volume occupied by n-octane saturated liquid, obtained by Peng-Robinson\
equation of state =  %.3e m**3/mol'%(vf);

 The volume occupied by n-octane saturated vapour, obtained by Peng-Robinson equation of state =  1.514e-02 m**3/mol
The volume occupied by n-octane saturated liquid, obtained by Peng-Robinson equation of state =  2.003e-04 m**3/mol