# Chapter 3: First Law of Thermodynyamics¶

## Example 1, page no. 76¶

In [1]:

#Variable Declaration:
#Pressure in the gas cylinder(in kPa):
p=689
#Final volume(in m**3):
v2=0.045
#Initial volume(in m**3):
v1=0.04
#Work done by the paddle(in kJ):
Pw=-4.88

#Calculation:
#Work done by the system on the piston(in kJ):
w=p*(v2-v1)
#Net Work of the system(in kJ):
wn=w+Pw

#Results:
print "Work done on the piston in kJ: ",w
print "Work done on the system in  kJ: ",-wn

Work done on the piston in kJ:  3.445
Work done on the system in  kJ:  1.435


## Example 2, page no. 76¶

In [2]:

#Variable Declaration:
#Mass of the gas(in kg):
m=0.5
#Initial internal energy(in kJ/kg):
u1=26.6
#Final internal energy(in kJ/kg):
u2=37.8

#Calculation:
#Heat required(in kJ):
Q=(u2-u1)*m

#Results:
print "Heat required (kJ): ",Q

Heat required (kJ):  5.6


## Example 3, page no. 77¶

In [3]:

#Variable Declaration:
#Mass flow rate(in kg/hr):
m=50
#Initial temp(in C):
t1=800
#Final temp(in C):
t2=50
#Heat capacity at const pressure(in kJ/kg.K):
Cp=1.08

#Calculation:
#Heat to be removed(in kJ/hr):
Q=m*Cp*(t2-t1)

#Results:
print "Heat should be removed at (kJ/hr): ",-Q

Heat should be removed at (kJ/hr):  40500.0


## Example 4, page no. 77¶

In [4]:

#Variable Declaration:
#Volume of the cylinnder(in m**3):
v=0.78
#Atmospheric pressure(in kPa):
p=101.325

#Calculation:
#Work done(in kJ):
w=round(p*v,2)

#Results:
print "Work done by air (KJ): ",-w
print "Work done by surroundings (KJ): ",w

Work done by air (KJ):  -79.03
Work done by surroundings (KJ):  79.03


## Example 5, page no. 77¶

In [5]:
#Variable Declaration:
#Mass of the gas(in kg):
m=5
#Value of n in P*(V**n)=const:
n=1.3
#Initial pressure(in MPa):
p1=1
#Initial volume(in m**3):
v1=0.5
#Final pressure(in MPa):
p2=0.5

#Calculation:
#Final volume(in m**3):
v2=round(v1*((p1/p2)**(1/n)),3)
#Work done(in kJ):
w=(p2*v2-p1*v1)*10**3/(1-n)
#Change in internal energy(in kJ/kg):
du=1.8*(p2*v2-p1*v1)*10**3
#Heat interaction(in kJ):
Q=du+w

#Results:
print "Heat interaction (kJ): ",round(Q,1)
print "Work interaction (kJ): ",round(w,1)
print "Change in internal energy (kJ): ",round(du,1)

Heat interaction (kJ):  113.5
Work interaction (kJ):  246.7
Change in internal energy (kJ):  -133.2


## Example 6, page no. 78¶

In [6]:
#Variable Declaration:
#Initial pressure(in MPa):
p1=1.0
#Final pressure(in MPa):
p2=2.0
#Initial volume(in m**3):
v1=0.05
#Value of n:
n=1.4

#Calculation:
#Final volume(in m**3):
v2=round(v1*((p1/p2)**(1/n)),2)

#Change in internal energy(in kJ/kg):
du=7.5*(p2*v2-p1*v1)*10**3
#Work done(in kJ):
w=(p2*v2-p1*v1)*10**3/(1-n)
#Heat interaction(in kJ):
Q=du+w

#Results:
print "Heat interaction (kJ): ",Q
print "Work interaction (kJ): ",w
print "Change in internal energy (kJ): ",du

#If 180 kJ heat transfer takes place:
#Work done(in kJ):
w2=180-du
print "New work (kJ): ",w2

Heat interaction (kJ):  50.0
Work interaction (kJ):  -25.0
Change in internal energy (kJ):  75.0
New work (kJ):  105.0


