#calculate the work done and the net heat transferred
#initialization of varaibles
import math
R=53.34
T1=540 #R
n=1.4
g=n
n2=1.3
P2=90. #psia
P1=15. #psia
cv=0.171
cp=0.24
#calculations
pv=R*T1
Wk=n*R*T1*(math.pow((P2/P1),((g-1)/g)) -1) /(n-1)
Wn=n2*R*T1*(math.pow((P2/P1),((n2-1)/n2)) -1) /(n2-1)
Wt=R*T1*math.log(P2/P1)
Q=cv*(n-n2)*778*T1*(math.pow((P2/P1),((n2-1)/n2)) -1) /(1-n2)*0.001305
#0.001305 is the conversion factor
#results
print '%s %d %s' %("\n Work in case 1 =",Wk,"ft lb/lb")
print '%s %d %s' %("\n Work in case 2 =",Wn,"ft lb/lb")
print '%s %d %s' %("\n Work in case 3 =",Wt,"ft lb/lb")
print '%s %.1f %s' %("\n Heat transferred =",Q,"B/lb")
#Calculate the adiabatic and isothermal efficiencies
#initialization of varaibles
import math
R=53.34
T1=540 #R
n=1.4 #gamma
g=n
n2=1.3 #gamma
P2=90. #psia
P1=15. #psia
cv=0.171
#calculations
pv=R*T1
Wk=n*R*T1*(math.pow((P2/P1),((g-1)/g)) -1) /(n-1)
Wn=n2*R*T1*(math.pow((P2/P1),((n2-1)/n2)) -1) /(n2-1)
Wt=R*T1*math.log(P2/P1)
eta1=Wt/Wn
eta2=Wk/Wn
#results
print '%s %.2f' %("Adiabatic efficiency = ",eta2)
print '%s %.2f' %("\n Isothermal efficiency = ",eta1)
#calculate the heat transferred
#initialization of varaibles
import math
R=53.34
T1=540 #R
n=1.4 #gamma
g=n
n2=1.3 #gamma
P2=90 #psia
P1=15 #psia
cv=0.171
eta=0.95
cp=0.24
#calculations
pv=R*T1
Wk=n*R*T1*(math.pow((P2/P1),((g-1)/g)) -1) /(n-1)
Wn=n2*R*T1*(math.pow((P2/P1),((n2-1)/n2)) -1) /(n2-1)
Wt=R*T1*math.log(P2/P1)
Wx=-Wk/eta
dh=cp*T1*(1.52 - 1)
Q=dh+Wx/778.
#results
print '%s %.1f %s' %("Heat transferred =",Q,"B/lb")
#calculate the volumetric efficiency
#initialization of varaibles
import math
n=1.3
P1=15. #psia
P2=75. #psia
eta=0.5
eta2=0
#calculations
Pr=math.pow((P2/P1),(1/n))
Cl=(1-eta)/(Pr-1)
Cl2=(1-eta2)/(Pr-1)
#results
print '%s %.3f' %("For volumetric efficiency to be 0.5, Clearance = ",Cl)
print '%s %.3f' %("\n For volumetric efficiency to be 0, Clearance = ",Cl2)
#Calculate the single stage and two stage efficiencies
#initialization of varaibles
import math
P1=5 #psia
P2=83.5 #psia
n=1.25
per=0.03
#calculations
nv1=1- per*(math.pow((P2/P1),(1/n)) -1)
nv2=1-per*(math.pow((math.sqrt(P2/P1)),(1/n)) -1)
#results
print '%s %.3f' %("For single stage machine = ",nv1)
print '%s %.3f' %("\n For Two stage machine = ",nv2)