#For the mixture, determine the molefractions, average mol. wt., specific gas constant, volume and density, partial pressures and volumes
#Initialization of variables
m1=10. #lbm
m2=15. #lnm
p=50. #psia
t=60.+460 #R
M1=32.
M2=28.02
R0=1545
#calculations
n1=m1/M1
n2=m2/M2
x1=n1/(n1+n2)
x2=n2/(n1+n2)
M=x1*M1+x2*M2
R=R0/M
V=(n1+n2)*R0*t/p/144.
rho=p*144/(R0*t)
rho2=M*rho
p1=x1*p
p2=x2*p
v1=x1*V
v2=x2*V
#results
print '%s' %("part a")
print '%s %.3f %s %.3f %s' %("Mole fractions of oxygen and nitrogen are",x1," and",x2,"respectively")
print '%s' %("part b")
print '%s %.1f' %("Average molecular weight (gm) =",M)
print '%s' %("part c")
print '%s %.2f %s' %("specific gas constant =",R,"psia ft^3/lbm R")
print '%s' %("part d")
print '%s %.1f %s' %("volume of mixture =",V,"ft^3")
print '%s %.5f %s %.3f %s' %("density of mixture is",rho, "mole/ft^3 and",rho2, "lbm/ft^3")
print '%s' %("part e")
print '%s %.2f %s %.2f %s' %("partial pressures of oxygen and nitrogen are",p1, "psia and",p2, "psia respectively")
print '%s %.2f %s %.2f %s' %("partial volumes of oxygen and nitrogen are",v1, "ft^3 and",v2, "ft^3 respectively")
print '%s' %("The answers are a bit different due to rounding off error in textbook")
#calculate the gravimetric analysis
#Initialization of variables
m1=5.28
m2=1.28
m3=23.52
#calculations
m=m1+m2+m3
x1=m1/m
x2=m2/m
x3=m3/m
C=12./44. *m1/ m
O=(32./44. *m1 + m2)/m
N=m3/m
sum1=(x1+x2+x3)*100
sum2=(C+N+O)*100
#results
print '%s %.1f %s %.1f %s %.1f %s' %("From gravimetric analysis, co2 =",x1*100," percent , o2 =",x2*100,"percent and n2 =",x3*100,"percent")
print '%s %.2f %s %.2f %s %.2f %s' %("\n From ultimate analysis, co2 =",C*100,"percent , o2 =",O*100,"percent and n2 =",N*100,"percent")
print '%s %.1f %s' %("\n Sum in case 1 =",sum1,"percent")
print '%s %.1f %s' %("\n Sum in case 2 =",sum2,"percent")
#calculate the entropy of the mixture
#Initialization of variables
import math
x1=1./3.
n1=1
n2=2
x2=2./3.
p=12.7 #psia
cp1=7.01 #Btu/mole R
cp2=6.94 #Btu/mole R
R0=1.986
T2=460+86.6 #R
T1=460 #R
p0=14.7 #psia
#calculations
p1=x1*p
p2=x2*p
ds1= cp1*math.log(T2/T1) - R0*math.log(p1/p0)
ds2= cp2*math.log(T2/T1) - R0*math.log(p2/p0)
S=n1*ds1+n2*ds2
#results
print '%s %.2f %s' %("Entropy of mixture =",S,"Btu/R")
print '%s' %("\n the answer given in textbook is wrong. please check using a calculator")
#calculate the change in internal energy and entropy of the gas
#Initialization of variables
import math
c1=4.97 #Btu/mol R
c2=5.02 #Btu/mol R
n1=2
n2=1
T1=86.6+460 #R
T2=50.+460 #R
#calculations
du=(n1*c1+n2*c2)*(T2-T1)
ds=(n1*c1+n2*c2)*math.log(T2/T1)
#results
print '%s %d %s' %("Change in internal energy =",du,"Btu")
print '%s %.3f %s' %("\n Change in entropy =",ds,"Btu/R")
#calculate the pressure and mixing temperature of the mixture
#Initialization of variables
n1=1.
n2=2.
c1=5.02
c2=4.97
t1=60. #F
t2=100. #F
R0=10.73
p1=30. #psia
p2=10. #psia
#calcualtions
t=(n1*c1*t1+n2*c2*t2)/(n1*c1+n2*c2)
V1= n1*R0*(t1+460)/p1
V2=n2*R0*(t2+460)/p2
V=V1+V2
pm=(n1+n2)*R0*(t+460)/V
#results
print '%s %.1f %s' %("Pressure of mixture =",pm,"psia")
print '%s %.1f %s' %("\n Mixing temperature =",t,"F")
#calculate the change in entropy in all cases
#Initialization of variables
import math
T2=546.6 #R
T1=520. #R
T3=560. #R
v2=1389.2
v1=186.2
R0=1.986
c1=5.02
c2=4.97
n1=1
n2=2
v3=1203.
#calculations
ds1=n1*c1*math.log(T2/T1) + n1*R0*math.log(v2/v1)
ds2=n2*c2*math.log(T2/T3)+n2*R0*math.log(v2/v3)
ds=ds1+ds2
ds3=n1*c1*math.log(T2/T1)+n2*c2*math.log(T2/T3)
ds4=n2*R0*math.log(v2/v3)+ n1*R0*math.log(v2/v1)
dss=ds3+ds4
#results
print '%s %.3f %s' %("Change in entropy for gas 1 =",ds1,"Btu/R")
print '%s %.3f %s' %("\n Change in entropy for gas 1 =",ds2,"Btu/R")
print '%s %.3f %s' %("\n Net change in entropy =",ds," Btu/R")
print '%s %.3f %s' %("\n In case 2, change in entropy =",dss," Btu/R")
print '%s' %("The answer is a bit different due to rounding off error in the textbook")
#calculate the final temperature and changes in entropy of air and water
#Initialization of variables
import math
m1=1 #lbm
m2=0.94 #lbm
M1=29.
M2=18.
p1=50. #psia
p2=100. #psia
t1=250. +460 #R
R0=1.986
cpa=6.96
cpb=8.01
#calculations
xa = (m1/M1)/((m1/M1)+ m2/M2)
xb=1-xa
t2=t1*math.pow((p2/p1),(R0/(xa*cpa+xb*cpb)))
d=R0/(xa*cpa+xb*cpb)
k=1/(1-d)
dsa=cpa*math.log(t2/t1) -R0*math.log(p2/p1)
dSa=(m1/M1)*dsa
dSw=-dSa
dsw=dSw*M2/m2
#results
print '%s %d %s' %("Final remperature =",t2,"R")
print '%s %.3f %s %.5f %s' %("\n Change in entropy of air =",dsa," btu/mole R and",dSa, "Btu/R")
print '%s %.4f %s %.5f %s' %("\n Change in entropy of water =",dsw," btu/mole R and",dSw, "Btu/R")
print '%s' %("The answers are a bit different due to rounding off error in textbook")
#calculate the volume occupied and mass of steam
#Initialization of variables
T=250. + 460 #R
p=29.825 #psia
pt=50. #psia
vg=13.821 #ft^3/lbm
M=29.
R=10.73
#calculations
pa=pt-p
V=1/M *R*T/pa
ma=V/vg
xa=p/pt
mb=xa/M *18/(1-xa)
#results
print '%s %.2f %s' %("In case 1, volume occupied =",V,"ft^3")
print '%s %.2f %s' %("\n In case 1, mass of steam =",ma," lbm steam")
print '%s %.3f %s' %("\n In case 2, mass of steam =",mb," lbm steam")
#calculate the percentage of alcohol evaporated
#Initialization of variables
ps=0.64 #psia
p=14.7 #psia
M=29
M2=46
#calculations
xa=ps/p
mb=xa*9/M *M2/(1-xa)*100
#results
print '%s %.1f %s' %("percentage of alcohol evaporated =",mb,"percent")
#calculate the partial pressure of water vapor
#Initialization of variables
ps=0.5069 #psia
p=20 #psia
m1=0.01
m2=1
M1=18.
M2=29.
#calculations
xw= (m1/M1)/(m1/M1+m2/M2)
pw=xw*p
#results
print '%s %.3f %s' %("partial pressure of water vapor =",pw,"psia")
#calculate the pressure, dew temperature of water. Calculate the density of water, air,specific humidity and the degree of saturation
#Initialization of variables
t1=80+460. #R
ps=0.5069 #psia
print '%s' %("from steam tables,")
vs=633.1 #ft^3/lbm
phi=0.3
R=85.6
Ra=53.3
p=14.696
#calculations
tdew=46 #F
pw=phi*ps
rhos=1/vs
rhow=phi*rhos
rhow2= pw*144/(R*t1)
pa=p-pw
rhoa= pa*144/(Ra*t1)
w=rhow/rhoa
mu=phi*(p-ps)/(p-pw)
Ws=0.622*(ps/(p-ps))
mu2=w/Ws
#results
print '%s' %("part a")
print '%s %.5f %s' %("partial pressure of water =",pw,"psia")
print '%s %d %s' %("\n dew temperature =",tdew,"F")
print '%s' %("part b")
print '%s %.6f %s' %("density of water =",rhow,"lbm/ft^3")
print '%s %.6f %s' %("\n in case 2, density of water =",rhow2,"lbm/ft^3")
print '%s %.6f %s' %("\n density of air =",rhoa,"lbm/ft^3")
print '%s' %("part c")
print '%s %.4f %s' %("specific humidity =",w,"lbm steam/lbm air")
print '%s' %("part d")
print '%s %.3f' %("In method 1, Degree of saturation = ",mu)
print '%s %.3f' %("\n In method 2, Degree of saturation = ",mu2)
#calculate the change in moisture content
#Initialization of variables
p=14.696 #psia
ps=0.0808 #psia
ps2=0.5069 #psia
phi2=0.5
phi=0.6
grain=7000
#calculations
pw=phi*ps
w1=0.622*pw/(p-pw)
pw2=phi2*ps2
w2=0.622*pw2/(p-pw2)
dw=w2-w1
dwg=dw*grain
#results
print '%s %.6f %s' %("change in moisture content =",dw,"lbm water/lbm dry air")
print '%s %.2f %s' %("\n in grains, change =",dwg,"grains water/lbm dry air")
print '%s' %("The answers are a bit different due to rounding off error in textbook")
#Calculate the humidity ratio, relative humidity and dew point of the gas
#Initialization of variables
t1=80. #F
t2=60. #F
p=14.696 #psia
ps=0.507 #psia
pss=0.256 #psia
cp=0.24
#calculations
ws=0.622*pss/(p-pss)
w=(cp*(t2-t1) + ws*1060)/(1060+ 0.45*(t1-t2))
pw=w*p/(0.622+w)
phi=pw/ps*100
td=46. #F
#results
print '%s %.4f %s' %("\n humidity ratio =",w,"lbm/lbm dry air")
print '%s %.1f %s' %("\n relative humidity =",phi," percent")
print '%s %d %s' %("\n Dew point =",td,"F")
#calculate the enthalpy and sigma function of the mixture
#Initialization of variables
W=0.0065 #lbm/lbm of dry air
t=80. #F
td=60. #F
#calculations
H=0.24*t+W*(1060+0.45*t)
sig=H-W*(td-32)
Ws=0.0111
H2=0.24*td+Ws*(1060+0.45*td)
sig2=H2-Ws*(td-32)
#results
print '%s %.2f %s' %("In case 1, enthalpy =",H,"Btu/lbm dry air")
print '%s %.2f %s' %("\n In case 1, sigma function =",sig,"Btu/lbm dry air")
print '%s %.2f %s' %("\n In case 2, enthalpy =",H2,"Btu/lbm dry air")
print '%s %.2f %s' %("\n In case 2, sigma function =",sig2,"Btu/lbm dry air")
#calculate the enthalpy and heat added
#Initialization of variables
t1=30. #F
t2=60. #F
t3=80. #F
W1=0.00206
W2=0.01090
#calculations
cm1=0.24+0.45*W1
H1=cm1*t1+W1*1060
cm2=0.24+0.45*W2
H2=cm2*t3+W2*1060
hf=t2-32
dq=H2-H1-(W2-W1)*hf
#results
print '%s %.2f %s' %("In case 1, Enthalpy =",H1,"Btu/lbm dry air")
print '%s %.2f %s' %("\n In case 2, Enthalpy =",H2,"Btu/lbm dry air")
print '%s %.2f %s' %("\n Heat added =",dq,"Btu/lbm dry air")
#calculate the partial pressure and dew temperature of water. Calculate the density of water and air and also the specific humidity
#Initialization of variables
pw=0.15#psia
print '%s' %("using psychrometric charts,")
tdew=46. #F
#calculations
va=13.74 #ft^3/lbm dry air
rhoa=1/va
V=13.74
mw=46./7000.
rhow=mw/V
w=0.00657
#results
print '%s' %("part a")
print '%s %.2f %s' %("partial pressure of water =",pw,"psia")
print '%s %d %s' %("\n dew temperature =",tdew,"F")
print '%s' %("part b")
print '%s %.6f %s' %("density of water =",rhow,"lbm/ft^3")
print '%s %.4f %s' %("\n density of air =",rhoa,"lbm/ft^3")
print '%s' %("part c")
print '%s %.5f %s' %("specific humidity =",w,"lbm steam/lbm air")
#calculate the change in enthalpy
#Initialization of variables
W1=0.00206 #lbm/lbm dry air
W2=0.01090 #lbm/lbm dry air
t=60 #F
#calculations
dw=W1-W2
hs=144.4
hs2=66.8-32
w1=14.4 #Btu/lbm
ws1=20 #Btu/lbm
w2=76.3 #Btu/lbm
ws2=98.5 #Btu/lbm
dwh1=-(w1-ws1)/7000. *hs
H1=9.3+dwh1
dwh2=(w2-ws2)/7000. *hs2
H2=31.3+dwh2
dwc=dw*(t-32)
dq=H2-H1+dwc
#results
print '%s %.2f %s' %("Enthalpy change =",dq,"Btu/lbm dry air")
#calculate the humidity and temperature of the gas
#Initialization of variables
print '%s' %("From psychrometric charts,")
va1=13. #ft^3/lbm dry air
va2=13.88 #ft^3/lbm dry air
flow=2000. #cfm
#calculations
ma1= flow/va1
ma2=flow/va2
t=62.5 # F
phi=0.83 #percent
#results
print '%s %.2f' %("humidity = ",phi)
print '%s %.1f %s' %("\n Temperature =",t,"F")
#calculate the dry bulb temperature and percentage humidity
#Initialization of variables
t=90 #F
ts=67.2 #F
phi=0.3
per=0.8
#calculations
dep=t-ts
dt=dep*per
tf=t-dt
print '%s' %("from psychrometric charts,")
phi2=0.8
#results
print '%s %.2f %s' %("Dry bulb temperature =",tf,"F")
print '%s %.2f' %("\n percent humidity =",phi2)
#calculate the cooling range, approach and amount of water cooled and percentage of water lost by evaporation
#Initialization of variables
m=1 #lbm
t1=100. #F
t2=75. #F
db=65. #F
print '%s' %("From psychrometric charts,")
t11=82 #F
phi1=0.4
H1=30 #Btu/lbm dry air
w1=65 #grains/lbm dry air
w2=250 #grains/lbm dry air
#calculations
cr=t1-t2
appr=t2-db
dmf3=(w2-w1)*0.0001427
hf3=68
hf4=43
H2=62.2
H1=30
mf4= (H1-H2+ dmf3*hf3)/(hf4-hf3)
per=dmf3/(dmf3+mf4)*100
#results
print '%s %d %s' %("cooling range =",cr,"F")
print '%s %d %s' %("\n Approach =",appr,"F")
print '%s %.3f %s' %("\n amount of water cooled per pound of dry air =",mf4,"lbm dry air/lbm dry air")
print '%s %.2f %s' %("\n percentage of water lost by evaporation =",per,"percent")
#calculate the pressure and error in both cases
#Initialization of variables
R0=0.73 #atm ft^3/mol R
a1=578.9
a2=3675
b1=0.684
b2=1.944
n1=0.396 #mol
n2=0.604 #mol
V=8.518 #ft^3
T=460+460. #R
#calculations
p1=R0*n1*T/(V-n1*b1) - a1*n1*n1 /V/V
p2= R0*n2*T/(V-n2*b2) -a2*n2*n2 /V/V
p=p1+p2
pa=(n1+n2)*R0*T/V
err=(pa-p)/p*100
pb=58.7 #atm
err2= (p-pb)/p*100
#results
print '%s %.1f %s' %("Pressure =",p," atm")
print '%s %.1f %s' %("\n Pressure in case 2 =",pb,"atm")
print '%s %.1f %s' %("\n error in ideal case =",err," percent")
print '%s %.1f %s' %("\n error in case 2 =",err2," percent")
print '%s' %('The answer is a bit different due to rounding off error in textbook')
#calculate the pressure using both cases
#Initialization of variables
p1=45.8 #atm
p2=36 #atm
t1=343.3 #R
t2=766.8 #R
n1=0.396 #mol
n2=0.604 #mol
V=8.518 #ft^3
R0=0.73
T=920 #R
#calcualtions
vr1=p1*(V/n1)/(R0*t1)
vr2=p2*(V/n2)/(R0*t2)
tr1=T/t1
tr2=T/t2
print '%s' %("From compressibility charts,")
z1=1
z2=0.79
Z=n1*z1+n2*z2
p=Z*R0*T/V
p2=62. #atm
err=(p-p2)/p*100
#results
print '%s %.1f %s' %("In case 1, pressure =",p,"atm")
print '%s %d %s' %("\n In case 2, pressure using trail and error method =",p2,"atm")
print '%s %d %s' %("\n Error =",err,"percent")
#calculate the pressure required
#Initialization of variables
t1=343.3 #R
t2=766.8 #R
n1=0.396 #mol
n2=0.604 #mol
V=8.518 #ft^3
p1=45.8 #atm
p2=36 #atm
R0=0.73
T=920 #R
#calculations
tcd=n1*t1+n2*t2
pcd=n1*p1+n2*p2
Tr=T/tcd
Vr=pcd*V/(R0*tcd)
Z=0.87
p=Z*R0*T/V
#results
print '%s %.1f %s' %("Pressure =",p,"atm")