## Example 7, page no. 79¶

In [7]:
#Variable Declaration:
#Universal Gas Constant (in KJ.mol/Kg.K):
r=8.3143
#Molecular weight of perfect gas:
M=16
#Molar specific heat at constant pressure for perfect gas(KJ/Kg.K):
Cp=1.7
#Initial pressure (Kpa):
p1=101.3
#Final pressure (Kpa):
p2 = 600
#Initial tempreture (K):
T1 = 273+20
#Polytripic index from PV^1.3 = const
n = 1.3

#Calculations:
#Characterstic Gas Constant (KJ/Kg.K):
R=r/M
#Molar specific heat at constant volume for perfect gas(KJ/Kg.K):
Cv=Cp-R
#Specific heat ratio:
y = Cp/Cv
#Final Tempreture (K):
T2 = T1*(p2/p1)**((n-1)/n)
#Polytropic work (KJ/Kg):
W = R*(T1-T2)/(n-1)
#Polytropic process heat (KJ/Kg):
Q = W*(y-n)/(y-1)

#Results:
print "Heat transfered (KJ/Kg): ",round(Q,2)

Heat transfered (KJ/Kg):  -82.06


## Example 8, page no. 80¶

In [8]:
import math as m

#Variable Declaration:
#Initial temperature(in K):
t1=627+273
#Final temperature(in K):
t2=27+273
#Specific heat at const pressure(in kJ/kg.K):
Cp=1.005

#Calculation
#Exit velocity(in m/s):
c2=m.sqrt(2*Cp*10**3*(t1-t2))

#Results:
print "Exit Velocity (m/s): " ,round(c2,1)

Exit Velocity (m/s):  1098.2


## Example 9, page no. 80¶

In [9]:
#Variable Declaration:
#Work interaction(in kJ):
w=-200
#Increase in enthalpy(in kJ/kg):
dh=100
#Heat picked up by the cooling water(in kJ/kg):
qc=-90

#Calculation:
#Heat flow(in kJ/kg):
Q=dh+w
#Heat transferred to atmosphere(in kJ/kg):
Qa=Q-qc

#Results:
print "Heat transferred to atmosphere (kJ/kg): ",Qa

Heat transferred to atmosphere (kJ/kg):  -10


## Example 10, page no. 81¶

In [10]:

#Variable Declaration:
c=500 #Seating capacity:
q=50  #Heat requirement per person(in kcal/hr):
h1=80 #Enthalpy of water entering the pipe(in kcal/kg):
h2=45 #Enthalpy of water leaving the pipe(in kcal/kg):
z=10  #Difference in elevation of inlet and exit pipe(in m):
g=9.81 #Acceleration due to gravity(in m/s**2):

#Calculation:
Q=c*q #Heat to be supplied(in kcal/hr):
Ql=-Q #Heat lost by water(in kcal/kg):
m=(Ql*10**3*4.18)/(g*z+(h2-h1)*10**3*4.18) #Quantity of water circulated(in kg/hr):

#Results:
print "Water circulation rate (kg/min):",round(m/60,2)

Water circulation rate (kg/min): 11.91


## Example 11, page no. 81¶

In [11]:
#Variable Declaration:
h1=720.0 #Enthalpy of steam entering the injector(in kcal/kg):
h2=24.6  #Enthalpy of water entering(in kcal/kg):
h3=100.0 #Enthalpy of water and steam mixture leaving the injector(in kcal/kg):
z=2.0 #Depth of water injector from steam injector(in m):
v1=50.0 #Velocity of steam entering the injector(in m/s):
v3=25.0 #Velocity of mixture leaving the injector(in m/s):
q=12.0 #Heat loss from injector to surroundings(in kcal/kg):
g=9.8 #Acceleration due to gravity (m/s^2):

#Calculation:
m=(((v3**2)/2+h3*10**3*4.18)-(h2*10**3*4.18+g*z))/(((v1**2)/2+h1*10**3*4.18)-((v3**2)/2+h3*10**3*4.18)-(q*10**3*4.18))

