Chapter 7 : Ideal Gases

Example 7.3 Page No : 125

In [2]:
import math 
from scipy.integrate import quad

#Given
P1 = 15.0;#initial pressure in Kgf/cm**2
P2 = 1.0;#final pressure in Kgf/cm**2
V1 = 0.012;#initial volume in m**3
V2 = 0.06;#final volume in m**3
T1 = 420.0;#initial temperature in K
M = 28.0;#molecular weight of the gas
Cp = 0.25;#specific heat at consmath.tant pressure in Kcal/Kg K
R = 1.98;#gas consmath.tant in Kcal/Kg mole K
R2 = 848.0;#gas consmath.tant in mKgf/Kgmole K
#Cv = a+0.0005*T1; Specific heat at consmath.tant volume

#To Calculate the final temperature of the ideal gas, work done in an open and closed system,internal energy change for the process
#(a)Calculation of final temperature
#Umath.sing ideal gas law:(P*V)/(R*T)
T2 = (P2*V2*T1)/(P1*V1);
print "a)The final temperature is %d K"%(T2);

#(b)Calculation of work in an open and closed system
#From equation 7.22(page no 147): P1*(V1**n)=P2*(V2**n)
n = (math.log(P2/P1))/(math.log(V1/V2));
#From equation 7.25(page no 149)
W = ((P1*V1)-(P2*V2))/(n-1)*10**4;#work in mKgf
W1 = W/427;#Work in Kcal
print " b)The work in a closed system is %f Kcal"%(W1);
Ws = n*W1;#from equation 7.28(page no 149)
print "    The work in an open system is %f Kcal"%(Ws);

#(c)Calculation of internal energy change
R1 = R/M;#gas consmath.tant in Kcal/Kg
Cv = Cp-R1;#specific heat at consmath.tant volume in Kcal/Kg K
a = Cv-(0.0005*T1);
m = (P1*10**4*V1*M)/(R2*T1);#mass of gas in Kg
def y(T):
    val = m*(a+(0.0005*T));
    return val
del_E = quad(y,T1,T2)[0];#internal energy change in Kcal/Kg
del_E1 = M*del_E;#internal energy change in Kcal/Kgmole
print " c)The internal energy change for the process is %f Kcal/Kgmole"%(del_E1);
a)The final temperature is 140 K
 b)The work in a closed system is 4.117022 Kcal
    The work in an open system is 6.927326 Kcal
 c)The internal energy change for the process is -121.245283 Kcal/Kgmole

Example 7.5 Page No : 126

In [3]:
import math
import numpy

#Given
P1 = 1.0;#Initial pressure of air in atm
T1 = 15+273.0;#Initial temperature in K
P2 = 5.0;#Final pressure of air in atm
T2 = 15+273.0;#Final temperature in K
Cv = 5.0;#specific heat of air at consmath.tant volume in Kcal/Kgmole K
Cp = 7.0;#specific heat of air at consmath.tant pressure in Kcal/Kgmole K
R = 0.082;#gas consmath.tant in atm-m**3/Kgmole K
R1 = 2.0;#gas consmath.tant in Kcal/Kgmole K
#From the P-V diagram given in page no 155:
#Line 12 represents Isothermal process
#Line b2,c2 & 1a represent Isometric process
#Line a2 & 1c represent Isobaric process
#Line 1b reprsent Adiabatic process

#To find Approx Value
def approx(V,n):
    A=numpy.around([V*10**n])[0]/10**n;
    return A

#To Compute del_H, del_E, Q, W, del_S for the processes given above.
#To indicate the quantities that are state functions 
#To verify that the work required in an isothermal process is less than that in an adiabatic process

#Basis:1 Kgmole of air
V1 = (R*T1)/P1;#Initial volume in cubic meter
V2 = (R*T2)/P2;#Final volume in cubic meter

#(i)Isothermal path 12
#Equations 7.7 to 7.9 will be used (page no 145)
del_E_12 = Cv*(T2-T1);
del_H_12 = Cp*(T2-T1);
W_12 = R1*T1*math.log(P1/P2);
Q_12 = W_12;
del_S_12 = approx((R1*math.log(P1/P2)),4);
print "i)For isothermal process or path 12 change in internal energy is %f"%(del_E_12);
print "   For isothermal process or path 12 change in enthalpy is %f"%(del_H_12);
print "   For isothermal process or path 12 heat released is %f Kcal"%(Q_12);
print "   For isothermal process or path 12 work is %f Kcal"%(W_12);
print "   For isothermal process or path 12 change in entropy is %f Kcal/Kgmole K"%(del_S_12);

#(ii)Path 1a2 = 1a(isometric)+a2(isobaric)
#Equation 7.1 to 7.6 will be used (page no 144 & 145)
Pa = P2;
Ta = (Pa/P1)*T1;#in K
Q_1a = Cv*(Ta-T1);
del_E_1a = Q_1a;
del_H_1a = Cp*(Ta-T1);
W_1a = 0;# Consmath.tant volume process
del_E_a2 = Cv*(T2-Ta);
del_H_a2 = Cp*(T2-Ta);
Q_a2 = del_H_a2;
W_a2 = P2*(V2-V1)*((10**4*1.03)/427);
del_H_1a2 = del_H_1a+del_H_a2;
del_E_1a2 = del_E_1a+del_E_a2;
Q_1a2 = Q_1a+Q_a2;
W_1a2 = W_1a+W_a2;
del_S_1a = Cv*math.log(Ta/T1);
del_S_a2 = Cp*math.log(T2/Ta);
del_S_1a2 = approx((del_S_1a+del_S_a2),4);
print "ii)For path 1a2 change in internal energy is %f"%(del_E_1a2);
print "   For path 1a2 change in enthalpy is %f"%(del_H_1a2);
print "   For path 1a2 heat released is %f Kcal"%(Q_1a2);
print "   For path 1a2 work is %f Kcal"%(W_1a2);
print "   For path 1a2 change in entropy is %f Kcal/Kgmole K"%(del_S_1a2);

