10.3. Exercise 3 Solutions#

Section 5.3.2 Exercise 3

#5.3.2 Exercise 1
#A closed rigid container of 0.5 m3 is placed on a hot plate. Initially it contains a two phase mixture of saturated liquid and saturated vapor H2O at  𝑝1 = 1 bar with x = 0.5. After heating  𝑝2 = 1.5 bar. 
#Determine T at states 1 and 2. Determine the heat transfer during the process.

V1 = 0.5 #m3
Q1 = 0.5
P1 = 100*1000 #Pa
P2 = 150*1000 #Pa

#Using Cantera:
import cantera as ct
#define state 1
species1=ct.Water()

species1.PQ=P1,Q1

print(f"Initial temperature:  {round(species1.TQ[0],2)} K")

v1 = v2 = species1.TV[1] # Initial and final specific volume since it is a rigid container

#define state 2
species2=ct.Water()

species2.PV=P2,v2

print(f"Final temperature:  {round(species2.TQ[0],2)} K")

m = V1/v1 # kg
u1 = species1.UV[0]
u2 = species2.UV[0]
Q = m*(u2-u1) # From Delta_U = Q-W, work is zero because volume is fixed

print(f"Heat Transfer:  {round(Q/1000,2)} kJ")
Initial temperature:  372.81 K
Final temperature:  384.55 K
Heat Transfer:  298.1 kJ
#5.3.2 Exercise 2
#A piston cylinder assembly initially (State 1) contains 10 kg of H2O at 1200 kPa.
# a) If 8 kg is in the liquid form and the rest vapor, determine the temperature, specific volume and specific enthalpy.
# b) The cylinder continues to be heated at constant pressure until the temperature reaches 300 °C (State 2). Determine the final state (compressed liquid, saturated mixture, superheated vapor), specific volume and specific enthalpy.
# c) Determine the heat transfer and work for this process.

# part a
m=10 #kg
P1 = 1200*1000 #Pa
mg = 2 #kg
Q1 = mg/m

#Using Cantera:
import cantera as ct
#define state 1
species1=ct.Water()

species1.PQ=P1,Q1
T1 = species1.TV[0]
v1 = species1.TV[1]
h1 = species1.HP[0]

print(f"Initial temperature:  {round(T1,2)} K")
print(f"Initial specific volume:  {round(v1,6)} K")
print(f"Initial specific enthalpy:  {round(h1,2)} K")

# part b
T2 = 300+273.15 # K
P2=P1

#define state 2
species2=ct.Water()

species2.TP=T2,P2
v2 = species2.TV[1]
phase = species2.phase_of_matter
h2 = species2.HP[0]

print(f"Final state of matter:  {phase}")
print(f"Final specific volume:  {round(v2,6)} K")
print(f"Final specific enthalpy:  {round(h2,2)} K")

# part c

Q = m*(h2-h1) # J, constant pressure process
W = P2*(v2-v1) # J,constant volume process

print(f"Work:  {round(W/1000,2)} kJ")
print(f"Heat Transfer:  {round(Q/1000,2)} kJ")
Initial temperature:  461.18 K
Initial specific volume:  0.033582 K
Initial specific enthalpy:  -14774746.42 K
Final state of matter:  gas
Final specific volume:  0.213816 K
Final specific enthalpy:  -12925000.32 K
Work:  216.28 kJ
Heat Transfer:  18497.46 kJ
#5.3.2 Exercise 3
#Water initially at 200 kPa and 300C is contained in a piston-cylinder device fitted with stops. The water is allowed to cool at constant pressure until it exists as a saturated vapor and the piston rests on its stops. Then the water continues to cool until the pressure is 100 kPa.
import cantera as ct
P1 = 200e3 #Pa
T1 = 300 + 273.15 #K
P2 = P1
P3 = 100e3 #Pa
Q2 = 1

state1 = ct.Water()
state1.TP = T1, P1

state2 = ct.Water()
state2.PQ = P2, Q2
v2 = state2.TV[1]
v3 = v2

state3 = ct.Water()
state3.PV = P3, v3

# Part A

# Find internal energy change between states 1 and 3
state1 = ct.Water()
state1.TP = T1, P1
u1 = state1.UP[0]

# P2 = P1, Q2 = 1
state2 = ct.Water()
state2.PQ = P2, Q2
u2 = state2.UP[0]