#Results:
print "Steam supply rate (kg/s): ",round(m,3)

Steam supply rate (kg/s):  0.124


## Example 12, page no. 82¶

In [12]:
#Variable Declaration:
p=1.013 #Atmospheric pressure(in bar):
v=0.4 #Volume to which the baloon is inflated(in m**3):
w1=0 #Work done by cylinder(in kJ):

#Calculation:
w2=p*10**5*v #Work done by the balloon(in kJ):
w=w1+w2 #Total work(in kJ):

#Results:
print "Work done by the system upon atmoshere (KJ): ",w/(10**3)
print "Work done by the atmoshere (KJ): ",-w/(10**3)

Work done by the system upon atmoshere (KJ):  40.52
Work done by the atmoshere (KJ):  -40.52


## Example 13, page no. 82¶

In [13]:
#Variable Declaration:

#Calculation:
Wt=0.25*Qa #Turbine work(in J/s):
Qr=0.75*Qa #Heat rejected(in J/s):
Wp=0.002*Qa #Work by feed pump(in J/s):
C=Wt-Wp #Capacity of generator(in W):

#Results:
print "Capacity of generator (KW): ",C/(10**3)

Capacity of generator (KW):  1.24


## Example 14, page no. 83¶

In [14]:
import math as m

#Variable Declaration:
T1=27+273 #Ambient temperature(in K):
T2=750+273 #Temperature of air inside heat exchanger(in K):
T3=600+273 #Temperature of air leaving turbine(in K):
T4=500+273 #Temperature of air leaving turbine(in K):
c2=50 #Velocity of air entering turbine(in m/s):
c3=60 #Velocity of air entering the nozzle(in m/s):
Cp=1.005#Specific heat at constant pressure(in kj?kg.K):

#Calculation:
Q12=Cp*(T2-T1) #Heat transfer to air in heat exchanger(in kJ):
Wt=Cp*(T2-T3)+(c2**2-c3**2)*10**(-3)/2 #Power output from turbine(in kJ/s):
c4=m.sqrt(2*(Cp*(T3-T4)+(c3**2)*10**(-3)/2))#Velocity at exit of the nozzle(in m/s):

#Results:
print "Heat transfer to air in heat exchanger (KJ): ",round(Q12,2)
print "Power output from turbine (KJ/s): ",Wt
print "Velocity at exit of the nozzle (m/s): ",round(c4,1)

Heat transfer to air in heat exchanger (KJ):  726.61
Power output from turbine (KJ/s):  150.2
Velocity at exit of the nozzle (m/s):  14.3


## Example 15, page no. 85¶

In [15]:
import math as m

#Variable Declaration:
p1=0.5 #Initial pressure(in MPa):
T1=400 #Initial temperature(in K):
r1=2 #Ratio of v2 to v1:
r2=6 #Ratio of v3 to v1:
R=8.314 #Universal gas constant(in kJ/kg):

#Calculation:
Wa=R*T1 #Work from state 1 to 2(in kJ):
T2=2*T1 #Temperature at point 2(in K):
Wb=R*T2*m.log(r2/r1) #Work done from state 2 to 3(in kJ):
W=Wa+Wb#Total work done by air(in kJ):

#Results:
print "Work done (KJ): ",round(W,2)

Work done (KJ):  10632.69


## Example 16, page no. 85¶

In [16]:
#Variable Declaration:
pi=0.5*10**6 #Initial pressure(in Pa):
vi=0.5 #Initial volume(in m**3):
pf=1*10**6 #Final pressure(in Pa):
patm=1.013*10**5 #Atmospheric pressure(in Pa):

#Calculation:
vf=3*vi #Final volume(in m**3):
W=(vf-vi)*(pi+pf)/2 #Work done(in J):

#Results:
print "Work done (MJ): ",W/10**6

Work done (MJ):  0.75


## Example 17, page no. 87¶

