10.4. Exercise 4 Solutions#

Section 6.7.3 Exercise 4

#6.7.3 Exercise 1
#Determine the change in specific enthalpy of O<sub>2</sub> as it is heated from 500 K 
#to 700 K using
    # a) property evaluation in Cantera
    # b) polynomial expression for specific heat as a function of temperature
    # c) average specific heats
    # d) constant specific heat at 300 K.

import cantera as ct
species1=ct.Oxygen()
species2=ct.Oxygen()
T1=500 #K
T2=700 #K
P = 100000 # Pressure not specificed and not necessary because ideal gas. Use 1 bar
#a)
species1.TP = T1,P
species2.TP = T2,P
h1=species1.TH[1] #J/kg
h2=species2.TH[1] #J/kg
print("Change in specific enthalpy using Cantera property evaluation is ", round((h2-h1)/1000,3), "kJ/kg") 
Change in specific enthalpy using Cantera property evaluation is  200.537 kJ/kg
#b)
A,B,C,D,E = 31.32234,-20.23531,57.86644,-36.50624,-0.007374 # from NIST Webbook
def cp_int(T,A,B,C,D,E): #this is the integrated form of the shomate equation, which we will evaluate at T1 and T2. Units J/mol
    return A*T + B*T**2/2 + C*T**3/3 + D*T**4/4 + E*T**(-1)/(-1)
delta_h=cp_int(T2/1000,A,B,C,D,E)-cp_int(T1/1000,A,B,C,D,E) # The Cp units are J/mol, as seen from the NIST website, but when integrating with T/1000 become kJ/mol. To convert to kJ/kg we need to multiply by 1000.
M_O2 = 32 # kg/kmol
delta_h=delta_h*1000/M_O2
print("The change in enthalpy using the Shomate Equation is", round(delta_h,3), "kJ/kg" )
The change in enthalpy using the Shomate Equation is 200.503 kJ/kg
#c)
species1.TP = T1,P
species2.TP = T2,P
cp1=species1.cp #J/kg
cp2=species2.cp #J/kg
cp_avg=(cp1+cp2)/2
print("Change in specific enthalpy using Cantera property evaluation is ", round(cp_avg*(T2-T1)/1000,3), "kJ/kg") 
Change in specific enthalpy using Cantera property evaluation is  200.318 kJ/kg
#d)
species1.TP = 300,P
cp=species1.cp #J/kg
print("Change in specific enthalpy using Cantera property evaluation is ", round(cp*(T2-T1)/1000,3), "kJ/kg") 
Change in specific enthalpy using Cantera property evaluation is  183.987 kJ/kg
#6.7.3 Exercise 2
#A cylinder is fitted with a piston and has an initial volume of 0.1 m3 and contains
#N2 gas at 150 kPa, 25 °C. The piston is moved, compressing the N2 until the 
#pressure is 1 MPa and T = 150 °C. During compression, heat is transferred from the N2, 
#and the work done on the system is 20 kJ. Determine the amount of heat transfer using average specific heats.

import cantera as ct
species1=ct.Nitrogen()
species2=ct.Nitrogen()
V1=0.1 # m3
T1=25+273.15 #K
T2=150+273.15 #K
P1 = 150000 # Although pressure changes, not necessary to account for because ideal gas. Use 1.5 bar.
species1.TP = T1,P1
species2.TP = T2,P1
cv_avg = (species1.cv+species2.cv)/2 # J/kg
# delta_U = Q-W, from first law
W = -20 #kJ
v1=species1.TV[1] #m3/kg
m=V1/v1 #kg
Q=cv_avg*(T2-T1)/1000*m+W #kJ
print("Heat transferred from the system is ", round(Q,3), "kJ/kg") 
Heat transferred from the system is  -4.199 kJ/kg
#6.7.3 Exercise 3
#A cylinder is fitted with a piston contains N2 gas at 150 kPa, 25 °C. 300 kJ/kg of heat is transferred 
#to the system at constant pressure. Determine the temperature after heat addition using average specific 
#heats. Note that an iterative solution approach is necessary.

import cantera as ct
species1=ct.Nitrogen()
species2=ct.Nitrogen()
T1=25+273.15 #K
P1 = 150000 # Although pressure changes, not necessary to account for because ideal gas. Use 1.5 bar.

