#calculate the cop, hp required, work of compression and expansion
#Initialization of variables
Ta=500. #R
Tr=540. #R
#calculations
cop=Ta/(Tr-Ta)
hp=4.71/cop
print '%s' %("From steam tables,")
ha=48.02
hb=46.6
hc=824.1
hd=886.9
Wc=-(hd-hc)
We=-(hb-ha)
#results
print '%s %.1f' %("Coefficient of performance =",cop)
print '%s %.3f %s' %("\n horsepower required per ton of refrigeration =",hp," hp/ton refrigeration")
print '%s %.1f %s' %("\n Work of compression =",Wc," Btu/lbm")
print '%s %.2f %s' %("\n Work of expansion =",We,"Btu/lbm")
#calculate the cop
#Initialization of variables
x=0.8
he=26.28 #Btu/lbm
hb=26.28 #Btu/lbm
pe=98.76 #psia
pc=51.68 #psia
hc=82.71 #Btu/lbm
hf=86.80+0.95
#calculations
dwisen=-(hf-hc)
dwact=dwisen/x
hd=hc-dwact
cop=(hc-hb)/(hd-hc)
#results
print '%s %.2f' %("Coefficient of performance = ",cop)
#calculate the work done, hp required, relative efficiency and mass flow rate, Compressor capacity
#Initialization of variables
hc=613.3#btu/lbm
hb=138.9#btu/lbm
ha=138.9#btu/lbm
hd=713.4 #btu/lbm
ta=464.7 #R
t0=545.7 #R
v=8.150 #ft^3/lbm
#calculations
Qa=hc-hb
Qr=ha-hd
Wcd=Qa+Qr
cop=abs(Qa/Wcd)
hp=abs(4.71/cop)
carnot=abs(ta/(t0-ta))
rel=abs(cop/carnot)
mass=200/Qa
C=mass*v
#results
print '%s %.1f %s' %("Work done =",Wcd,"Btu/lbm")
print '%s %.3f %s' %("\n horsepower required per ton of refrigeration =",hp," hp/ton refrigeration")
print '%s %.2f' %("\n Coefficient of performance actual = ",cop)
print '%s %.3f' %("\n Ideal cop = ",carnot)
print '%s %.3f' %("\n relative efficiency =",rel)
print '%s %.3f %s' %("\n Mass flow rate =",mass,"lbm/min ton")
print '%s %.2f %s' %("\n Compressor capacity =",C,"cfm/ton")
#calculate the Pressure ratio, Heat, Water make up required and Volume of vapor entering ejector
#Initialization of variables
pc=0.6982 #psia
pe=0.1217 #psia
m=200 #gal/min
qual=0.98
h1=23.07 #Btu/lbm
h2=8.05 #Btu/lbm
hw=1071.3
#calculations
rp=pc/pe
m2=m/0.01602 *0.1388 #Conversion of units
m2=1670
dh=15.02
Qa=m2*(h1-h2)
h3=h2 + qual*hw
m3=Qa/(h3-h1)
v=0.016+ qual*2444
C=m3*v
#results
print '%s %.2f' %("Pressure ratio =",rp)
print '%s %d %s' %("\n Heat =",Qa,"Btu/min")
print '%s %.2f %s' %("\n Water make up required =",m3,"lbm/min")
print '%s %d %s' %("\n Volume of vapor entering ejector =",C,"cfm")
print '%s' %("The answers are a bit different due to rounding off error in textbook")