8.2. Exercise 2 Solutions#

Section 4.3.5 Exercise 2

#4.3.5 Exercise 1
#4.3.5 Exercise 2
#4.3.5 Exercise 3
#4.3.5 Exercise 4
#4.3.5 Exercise 5
#4.3.5 Exercise 6

#Compare the specific volume of nitrogen (N2) at 35°C and 150 kPa using the ideal gas law and Cantera. 
#In Cantera use ct.Nitrogen() rather than ct.Water() as we have been for H2O.

#Using the ideal gas law:
#define known values
#convert temperature to kelvin
T=35+273.15
P=150
M=28
def v_ideal(T,P,M):
    return 8.314*T/(M*P)
print(f"Specific volume using Ideal Gas Law:  {v_ideal(T,P,M)} m^3/kg")

#Using Cantera:
import cantera as ct
#define species 2 as nitrogen 
species2=ct.Nitrogen()
#redefine pressure in Pa
P=150*1000
species2.TP=T,P
print(f"Specific volume using Cantera:  {species2.PV[1]} m^3/kg")
Specific volume using Ideal Gas Law:  0.6099902619047619 m^3/kg
Specific volume using Cantera:  0.6096046212951401 m^3/kg
#4.3.5 Exercise 7
#given: CO2, pressure is 5 MPa, near the critical pressure (7.38 MPa), therefore cannot assume ideal gas behavior

#2a
#determine vf and vg of CO2 at 5MPa
species3=ct.CarbonDioxide()
#get saturated liquid (vf) values (quality=0)
species3.PQ=5000000,0
print(f"Saturated liquid value:   {species3.PV[1]} m^3/kg")
#get saturated vapor (vg) values (quality=1)
species3.PQ=5000000,1
print(f"Saturated vapor value: {species3.PV[1]} m^3/kg")
Saturated liquid value:   0.0012052903896509952 m^3/kg
Saturated vapor value: 0.006414524448873753 m^3/kg
#7b
#What is the saturated temperature of CO2 at 5 MPa?
#can use either 1 or 0 for the quality- either one will yield the saturation temperature 
species3.PQ=5000000,1
#print the saturation temperature 
print(f"Saturated temperature of CO2 at 5 MPa:  {species3.TV[0]} K")
Saturated temperature of CO2 at 5 MPa:  287.4532698240636 K
#7c
#Compare the specific volume of CO2 at 5 MPa at saturated vapor conditions using Cantera and the ideal gas law 
#at the same Tsat and Psat.

#intuitively we know these should differ because CO2 does not exhibit ideal gas behavior at high pressures

#using Cantera 
#saturated vapor, quality=1
species3.PQ=5000000,1
print(f"Saturated vapor value: {species3.PV[1]} m^3/kg")
satvap=species3.PV[1]
Tsat=species3.TV[0]
#using the Ideal Gas Law 
#molar mass for CO2
M=44
#convert pressure to kPa
P=500
T=Tsat
def v_ideal(T,P,M):
    return 8.314*T/(M*P)
print(f"Specific volume using ideal gas law: {v_ideal(T,P,M)} m^3/kg")

#as expected, these values differ by several orders of magnitude 
Saturated vapor value: 0.006414524448873753 m^3/kg
Specific volume using ideal gas law: 0.1086312038780575 m^3/kg
#7d
#Plot specific volume from the saturated vapor point at 5 MPa to 5 times vg at the same pressure. 
#Use both Cantera and the ideal gas EOS.

#import relevant libraries 
import numpy as np
import matplotlib.pyplot as plt
#using previously calculated vg
satvap=0.006414524448873753
P=5000000
species3.PQ=P,1
#create an array of specific volume values from vg @ 5 MPa to 5 times that 
sv=np.arange(satvap,5*satvap,.003)
#create an empty array in which to hold the temperature values 
T=[]
for i in sv: 
    species3.PV=[P,i]
    T.append(species3.TP[0])
P=5000 #convert pressure to kPa
M = 44 # molecular weight of CO2
def T_ideal(P,sv,M):
    return (P*sv)/(8.314/M)
Tideal=T_ideal(P,sv,M) 

plt.plot(sv,T,color='blue')
plt.plot(sv,Tideal,color='green')
plt.xlabel('$v$ $(\mathrm{m^3} \mathrm{kg^{-1}})$',  fontsize=12)
plt.ylabel('$T$ $({\mathrm{K})}$',  fontsize=12)
plt.annotate('Cantera', (.008,400), color='Blue', rotation = 0,fontsize=12)
plt.annotate('Ideal Gas Law', (.0125,250), color='Green', rotation = 0,fontsize=12)
plt.show()
../../_images/Exercise 2_11_0.png
#4.3.5 Exercise 8
#4.3.5 Exercise 9
#4.3.5 Exercise 10
#4.3.5 Exercise 11
#4.3.5 Exercise 12