species1.TP = T1,P1
cp1=species1.cp
def cp2(Tguess):
    species2.TP = Tguess,P1
    return species2.cp
def cv_avg(Tguess):
    return (cp1+cp2(Tguess))/2 # J/kg
# guess T until cv_avg*(Tguess-T1) = 300 kJ/kg
def Q(Tguess):
    return cv_avg(Tguess)*(Tguess-T1)/1000
Tguess=583 #K
print("Q using Tguess", round(Q(Tguess),2), "kJ/kg. T2 is ", Tguess, "K")

# use fsolve to determine T2
import numpy as np
from scipy.optimize import fsolve
def T2(Tguess):
    return Q(Tguess)-300
root = fsolve(T2, 500)
print
print("T2 using fsolve", round(root[0],2), "K")
Q using Tguess 300.76 kJ/kg. T2 is  583 K
T2 using fsolve 582.3 K
#6.7.3 Exercise 4
#A  frictionless piston–cylinder device contains 5 kg of nitrogen at 100 kPa and 250 K. Nitrogen is now compressed slowly according to the relation 
#𝑃𝑉^1.4 = constant until it reaches a final temperature of 450 K. Calculate the work input during this process.

m = 5 # kg
P1 = 100 # kPa
T1 = 250 # K
T2 = 450 # K
n = 1.4 # polytropic process
R = 0.2969 # kJ/kgK = M_bar/M_N2

# polytropic proces, n =/= 1, > W = (P2V2 - P1V1)/(1-n)
# need P2, v2, v1. Put in terms of temperatures using ideal gas law
 
W = (m*R*T2 - m*R*T1)/(1-n)
print(f"The work input is {round(W,3)} kJ")
The work input is -742.25 kJ
#6.7.3 Exercise 5
# Nitrogen at an initial state of 300 K, 150 kPa, and 0.2 m3 is compressed slowly in an isothermal process to 
#a final pressure of 800 kPa. Determine the work done during this process.

import numpy as np
# Given: 
T1 = 300 # K
T2 = T1
n = 1
P1 = 150 # kPa
V1 = 0.2 # m3
P2 = 800 # kPa

# Find: work done 
# isothermal so W = P1V1ln(V2/V1) , V2/V1 = P2/P1

W = P1*V1*np.log(P2/P1)
print(f"The work is -{round(W,2)} kJ")
The work is -50.22 kJ
#6.7.3 Exercise 6
# Argon is compressed in a polytropic process with n = 1.2 from 120 kPa and 30°C to 1200 kPa in a piston–cylinder device. 
#Determine the final temperature of the argon.

import cantera as ct
import numpy as np
Kc = 273.15

# Given: 
n = 1.2
P1 = 120 # kPa
T1 = 30 + Kc # K
P2 = 1200 # kPa
R_bar = 8.314 #kJ/kmol/K
M_Ar = 40 # kg/kmol
R=R_bar/M_Ar

v1=R*T1/P1

#P1v1^n = P2v2^n
#P1/P2=(v2/v1)^n
#v2/v1=(P1/P2)^(1/n)

v2=v1*(P1/P2)**(1/n)
T2=P2*v2/R

# or we could show from algebra that

#T2 = T1*(P2/P1)**((n-1)/n)
print(f"The temperature at state 2 is {round(T2-Kc,2)} C")
The temperature at state 2 is 171.81 C
#6.7.3 Exercise 7
#Determine the change in specific internal energy of hydrogen as it is heated from 200 to 800 K using 
#a) the Shomate specific heat equation as a function of temperature, b) using an average cv value, 
#c) using a room temperature cv value, and d) using Cantera.

# Hydrogen
T1 = 200 # K
T2 = 800 # K
P = 100e3 # Pa
species1=ct.Hydrogen()
species2=ct.Hydrogen()
T_amb = 293 # K 
R = 8.314

# Part A 
A,B,C,D,E = 33.066178, -11.363417, 11.432816, -2.772874, -0.158558
def cv_int(T,A,B,C,D,E,R): #this is the integrated form of the shomate equation, which we will evaluate at T1 and T2. Units J/mol
    return (A-R)*T + B*T**2/2 + C*T**3/3 + D*T**4/4 + E*T**(-1)/(-1)