deltau21 = u2 - u1 
print(f"A) : The change in internal energy between states 1 and 2 is {deltau21/1000} kJ/kg")
A) : The change in internal energy between states 1 and 2 is -279.015197695978 kJ/kg
# Part B 
v1 = state1.TV[1]
v2 = state2.TV[1]
print(f"B) : The change in specific volume between states 1 and 2 is {(v2 -v1)/1000} kJ/kg")
B) : The change in specific volume between states 1 and 2 is -0.00043035589952211537 kJ/kg
# Part C
h1 = state1.HP[0]
h2 = state2.HP[0]
print(f"C): The change in specific enthalpy between states 1 and 2 is {round((h2 - h1)/1000,2)} kJ/kg") 
C): The change in specific enthalpy between states 1 and 2 is -365.09 kJ/kg
# Part D
Q = (u2 - u1) + (P1*(v2 - v1))
print(f"D) : The heat transfer between states 1 and 2 is {round(Q/1000,2)} kJ/kg")
D) : The heat transfer between states 1 and 2 is -365.09 kJ/kg
# Part E
# specific heat transfer from cooling to stops
print(f"E) : The heat transfer between states 1 and 2 is {round((h2 - h1)/1000,2)} kJ/kg") 
E) : The heat transfer between states 1 and 2 is -365.09 kJ/kg
# Part F
state3 = ct.Water()
state3.PV = P3, v3
u3 = state3.UP[0]
deltau32 = u3 - u2
print(f"F) : The change in internal energy between states 2 and 3 is {deltau32/1000} kJ/kg")
F) : The change in internal energy between states 2 and 3 is -1020.621570467569 kJ/kg
# Part G  (total specific heat transfer)
q12 = h2 - h1 
q23 = u3 - u2 
qtotal = q12 + q23 
print(f"G) : The total specific heat transfer is {round(qtotal/1000, 2)} kJ/kg")
G) : The total specific heat transfer is -1385.71 kJ/kg
#5.3.2 Exercise 4
#A piston-cylinder contains 0.005 m3 of liquid water and 0.9 m3 of water vapor at 
#600 kPa. Heat is transferred at constant presssure until the temperature reaches 
#200 °C.
import cantera as ct
import numpy as np
Kc = 273.15

Vf = 0.005 # m^3
Vg = 0.9   # m^3
P1 = 600e3 # kPa
P2 = P1      
T2 = 200 + Kc 

# Find: 
# a) Q using enthalpies 
# we already can define state 2 because we know two independent properties - P,T 
state2 = ct.Water()
state2.TP = T2, P2
h2 = state2.HP[0]
# now find h1
# how do we do this? we need to solve for a third independent property 
# we have Vg and Vf, so we can solve for quality (which is the ratio of mass of vapor to total mass of mixture)

state1_liq = ct.Water()
state1_liq.PQ = P1, 0 # 0 percent of the mixture is gas 
vf = state1_liq.PV[1]
state1_gas = ct.Water()
state1_gas.PQ = P1, 1 # 100 percent of the mixture is gas 
vg = state1_gas.PV[1]

# now get the mass vapor, mass mixture
mf = Vf/vf 
mg = Vg/vg
mtotal = mf + mg
x1 = mg/(mg+mf)
state1 = ct.Water()
state1.PQ = P1,x1 # now we can set the state
h1 = state1.HP[0]

q12 = h2 - h1
q12 = q12*mtotal
print(f'q12 = {round(q12/1000,3)} kJ')

# b) Q without using enthalpies 
# Q = W - change in internal energy
# first find work

#W = PdeltaV
# find v1, v2
v1 = state1.PV[1]
v2 = state2.PV[1]
W = P1*(v2-v1)

# find u1,u2
u1 = state1.UV[0]
u2 = state2.UV[0]

q12 = W - (u1-u2)
q12 = q12*mtotal
print(f'q12 = {round(q12/1000,3)} kJ')
q12 = 10166.229 kJ
q12 = 10166.229 kJ
#5.3.2 Exercise 5
#A 1-m3 tank containing air at 10°C and 350 kPa is connected through a valve to 
#another tank containing 3 kg of air at 35°C and 150 kPa. Now the valve is opened, 
#and the entire system is allowed to reach thermal equilibrium with the surroundings,
#which are at 20°C. Determine the volume of the second tank and the final 
#equilibrium pressure of air.

V1 = 1 # m3
T_t1 = 10 + 273.15 # K
P_t1 = 350  # kPa
m_air_t2 = 3 # kg
T_t2 = 35 + 273.15 # K
P_t2 = 150   # kPa
T_atm = 20 +273.15 # K

# Find:
# a) Volume of tank 2 
# use ideal gas law PV = mRT
R = 0.287 # kJ/kgK, R_bar/M_air, where M_air = 28.97 kg/kmol
V2 = m_air_t2*R*T_t2/P_t2
print(f'Volume of tank 2: {round(V2,3)} m^3')

