summaryrefslogtreecommitdiff
path: root/Thermodynamics_Demystified/Chapter5.ipynb
blob: a93ee1a4661f348930e5825605f29abd154ec9f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
{
 "metadata": {
  "name": "",
  "signature": "sha256:3928ce1341a76de85540172b210e9512b16c46c42e882063576b52bdb907073d"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 5:The Second Law of Thermodynamics"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5.4:PG-112"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# initialization of variables\n",
      "Th=200+273.0 # higher temperture in kelvin \n",
      "Tl=20+273.0 # lower temperture in kelvin\n",
      "Wdot=15 # output of engine in kW\n",
      "\n",
      "ef=1-(Tl/Th) # carnot efficiency\n",
      "\n",
      "Qhdot=Wdot/ef # heat supplied by reservoir\n",
      "print \" The heat suppled by higher temperature reservoir is\",round(Qhdot,2),\"kW \\n \"\n",
      "# using forst law\n",
      "Qldot=Qhdot-Wdot # heat rejected to reservoir\n",
      "print \" The heat suppled by lower temperature reservoir is\",round(Qldot,2),\"kW\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The heat suppled by higher temperature reservoir is 39.42 kW \n",
        " \n",
        " The heat suppled by lower temperature reservoir is 24.42 kW\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5.5:PG-113"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# initialization of variables\n",
      "TL1=-5+273.0 # lower temperature in kelvin for first situation\n",
      "TH=20+273.0 # higher temperature in kelvin\n",
      "TL2=-25+273.0 #lower temperature in kelvin for second situation\n",
      "\n",
      "#solution\n",
      "\n",
      "COP1=TL1/(TH-TL1) # carnot refrigerator COP for first situation\n",
      "# Let Heat be 100 kJ\n",
      "QL=100.0 # assumption\n",
      "W1=QL/COP1 # work done for situation 1\n",
      "\n",
      "# for situation 2\n",
      "COP2=TL2/(TH-TL2) # COP carnot for second situation\n",
      "W2=QL/COP2 # work done\n",
      "\n",
      "Per=(W2-W1)*100/W1 # percentage increase in work done \n",
      "#result\n",
      "print\" The perccentage increase in work is \",round(Per,1),\"%\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The perccentage increase in work is  94.5 %\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5.6:PG-117"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# initialization of variables\n",
      "T1=20+273 # initial temperature in kelvin\n",
      "P=200 # pressure in kPa\n",
      "V=2 # volume in m^3\n",
      "R=0.287 # gas constant for air\n",
      "W=720 # work done on air in kJ\n",
      "Cv=0.717 # specific heat at constant volume for air\n",
      "\n",
      "#solution\n",
      "m=(P*V)/(R*T1) # mass of air\n",
      "\n",
      "T2=T1+(W/(m*Cv))# final temperature in kelvin\n",
      "\n",
      "delS=m*Cv*math.log(T2/T1) # ENROPY CHANGE FOR CONSTANT VOLUME PROCESS\n",
      "print \" The Entropy increase is\",round(delS,3),\"kJ/K \""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The Entropy increase is 1.851 kJ/K \n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5.7:PG-118"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# initialization of variables\n",
      "T1=350+273 # initial temperature in kelvin\n",
      "P1=1200.0 # initial pressure in kPa\n",
      "P2=140 # final pressure in kPa\n",
      "k=1.4 # polytopic index for air\n",
      "Cv=0.717 # specific heat at  constant volume for air\n",
      "#solution\n",
      "T2=T1*((P2/P1)**((k-1)/k))  # reversible adiabatic process relation\n",
      "\n",
      "w=-Cv*(T2-T1) # work done by gases in reversible adiabatic process\n",
      "print\" The work done by gases is\",round(w),\"kJ/kg\"\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The work done by gases is 205.0 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5.8:PG-120"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# initialization of variables\n",
      "T1=20+273.0 # initial temperature in kelvin\n",
      "P1=200.0 # pressure in kPa\n",
      "V=2 #volume in m^3\n",
      "R=0.287 # gas constant for air\n",
      "W=-720 # negative as work is done on air in kJ\n",
      "\n",
      "#solution\n",
      "\n",
      "m=(P1*V)/(R*T1)# mass of air\n",
      "\n",
      "u1=209.1 #specific internal energy of air at 293K and 200 kPa from table E.1\n",
      "s1=1.678 # by interpolation from table E.1\n",
      "# change  in internal energy= work done\n",
      "u2=-(W/m)+u1 # final internal energy\n",
      "T2=501.2# final temperature interpolated from table E.1 corresponding to value of u2\n",
      "s2=2.222 # value of s from table E.3 by interpolating from corresponding to value of u2\n",
      "\n",
      "P2=P1*(T2/T1) # final pressure in kPa\n",
      "\n",
      "delS=m*(s2-s1-R*math.log(P2/P1))# entropy change\n",
      "# result\n",
      "print \" The Entropy increase is\",round(delS,3),\"kJ/K \""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The Entropy increase is 1.855 kJ/K \n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5.9:PG-120"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# initialization of variables\n",
      "T1=350+273.0 # initial temperature in kelvin\n",
      "P1=1200.0 # initial pressure in kPa\n",
      "P2=140.0 # final pressure in kPa\n",
      "k=1.4 # polytopic index for air\n",
      "\n",
      "#solution\n",
      "# The values are taken from table E.1\n",
      "Pr660=23.13# relative pressure @ 660K\n",
      "Pr620=18.36# relative pressure @ 620K\n",
      "Pr1=((Pr660-Pr620)*3/40)+Pr620 # relative pressure by interpolation\n",
      "\n",
      "Pr2=Pr1*(P2/P1) # relative pressure at state 2\n",
      "\n",
      "Pr340=2.149 # relative pressure @ 340K\n",
      "Pr380=3.176 # relative pressure @ 380K\n",
      "T2=((Pr2-Pr340)/(Pr380-Pr340))*40+340 # interpolating final temperature from table E.1\n",
      "\n",
      "# now interpolating u1 AND u2 from table E.1\n",
      "u620=451.0# specific internal energy @ 620k\n",
      "u660=481.0# specific internal energy @ 660k\n",
      "u1=(u660-u620)*(3/40.0)+u620 # initial internal energy\n",
      "\n",
      "u380=271.7 #specific internal energy @ 380k\n",
      "u340=242.8 #specific internal energy @ 340k\n",
      "u2=((Pr2-Pr340)/(Pr380-Pr340))*(u380-u340)+u340 # final internal energy\n",
      "\n",
      "w=u2-u1 # work= change in internal energy\n",
      "print \" The work done by gas is\",int(w),\"kJ/kg\"\n",
      "# The answer is slightly different as values are approximated in textbook\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The work done by gas is -209 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 33
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5.10:PG-123"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# initialization of variables\n",
      "T1=300+273.0 # initial temperature in kelvin\n",
      "P1=600 # initial pressure in kPa\n",
      "P2=40 # final pressure in kPa\n",
      "\n",
      "#solution\n",
      "#please refer to steam table for values\n",
      "v1=0.4344 # specific volume from steam table @ 573k and 600 kPa\n",
      "v2=v1 # rigid container\n",
      "u1=2801.0 # specific internal energy from steam table @ 573k and 600 kPa\n",
      "s1=7.372 # specific entropy @ 600 kPa and 573 K\n",
      "\n",
      "vg2=0.4625 # specific volume of saturated vapour @ 40 kPa and 573 K\n",
      "vf2=0.0011 # specific volume of saturated liquid @ 40 kPa and 573 K\n",
      "sf2=1.777 # specific entropy of saturated liquid @ 40 kPa and 573 K\n",
      "sg2=5.1197 # specific entropy of saturated vapour @ 40 kPa and 573 K\n",
      "x=(v2-vf2)/(vg2-vf2)# quality of steam using pure substance relation\n",
      "\n",
      "s2=sf2+x*sg2 # overall specific enthalpy at quality 'x' \n",
      "delS=s2-s1 # entropy change\n",
      "print\" The entropy change  is\",round(delS,3),\"kJ/kg.K \\n \"\n",
      "\n",
      "#heat transfer\n",
      "uf2=604.3 #specific internal energy of saturated liquid @ 40 kPa and 573 K\n",
      "ug2=1949.3 #specific internal energy of saturated vapour @ 40 kPa and 573 K\n",
      "u2=uf2+x*ug2 #specific internal energy @ quality x\n",
      "q=u2-u1 # heat transfer in kJ/kg from first law as W=0\n",
      "print \" The heat transfer is\",int(q),\"kJ/kg\"\n",
      "# result\n",
      "# the answers are approximated in textbook but here they are precise thus minute difference is there"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The entropy change  is -0.787 kJ/kg.K \n",
        " \n",
        " The heat transfer is -366 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 37
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5.11:PG-126"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# initialization of variables\n",
      "v1=0.5 # assumed as air is filled in half of the tank\n",
      "v2=1.0 # final volume when partition is removed\n",
      "R=0.287 # gas contant for air\n",
      "#solution\n",
      "q=0 # heat transfer is zero\n",
      "w=0 # work done is zero\n",
      "# temperatue is constant as no change in internal energy by first law\n",
      "dels=R*math.log(v2/v1)# change in entropy when temperature is constant\n",
      "print \"The change in specific entropy is\",round(dels,3),\"kJ/kg.K\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The change in specific entropy is 0.199 kJ/kg.K\n"
       ]
      }
     ],
     "prompt_number": 49
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5.12:PG-127"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# initialization of variables\n",
      "T1=400+273.0 # initial temperature in kelvin\n",
      "P=600 # pressure in kPa\n",
      "Tsurr=25+273.0 # surrounding temperature in K\n",
      "m=2 # mass of steam in kg\n",
      "\n",
      "#solution\n",
      "#please refer to steam table for values\n",
      "s1=7.708 # specific entropy of steam @ 400 degree celsius and 0.6 MPa\n",
      "s2=1.9316# specific enropy of condensed water @ 25 degree celsius and 0.6 MPa\n",
      "delSsys=m*(s2-s1) # entropy change in system i.e of steam\n",
      "\n",
      "h1=3270 # specific enthalpy of steam @ 400 degree celsius and 0.6 MPa\n",
      "h2=670.6#specific enropy of condensed water @ 25 degree celsius and 0.6 MPa\n",
      "\n",
      "Q=m*(h1-h2)# heat transfer at constant pressure\n",
      "delSsurr=Q/Tsurr # entropy change in surroundings\n",
      "\n",
      "sigma=delSsys+delSsurr # net entropy change\n",
      "\n",
      "print \"The net entropy production is\",round(sigma,1),\"kJ/K\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The net entropy production is 5.9 kJ/K\n"
       ]
      }
     ],
     "prompt_number": 53
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5.13:PG-130"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# initialization of variables\n",
      "T1=600+273 # initial temperature in kelvin\n",
      "P1=2 # initial pressure in MPa\n",
      "P2=10 # final pressure in kPa\n",
      "mdot=2 # mass flow rate in kg/s\n",
      "\n",
      "#solution\n",
      "#please refer to steam table for values\n",
      "h1=3690 # specific enthalpy in kJ/kg @ 2MPa and 600 degree celsius\n",
      "s1=7.702 #specific entropy in kJ/kg.K @ 2MPa and 600 degree celsius\n",
      "s2=s1 # Reversible adiabatic process thus entropy is constant\n",
      "sf2=0.6491 #specific entropy of saturated liquid from steam table @ 10 kPa\n",
      "sg2=8.151 #specific entropy of saturated vapour from steam table @ 10 kPa\n",
      "\n",
      "x2=(s2-sf2)/(sg2-sf2) # quality of steam at turbine exit\n",
      "\n",
      "h2f=191.8 #specific enthalpy of saturated liquid from steam table @ 10 kPa\n",
      "h2g=2584.8 #specific enthalpy of saturated vapour from steam table @ 10 kPa\n",
      "h2=h2f+x2*(h2g-h2f) # specific enthalpy @ quality 'x' \n",
      "\n",
      "WdotT=mdot*(h1-h2)# from work done in adiabatic process\n",
      "# result\n",
      "print \" The maximum power output is\",int(WdotT),\"kJ/s\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The maximum power output is 2496 kJ/s\n"
       ]
      }
     ],
     "prompt_number": 56
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5.14:PG-130"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# initialization of variables\n",
      "\n",
      "T1=600+273 # initial temperature in kelvin\n",
      "P1=2 # initial pressure in MPa\n",
      "P2=10 # final pressure in kPa\n",
      "mdot=2 # mass flow rate in kg/s\n",
      "EffT=0.8 # efficiency of turbine \n",
      "WdotT=2496 # theoritical power of turbine in kW\n",
      "\n",
      "#solution\n",
      "Wdota=EffT*WdotT # actual power output of turbine\n",
      "h1=3690 # specific enthalpy @ 2MPa and 600 degree celsius\n",
      "h2=h1-(Wdota/mdot) # final enthalpy from first law of thermodynamics\n",
      "\n",
      "T2=((h2-2688)/(2783-2688))*(150-100)+100 # by interpolating from steam table @ P2= 10 kPa, h2=2770 \n",
      "s2=8.46 # final specific entropy by interpolation from steam table\n",
      "\n",
      "print \"The temperature by interpolation is\",round(T2),\" degree celsius \\n\"\n",
      "print \"The final entropy by interpolation is\",round(s2,2),\"kJ/kg.K\"\n",
      "# The temperature and entropy are found by interpolation from steam table and cannot be shown here.\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The temperature by interpolation is 102.0  degree celsius \n",
        "\n",
        "The final entropy by interpolation is 8.46 kJ/kg.K\n"
       ]
      }
     ],
     "prompt_number": 59
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5.15:PG-131"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# initialization of variables\n",
      "\n",
      "T2=250.0 # temperature of steam in degree celsius\n",
      "mdot2=0.5 # mass flow rate of steam in kg/s\n",
      "T1=45 # temperature of water in degree celsius\n",
      "mdot1=4 # mass flow rate of water in kg/s\n",
      "P=600.0 # pressure in kPa\n",
      "\n",
      "\n",
      "mdot3=mdot1+mdot2 # by mass balance\n",
      "\n",
      "h2=2957 # specific enthalpy in kJ/kg of steam @ 600 Kpa from steam table\n",
      "h1=188.4 # specific enthalpy in kJ/kg  of water @ 600 Kpa from steam table\n",
      "\n",
      "h3=(mdot1*h1+mdot2*h2)/mdot3 # specific enthalpy in kJ/kg at exit\n",
      "\n",
      "# by interpolation from saturated steam table\n",
      "T3=(h3-461.3)*10/(503.7-461.3)+110 # temperature of mixture\n",
      "\n",
      "sf3=1.508 # entropy of saturated liquid in kJ/kg.K at 600Kpa and T3 temperature from steam table\n",
      "s3=sf3  # by interpolating sf\n",
      "s2=7.182 # entropy of superheated steam in kJ/kg.K @ 600Kpa from steam table\n",
      "s1=0.639 # entropy of entering water in kJ/kg.K at T= 45 degree celsius\n",
      "\n",
      "sigmaprod=mdot3*s3-mdot2*s2-mdot1*s1\n",
      "# result\n",
      "print \"The rate of entropy production is\",round(sigmaprod,3),\"kW/K \""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The rate of entropy production is 0.639 kW/K \n"
       ]
      }
     ],
     "prompt_number": 60
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}