In [18]:
#Variable Declaration:
p1=0.5*10**6 #Initial pressure(in Pa):
pf=1*10**6 #Final pressure(in Pa):
v1=0.5 #Initial volume(in m**3):
v2=0.25 #Final volume(in m**3):
vN2=0.75#Final Nitrogen volume(in m**3):
T1=273+27#Initial Tempereature (K):
patm=1.013*10**5 #Atmospheric pressure(in Pa):
CpH2=14.307 #Cp of hydrogen (KJ/Kg)
CpN2=1.039 #Cp of hydrogen (KJ/Kg)
RN2=0.2968
RH2=4.1240

#Calculations:
rH2=CpH2/(CpH2-RH2) #Adiabatic index of compression for H2:
rN2=CpN2/(CpN2-RN2) #Adiabatic index of compression for N2:
p2=p1*(v1/v2)**rH2 #Final pressure of hydrogen(in Pa):
Pw=0 #Partition work:
WH2=(p1*v1-p2*v2)/(rH2-1) #Work done upon H2(in J):
WN2=-WH2 #Work done by nitrogen(in J):
mN2=round(p1*v1/(RN2*10**3*T1),1) #Mass of N2(in kg):
T2=p2*vN2*T1/(p1*v1) #Final temperature of N2(in K):
CvN2=CpN2-RN2 #Cv of N2(in kJ/kg):
QN2=mN2*CvN2*10**3*(T2-T1)+WN2 #Heat added to N2(in kJ):

#Results:
print "Final pressure of hydrogen (MPa): ",round(p2/(10**6),3)
print "Partition work (KJ): ",Pw
print "Work done by hyrogen (10^5 J): ",round(WH2/10**5)
print "Work done by nitrogen (10^5 J): ",round(WN2/10**5)
print "Heat added to nitrogen (kJ): ",round(QN2/(10**3),2)

Final pressure of hydrogen (MPa):  1.324
Partition work (KJ):  0
Work done by hyrogen (10^5 J):  -2.0
Work done by nitrogen (10^5 J):  2.0
Heat added to nitrogen (kJ):  2053.09


## Example 18, page no. 88¶

In [19]:
#Variable Declaration:
v1=2 #Volume of the cylinder(in m**3):
p1=0.5*10**6 #Pressure in the cylinder(in Pa):
T1=375 #Temperature of the cylinder(in K):
Cp=1.003 #Specific heat at const pressure(in kJ/kg.K):
Cv=0.716 #Specific heat at const volume(in kJ/kg.K):
Ra=0.287 #Gas constant for air(in kJ/kg.K):
patm=1.013*10**5 #Atmospheric pressure(in Pa):
r=1.4 #Compression ratio:

#Calculation:
m1=p1*v1/(Ra*T1) #Initial mass of air(in kg):
T2=T1*(patm/p1)**((r-1)/r) #Final temperature(in K):
m2=patm*v1/(Ra*T2) #Final mass of air left in tank(in kg):
KE=m1*Cv*T1-m2*Cv*T2-(m1-m2)*Cp*T2 #Kinetic energy available(in kJ):

#Results:
print "Amount of work available (KJ): ",round(KE/10**3,2)

Amount of work available (KJ):  482.67


## Example 19, page no. 89¶

In [20]:
#Variable Declaration:
p1=0.5*10**6 #Pressure in the vessel(in Pa):
v1=0.5 #Volume of 1st chamber(in m**3):
T1=300 #Temperature in the vessel(in K):
p2=10**6 #Final pressure(in Pa):
v2=0.5 #Volume of 2nd chamber(in m**3):
T2=500 #Final temperature(in K):
R=8314 #Universal gas constant(in J/kg.K):

#Calculation:
n1=p1*v1/(R*T1) #Moles in chamber 1:
n2=p2*v2/(R*T2) #Moles in chamber 2:
T3=(n1*T1+n2*T2)/(n1+n2) #Temperature of the mixture(in K):
p3=(n1+n2)*R*T3/(v1+v2) #Final pressure(in MPa):

#Results:
print "Final pressure (MPa): ",p3/(10**6)
print "Final temperature (K): ",round(T3,2)

Final pressure (MPa):  0.75
Final temperature (K):  409.09


## Example 20, page no. 90¶

