#A certain piece of apparatus of constant volume is filled with nitrogen
#at 15 psia, 80 F. from a nitrogen bottle on a weighing scale exactly 3 lb
#of nitrogen is added to the apparatus. The final pressure and temperature
#are 25 psia, 75 F. Find the volume of the apparatus.
import math
#initialisation of variables
P= 15. #psia
T= 80. #F
m= 3. #lb
P1= 25. #psia
T1= 75. #F
#CALCULATIONS
r= (P*(460+T1))/(P1*(T+460)) #ratio
m2= m/(1-r) #Mass 2
V2= (m2*55.16*(460+T1))/(P1*144.) #Volume 2
#RESULTS
print '%s %.2f' %('Volume of the apparatus (cu ft) = ',V2)
raw_input('press enter key to exit')
#Given that O2 has a gas constant of 48.3 and is a diatomic gas, compare its
#actual Cp at 100, 500, 1500 F with the values computed from the simple KTG
#initialisation of variables
R= 48.3 #ft lb/lb R
T= 100 #F
T1= 500 #F
T2= 1500 #F
k= 1.4
k1= 1.36
k2= 1.31
#CALCULATIONS
dc= R/778. #Cp-Cv
cp= (k/(k-1))*dc #Specific heat at constant pressure
cv= cp/k #Specific heat at constant volume
cp1= (k1/(k1-1))*dc #Specific heat at constant pressure 2
cv1= cp/k1 #Specific heat at constant volume 2
cp2= (k2/(k2-1))*dc #Specific heat at constant pressure 3
cv2= cp2/k2 #Specific heat at constant volume 3
#RESULTS
print '%s %.3f' %('#Specific heat at constant pressure (Btu/lb R) = ',cp)
print '%s %.3f' %(' \nSpecific heat at constant volume (Btu/lb R) = ',cv)
print '%s %.3f' %(' \nSpecific heat at constant pressure 2 (Btu/lb R) = ',cp1)
print '%s %.3f' %(' \nSpecific heat at constant volume 2 (Btu/lb R) = ',cv1)
print '%s %.3f' %(' \nSpecific heat at constant pressure 3 (Btu/lb R) =',cp2)
print '%s %.3f' %(' \nSpecific heat at constant volume 3 (Btu/lb R) = ',cv2)
raw_input('press enter key to exit')
#Nitrogen in a frictionless adiabatic process, expands from an initial state
#of 100 psia, 140 F to a final pressure of 10 psia. How much does the enthalpy
#change?
import math
#initialisation of variables
P= 10. #psia
P1= 100. #psia
T= 140. #F
k= 1.4
R= 55.16 #ft lb/lb R
#CALCULATIONS
dh= (k*R*(T+460)/(k-1))*(math.pow((P/P1),((k-1)/k))-1)*(72./56000.)
#RESULTS
print '%s %.2f' %('Enthalpy change (Btu/lb) = ',dh)
raw_input('press enter key to exit')
#Air initially at 100 psia, 2000 F, expands reversibly and adiabatically
#to 15 psia. Find the change of enthalpy and of V by perfect gas laws, and
#by variable specific heats using the gas tables
import math
#initialisation of variables
P= 100 #psia
P1= 15 #psia
T= 2000 #F
k= 1.4
R= 53.34 #ft lb/lb R
cp= 0.240 #Btu/lb R
#CALCULATIONS
v1= (R*(T+460)/(P*144))*math.pow((P/P1),(1/k)) #Initial volume
T1= (T+460)*(P1*v1/(P*(R*(T+460)/(P*144)))) #Initial temperature
dh= cp*(T1-T) #Change in enthalpy
dv= v1-(R*(T+460)/(P*144)) #Change in volume
print('case 1')
print '%s %.2f' %('\n change in volume =', dv)
print('\n case 2')
T2=1500 #F
v2=R*(T+460)/(P*144)/0.241 #Volume in case 2
T2=(T2+460)*(P1*v2/(P*(R*(T2+460)/(P*144)))) #Temperature in case 2
deltah=0.276*(T2-460-T) #Change in enthalpy
dv2=v2-(R*(T+460)/(P*144)) #Change in volume
print '%s %.2f' %('\n change in volume (cu ft/lb) = ', dv2)
print('At T1=2460 R, from table 1, case 3')
h1=634.34
pr1=407.3
pr2=pr1*P1/P #pressure 2
T2=1075 #F
h2=378.44
deltah=h2-h1 #Change in enthalpy
v2=53.34*(T2+460)/(P1*144) #Final volume
dv3=v2-(R*(T+460)/(P*144)) #Change in volume
print '%s %.2f' %('\n change in volume (cu ft/lb) = ',dv3)
raw_input('press enter key to exit')