# b) final equilibrium pressure 
# again use ideal gas law 
V_total = V1 + V2
# need to find m tank 1
m_air_t1 = P_t1*V1/(R*T_t1)
m_total = m_air_t1 + m_air_t2
# the final temp is T_atm
P_final = m_total*R*T_atm/V_total
print(f'The final pressure is {round(P_final,2)} kPa')
Volume of tank 2: 1.769 m^3
The final pressure is 222.03 kPa
#5.3.2 Exercise 6
#A mass of 0.1 kg of helium fills a 0.2 m3 rigid vessel at 350 kPa. 
#The vessel is heated until the pressure is 700 kPa. Calculate the temperature 
#change of helium as a result of this heating.

m = 0.1 # kg 
V1 = 0.2 # m^3
V2 = V1 # rigid vessel
P1 = 350 # kPa 
P2 = 700 # kPa
R = 2.0769 # kJ/kgK
# find T1, T2
T1 = P1*V1/(m*R)
T2 = P2*V2/(m*R)
deltaT = T2-T1
print(f'The temperature change is {round(deltaT,3)} K')
The temperature change is 337.041 K
#5.3.2 Exercise 7
#Determine the specific volume of refrigerant-134a vapor at 0.9 MPa and 70°C 
#based on (a) the ideal-gas equation and (b) using Cantera.

import cantera as ct
import numpy as np
Kc = 273.15

# substance is R-134a
P = 0.9E3
T = 70 + 273.15
R = 0.08144 # kJ/kgK

# ideal gas equation 
# PV = mRT so Pv = RT, v = RT/P
v = R*T/P
print(f'Based on ideal gas law, v = {round(v,6)} kJ/kg')


# part b
state = ct.Hfc134a()
P = 0.9E6
state.TP = T,P
v = state.PV[1]
print(f'Using Cantera, v = {round(v,6)} kJ/kg')
Based on ideal gas law, v = 0.031051 kJ/kg
Using Cantera, v = 0.027414 kJ/kg
#5.3.2 Exercise 8
#Carbon dioxide gas enters a pipe at 3 MPa and 500 K at a rate of 2 kg/s. 
#CO2 is cooled at constant pressure as it flows in the pipe, and the temperature 
#of the CO2 drops to 450 K at the exit. Determine the volume flow rate and the 
#density of carbon dioxide at the inlet and the volume flow rate at the exit of the 
#pipe using (a) the ideal-gas equation and (b) using Cantera.

import cantera as ct
import numpy as np
Kc = 273.15

P1 = 3e6 # Pa
T1 = 500 # K
mdot = 2 # kg/s 
P2 = P1
T2 = 450 # K
R = 0.1889 # kJ/kgK

# Find: 
# volume flow rate (Vdot) of entrance and exit, density of CO2 using:

# a) ideal gas equation
# recall, Pv = RT, v is the reciprocal of density, therefore P/RT = rho
rho = P2/1000/(R*T1)
print(f'The density of CO2 is approximately {round(rho,3)} kg/m^3 at the inlet') 
# P*Vdot = mdot*R*T

def vdot(mdot,R,T,P):
    return (mdot*R*T)/P
Vdot_i = vdot(mdot,R,T1,P1/10**3)
Vdot_e = vdot(mdot,R,T2,P2/10**3)
print(f'The vdot of the inlet is {round(Vdot_i,6)} m^3/s and exit is {round(Vdot_e,3)} m^3/s')

# b) using cantera

species1,species2=ct.CarbonDioxide(),ct.CarbonDioxide()
species1.TP=T1,P1
species2.TP=T2,P2
# recall, Pv = RT, v is the reciprocal of density, therefore P/RT = rho
rho = 1/species1.TV[1]
print(f'The density of CO2 is approximately {round(rho,3)} kg/m^3 at the inlet') 

Vdot_i = species1.TV[1]*mdot
Vdot_e = species2.TV[1]*mdot
print(f'The vdot of the inlet is {round(Vdot_i,6)} m^3/s and exit is {round(Vdot_e,3)} m^3/s')
The density of CO2 is approximately 31.763 kg/m^3 at the inlet
The vdot of the inlet is 0.062967 m^3/s and exit is 0.057 m^3/s
The density of CO2 is approximately 32.458 kg/m^3 at the inlet
The vdot of the inlet is 0.061618 m^3/s and exit is 0.055 m^3/s
#5.3.2 Exercise 9
#A rigid 10-L vessel initially contains a mixture of liquid water and vapor at 100°C with 12.3 percent quality. 
#The mixture is then heated until its temperature is 180°C. Calculate the heat transfer required for this process.