delta_u=cv_int(T2/1000,A,B,C,D,E,R)-cv_int(T1/1000,A,B,C,D,E,R) # The units are J/mol
delta_u=delta_u*1000/2.016
print("Change in internal energy using the Shomate Equation is", round(delta_u,2), "kJ/kg" )

# Part B 
species1.TP = T1,P
species2.TP = T2,P
cv1=species1.cv #J/kg
cv2=species2.cv #J/kg
cv_avg=(cv1+cv2)/2
print("Change in internal energy using average cv is ", round(cv_avg*(T2-T1)/1000,2), "kJ/kg") 

# Part C
species1.TP = T_amb,P
cv=species1.cv #J/kg
print("Change in specific enthalpy using cv at room temp is ", round(cv*(T2-T1)/1000,2), "kJ/kg") 

# Part D 
species1.TP = T1,P
species2.TP = T2,P
u1=species1.UP[0] #J/kg
u2=species2.UP[0] #J/kg
print("Change in specific internal energy using Cantera property evaluation is ",round((u2 - u1)/1000,2), "kJ/kg") 
Change in internal energy using the Shomate Equation is 6193.24 kJ/kg
Change in internal energy using average cv is  6773.47 kJ/kg
Change in specific enthalpy using cv at room temp is  6469.82 kJ/kg
Change in specific internal energy using Cantera property evaluation is  6359.89 kJ/kg
#6.7.3 Exercise 8
#1 kg of oxygen is heated from 20 to 120°C. Determine the amount of heat transfer required when this is done during both  
#a constant-volume process and an isobaric process. For each use  a) specific heat equation as a function of temperature, b) using an average cv value, c) using a room temperature cv value, and d) using Cantera.

import cantera as ct
import numpy as np
Kc = 273.15

m = 1 # kg
T1 = 20 + Kc
T2 = 120 + Kc
deltaT = T2 - T1
P = 100e3 # Pa
R = 8.314


# Constant volume process
print("Specific heat Eqn:")
#a 
A,B,C,D,E = 31.32234, -20.23531, 57.86644, -36.50624, -0.007374
def cv_int(T,A,B,C,D,E,R): #this is the integrated form of the shomate equation, which we will evaluate at T1 and T2. Units J/mol
    return (A-R)*T + B*T**2/2 + C*T**3/3 + D*T**4/4 + E*T**(-1)/(-1)
delta_u=cv_int(T2/1000,A,B,C,D,E,R)-cv_int(T1/1000,A,B,C,D,E,R) # The units are J/mol
delta_u=delta_u*1000/32
deltaU = cv*deltaT
Q12 = m*deltaU/1000
print(f"Constant-volume: The heat transfer required is {round(Q12,2)} kJ")

# Constant pressure process
#a)
A,B,C,D,E = 31.32234,-20.23531,57.86644,-36.50624,-0.007374 
def cp_int(T,A,B,C,D,E): 
    return A*T + B*T**2/2 + C*T**3/3 + D*T**4/4 + E*T**(-1)/(-1)
delta_h=cp_int(T2/1000,A,B,C,D,E)-cp_int(T1/1000,A,B,C,D,E) 
M_O2 = 32
delta_h=delta_h*1000/M_O2
print("Isobaric:The heat transfer required is", round(delta_h,3), "kJ/kg" )

# Constant volume process
#b)
print("Average cv:")
species1 = ct.Oxygen()
species2 = ct.Oxygen()
species1.TP = T1,P
species2.TP = T2,P
cv1=species1.cv #J/kg
cv2=species2.cv #J/kg
cv_avg=(cv1+cv2)/2
deltaU = cv_avg*deltaT
Q12 = m*deltaU/1000
print(f"Constant-volume: The heat transfer required is {round(Q12,2)} kJ")

#Constant pressure process
#b)
cp1=species1.cp #J/kg
cp2=species2.cp #J/kg
cp_avg=(cp1+cp2)/2
deltaH = cp_avg*deltaT
Q12 = m*deltaH/1000
print(f"Isobaric: The heat transfer required is {round(Q12,2)} kJ")