In [21]:


#Variable Declaration:
v=0.5 #Volume of the bottle(in m**3):
p=1.0135 #Pressure in the bottle(in Bar):

#Calculation:
W=p*10**5*(0-v) #Displacement work(in N-m):
Q=-W #Heat transfer(in N-m):

#Results:
print "Heat transferred (N-m): ",Q

Heat transferred (N-m):  50675.0


## Example 21, page no. 90¶

In [22]:
#Variable Declaration:
v1=0.3 #Volume of bottle(in m**3):
p1=35.0 #Pressure in the bottle(in bar):
T1=40.0+273.0 #Temperature in the bottle(in K):
w1=5.0 #Turbo generator's actual output(in kJ/s):
v2=v1 #Final volume(in m**3):
Ra=0.287 #Gas constant for air(in kJ/kg.K):
r=1.4 #Compression ratio:
Cv=0.718 #Specific heat at const volume(in kJ/kg):
Cp=1.005 #Specific heat at const pressure(in kJ/kg):

#Calculation:
T2=T1*(p2/p1)**((r-1)/r) #Final temperature(in K):
m1=p1*10**2*v1/(Ra*T1) #Initial mass in the bottle(in kg):
m2=p2*10**2*v2/(Ra*T2) #Final mass in the bottle(in kg):
W=(m1*Cv*T1-m2*Cv*T2)-(m1-m2)*Cp*T2 #Maximum work that can be obtained(in kJ):
i=w1/0.6 #Input to the turbo generator(in kJ/s):
t=W/round(i,2) #Time duration(in s):

#Results:
print "Duration (Seconds): ",round(t,2)

Duration (Seconds):  159.11


## Example 22, page no. 91¶

In [23]:
import math as M
#Variable Declaration:
p1=1.5 #Pressure at state 1(in bar):
T1=77+273 #Temperature at state 1(in K):
p2=7.5 #Pressure at state 2(in bar):
m=3 #Mass of the air(in kg):
n=1.2 #Value of n:
Ra=0.287

#Calculation:
T2=T1*(p2/p1)**((n-1)/n) #Temperature at state 2(in K):
v1=m*Ra*T1/(p1*10**2) #Initial volume(in m**3):
v2=(p1*(v1**n)/p2)**(1/n) #Volume at state 2(in m**3):
T3=T1 #Temperature at state 3(in K):
v3=v2*T3/T2 #Volume at state 3(in m**3):
p3=7.5 #Pressure at state 3(in bar):
W12=m*Ra*(T2-T1)/(1-n) #Compression work during process 1-2(in kJ):
W23=p2*(10**2)*(v3-v2) #Work during process 2-3(in kJ):
W31=p3*10**2*v3*M.log(v1/v3) #Work during process 3-1(in kJ):
Wn=W12+W23+W31 #Net work(in kJ):

#Results:
print "Heat transferred from the system (kJ): ",round(-Wn,2)

Heat transferred from the system (kJ):  71.28


## Example 23, page no. 93¶

In [24]:
#Variable Declaration:
v1=0.15 #Volume of air bottle(in m**3):
p1=40 #Initial pressure(in bar):
T1=27+273 #Initial temperature(in K):
p2=2.0 #Final presure(in bar):
Ra=0.287 #Gas constant for air(in kJ/kg):
Cp=1.005 #Specific heat at const pressure(in kJ/kg):
Cv=0.718 #Specific heat at const volume(in kJ/kg):
r=1.4 #Compression ratio:

#Calculation:
v2=v1 #Final volume(in m**3):
m1=p1*10**2*v1/(Ra*T1) #Initial mass of air in bottle(in kg):
T2=T1*(p2/p1)**((r-1)/r) #Final temperature(in K):
m2=p2*10**2*v2/(Ra*T2) #Final mass of air in bottle(in kg):
E=m1*Cv*T1-m2*Cv*T2-(m1-m2)*Cp*T2 #Energy available for running of turbine due to emptying of bottle(in kJ):

#Results:
print "Work available from turbine(KJ):",round(E,2)

Work available from turbine(KJ): 638.33