import cantera as ct
import numpy as np
Kc = 273.15

# Given: 
V = 0.01 # m3
x1 = .123
T1 = 100 + Kc
T2 = 180 + Kc

# Find: Q 
# Q = m(u2 - u1)
state1 = ct.Water()
state1.TQ = T1, x1
u1 = state1.UP[0]
v1 = state1.TV[1]
v2 = v1
state2 = ct.Water()
state2.TV = T2, v2
u2 = state2.UP[0]

m = V/v1

print(f"The heat transfer required for this process is therefore {round(m*(u2-u1)/1000,1)} kJ")
The heat transfer required for this process is therefore 92.4 kJ
#5.3.2 Exercise 10
#Two tanks (Tank A and Tank B) are separated by a partition. Initially Tank A contains 2 kg of steam at 1 MPa and 300°C 
#while Tank B contains 3 kg of saturated liquid–vapor mixture at 150°C with a vapor mass fraction of 50 percent. 
#The partition is now removed and the two sides are allowed to mix until mechanical and thermal equilibrium are established. 
#If the pressure at the final state is 300 kPa, determine (a) the temperature and quality of the steam (if mixture) at the final state and 
#(b) the amount of heat lost from the tanks.

import cantera as ct
import numpy as np
Kc = 273.15

# Given: 
# Tank A
m_a = 2 # kg
P_a = 1e6 # Pa
T_a = 300 + Kc # K
# Tank B
m_b = 3 # kg
T_b = 150 + Kc # K
x_b = 0.5 
# state2 
P2 = 300e3 # Pa

# Find: a) T2, x2 b) Qout
mtotal = m_a + m_b
tanka = ct.Water()
tanka.TP = T_a,P_a
tankb = ct.Water()
tankb.TQ = T_b, x_b
v_a = tanka.PV[1]
v_b = tankb.PV[1]
u1a = tanka.UV[0]
u1b = tankb.UV[0]
V = v_a*m_a + v_b*m_b
v_total = V/mtotal

state_final = ct.Water()
state_final.PV = P2,v_total
T = state_final.TP[0]
x = state_final.TQ[1]
u2 = state_final.UV[0]
print(f"The final temperature is {round(T-Kc,2)} C and the quality is {round(x,2)}")

deltaU_a = u2 - u1a

deltaU_b = u2 - u1b

Qloss = m_a*deltaU_a + m_b*deltaU_b

print(f"The heat loss is {round(Qloss/1000,1)} kJ")
The final temperature is 133.58 C and the quality is 0.36
The heat loss is -3955.2 kJ
#5.3.2 Exercise 11
# A 3 m3 rigid tank contains hydrogen at 250 kPa and 550 K. The gas is now cooled until its temperature drops to 350 K. 
# Determine (a) the final pressure in the tank with and without using the ideal gas law (i.e., Cantera property evaluation) and
# (b) the amount of heat transfer with and without using specific heats (i.e., Cantera property evaluation).


import cantera as ct
import numpy as np
Kc = 273.15

# Given: 
V = 3 # m3
P1 = 250e3 # Pa
T1 = 550 # K
T2 = 350 # K

# Find: P2,Q using Cantera 
state1 = ct.Hydrogen()
state2 = ct.Hydrogen()
state1.TP = T1, P1
v1 = state1.TV[1]
v2 = v1
state2.TV = T2, v2
P2 = state2.TP[1]
print(f"The pressure using Cantera is {round(P2/1000,2)} kPa")

m = V/v2
u1 = state1.UP[0]
u2 = state2.UP[0]
deltaU = u2 - u1 
Q = m*deltaU/1000
print(f"The heat transfer using Cantera is {round(Q,2)} kJ")

# Find: P2,Q using ideal gas law and constant specific heats 
R_bar = 8.314 #kJ/kmol/K
M_H2 = 2 # kg/kmol
R=R_bar/M_H2
v1 = R*T1/(P1/1000)
v2 = v1
P2 = R*T2/v2
print(f"The pressure using ideal gas law is {round(P2,2)} kPa")

state1 = ct.Hydrogen()
state1.TP = T1, P1
cv = state1.cv #set cv to be constant at initial temperature
m = V/v2
deltaU = cv*(T2 - T1) 
Q = m*deltaU/1000
print(f"The heat transfer using Cantera is {round(Q,2)} kJ")
The pressure using Cantera is 159.08 kPa
The heat transfer using Cantera is -688.19 kJ
The pressure using ideal gas law is 159.09 kPa
The heat transfer using Cantera is -681.63 kJ