# Constant volume process
# c)
print("Room temp cv:")
species1.TP = T_amb,P
cv=species1.cv #J/kg
cp=species1.cp

deltaU = cv*deltaT
Q12 = m*deltaU/1000
print(f"Constant-volume: The heat transfer required is {round(Q12,2)} kJ")


#Constant pressure process
#c)
deltaH = cp*deltaT
Q12 = m*deltaH/1000
print(f"Isobaric: The heat transfer required is {round(Q12,2)} kJ")


#Using Cantera
print("Cantera:")
state1 = ct.Oxygen()
state2 = ct.Oxygen()
# constant volume
# d)
state1.TP = T1,P
v1 = state1.TV[1]
v2 = v1
state2.TV = T2, v2
u1 = state1.UP[0]
u2 = state2.UP[0]
deltaU = u2 - u1 
Q12 = m*deltaU/1000
print(f"Constant-volume: The heat transfer required is {round(Q12,2)} kJ")

# constant pressure
# d)
state1.TP = T1,P
state2.TP = T2,P
h1 = state1.HP[0]
h2 = state2.HP[0]
deltaH = h2 - h1 
Q12 = m*deltaH/1000
print(f"Isobaric: The heat transfer required is {round(Q12,2)} kJ")
Specific heat Eqn:
Constant-volume: The heat transfer required is 1078.3 kJ
Isobaric:The heat transfer required is 92.72 kJ/kg
Average cv:
Constant-volume: The heat transfer required is 66.85 kJ
Isobaric: The heat transfer required is 92.94 kJ
Room temp cv:
Constant-volume: The heat transfer required is 65.77 kJ
Isobaric: The heat transfer required is 91.9 kJ
Cantera:
Constant-volume: The heat transfer required is 66.75 kJ
Isobaric: The heat transfer required is 92.82 kJ
#6.7.3 Exercise 9
# Argon (cv = 0.3122 kJ/kg/K) is compressed in a polytropic process with n = 1.2 from 120 kPa and 10°C to 800 kPa in a piston–cylinder device. 
#Determine the work produced and heat transferred during this compression process, in kJ/kg.

n = 1.2 
P1 = 120e3 # Pa
T1 = 10 + Kc
P2 = 800e3 # Pa
R_bar = 8.314 #kJ/kmol/K
M_Ar = 40 # kg/kmol
R=R_bar/M_Ar
T2 = T1*(P2/P1)**((n-1)/n)
deltaT = T2 - T1
w = R*deltaT/(1-n)
cv = 0.3122 # kJ/kgK
deltau = -1*cv*deltaT
q = deltau - w
print(f"The work is {round(w,2)} kJ/kg and the heat transfer is {round(q,2)} kJ/kg")
The work is -109.43 kJ/kg and the heat transfer is 76.56 kJ/kg
#6.7.3 Exercise 10
# A piston–cylinder device contains 2.2 kg of nitrogen initially at 100 kPa and 25°C. The nitrogen is now compressed slowly in a polytropic process during which
#𝑃𝑉^1.3 = constant until the volume is reduced by one-half. Determine the work done and the heat transfer for this process.

import cantera as ct
import numpy as np
Kc = 273.15

m = 2.2 # kg
P1 = 100 # kPa
T1 = 25 + Kc
n = 1.3
V1 = 1 # will cancel
V2 = 0.5*V1
P2 = P1*(V1/V2)**n
T2 = (P2*V2*T1)/(P1*V1)

species1 = ct.Nitrogen()
species2 = ct.Nitrogen()
species1.TP = T1,P1
species2.TP = T2,P1
cv1=species1.cv 
cv2=species2.cv 
cv=(cv1+cv2)/2/1000

deltaT = T2 - T1
R_bar = 8.314 #kJ/kmol/K
M_N2 = 28 # kg/kmol
R=R_bar/M_N2

W = m*R*deltaT/(1-n) # from (P2V2-P1V1)/(1-n), V2=mRT2/P2 and V1=mRT1/P1
deltaU = m*cv*deltaT
Q = deltaU+W
print(f"The work done is {round(W,1)} kJ, and the heat transfer for the process is {round(Q,1)} kJ")
The work done is -150.1 kJ, and the heat transfer for the process is -37.4 kJ