from __future__ import division
# Given data
P1= 250 # in kN/m**2
V1= 6.2 # in m**3
V2= 1.82 # in m**3
# Formula P1*V1 = P2*V2
P2= P1*V1/V2 # in kN/m**2
print "Pressure of air after compression = %0.1f kN/m**2 " %P2
# Given data
guagePressure= 1500 # in kN/m**2
atmPressure= 100 # in kN/m**2
P1= guagePressure+atmPressure # in kN/m**2
V1= 0.1 # in m**3
V2= 0.4 # in m**3
# Formula P1*V1 = P2*V2
P2= P1*V1/V2 # in kN/m**2
NewGuagePressure= P2-atmPressure # in kN/m**2
print "New guage pressure = %0.f kN/m**2 (3 bar)" %NewGuagePressure
# Given data
P1= -4+101.3 # in kN/m**2
V1= 96+475 # in cm**3
V2= 96 # in cm**3
# Formula P1*V1 = P2*V2
P2= P1*V1/V2 # in kN/m**2
print "Pressure at the end of the compression stroke = %0.1f kN/m**2 " %P2
print "Pressure at the end of the compression stroke = %0.3f bar " %(P2*10**-2)
# Given data
V0= 1 # in m**3
t= 300 # in °C
V= V0*(1+t/273) # in m**3
print "The volume occupied = %0.1f m**3 " %V
# Given data
V1= 2 # in m**3
T1= 30+273 # in K
T2= 230+273 # in K
# V1/T1 = V0/T0 = V2/T2
V2= V1*T2/T1 # in m**3
print "The final volume = %0.3f m**3 " %V2
# Given data
P1= 7*10**5 # in N/m**2
V1= 3 # in m**3
V2= 9 # in m**3
T1= 150+273 # in K
T2= 10+273 # in K
# Formula P1*V1/T1 = P2*V2/T2
P2= P1*V1*T2/(T1*V2) # in N/m**2
print "Pressure of the gas = %0.3f bar " %(P2*10**-5)
# Given data
P1= 100 # in kN/m**2
V1byV2= 12 # in
T1= 115+273 # in K
T2= 180+273 # in K
# Formula P1*V1/T1 = P2*V2/T2
P2= P1*V1byV2*T2/T1 # in N/m**2
print "Absolute pressure at the end of compression stroke = %0.2f bar " %(P2*10**-2)
# Given data
mR= 8314.3 # in J/kg-mole-K
P= 200*10**3 # in N/m**2
T= 30+273 # in K
# Formula P*V = mR*T
V= mR*T/P # in m**3
print "The molecular volume of all the gases = %0.3f m**3 " %V
# Given data
P1= 96 # in kN/m**2
P2= 725 # in kN/m**2
V1= 600 # in cm**3
V2= 100 # in cm**3
T1= 100+273 # in K
# Formula P1*V1/T1 = P2*V2/T2
T2= P2*V2*T1/(P1*V1) # in K
print "Temperature at the end of compression = %0.3f °C " %(T2-273)
# Note:- In the book, There is an error to calculate the value of T2.
# Given data
MR= 8314.2 # in J/kg-mole-K
mass= 44 # Molecular mass of carbon dioxide in kg
R= MR/mass # in J/kg-K
P= 11 # in MPa
P=P*10**6 # in Pa
V= 50*10**-3 # in m**3
T= 18+273 # in K
# Formula P*V= m*R*T
m= P*V/(R*T) # in kg
m=round(m) # in kg
MolecularVolume= MR*T/P # in m**3
D= m/V # density of the gas in kg/m**3
SpecificVolume= 1/D # in m**3/kg
print "The mass of the gas = %0.f kg " %m
print "The Molecular volume = %0.2f m**3 " %MolecularVolume
print "The density of the gas = %0.f kg/m**3 " %D
print "The specific volume of the gas = %0.3f m**3/kg " %SpecificVolume
# Given data
P1= 350 # in kN/m**2
P1=P1*10**3 # in N/m**2
P2= 1.05 # in kN/m**2
P2=P2*10**6 # in N/m**2
V= 0.3 # in m**3
R= 0.29 # in kJ/kg-K
R= R*10**3 # in j/kgK
T1= 35+273 # in K
# Formula P*V= m*R*T
m= P1*V/(R*T1) # in kg
# Formula P1*V1/T1 = P2*V2/T2 and since V1= V2
T2= P2*T1/P1 # in K
print "Temperature at constant volume compression = %0.f °C " %(T2-273)
# Given data
g1= 1.75 # gauge reading in bar
atm= 1.013 # in atmospheric pressure in bar
P1= g1+atm # in bar
T1= 12+273 # in K
T2= 45+273 # in K
# Formula P1*V1/T1 = P2*V2/T2 and since V1= V2
P2= P1*T2/T1 # in bar
g2=P2-atm # tyre gauge reading in bar
print"Tyre guage reading at 45°C = %0.2f bar "%g2
# Given data
Q= 120 # in kJ
W= 150 # in kJ
E= Q-W # change in internal energy in kJ
print "The internal energy of the system decreases by %0.0f kJ" %abs(E)
# Given data
Q= -40 # in kJ/kg
W= -80 # in kJ/kg
E= Q-W # change in internal energy in kJ/kg
print "Change in internal energy = %0.0f kJ/kg " %E
print "Thus internal energy of the working substance increases "
# Given data
Int_energy_changes= 20 # in kJ/kg
Q= 0 # in kJ
W= -90 # in kJ
E= Q-W # change in internal energy in kJ/kg
m= E/Int_energy_changes # in kg
print "The mass of the fluid in the system = %0.1f kg " %m
# Given data
U= 2800 # in kJ/kg
P= 20 # in bar
P= P*10**5 # in N/m**2
V= 0.23/1000 # in m**3
SP= U+P*V # specific enthalpy in kJ/kg
print "The specific enthalpy = %0.0f kJ/kg " %SP
# Given data
h1= 210 #first heat transfer in kJ
h2= -20 # second heat transfer in kJ
h3= -190 # third heat transfer in kJ
h4= 60 # fourth heat transfer in kJ
W1= -180 # first work transfer in kJ
W2= 200 # second work transfer in kJ
W3= -300 # third work transfer in kJ
# Total Heat transfer = Total work transfer
W4= h1+h2+h3+h4-W1-W2-W3 # forth work transfer in kJ
print "Fourth work transfer = %0.0f kJ is :" %W4
print "Thus the system delivers",int(W4),"kJ of work"
# Given data
Cv= 0.718 # in kJ/kgK
R= 0.278 # in kJ/kgK
T1= 15+273 # in K
T2= 135+273 # in K
m= 2 # mass in kg
V1= 0.7 # in m**3
Q= m*Cv*(T2-T1) # in kJ
print "Heat supplied to gas = %0.2f kJ " %Q
# Formula P1*V1= m*R*T1
P1= m*R*T1/V1 # in kN/m**2 absolute
# From P1/T1= P2/T2
P2= P1*T2/T1 # in kN/m**2
print "The final pressure = %0.1f kN/m**2 " %P2
# Note : The calculation in the book is not accurate
# Given data
Cv= 1.005 # in kJ/kgK
T1= 200+273 # in K
T2= 15+273 # in K
V1= 0.12 # in m**3
m= 0.25 # mass in kg
Q= m*Cv*(T1-T2) # in kJ
print "Heat extracted from the gas = %0.2f kJ " %Q
# From V1/T1= V2/T2
V2= V1*T2/T1 # in m**3
print "The final volume of the gas = %0.3f m**3 " %V2
# Given data
m=2 # molecular mass
UGC= 8.3143 # universal gas constant in kJ/kg-mole-K
Cp= 14.41 # in kJ/kg-K
R= UGC/m # in kJ/kgK
Cv= Cp-R # in kJ/kgK
gama= Cp/Cv
print "The value of R = %0.3f kJ/kgK is :" %R
print "The value of Cv = %0.3f kJ/kgK " %Cv
print "The value of gama = %0.1f" %gama
# Given data
Cp = 0.796 # in kJ/kg-K
Cv = 0.67 # in kJ/kg-K
P1=1 # in bar
P1= P1*10**5 # in N/m**2
P2=3.5 # in bar
P2= P2*10**5 # in N/m**2
V1= 0.12 # in m**3
V2= 0.05 # in m**3
m=1 # in kg
R= Cp-Cv # in kJ/kg-K
R= R*10**3 # in J/kg-K
# Formula P*V= m*R*T
T1= P1*V1/(m*R) # in K
# Formula P1*V1/T1 = P2*V2/T2
T2= P2*V2*T1/(P1*V1) # in K
T= T2-T1 # Temperature rise in K
print "Temperature rise = %0.1f K " %T
E= m*Cv*(T2-T1) # change in internal energy kJ
print "Change in internal energy = %0.1f kJ " %E
# Given data
CO2= 0.12 #volume of CO2 in m**3
CO= 0.25 # in m**3
H2= 0.06 # in m**3
CH4= 0.02 # in m**3
N2= 0.55 # in m**3
R= 8.3143 # Universal gas constant in kJ/kg-mol-K
mm_CO2= 44 # molecular mass of CO2
mm_CO= 28
mm_H2= 2
mm_CH4= 16
mm_N2= 28
Gm_CO2= 5.28 # gravimetric mass of CO2
Gm_CO= 7.00
Gm_H2= 0.12
Gm_CH4= 0.32
Gm_N2= 15.40
total_Gm= Gm_CO2+Gm_CO+Gm_H2+Gm_CH4+Gm_N2
Per_relative_CO2= Gm_CO2/total_Gm*100 # in %
Per_relative_CO= Gm_CO/total_Gm*100 # in %
Per_relative_H2= Gm_H2/total_Gm*100 # in %
Per_relative_CH4= Gm_CH4/total_Gm*100 # in %
Per_relative_N2= Gm_N2/total_Gm*100 # in %
print "Analysis % Relative : "
print "CO2 : ",round(Per_relative_CO2,1)
print "CO : ",round(Per_relative_CO,1)
print "H2 : ",round(Per_relative_H2,3)
print "CH4 : ",round(Per_relative_CH4,2)
print "N2 : ",round(Per_relative_N2,1)
App_Gas_Constant= R/total_Gm # in kJ/kg-K
mol_Vol= 22.4 #mole volume at NTP in m**3
Average_Density= total_Gm/mol_Vol # in kg/m**3 at NTP
print "The Apparent gas constant = %0.4f kJ/kg-K " %App_Gas_Constant
print "The average density = %0.3f kg/m**3 at NTP. " %Average_Density
# Given data
Cv = 652 # in J/kg-K
R= 287 # in J/kg-K
Cp= Cv+R # in J/kg-K
m=0.3 # in kg
P= 1.5*10**5 # in N/m**2
V= 0.283 # in m**3
# Formula P*V= m*R*T
T= P*V/(m*R) # in K
T= T-273 # in °C
T1= -40 # in °C
delta_U= m*Cv*(T-T1) # in J
print "Internal energy = %0.3f kJ " %(delta_U*10**-3)
# Given data
H2= 0.50 #volume of H2 in m**3
CH4= 0.19 # in m**3
CO= 0.18 # in m**3
C2H4= 0.02 # in m**3
CO2= 0.05 # in m**3
N2= 0.06 # in m**3
P= 100 # pressure of mixture in kN/m**2
mm_CO2= 44 # molecular mass of CO2
mm_CO= 28
mm_H2= 2
mm_CH4= 16
mm_C2H4= 28
mm_N2= 28
R= 8.3143 # Universal gas constant in kJ/kg-mol-K
R_H2= R/mm_H2 # gas constant for H2
R_CO2= R/mm_CO2
R_CO= R/mm_CO
R_C2H4= R/mm_C2H4
R_CH4= R/mm_CH4
R_N2= R/mm_N2
M= mm_CO2*CO2+mm_H2*H2+mm_CH4*CH4+mm_CO*CO+mm_C2H4*C2H4+mm_N2*N2 # in kg
print "Apparent molecular mass of the gas = %0.2f kg " %M
mol_Vol= 22.4 #mole volume at NTP in m**3
density= M/mol_Vol # in kg/m**3
print "Density of the mixture = %0.3f kg/m**3 " %density
mixture_G_constant= R/M # in kJ/kg-K
print "The mixture gas constant = %0.3f kJ/kg-K " %mixture_G_constant
P_H2= P*H2 #partial pressure of H2 in kN/m**2
P_CH4= P*CH4 # in kN/m**2
P_CO= P*CO # in kN/m**2
P_C2H4= P*C2H4 # in kN/m**2
P_CO2= P*CO2 # in kN/m**2
P_N2= P*N2 # in kN/m**2
print "The partial pressure of H2 = %0.0f kN/m**2" %P_H2
print "The partial pressure of CH4 = %0.0f kN/m**2" %P_CH4
print "The partial pressure of CO = %0.0f kN/m**2" %P_CO
print "The partial pressure of C2H4 = %0.0f kN/m**2" %P_C2H4
print "The partial pressure of CO2 = %0.0f kN/m**2" %P_CO2
print "partial pressure of N2 = %0.0f kN/m**2" %P_N2