summaryrefslogtreecommitdiff
path: root/Engineering_Thermodynamics_by_P._K._Nag/ch7.ipynb
blob: 09b2856d73cac65b449354e2d793b568e6274408 (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
{
 "metadata": {
  "name": "",
  "signature": "sha256:f22779b8fff9ea06914fd530daf547f36c0e2d7163616b6b2b466ab75a676e0a"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7 : Entropy"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.1 Page No : 185"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "T1 = 37.+273;\n",
      "T2 = 35.+273;\n",
      "m = 1.;\n",
      "cv = 4.187;\n",
      "\n",
      "# Calculation\n",
      "S = m*cv*math.log(T1/T2); \t\t\t# S = S2-S1\n",
      "\n",
      "# Results\n",
      "print \"Change in the entropy of the water is %.4f KJ/K\"%S\n",
      "\n",
      "# note : answer is accurate. please check."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in the entropy of the water is 0.0271 KJ/K\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.2 Page No : 186"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Part (a)\n",
      "T1 = 273.;\n",
      "T2 = 373.;\n",
      "m = 1. ;\n",
      "cv = 4.187;\n",
      "\n",
      "# Calculation and Results\n",
      "Ss = m*cv*math.log(T2/T1); \t\t\t# S = S2-S1\n",
      "Q = m*cv*(T2-T1);\n",
      "Sr = -(Q/T2);\n",
      "S = Ss+Sr;\n",
      "\n",
      "print \"The entropy change of the universe is %.3f kJ/K\"%S\n",
      "\n",
      "# Part (b)\n",
      "T3 = 323.;\n",
      "Sw = m*cv*(math.log(T3/T1)+math.log(T2/T3));\n",
      "Sr1 = -m*cv*(T3-T1)/T3;\n",
      "Sr2 = -m*cv*(T2-T3)/T2;\n",
      "Su = Sw+Sr1+Sr2;\n",
      "print \"The entropy change of the universe is %.3f kJ/K\"%Su\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The entropy change of the universe is 0.184 kJ/K\n",
        "The entropy change of the universe is 0.097 kJ/K\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.3 Page No : 187"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "# Part (a)\n",
      "m = 1.;\n",
      "T1 = -5.+273;\n",
      "T2 = 20.+273;\n",
      "T0 = 0.+273;\n",
      "cp = 2.093;\n",
      "cv = 4.187;\n",
      "lf = 333.3;\n",
      "\n",
      "# Calculation\n",
      "Q = m*cp*(T0-T1)+1*333.3+m*cv*(T2-T0);\n",
      "Sa = -Q/T2;\n",
      "Ss1 = m*cp*math.log(T0/T1);\n",
      "Ss2 = lf/T0;\n",
      "Ss3 = m*cv*math.log(T2/T0);\n",
      "St = Ss1+Ss2+Ss3;\n",
      "Su = St+Sa;\n",
      "\n",
      "# Results\n",
      "print \"The entropy change of the universe is %.4f kJ/K\"%Su\n",
      "\n",
      "# Part (b)\n",
      "S = 1.5549; \t\t\t# S = S4-S1\n",
      "Wmin = T2*(S)-Q;\n",
      "print \"The minimum risk required is %.1f kJ\"%Wmin\n",
      "\n",
      "# rounding off error. please check."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The entropy change of the universe is 0.0965 kJ/K\n",
        "The minimum risk required is 28.1 kJ\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.5 Page No : 190"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "Vo = 8.4;\n",
      "Vh = 14.;\n",
      "n1 = Vo/22.4; \n",
      "n2 = Vh/22.4;\n",
      "R = 8.31;\n",
      "\n",
      "# Calculation\n",
      "x1 = n1/(n1+n2);\n",
      "x2 = n2/(n1+n2);\n",
      "S = -R*(n1*math.log(x1)+n2*math.log(x2));\n",
      "\n",
      "# Results\n",
      "print \"Entropy change for the process is %.2f J/K\"%S\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Entropy change for the process is 5.50 J/K\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.8 Page No : 192"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "from hornerc import horner\n",
      "import sys\n",
      "\n",
      "# Variables\n",
      "#T = poly(0,'T'); \t\t\t# T = Tf\n",
      "Tf_ = [700,-2]   #700-2*T; \t\t\t# Tf_ = Tf'\n",
      "\n",
      "# Calculation\n",
      "# Bisection method to solve for the polynomial\n",
      "def Temperature(a,b,f):\n",
      "    N = 100.;\n",
      "    eps = 1e-5;\n",
      "    if((f(a)*f(b))>0):\n",
      "        print ('no root possible f(a)*f(b)>0');\n",
      "        sys.exit(0);\n",
      "\n",
      "    if(abs(f(a))<eps):\n",
      "        print ('solution at a');\n",
      "        sys.exit(0)\n",
      "\n",
      "    if(abs(f(b))<eps):\n",
      "        print ('solution at b');\n",
      "        sys.exit(0)\n",
      "\n",
      "    while(N>0):\n",
      "        c = (a+b)/2\n",
      "        if(abs(f(c))<eps):\n",
      "            x = c ;\n",
      "            return x;\n",
      "\n",
      "        if((f(a)*f(c))<0 ):\n",
      "            b = c ;\n",
      "        else:\n",
      "            a = c ;\n",
      "        N = N-1;\n",
      "    print ('no convergence');\n",
      "    sys.exit(0);\n",
      "\n",
      "\n",
      "def p(T): \n",
      "\t return  2*T**3-700*T**2+9000000 \n",
      "T = Temperature(100,200,p);\n",
      "\n",
      "Tf_ = horner(Tf_,T);\n",
      "\n",
      "print \"The final temperature of the body C is\",Tf_,\"K\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The final temperature of the body C is 400 K\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.9 Page No : 193"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "from scipy.integrate import quad \n",
      "import sys\n",
      "from numpy import poly1d\n",
      "from sympy import Symbol\n",
      "\n",
      "# Variables\n",
      "T1 = 200.;\n",
      "T2 = 100.;\n",
      "A = 0.042;\n",
      "\n",
      "# Calculation\n",
      "def f10(T): \n",
      "\t return A*T**2\n",
      "\n",
      "Q1 =  quad(f10,T1,T2)[0]\n",
      "\n",
      "\n",
      "def f11(T): \n",
      "\t return A*T**2/T\n",
      "\n",
      "S =   quad(f11,T1,T2)[0]\n",
      "\n",
      "W = Symbol('W');\n",
      "Z = (-Q1-W)/T2 + S; \t\t\t# Polynomial to be solved for W\n",
      "\n",
      "# Bisection method to solve for the Work\n",
      "def Work(a,b,f):\n",
      "    N = 100.;\n",
      "    eps = 1e-5;\n",
      "    if((f(a)*f(b))>0):\n",
      "        print ('no root possible f(a)*f(b)>0');\n",
      "        sys.exit(0);\n",
      "\n",
      "    if(abs(f(a))<eps):\n",
      "        print ('solution at a');\n",
      "        sys.exit(0)\n",
      "\n",
      "    if(abs(f(b))<eps):\n",
      "        print ('solution at b');\n",
      "        sys.exit(0)\n",
      "\n",
      "    while(N>0):\n",
      "        c = (a+b)/2\n",
      "        if(abs(f(c))<eps):\n",
      "            x = c ;\n",
      "            return x;\n",
      "        if((f(a)*f(c))<0 ):\n",
      "            b = c ;\n",
      "        else:\n",
      "            a = c ;\n",
      "        N = N-1;\n",
      "    print ('no convergence');\n",
      "    sys.exit(0)\n",
      "\n",
      "def p(W): \n",
      "\t return  350-0.01*W \n",
      "\n",
      "W = Work(34000,36000,p);\n",
      "\n",
      "print \"The maximum work that can be recovered is\",W/1000,\"kJ\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The maximum work that can be recovered is 35 kJ\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.10 Page No : 194"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "from scipy.integrate import quad \n",
      "\n",
      "# Variables\n",
      "P1 = 0.5e06;\n",
      "V1 = 0.2\n",
      "V2 = 0.05;\n",
      "n = 1.3\n",
      "\n",
      "# Calculation\n",
      "P2 = P1*(V1/V2)**n;\n",
      "def H(p):\n",
      "    return ((P1*V1**n)/p)**(1./n);\n",
      "\n",
      "def f0(p): \n",
      "\t return H\n",
      "\n",
      "H =  quad(H,P1,P2)[0]\n",
      "\n",
      "U = H-(P2*V2-P1*V1);\n",
      "W12 = -U;\n",
      "\n",
      "# Results\n",
      "print \"Change in enthalpy is %.1f kJ\"%(H/1000)\n",
      "print \"Change in internal energy is %.2f kJ\"%(U/1000)\n",
      "print \"The change in entropy and heat transfer are\",0,\"and\",0,\"kJ\"\n",
      "print \"The work transfer during the process is %.2f kJ\"%(W12/1000)\n",
      "\n",
      "# rounding off error."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in enthalpy is 223.5 kJ\n",
        "Change in internal energy is 171.91 kJ\n",
        "The change in entropy and heat transfer are 0 and 0 kJ\n",
        "The work transfer during the process is -171.91 kJ\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.11 Page No : 195"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "from scipy.integrate import quad \n",
      "\n",
      "# Variables\n",
      "Pa = 130e03; \n",
      "Pb = 100e03;\n",
      "Ta = 50+273; \n",
      "Tb = 13+273;\n",
      "cp = 1.005;\n",
      "\n",
      "# Calculation\n",
      "def f1(T): \n",
      "\t return cp/T\n",
      "\n",
      "def f2(p):\n",
      "    return .287/p\n",
      "Ss =  quad(f1,Ta,Tb)[0] - quad(f2,Pa,Pb)[0]\n",
      "Ssy = 0;\n",
      "Su = Ss+Ssy;\n",
      "\n",
      "# Results\n",
      "print \"Change in the entropy of the universe is %.3f kJ/Kg k\"%Su\n",
      "print \"As the change in entropy of the universe in the process A-B is negative so the flow must be from B-A\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in the entropy of the universe is -0.047 kJ/Kg k\n",
        "As the change in entropy of the universe in the process A-B is negative so the flow must be from B-A\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.12 Page No : 196"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "T1 = 300.\n",
      "T2 = 330.\n",
      "T3 = 270.\n",
      "P1 = 4.\n",
      "P2 =1.\n",
      "P3 =1.\n",
      "cp = 1.0005\n",
      "R = 0.287;\n",
      "\n",
      "# Calculation\n",
      "S21 = cp*math.log(T2/T1)-R*math.log(P2/P1); \t\t\t# S21 = S2-S1\n",
      "S31 = cp*math.log(T3/T1)-R*math.log(P3/P1); \t\t\t# S31 = S3-S1\n",
      "Sgen = 1*S21 + 1*S31;\n",
      "\n",
      "# Results\n",
      "print \"The entropy generated during the process is %.3f kW/K\"%Sgen\n",
      "print \"As the entropy generated is positive so such device is possible\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The entropy generated during the process is 0.786 kW/K\n",
        "As the entropy generated is positive so such device is possible\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.13 Page No : 197"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "A = 5.*7;\n",
      "k = 0.71;\n",
      "L = 0.32;\n",
      "Ti = 21.+273;\n",
      "To = 6.+273;\n",
      "\n",
      "# Calculation and Results\n",
      "Q = k*A*(Ti-To)/L ;\n",
      "print \"The rate of heat transfer through the wall is %.2f W\"%Q\n",
      "\n",
      "Sgen_wall = Q/To - Q/Ti;\n",
      "print \"The rate of entropy through the wall is %.3f W/K\"%Sgen_wall\n",
      "\n",
      "Tr = 27+273.;\n",
      "Ts = 2+273.;\n",
      "Sgen_total = Q/Ts-Q/Tr;\n",
      "print \"The rate of total entropy generation with this heat transfer process is %.3f W/K\"%Sgen_total\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The rate of heat transfer through the wall is 1164.84 W\n",
        "The rate of entropy through the wall is 0.213 W/K\n",
        "The rate of total entropy generation with this heat transfer process is 0.353 W/K\n"
       ]
      }
     ],
     "prompt_number": 11
    }
   ],
   "metadata": {}
  }
 ]
}