#(iii)Path 1b2 = 1b(adiabatic)+b2(isometric)
#From equation 7.11 (page no 146)
y = Cp/Cv;
Tb = T1*((V1/V2))**(y-1);
#From equation 7.1 to 7.3,7.10 & 7.21,(page no 144,146,147)
Q_1b = 0;#adiabatic process
del_E_1b = Cv*(Tb-T1);
del_H_1b = Cp*(Tb-T1);
W_1b = -1*del_E_1b;
Q_b2 = Cv*(T1-Tb);
del_H_b2 = Cp*(T1-Tb);
W_b2 = 0;#consmath.tant volume prcess
del_E_b2 = Cv*(T2-Tb);
del_H_1b2 = del_H_1b+del_H_b2;
del_E_1b2 = del_E_1b+del_E_b2;
W_1b2 = W_1b+W_b2;
Q_1b2 = Q_1b+Q_b2;
del_S_1b2 = approx((Cv*math.log(T1/Tb)),4);
print "iii)For path 1b2 change in internal energy is %f"%(del_E_1b2);
print "   For path 1b2 change in enthalpy is %f"%(del_H_1b2);
print "   For path 1b2 heat released is %f Kcal"%(Q_1b2);
print "   For path 1b2 work is %f Kcal"%(W_1b2);
print "   For path 1b2 change in entropy is %f Kcal/Kgmole K"%(del_S_1b2);

#(iv)Path 1c2 = 1c(isobaric)+c2(isometric);
Pc = P1;
Vc = V2;
Tc = (Pc/P2)*T2;
del_E_1c = Cv*(Tc-T1);
Q_1c = Cp*(Tc-T1);
del_H_1c = Q_1c;
W_1c = P1*(Vc-V1)*((10**4*1.03)/427);
del_E_c2 = Cv*(T2-Tc);
Q_c2 = del_E_c2;
del_H_c2 = Cp*(T2-Tc);
W_c2 = 0.0;#consmath.tant volume process
del_E_1c2 = del_E_1c+del_E_c2;
del_H_1c2 = del_H_1c+del_H_c2;
Q_1c2 = Q_1c+Q_c2;
W_1c2 = W_1c+W_c2;
del_S_1c = Cp*math.log(Tc/T1);
del_S_c2 = Cv*math.log(T2/Tc);
del_S_1c2 = approx((del_S_1c+del_S_c2),4);
print "iv)For path 1c2 change in internal energy is %f"%(del_E_1c2);
print "   For path 1c2 change in enthalpy is %f"%(del_H_1c2);
print "   For path 1c2 heat released is %f Kcal"%(Q_1c2);
print "   For path 1c2 work is %f Kcal"%(W_1c2);
print "   For path 1c2 change in entropy is %f Kcal/Kgmole K"%(del_S_1c2);

#Determination of state & path functions
if((del_E_12 == del_E_1a2)&(del_E_12 == del_E_1b2)&(del_E_12 == del_E_1c2)):
    print " del_E is a state function";
else:
    print " del_E is a path function";
if((del_H_12 == del_H_1a2)&(del_H_12 == del_H_1b2)&(del_H_12 == del_H_1c2)):
    print " del_H is a state function";
else:
    print " del_H is a path function";
if(del_S_12 == del_S_1a2)&(del_S_12 == del_S_1b2)&(del_S_12 == del_S_1c2):
    print " del_S is a state function";
else:
    print " del_S is a path function";
if((Q_12 == Q_1a2)&(Q_12 == Q_1b2)&(Q_12 == Q_1c2)):
    print " Q is a state function";
else:
    print " Q is a path function";
if((W_12 == W_1a2)&(W_12 == W_1b2)&(W_12 == W_1c2)):
    print " W is a state function";
else:
    print " W is a path function";

#Comparison of work required by isothermal & adiabatic process
if(-(W_12)<-(W_1b2)):
    print "  Work required by isothermal process is less than the work required by an adiabatic process";
else:
    print " Statement is incorrect";
#end
i)For isothermal process or path 12 change in internal energy is 0.000000
   For isothermal process or path 12 change in enthalpy is 0.000000
   For isothermal process or path 12 heat released is -927.036238 Kcal
   For isothermal process or path 12 work is -927.036238 Kcal
   For isothermal process or path 12 change in entropy is -3.218900 Kcal/Kgmole K
ii)For path 1a2 change in internal energy is 0.000000
   For path 1a2 change in enthalpy is 0.000000
   For path 1a2 heat released is -2304.000000 Kcal
   For path 1a2 work is -2278.639813 Kcal
   For path 1a2 change in entropy is -3.218900 Kcal/Kgmole K
iii)For path 1b2 change in internal energy is 0.000000
   For path 1b2 change in enthalpy is 0.000000
   For path 1b2 heat released is -1301.261672 Kcal
   For path 1b2 work is -1301.261672 Kcal
   For path 1b2 change in entropy is -3.218900 Kcal/Kgmole K
iv)For path 1c2 change in internal energy is 0.000000
   For path 1c2 change in enthalpy is 0.000000
   For path 1c2 heat released is -460.800000 Kcal
   For path 1c2 work is -455.727963 Kcal
   For path 1c2 change in entropy is -3.218900 Kcal/Kgmole K
 del_E is a state function
 del_H is a state function
 del_S is a state function
 Q is a path function
 W is a path function
  Work required by isothermal process is less than the work required by an adiabatic process