summaryrefslogtreecommitdiff
path: root/Thermodynamics/Chapter5.ipynb
blob: 4cdef356752c47d9ecddd8bfad1f2a10fc5599a1 (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
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
{
 "metadata": {
  "name": "",
  "signature": "sha256:a6720a62663d7e9e40aacc296786087fbeb2c2cce5605db25fafd27c8d98c84c"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 5:FIRST LAW,INTERNAL ENERGY AND ENTHALPY"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Exapmle 5.1, Page No:169"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "Q12=-250; # Heat transfer during Discharging of battery in kcal\n",
      "W21=-0.53; # Consumption of electricity dring Charging process in kWh\n",
      "\n",
      "#Calculation\n",
      "Q21=(W21*3600)-(Q12*4.1868); # First law of thermodynamics\n",
      "\n",
      "#Result\n",
      "print \"Heat loss from battery during charging process = \",Q21,\"kJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat loss from battery during charging process =  -861.3 kJ\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.2, Page No:173"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "m=5; # Mass of water in a tank in kg\n",
      "T1=30; # Temperature of water at initial state (1) in degree celcius\n",
      "T2=95; # Temperature of water at final state (2) in degree celcius\n",
      "Qout=70; # Heat transfer from the water tank to the surrounding air in kJ\n",
      "W=75; #Electric energy input to a stirrer inside water in kJ\n",
      "mf=32.3; # Mass of fel in bomb in grams\n",
      "u1=125.78; # Internal energy of water from steam table (uf at T1) in kJ/kg\n",
      "u2=397.88; # Internal energy of water from steam table (uf at T2) in kJ/kg\n",
      "\n",
      "#Calculation\n",
      "Qf=m*(u2-u1)-W+Qout; # From First law of thermodynamics\n",
      "qf=Qf/(mf*10**-3); # Heat consumption per unit mass of fuel \n",
      "\n",
      "#Result\n",
      "print \"Heat consumption per unit mass of fuel =\",round(qf,0),\"kJ/kg\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat consumption per unit mass of fuel = 41966.0 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.3, Page No:173"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "V=50; # Volume of water in a tank in litres\n",
      "T1=120; # Temperature of water at initial state (1) in degree celcius\n",
      "x1=0.6; # Dryness fraction at initial state (1)\n",
      "T2=-10; # Temperature of water at final state (2) in degree celcius\n",
      "vf1=0.00106; # specific volume of water from steam tables at T1 in m^3/kg\n",
      "vg1=0.8919; # specific volume of water from steam tables at T1 in m^3/kg\n",
      "v1=(1-x1)*vf1+x1*vg1; # Specific volume of misture of liquid and water at state (1)\n",
      "m=(V*10**-3)/v1; # Mass of water in the tank\n",
      "vs2=0.0010891; # Specific volume of saturated ice at T2 in m^3/kg\n",
      "vg2=466.7; # Specific volume of water vapour at T2 in m^3/kg\n",
      "v2=v1; # constant specific volume during cooling process\n",
      "x2=(v2-vs2)/(vg2-vs2); # Dryness fraction at state (2)\n",
      "uf1=503.5; # Specific internal energy at state (1) in kJ/kg\n",
      "ug1=2529.3; # Specific internal energy at state (1) in kJ/kg\n",
      "us2=-354.09; # Specific internal energy at state (2) in kJ/kg\n",
      "ug2=2361.4; # Specific internal energy at state (2) in kJ/kg\n",
      "\n",
      "#Calculation\n",
      "u1=(1-x1)*uf1+x1*ug1; # Total Specific internal energy at state (1) in kJ/kg\n",
      "u2=(1-x2)*us2+x2*ug2; # Total Specific internal energy at state (2) in kJ/kg\n",
      "Q12=m*(u2-u1); # Heat transfer during cooling pocess\n",
      "\n",
      "#Result\n",
      "print \"Heat transfer during cooling pocess = \",round(Q12,1),\"kJ   (round off error)\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat transfer during cooling pocess =  -193.3 kJ   (round off error)\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.4, Page No:174"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "V1=0.3; # Initial volume of water upto stop 1 in m^3\n",
      "p1=1; # Initial pressure of water in bar\n",
      "x1=0.2; # Dryness fraction at initial state (1)\n",
      "p2=3; # Pressur required to lift the piston in bar\n",
      "V4=0.45; # Volume of water upto stop 2 in m^3\n",
      "vf1=0.001043; # Specific volume at state (1) from steam table in m^3/kg\n",
      "vg1=1.694; # Specific volume at state (1) from steam table in m^3/kg\n",
      "\n",
      "#Calculation for (a)\n",
      "v1=vf1+x1*(vg1-vf1); # Total Specific volume at state (1) from steam table in m^3/kg\n",
      "m=V1/v1; # Mass of water\n",
      "v3=V4/m; # Specific volume at stop 2\n",
      "v2=v1; p3=p2; v4=v3; V3=V4; V2=V1; # From process diagram\n",
      "#  (a)\n",
      "p4=0.361; # Final Pressure at v4 from steam table in Mpa\n",
      "\n",
      "#Result for (a)\n",
      "print \"(a)\",\"\\nFianl pressure = \",p4,\"MPa\"\n",
      "\n",
      "#Calculation for (b)\n",
      "#  (b)\n",
      "W14=p2*10**2*(V3-V2); # Work done in process \n",
      "uf1=417.36; # Specific internal energ at initial state in kJ/kg\n",
      "ufg1=2088.7; # Specific internal energ at initial state in kJ/kg\n",
      "u1=uf1+x1*ufg1;  # Total Specific internal energr at initial state in kJ.kg\n",
      "u4=2550.2; # Specific internal energ at final state in kJ/kg\n",
      "Q14=m*(u4-u1)+W14; # From first law of thermodynamics\n",
      "\n",
      "#Result for (b)\n",
      "print \"\\n\\n(b)\",\"\\nWork done during the process = \",W14,\"kJ\",\"\\nHeat transfer during the process = \",round(Q14,1),\"kJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a) \n",
        "Fianl pressure =  0.361 MPa\n",
        "\n",
        "\n",
        "(b) \n",
        "Work done during the process =  45.0 kJ \n",
        "Heat transfer during the process =  1560.0 kJ\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.5, Page No:177"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "V1=0.01; # Initial Volume of Freon 12 vapour in cylinder in m^3\n",
      "T1=15; # Initial Temperature of Freon 12 vapour in degree celcius\n",
      "p1=4.914; # Initial pressure (Psat at T1) in bar\n",
      "p2=9; # Final pressure of Freon 12 vapour after compression in bar\n",
      "T2=65; # Final temperature of Freon 12 vapour after compression in degree celcius\n",
      "Q=-0.5; # Heat lost to surroundings during compresson process in kJ\n",
      "v1=0.035413; # Initial specific volume of Freon 12 vapour from table in m^3/kg\n",
      "\n",
      "#Calculation\n",
      "m=V1/v1; # Mass of vapour\n",
      "hg1=193.644; # specific enthalpy of Freon 12 vopour at state 1 in kJ/kg\n",
      "u1=hg1-(p1*10**2*v1); # Total Specific internal energy at state 1\n",
      "h2=222.9; # specific enthalpy of Freon 12 vapour at state 2 in kJ/kg\n",
      "v2=0.022537; # specific volume of Freon 12 vapour at state 2 in m^3/kg\n",
      "u2=h2-(p2*10**2*v2); # Total Specific internal energy at state 2\n",
      "W=-m*(u2-u1)+Q; # From first law of thermodynamics\n",
      "\n",
      "#Result\n",
      "print \"Work of compression = \",round(W,2),\"kJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work of compression =  -7.95 kJ\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.6, Page No:181"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "tS=-10; # initial temperature of ice in degree celcius\n",
      "ts=0; # Melting temperature of ice in degree celcius\n",
      "Cs=1.94; # Specific heat of ice in kJ/kg k\n",
      "m=1000; # Mass of ice in kg\n",
      "tF=10; # Temperature of water after 24 hours in degree celcius\n",
      "tf=0; # Freezing temperature of water in degree celcius\n",
      "Cf=4.1868; # Specific heat of water in kJ/kg K\n",
      "hsg=335; # Latent heat of fusion of ice in kJ/kg\n",
      "\n",
      "#Calculation\n",
      "Q=m*(Cs*(ts-tS)+hsg+Cf*(tF-tf)); # Heat gain of water\n",
      "Q_dot=Q/(24*3600); # Rate of cooling\n",
      "\n",
      "#Result\n",
      "print \"Rate of cooling = \",round(Q_dot,3),\"kW\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Rate of cooling =  4.586 kW\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.7, Page No:188"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "T1=300; # Temperature of air at state 1 in Kelvin\n",
      "T2=500; # Temperature of air at state 2 in Kelvin\n",
      "m_=28.966; # Molecular weight oh air in kg\n",
      "Cpoav=1.017; # Average value of specific heat of air in kJ/kg K\n",
      "\n",
      "#Calculation for (a)\n",
      "# (a). change in enthalpy\n",
      "h_=27.43*(T2-T1)+3.09*10**-3*(T2**2-T1**2)-0.2296*10**-6*(T2**3-T1**3); #change in enthalpy during process in kJ/kmol\n",
      "h=h_/m_; # change in enthalpy during process in kJ/kg\n",
      "\n",
      "#Result for (a)\n",
      "print \"(a).change in enthalpy during process = \",round(h,2),\"kJ/kg\"\n",
      "\n",
      "#Calculation for (b)\n",
      "# (b).change in enthalpy\n",
      "h=Cpoav*(T2-T1); # change in enthalpy in kJ/kg\n",
      "\n",
      "#Result for (b)\n",
      "print \"(b).change in enthalpy during process with average specfic heat = \",h,\"kJ/kg\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a).change in enthalpy during process =  205.69 kJ/kg\n",
        "(b).change in enthalpy during process with average specfic heat =  203.4 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.8, Page No:189"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "m=0.1; # mass of nitrogen gas in kg\n",
      "V1=0.1; # Initial volme of nitrogen gas in m^3\n",
      "p1=1.2; # Initial pressure of nitrogen gas in bar\n",
      "V2=0.075; # Final volume of nitrogen gas in m^3\n",
      "Cpo=1.041; # Specific heat at constant pressure of nitrogen in kJ/kg K\n",
      "R=0.2969393; # Characteristic gas constant of nitrogen in Kj/kg K\n",
      "\n",
      "#Calculation\n",
      "T1=(p1*10**2*V1)/(m*R); # Initial temperature of nitrogen gas \n",
      "T2=T1*(V2/V1); # Final temperature of nitrogen gas (constant pressure process)\n",
      "Q=m*Cpo*(T2-T1); # Heat transfer to surroundings\n",
      "W=p1*10**2*(V2-V1); # Work done\n",
      "\n",
      "#Result\n",
      "print \"Final Temperature of nitrogen gas = \",round(T2,0),\"K\",\"\\nHeat transfer to surroundings = \",round(Q,1),\"kJ\"\n",
      "print \"Work done = \",W,\"kJ\",\"  The Work is done on the gas\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Final Temperature of nitrogen gas =  303.0 K \n",
        "Heat transfer to surroundings =  -10.5 kJ\n",
        "Work done =  -3.0 kJ   The Work is done on the gas\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.9, Page No:190"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "p=1; # pressure inside piston cylinder arrangement in MPa\n",
      "# stae 1 = saturated liquid\n",
      "# state 2 = saturated vapour\n",
      "# state 3 = superheated vapour\n",
      "v1=0.001127; # specific volume at state 1 in m^3/kg\n",
      "v2=0.19444; # specific volume at state 2 in m^3/kg\n",
      "v3=0.4011; # specific volume at state 3 in m^3/kg\n",
      "u1=761.68; # specific internal energy at state 1 in kK/kg\n",
      "u2=2583.6; # specific internal energy at state 2 in kK/kg\n",
      "u3=3296.8; # specific internal energy at state 3 in kK/kg\n",
      "h1=762.81; # specific enthalpy at state 1 in kJ/kg\n",
      "h2=2778.1; # specific enthalpy at state 2 in kJ/kg\n",
      "h3=3697.9; # specific enthalpy at state 3 in kJ/kg\n",
      "\n",
      "#Calculation for (Method I)\n",
      "w12=p*10**3*(v2-v1); # Work done during process 1-2\n",
      "w23=p*10**3*(v3-v2); # Work done during process 2-3\n",
      "wtotal=w12+w23; # Total work done\n",
      "# Calculation of heat transfer\n",
      "# Method I\n",
      "q12=(u2-u1)+w12; # Heat transfer during process 1-2\n",
      "q23=(u3-u2)+w23; # Heat transfer during process 2-3\n",
      "qtotal=q12+q23; # Total Heat transfer\n",
      "\n",
      "#Results for (Method I)\n",
      "print \"Work done = \",round(wtotal,0),\"kJ/kg\"\n",
      "print \"\\n\\nCalculation of Heat Transfer\",\"\\nMethod I\",\"\\nHeat Transfer = \",round(qtotal,1),\"kJ/kg\"\n",
      "\n",
      "#Calculation for (Method II)\n",
      "# Method II\n",
      "q12=h2-h1; # Heat transfer during process 1-2\n",
      "q23=h3-h2; # Heat transfer during process 2-3\n",
      "qtotal=q12+q23; # Total Heat transfer\n",
      "\n",
      "#Result for (Method II)\n",
      "print \"\\nMethod II\",\"\\nHeat Transfer = \",round(qtotal,1),\"kJ/kg\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work done =  400.0 kJ/kg\n",
        "\n",
        "\n",
        "Calculation of Heat Transfer \n",
        "Method I \n",
        "Heat Transfer =  2935.1 kJ/kg\n",
        "\n",
        "Method II \n",
        "Heat Transfer =  2935.1 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.10, Page No:191"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from __future__ import division\n",
      "#Variable declaration\n",
      "p1=1; # initial pressure of air in piston cylinder arrangement in bar\n",
      "T=300; # Temperature of air in piston cylinder arrangement in kelvin\n",
      "p2=10; # Final pressure of air in piston cylinder arrangement in bar\n",
      "R=0.287; # Characteristic gas constant of air in kJ/kg K\n",
      "\n",
      "#Calculation\n",
      "w=R*T*math.log(p1/p2); # Work done\n",
      "q=w; # From first law of thermodynamics\n",
      "\n",
      "#Results\n",
      "print \"The change in internal energy during the isothermal process is zero\"\n",
      "print \"Work done = \",round(w,1),\"kJ/kg\",\"\\nHeat transfer = \",round(q,1),\"kJ/kg\"\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The change in internal energy during the isothermal process is zero\n",
        "Work done =  -198.3 kJ/kg \n",
        "Heat transfer =  -198.3 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.12, Page No:195"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "p1=65;# (Error in textbook) # Pressure of air at state 1 in bar\n",
      "v1=0.0135; # Volume of air at state 1 in m^3\n",
      "v2=0.1; # Volume of air at state 2 in m^3\n",
      "R=0.287; # Characteristic gas constant of air in kJ/kg K\n",
      "Cvo=0.7165; # Specific heat at constant volume in kJ/kg K\n",
      "\n",
      "#Calculation for (a)\n",
      "# (a).Adiabatic process\n",
      "k=1.4; # Index of adiabatic process\n",
      "p2=p1*(v1/v2)**k; # Pressure of air at state 2 \n",
      "T1=p1*10**2*v1/R;# Tempewrature of air at state 1\n",
      "T2=p2*10**2*v2/R;# Tempewrature of air at state 2\n",
      "w=R*(T2-T1)/(1-k); # work done\n",
      "q=0; # Adiabatic expansion process\n",
      "delta_u=Cvo*(T2-T1); # Change in internal energy of air\n",
      "\n",
      "#Result for (a)\n",
      "print \"(a).Adiabatic Process\",\"\\nFinal Temperature = \",round(T2,1),\"K\",\"\\nWork done = \",round(w,1),\"kJ\"\n",
      "print \"Change in internal energy of air = \",round(delta_u,1),\"kJ\",\"\\nHeat Ineraction = \",round(q,1),\"kJ\"\n",
      "\n",
      "#Calculation for (b)\n",
      "# (b).Polytropic  process\n",
      "n=1.3; # Index of adiabatic process\n",
      "p2=p1*(v1/v2)**n; # Pressure of air at state 2 \n",
      "T1=p1*10**2*v1/R;# Tempewrature of air at state 1\n",
      "T2=p2*10**2*v2/R;# Tempewrature of air at state 2\n",
      "w=R*(T2-T1)/(1-n); # work done\n",
      "delta_u=Cvo*(T2-T1); # Change in internal energy of air\n",
      "q=delta_u+w; # Adiabatic expansion process\n",
      "\n",
      "#Result for (b)\n",
      "print \"\\n\\n(b).Polytropic Process\",\"\\nFinal Temperature = \",round(T2,1),\"K\",\"\\nWork done = \",round(w,1),\"kJ\"\n",
      "print \"Change in internal energy of air = \",round(delta_u,1),\"kJ\",\"\\nHeat Ineraction = \",round(q,1),\"kJ\"\n",
      "\n",
      "#Calculation for (c)\n",
      "# (c).Isothermal process\n",
      "T1=p1*10**2*v1/R;# Tempewrature of air at state 1\n",
      "T2=T1; # Tempewrature of air at state 2\n",
      "p2=p1*(v1/v2); # Pressure of air at state 2\n",
      "w=R*T1*math.log (v2/v1); # work done\n",
      "delta_u=Cvo*(T2-T1); # Change in internal energy of air\n",
      "q=delta_u+w; # Adiabatic expansion process\n",
      "\n",
      "#Result for (c)\n",
      "print \"\\n\\n(c).Isothermal Process\",\"\\nFinal Temperature = \",round(T2,1),\"K\",\"\\nWork done = \",round(w,1),\"kJ\"\n",
      "print \"Change in internal energy of air = \",round(delta_u,1),\"kJ\",\"\\nHeat Ineraction = \",round(q,1),\"kJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a).Adiabatic Process \n",
        "Final Temperature =  137.2 K \n",
        "Work done =  120.9 kJ\n",
        "Change in internal energy of air =  -120.7 kJ \n",
        "Heat Ineraction =  0.0 kJ\n",
        "\n",
        "\n",
        "(b).Polytropic Process \n",
        "Final Temperature =  167.7 K \n",
        "Work done =  132.1 kJ\n",
        "Change in internal energy of air =  -98.9 kJ \n",
        "Heat Ineraction =  33.2 kJ\n",
        "\n",
        "\n",
        "(c).Isothermal Process \n",
        "Final Temperature =  305.7 K \n",
        "Work done =  175.7 kJ\n",
        "Change in internal energy of air =  0.0 kJ \n",
        "Heat Ineraction =  175.7 kJ\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.13, Page No:201"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "m=10; # mass flow rate of chilled water in kg/s\n",
      "V1=50; #velocity of chilled water at section 1 in m/s\n",
      "z1=30; # Elevation of section 1 in m\n",
      "V2=10; #velocity of chilled water at section 2 in m/s\n",
      "z2=60; # Elevation of section 2 in m\n",
      "h1=21; # Enthalpy of chilled water at section 1 in kJ/kg\n",
      "h2=43; # Enthalpy of chilled water at section 2 in kJ/kg\n",
      "W=35; # Rate of work done by pump in kW\n",
      "g=9.80665; # Acceleration due to gravity in m/s^2\n",
      "\n",
      "#Calculation \n",
      "Q=m*(h2-h1)+(m*(V2**2-V1**2)/2000)+(m*g*(z2-z1)/1000)-W; # Steady flow energy equation\n",
      "\n",
      "#Result\n",
      "print \"The rate of Heat Transfer From Building (Error in textbook)= \",round(Q,2),\"kW\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The rate of Heat Transfer From Building (Error in textbook)=  175.94 kW\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.14, Page No:206"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "p1=1; # Suction pressure of air in bar\n",
      "p2=5; # Delivery pressure of air in bar\n",
      "T1=310; # Suction Temperature of air in kelvin\n",
      "Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K\n",
      "# (a) Polytropic compression\n",
      "T2=475; # Delivery Temperature of air in kelvin\n",
      "Q=-0.15; # Heat loss to the cooling water in kW\n",
      "Wpoly=-5.3; # Power consumption of compressor in kW\n",
      "\n",
      "#Calculation for (a)\n",
      "m=(-Wpoly+Q)/(Cpo*(T2-T1)); # mass flow rate of air from SSSF energy equation\n",
      "n=1/((1-((math.log (T2/T1))/(math.log (p2/p1))))); # Index of polytropic process\n",
      "\n",
      "#Result for (a)\n",
      "print \"(a).Polytropic compression\",\"\\nmass flow rate of air = \",round(m,3),\"kg/s\",\"\\nIndex of polytropic process = \",round(n,4)\n",
      "\n",
      "#Calculation for (b)\n",
      "# (b) Adiabatic compression\n",
      "k=1.4; # Index of adiabatic process\n",
      "Wad=-m*Cpo*T1*((p2/p1)**((k-1)/k)-1); # power consumption of compressor\n",
      "\n",
      "#Result for (b)\n",
      "print \"\\n(b).Adiabatic compression\",\"\\nPower consumption of compressor = \",round(Wad,2),\"kW\"\n",
      "\n",
      "#Calculation for (c)\n",
      "# (c).Difference between specific work\n",
      "wdiff=(abs(Wad)-abs(Wpoly))/m; # Difference between specific work\n",
      "\n",
      "#Result for (c)\n",
      "print \"\\n(c).Difference between specific work\",\"\\nDifference between specific work = \",round(wdiff,2),\"kJ/kg   (roundoff error)\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a).Polytropic compression \n",
        "mass flow rate of air =  0.031 kg/s \n",
        "Index of polytropic process =  1.3608\n",
        "\n",
        "(b).Adiabatic compression \n",
        "Power consumption of compressor =  -5.65 kW\n",
        "\n",
        "(c).Difference between specific work \n",
        "Difference between specific work =  11.22 kJ/kg   (roundoff error)\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.15, Page No:208"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "W=500; # Power output from steam turbine in MW\n",
      "Q=10; # Heat loss to surroundings in MW\n",
      "p1=12.5; # Pressure of staem at steam turbine inlet in MPa\n",
      "p2=10; # Pressure of staem at steam turbine outlet in kPa\n",
      "V1=50; # Velocity of steam at steam turbine inlet in m/s\n",
      "V2=100; # Velocity of steam at steam turbine outlet in m/s\n",
      "x2=0.85; # Quality of steam at steam turbine outlet\n",
      "h1=3341.8; # Specific enthalpy of staem at inlet from steam table in kJ/kg\n",
      "hf2=191.83; hg2=2584.7;# Specific enthalpies of fluid and steam at outlet from steam table in kJ/kg\n",
      "\n",
      "#Calculation\n",
      "h2=(1-x2)*hf2+x2*hg2;# Specific enthalpy of staem at outlet in kJ/kg\n",
      "m=(W-Q)*10**3/((h1-h2)+(V1**2-V2**2)/2000); # Mass flow rate of steam\n",
      "\n",
      "#Result\n",
      "print \"Mass flow rate of steam = \",round(m,0),\"kg/s\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mass flow rate of steam =  441.0 kg/s\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.16, Page No:212"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "p1=3; # Pressre of air at state 1 in bar\n",
      "p2=p1; # constant pressure process\n",
      "T1=450; # Temperature of air at state 1 in kelvin\n",
      "T2=1250; # Temperature of air at state 2 in kelvin\n",
      "T3=1000; # Temperature of air at state 3 in kelvin\n",
      "V3=50; # Velocity of air at state 3 in m/s\n",
      "T4=800; # Temperature of air at state 4 in kelvin\n",
      "Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K\n",
      "\n",
      "#Calculation for (a)\n",
      "# (a).Combustion chamber\n",
      "q=Cpo*(T2-T1); # Heat added to air\n",
      "\n",
      "#Result for (a)\n",
      "print \"(a).Combustion chamber\",\"\\nHeat added to air = \",q,\"kJ/kg   (round off error)\"\n",
      "\n",
      "#Calculation for (b)\n",
      "# (b).Turbine \n",
      "k=1.4; # Index of adiabatic process\n",
      "w=Cpo*(T2-T3)-V3**2/2000; # Work done \n",
      "\n",
      "#Result for (b)\n",
      "print \"\\n(b).Turbine\",\"\\nWork done = \",w,\"kJ/kg   (round off error)\"\n",
      "\n",
      "#Calculation for (c)\n",
      "# (c).Nozzle\n",
      "V4=math.sqrt (2*Cpo*10**3*(T3-T4)+V3**2); # Velocity of air leaving the nozzle\n",
      "\n",
      "#Result for (c)\n",
      "print \"\\n(c).Nozzle\",\"\\nVelocity of air leaving the nozzle = \",round(V4,0),\"m/s   (round off error)\"\n",
      "\n",
      "#Calculation for (d)\n",
      "# (d).Pressure drop\n",
      "p3=p2*(T3/T2)**(k/(k-1)); # Pressure of air leaving turbine\n",
      "p4=p3*(T4/T3)**(k/(k-1)); # Pressure of air leaving nozzle\n",
      "\n",
      "#Result for (d)\n",
      "print \"\\n(d).Pressure drop\",\"\\nPressure of air leaving turbine = \",round(p3,3),\"bar\"\n",
      "print \"Pressure of air leaving nozzle = \",round(p4,2),\"bar\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a).Combustion chamber \n",
        "Heat added to air =  802.8 kJ/kg   (round off error)\n",
        "\n",
        "(b).Turbine \n",
        "Work done =  249.625 kJ/kg   (round off error)\n",
        "\n",
        "(c).Nozzle \n",
        "Velocity of air leaving the nozzle =  636.0 m/s   (round off error)\n",
        "\n",
        "(d).Pressure drop \n",
        "Pressure of air leaving turbine =  1.374 bar\n",
        "Pressure of air leaving nozzle =  0.63 bar\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.17, Page No:213"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "V=1000; # Speed of aircraft in kmph\n",
      "p1=0.35; # Ambient pressure in bar\n",
      "T1=258; # Ambient temperature in kelvin\n",
      "V1=V*1000/3600; # unit conversion kmph into m/s\n",
      "p=1.01325; # Atmospheric pressure in bar\n",
      "Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K\n",
      "k=1.4; # Index of compression process\n",
      "\n",
      "#Calculation\n",
      "T2=T1+(V1**2)/(2*Cpo*10**3); # The temperature after leaving inlet diffuser\n",
      "p2=p1*(T2/T1)**(k/(k-1)); # Pressure after leaving inlet diffuser\n",
      "r=p/p2; # Pressre ratio of compressor required for pressurization\n",
      "\n",
      "#Result\n",
      "print \"The temperature after leaving inlet diffuser = \",round(T2,1),\"K\"\n",
      "print \"Pressre ratio of compressor required for pressurization = \",round(r,2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The temperature after leaving inlet diffuser =  296.4 K\n",
        "Pressre ratio of compressor required for pressurization =  1.78\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.18, Page No:214"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "p1=50; # Pressre of steam at diffuser inlet in kPa\n",
      "T1=150; # Temperature of steam at diffuser inlet in degree celcius\n",
      "V1=180; # Velocity of steam at diffuser inlet in m/s\n",
      "A1=1000; # area of diffuser inlet in cm^2\n",
      "V2=90; # Velocity of steam at diffuser outlet in m/s\n",
      "p2=1; # Pressre of steam at diffuser outlet in bar\n",
      "Q=120; # Heat loss to the surroundings in kW\n",
      "v1=3.24; # Specific volume of steam from superheated steam table in m^3/kg at inlet\n",
      "h1=2645.9; #  # Specific enthalpy of steam from superheated steam table in m^3/kg at inlet\n",
      "\n",
      "#Calculation\n",
      "m=V1*A1*10**-4/v1; # Mass flow rate of steam\n",
      "q=Q/m; # Heat transfer per unit mass of steam\n",
      "h2=q+h1+(V1**2-V2**2)/2000; #  Specific enthalpy of steam from SSSF energy equationat outlet\n",
      "v2=1.704; # Specific volume of steam from superheated steam table in m^3/kg at outlet\n",
      "A2=m*v2/V2; # Area of diffuser exit and Answer given in the textbook is wrong\n",
      "\n",
      "#Result\n",
      "print \"Area of diffuser exit = \",round(A2*10**4,0),\"cm^2   (Answer was wrong in textbook because that\"   \n",
      "print \"the value considered in the textbook for V2 is incorrect. So there is a difference in solution.)\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Area of diffuser exit =  1052.0 cm^2   (Answer was wrong in textbook because that\n",
        "the value considered in the textbook for V2 is incorrect. So there is a difference in solution.)\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.19, Page No:217"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import matrix\n",
      "from numpy import linalg\n",
      "\n",
      "#Variable declaration\n",
      "p=0.15; # Pressure of Freon-12 gas in MPa\n",
      "T1=10; # Temperature of Freon-12 gas in degree celcius\n",
      "T2=35; # Temperature of Freon-12 gas in degree celcius\n",
      "h1=196.762; # Specific enthalpy of Freon-12 from table at 1 in kJ/kg \n",
      "h2=69.49; # Specific enthalpy of Freon-12 from table at 2 in kJ/kg \n",
      "h3=178.54; # Specific enthalpy of Freon-12 from table at 3 in kJ/kg \n",
      "\n",
      "#Calculation\n",
      "# For solving Conservation of mass and SSSF energy equations\n",
      "A=[[1,-1],[h3,-h2]];\n",
      "B=[[1] ,[h1]];\n",
      "M=linalg.solve(A, B) \n",
      "\n",
      "#Result\n",
      "print \"Mass of saturated liquid at 35 oC = \",round(M.item(1),3),\"kg/s\"\n",
      "print \"Mass of saturated vapour at 0.15 MPa = \",round(M.item(0),3),\"kg/s\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mass of saturated liquid at 35 oC =  0.167 kg/s\n",
        "Mass of saturated vapour at 0.15 MPa =  1.167 kg/s\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.20, Page No:219"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "p1=15;# Inlet pressure of condenser in kPa\n",
      "x=0.92; # Quality of steam\n",
      "ms=25; # mass flow rate of steam in kg/s\n",
      "d_t=12; # temperature rise of water \n",
      "Cpw=4.1868; # Specific heat of water in kJ/kg K\n",
      "hfg=225.94; h4_3=2599.1; # specific enthalpy in kJ/kg\n",
      "\n",
      "#Calculation\n",
      "h1=(1-x)*hfg+x*h4_3; # specific enthalpy \n",
      "h2=225.94; # specific enthalpy in kJ/kg\n",
      "Q=ms*(h1-h2); # Heat transfer rate in condenser\n",
      "mw=Q/(Cpw*d_t); # Mass flow rate of water \n",
      "\n",
      "#Result\n",
      "print \"Heat transfer rate in condenser = \",round(Q,0),\"kW\",\"\\nMass flow rate of water = \",round(mw,1),\"kg/s\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat transfer rate in condenser =  54583.0 kW \n",
        "Mass flow rate of water =  1086.4 kg/s\n"
       ]
      }
     ],
     "prompt_number": 19
    }
   ],
   "metadata": {}
  }
 ]
}