summaryrefslogtreecommitdiff
path: root/Basic_And_Applied_Thermodynamics_by_P._K._Nag/Chapter9.ipynb
blob: ceef1a802f798e092e44986d01a3caa6c0557997 (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
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 09:Properties of pure substances"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.1:pg-302"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.1\n",
      "\n",
      " At 1 MPa, \n",
      " saturation temperature is  179.91  degree celcius\n",
      "\n",
      " Changes in specific volume is  0.193313  m**3/kg\n",
      "\n",
      " Change in entropy during evaporation is  4.4478  kJ/kg K\n",
      "\n",
      " The latent heat of vaporization is  2015.3  kJ/kg\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "# At 1 MPa\n",
    "tsat = 179.91 # Saturation temperature in degree Celsius\n",
    "vf = 0.001127 # Specific volume of fluid in m**3/kg\n",
    "vg = 0.19444 # Specific volume of gas in m**3/kg \n",
    "sf = 2.1387 # Specific entropy of fluid in kJ/kgK\n",
    "sg = 6.5865# Specific entropy of gas in kJ/kgK\n",
    "print \"\\n Example 9.1\"\n",
    "vfg = vg-vf # Change in specific volume due to evaporation\n",
    "sfg = sg-sf# Change in specific entropy due to evaporation\n",
    "hfg = 2015.3\n",
    "print \"\\n At 1 MPa, \\n saturation temperature is \",tsat ,\" degree celcius\"\n",
    "print \"\\n Changes in specific volume is \",vfg ,\" m**3/kg\"\n",
    "print \"\\n Change in entropy during evaporation is \",sfg ,\" kJ/kg K\"\n",
    "print \"\\n The latent heat of vaporization is \",hfg ,\" kJ/kg\"\n",
    "# Data is given in the table A.1(b) in Appendix in the book\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.2:pg-302"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.2\n",
      "\n",
      " pressure =  0.6  Mpa\n",
      " Temperature =  158.85  degree centigrade\n",
      " Specific volume =  0.3156  m**3/kg\n",
      " enthalpy =  2756.8  kJ/kg\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "# Given that\n",
    "s = 6.76 # Entropy of saturated steam in kJ/kgK\n",
    "print \"\\n Example 9.2\"\n",
    "# From the table A.1(b) given in the book at s= 6.76 kJ/kgK\n",
    "p = 0.6\n",
    "t=158.85\n",
    "v_g=0.3156\n",
    "h_g=2756.8\n",
    "print \"\\n pressure = \",p ,\" Mpa\\n Temperature = \",t ,\" degree centigrade\\n Specific volume = \",v_g ,\" m**3/kg\\n enthalpy = \",h_g ,\" kJ/kg\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.3:pg-302"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.3\n",
      "\n",
      " The enthalpy and entropy of the system are\n",
      "  2614.55463998  kW and  5.96006442363  kJ/kg and kJ/kg K respectively.\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "v = 0.09  # Specific volume of substance at a point in m**3/kg\n",
    "vf = 0.001177 # Specific volume of fluid in m**3/kg\n",
    "vg = 0.09963  # Specific volume of gas in m**3/kg\n",
    "hf = 908.79 # Specific enthalpy of fluid in kJ/kg\n",
    "hfg = 1890.7 # Latent heat of substance in kJ/kg\n",
    "sf = 2.4474 # Specific entropy of fluid in kJ/kgK\n",
    "sfg = 3.8935 # Entropy change due to vaporization\n",
    "\n",
    "print \"\\n Example 9.3\"\n",
    "x = (v-vf)/(vg-vf) # steam quality\n",
    "h = hf+(x*hfg) # Specific enthalpy of substance at a point in kJ/kg\n",
    "s = sf+(x*sfg) # Specific entropy of substance at a point in kJ/kgK\n",
    "\n",
    "print \"\\n The enthalpy and entropy of the system are\\n \",h ,\" kW and \",s ,\" kJ/kg and kJ/kg K respectively.\"\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.5:pg-303"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.5\n",
      "\n",
      " The pressure is  3.973  MPa\n",
      "\n",
      " The total mass of mixture is  9.57329343706  kg\n",
      "\n",
      " Specific volume is  0.00417829039327  m3/kg\n",
      "\n",
      " Enthalpy is is  1188.13405609  kJ/kg\n",
      "\n",
      " The entropy is  2.9891336667  kJ/kg K\n",
      "\n",
      " The internal energy is  1171.53370836  kJ/kg\n",
      "\n",
      " At 250 degree Celsius, internal energy is  1171.53445483 kJ/kg\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "Psat = 3.973 # Saturation pressure in MPa\n",
    "vf = 0.0012512 # specific volume of fluid in m**3/kg\n",
    "vg = 0.05013 # Specific volume of gas in m**3/kg\n",
    "hf = 1085.36  # Specific enthalpy of fluid in kJ/kg\n",
    "hfg = 1716.2 # Latent heat of vaporization in kJ/kg\n",
    "sf = 2.7927 # Specific entropy of fluid in kJ/kgK\n",
    "sfg = 3.2802 # Entropy change due to vaporization in kJ/kgK\n",
    "mf = 9.0 # Mass of liquid in kg\n",
    "V = 0.04 # Volume of vessel in m**3\n",
    "# at T = 250\n",
    "uf = 1080.39 #Specific internal energy in kJ/kg \n",
    "ufg = 1522.0# Change in internal energy due to vaporization in kJ/kg\n",
    "\n",
    "print \"\\n Example 9.5\"\n",
    "Vf = mf*vf # volume of fluid\n",
    "Vg = V-Vf # volume of gas\n",
    "mg = Vg/vg # mass of gas\n",
    "m = mf+mg # mass if mixture\n",
    "x = mg/m # quality of steam\n",
    "v = vf+x*(vg-vf) # specific volume of mixture\n",
    "h = hf+x*hfg # enthalpy of mixture\n",
    "s = sf+(x*sfg) # entropy of mixture\n",
    "u = h-Psat*1e6*v*1e-03 # Internal energy of mixture\n",
    "u_ = uf+x*ufg # Internal energy at 250 degree Celsius\n",
    "print \"\\n The pressure is \",Psat ,\" MPa\"\n",
    "print \"\\n The total mass of mixture is \",m ,\" kg\"\n",
    "print \"\\n Specific volume is \",v ,\" m3/kg\"\n",
    "print \"\\n Enthalpy is is \",h ,\" kJ/kg\"\n",
    "print \"\\n The entropy is \",s ,\" kJ/kg K\"\n",
    "print \"\\n The internal energy is \",u ,\" kJ/kg\"\n",
    "print \"\\n At 250 degree Celsius, internal energy is \",u_ ,\"kJ/kg\" #The answer provided in the textbook is wrong\n",
    "\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.7:pg-305"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.7\n",
      "\n",
      " The ideal work output of the turbine is  882.40804932  kJ/Kg\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "# At T = 40 degree\n",
    "Psat = 7.384 # Saturation pressure in kPa\n",
    "sf = 0.5725 # Entropy of fluid in kJ/kgK\n",
    "sfg = 7.6845 # Entropy change due to vaporization in kJ/kgK\n",
    "hf = 167.57 # Enthalpy of fluid in kJ/kg\n",
    "hfg = 2406.7 # Latent heat of vaporization in kJ/kg\n",
    "s1 = 6.9189 # Entropy at turbine inlet in kJ/kgK\n",
    "h1 = 3037.6 # Enthalpy at turbine inlet in kJ/kg\n",
    "print \"\\n Example 9.7\"\n",
    "x2 = (s1-sf)/sfg # Steam quality\n",
    "h2 = hf+(x2*hfg) # Enthalpy at turbine exit\n",
    "W = h1-h2 # Net work done\n",
    "print \"\\n The ideal work output of the turbine is \",W ,\" kJ/Kg\"\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.9:pg-308"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.9\n",
      "\n",
      " The quality of steam in pipe line is  0.96097673702\n",
      "\n",
      " Maximum moisture content that can be determined is  5.47886817645  percent\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "h2 = 2716.2 # Enthalpy at turbine inlet in kJ/kg\n",
    "hf = 844.89 # Enthalpy of fluid in kJ/kg\n",
    "hfg = 1947.3 # Latent heat of vaporization in kJ/kg\n",
    "h3 = 2685.5 # Enthalpy at turbine exit in kJ/kg\n",
    "print \"\\n Example 9.9\"\n",
    "x1 = (h2-hf)/hfg\n",
    "x4 = (h3-hf)/hfg\n",
    "print \"\\n The quality of steam in pipe line is \",x1  #The answers vary due to round off error\n",
    "print \"\\n Maximum moisture content that can be determined is \",100-(x4*100) ,\" percent\"#The answer provided in the textbook is wrong\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.10:pg-309"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.10\n",
      "\n",
      " The quality of the steam in the pipe line is  0.909544295341\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "# At 0.1Mpa, 110 degree\n",
    "h2 = 2696.2 # Enthalpy at turbine inlet in kJ/kg\n",
    "hf = 844.89 # Enthalpy of fluid in kJ/kg\n",
    "hfg = 1947.3 # Latent heat of vaporization in kJ/kg\n",
    "vf = 0.001023 # at T = 70 degree\n",
    "V = 0.000150 # In m3\n",
    "m2 = 3.24 # mass of condensed steam in kg\n",
    "\n",
    "print \"\\n Example 9.10\"\n",
    "x2 = (h2-hf)/hfg # Quality of steam at turbine inlet\n",
    "m1 = V/vf # mass of moisture collected in separator\n",
    "x1 = (x2*m2)/(m1+m2) # quality of the steam\n",
    "print \"\\n The quality of the steam in the pipe line is \",x1 \n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.11:pg-310"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.11\n",
      "\n",
      " The heat transfer during the process is  1788.19203218  MJ\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "# P = 1MPa\n",
    "vf = 0.001127 # specific volume of fluid in m**3/kg\n",
    "vg = 0.1944# specific volume of gas in m**3/kg\n",
    "hg = 2778.1 # specific enthalpy of gas in kJ/kg\n",
    "uf = 761.68 # Specific internal energy of fluid in kJ/kg\n",
    "ug = 2583.6 # Specific internal energy of gas in kJ/kg\n",
    "ufg = 1822 # Change in specific internal energy due to phase change in kJ/kg \n",
    "# Initial anf final mass\n",
    "Vif = 5 # Initial volume of water in m**3 \n",
    "Viw = 5# Initial volume of gas in m**3 \n",
    "Vff = 6  # Final volume of gas in m**3 \n",
    "Vfw = 4 # Final volume of water in m**3 \n",
    "\n",
    "\n",
    "print \"\\n Example 9.11\"\n",
    "ms = ((Viw/vf)+(Vif/vg)) - ((Vfw/vf)+(Vff/vg)) \n",
    "U1 =  ((Viw*uf/vf)+(Vif*ug/vg))\n",
    "Uf =  ((Vfw*uf/vf)+(Vff*ug/vg))\n",
    "Q = Uf-U1+(ms*hg)\n",
    "print \"\\n The heat transfer during the process is \",Q/1e3 ,\" MJ\"\n",
    "#The answer provided in the textbook is wrong\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.12:pg-311"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.12\n",
      "\n",
      " The value of n is  1.23844995978\n",
      "\n",
      " The work done by the steam is  4.72026539673 kJ \n",
      "\n",
      " The heat transfer is  -1.80091923775 kJ \n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "m = 0.02 # Mass of steam in Kg\n",
    "d = 280 # diameter of piston in mm\n",
    "l = 305 # Stroke length in mm\n",
    "P1 = 0.6 # Initial pressure in MPa\n",
    "P2 = 0.12 # Final pressure in MPa\n",
    "# At 0.6MPa, t = 200 degree\n",
    "v1 = 0.352 # Specific volume in m**3/kg\n",
    "h1 = 2850.1 # Specific enthalpy in kJ/kg\n",
    "vf = 0.0010476 # specific volume of fluid in m**3/kg\n",
    "vfg = 1.4271 # Specific volume change due to vaporization in m**3/kg\n",
    "uf = 439.3 # specific enthalpy of fluid\n",
    "ug = 2512.0 # Specific enthalpy of gas\n",
    "print \"\\n Example 9.12\"\n",
    "V1 = m*v1 # total volume at point 1\n",
    "Vd = (math.pi/4)*(d*1e-3)**2*l*1e-3 # displaced volume\n",
    "V2 = V1+Vd  # Total volume at point 2\n",
    "n = math.log(P1/P2)/math.log(V2/V1) # polytropic index\n",
    "W12 = ((P1*V1)-(P2*V2))*1e6/(n-1) # work done\n",
    "print \"\\n The value of n is \",n\n",
    "print \"\\n The work done by the steam is \",W12/1e3 ,\"kJ \"\n",
    "#The answers vary due to round off error\n",
    "v2 = V2/m # specific volume\n",
    "x2 = (v2-vf)/vfg  # Steam quality\n",
    "# At 0.12MPa\n",
    "u2 = uf + (x2*(ug-uf)) # Internal energy \n",
    "u1 = h1-(P1*1e6*v1*1e-03) # Internal energy\n",
    "Q12 = m*(u2-u1)+ (W12/1e3) # Heat transfer\n",
    "print \"\\n The heat transfer is \",Q12 ,\"kJ \"\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.13:pg-312"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.13\n",
      "\n",
      " Final pressure is  3.5  bar\n",
      "\n",
      " Steam quality is  0.87 \n",
      " Entropy change during the process is  0.4227  kJ/K\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "x1 = 1 # Steam quality in first vessel\n",
    "x2 = 0.8 # Steam quality in second vessel\n",
    "# at 0.2MPa\n",
    "vg = 0.8857 # Specific volume of gas in m**3/kg\n",
    "h1 =  2706.7 # Enthalpy in first vessel  in kJ/kg\n",
    "v1 = vg # Specific volume of gas in first vessel in m**3/kg\n",
    "hg = h1 #  Enthalpy in first vessel  1 in kJ/kg\n",
    "m1 = 5  # mass in first vessel in kg\n",
    "V1 = m1*v1 # Volume of first vessel in m**3\n",
    "# at 0.5MPa\n",
    "m2 = 10 # mass in second vessel in kg\n",
    "hf = 640.23 # Enthalpy in second vessel  in kJ/kg\n",
    "hfg = 2108.5 # Latent heat of vaporization in kJ/kg\n",
    "vf = 0.001093 # Specific volume of fluid in second vessel in m**3/kg\n",
    "vfg = 0.3749 # Change in specific volume in second vessel due to evaporation of gas in m**3/kg\n",
    "v2 = vf+(x2*vfg) # Specific volume of gas in second vessel\n",
    "V2 = m2*v2 # Volume of second vessel in m**3\n",
    "#\n",
    "Vm = V1+V2 # Total volume \n",
    "m = m1+m2 # Total mass\n",
    "vm = Vm/m # net specific volume\n",
    "u1 = h1 # Internal energy\n",
    "h2 = hf+(x2*hfg) # Enthalpy calculation\n",
    "u2 = h2 # Internal energy calculation\n",
    "m3 = m # Net mass calculation\n",
    "h3 = ((m1*u1)+(m2*u2))/m3 # Resultant enthalpy calculation\n",
    "u3 = h3 # Resultant internal energy calculation\n",
    "v3 = vm # resultant specific volume calculation\n",
    "# From Mollier diagram\n",
    "x3 = 0.870  # Steam quality \n",
    "p3 = 3.5 # Pressure in MPa\n",
    "s3 = 6.29 # Entropy at state 3  in kJ/kgK\n",
    "s1 = 7.1271 # Entropy at state 1 in kJ/kgK\n",
    "sf = 1.8607  # Entropy in liquid state  in kJ/kgK\n",
    "sfg = 4.9606 # Entropy change due to vaporization in kJ/kgK\n",
    "s2 = sf+(x2*sfg) # Entropy calculation\n",
    "E = m3*s3-((m1*s1)+(m2*s2)) # Entropy change during process\n",
    "\n",
    "print \"\\n Example 9.13\"\n",
    "print \"\\n Final pressure is \",p3 ,\" bar\"\n",
    "print \"\\n Steam quality is \",x3 ,\n",
    "print \"\\n Entropy change during the process is \",E ,\" kJ/K\"\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.14:pg-314"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.14\n",
      "\n",
      " The availability of the steam before the throttle valve  1263.6894  kJ/kg\n",
      "\n",
      " The availability of the steam after the throttle valve  1237.5538  kJ/kg\n",
      "\n",
      " The availability of the steam at the turbine exhaust  601.851036792  kJ/kg\n",
      "\n",
      " The specific work output from the turbine is  546.253422512  kJ/kg\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "# At 6 MPa, 400 degree\n",
    "h1 = 3177.2 # Enthalpy in kJ/kg\n",
    "s1 = 6.5408 #Entropy in kJ/kgK\n",
    "# At 20 degree\n",
    "h0= 83.96 # Enthalpy in kJ/kg \n",
    "s0 = 0.2966#Entropy in kJ/kgK\n",
    "T0 = 20 # Surrounding temperature in degree Celsius \n",
    "f1 = (h1-h0)-(T0+273)*(s1-s0) # Availability before throttling\n",
    "# By interpolation at P= 5MPa, h= 3177.2\n",
    "s2 = 6.63 #Entropy in kJ/kgK\n",
    "h2 = h1 # Throttling\n",
    "f2 = (h2-h0)-(T0+273)*(s2-s0) # Availability after throttling\n",
    "df = f1-f2 # Change in availability\n",
    "x3s = (s2-1.5301)/(7.1271-1.5301) #Entropy at state 3 in kJ/kgK\n",
    "h3s = 504.7+(x3s*2201.9) #Enthalpy at state 3 in kJ/kg\n",
    "eis = 0.82 # isentropic efficiency\n",
    "h3 = h2-eis*(h1-h3s) # Enthalpy at state 3 in kJ/kgK\n",
    "x3 = (h3-504.7)/2201.7 # Steam quality at state 3\n",
    "s3 = 1.5301+(x3*5.597) # Entropy at state 3\n",
    "f3 = (h3-h0)-(T0+273)*(s3-s0) # Availability at state 3\n",
    "\n",
    "print \"\\n Example 9.14\"\n",
    "print \"\\n The availability of the steam before the throttle valve \",f1 ,\" kJ/kg\"\n",
    "print \"\\n The availability of the steam after the throttle valve \",f2 ,\" kJ/kg\"\n",
    "print \"\\n The availability of the steam at the turbine exhaust \",f3 ,\" kJ/kg\"\n",
    "print \"\\n The specific work output from the turbine is \",h2-h3 ,\" kJ/kg\"\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.15:pg-316"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.15\n",
      "\n",
      " Availability of steam entering is  1057.4864  kJ/kg\n",
      "\n",
      " Availability of steam leaving the turbine is  656.7062  kJ/kg\n",
      "\n",
      " Maximum work is  741.14568  kJ/kg\n",
      "\n",
      " Irreversibility is  21.36505104  kJ/kg\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "# At 25 bar, 350 degree\n",
    "h1 = 3125.87 # Enthalpy in kJ/kg\n",
    "s1 = 6.8481# Entropy in kJ/kgK\n",
    "# 30 degree\n",
    "h0 = 125.79 # Enthalpy in kJ/kg\n",
    "s0 = 0.4369# Entropy in kJ/kgK\n",
    "# At 3 bar, 200 degree\n",
    "h2 = 2865.5 # Enthalpy in kJ/kg\n",
    "s2 = 7.3115 #Entropy in kJ/kgK\n",
    "# At 0.2 bar 0.95 dry\n",
    "hf = 251.4 # Enthalpy of liquid in kJ/kg\n",
    "hfg = 2358.3 # Latent heat of vaporization in kJ/kg\n",
    "sf = 0.8320 # Entropy of liquid in kJ/kgK\n",
    "sg = 7.0765# Entropy of liquid in kJ/kgK\n",
    "h3 = hf+0.92*hfg # Enthalpy at state 3 in kJ/kg\n",
    "s3 = sf+(0.92*sg) # Entropy at state 3 in kJ/kgK\n",
    "# Part (a)\n",
    "T0 = 30 # Atmospheric temperature in degree Celsius\n",
    "f1 = (h1-h0)-((T0+273)*(s1-s0)) # Availability at steam entering turbine\n",
    "f2 = (h2-h0)-((T0+273)*(s2-s0)) # Availability at state 2\n",
    "f3 = (h3-h0)-((T0+273)*(s3-s0))# Availability at state 3\n",
    "\n",
    "print \"\\n Example 9.15\"\n",
    "print \"\\n Availability of steam entering is \",f1 ,\" kJ/kg\"\n",
    "print \"\\n Availability of steam leaving the turbine is \",f2 ,\" kJ/kg\"\n",
    "\n",
    "# Part (b)\n",
    "m2m1 = 0.25  # mass ratio\n",
    "m3m1 = 0.75 # mass ratio\n",
    "Wrev = f1-(m2m1*f2)-(m3m1*f3) # Maximum work\n",
    "print \"\\n Maximum work is \",Wrev ,\" kJ/kg\"\n",
    "\n",
    "# Part (c)\n",
    "w1 = 600 # mass flow at inlet of turbine in kg/h\n",
    "w2 = 150 # mass flow at state 2 in turbine in kg/h\n",
    "w3 = 450# mass flow at state 2 in  turbine in kg/h\n",
    "Q = -10  # Heat loss rate kJ/s\n",
    "I = ((T0+273)*(w2*s2+w3*s3-w1*s1)-Q*3600)*103/600\n",
    "print \"\\n Irreversibility is \",I/1e3 ,\" kJ/kg\"\n",
    "#The answer provided in the textbook is wrong\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.16:pg-317"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.16\n",
      "\n",
      " Energy of system in Part (a) is  73.2  kJ\n",
      "\n",
      " Energy of system in Part (b) is  197.3474  kJ\n",
      "\n",
      " Energy of system in Part (c) is  498.2624  kJ\n",
      "\n",
      " Energy of system in Part (d) is  121.8  kJ\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "# At dead state of 1 bar, 300K\n",
    "u0 = 113.1 # Internal energy in kJ/kg\n",
    "h0 = 113.2 # Enthalpy in kJ/kg\n",
    "v0 = 0.001005 # Specific volume in m**3/kg\n",
    "s0 = 0.395 # Entropy in kJ/kg\n",
    "T0 = 300 # Atmospheric temperature in K\n",
    "P0 = 1 # Atmospheric pressure in bar \n",
    "K = h0-T0*s0\n",
    "# Part (a)\n",
    "# At 1bar and 90 degree Celsius \n",
    "u = 376.9 # Internal energy in kJ/kg\n",
    "h = 377 # Enthalpy in kJ/kg\n",
    "v = 0.001035 # specific volume in m**3/kg\n",
    "s = 1.193 # Entropy in kJ/kgK\n",
    "m = 3 # Mass of water in kg\n",
    "fi = m*(h-(T0*s)-K)  #Energy of system\n",
    "\n",
    "print \"\\n Example 9.16\"\n",
    "print \"\\n Energy of system in Part (a) is \",fi ,\" kJ\"\n",
    "#The answers vary due to round off error\n",
    "\n",
    "# Part (b)\n",
    "# At P = 4 Mpa, t = 500 degree\n",
    "u = 3099.8# Internal energy in kJ/kg \n",
    "h = 3446.3 # Enthalpy in kJ/kg \n",
    "v = 0.08637 # specific volume in m**3/kg \n",
    "s = 7.090 # Entropy in kJ/kgK\n",
    "m = 0.2 # Mass of steam in kg \n",
    "fib = m*(u+P0*100*v-T0*s-K) # Energy of system\n",
    "print \"\\n Energy of system in Part (b) is \",fib ,\" kJ\"\n",
    "\n",
    "# Part (c) # P = 0.1 bar\n",
    "m = 0.4 # Mass of wet steam in kg \n",
    "x = 0.85 # Quality\n",
    "u = 192+x*2245 # Internal energy \n",
    "h = 192+x*2392# Enthalpy\n",
    "s = 0.649+x*7.499 # Entropy\n",
    "v = 0.001010+x*14.67 # specific volume\n",
    "fic = m*(u+P0*100*v-T0*s-K) # Energy of system\n",
    "print \"\\n Energy of system in Part (c) is \",fic ,\" kJ\"\n",
    "\n",
    "# Part (d) \n",
    "# P = 1 Bar, t = -10 degree Celsius\n",
    "m = 3 # Mass of ice in kg \n",
    "h = -354.1 # Enthalpy in kJ/kg  \n",
    "s = -1.298 # at 1000kPa, -10 degree\n",
    "fid = m*((h-h0)-T0*(s-s0)) # Energy of system\n",
    "\n",
    "print \"\\n Energy of system in Part (d) is \",fid ,\" kJ\" #The answer provided in the textbook is wrong\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.17:pg-318"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.17\n",
      "\n",
      " In parallel flow\n",
      "\n",
      " The rate of irreversibility is  10.98  kW\n",
      "\n",
      " The Second law efficiency is  24.275862069  percent\n",
      "\n",
      "\n",
      " In counter flow\n",
      "\n",
      " The rate of irreversibility is  10.9454545455  kW\n",
      "\n",
      " The Second law efficiency is  32.1594684385  percent\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "# Given\n",
    "th1 = 90.0 # Inlet temperature of hot water in degree Celsius\n",
    "tc1 = 25.0# Inlet temperature of cold water in degree Celsius\n",
    "tc2 = 50.0# Exit temperature of cold water in degree Celsius\n",
    "mc = 1.0 # mass flow rate of cold water in kg/s\n",
    "T0 = 300.0 # Atmospheric temperature in K\n",
    "th2p = 60.0 # Temperature limit in degree Celsius for parallel flow\n",
    "th2c = 35.0 # Temperature limit in degree Celsius for counter flow\n",
    "mhp = (tc2-tc1)/(th1-th2p) # mass flow rate of hot water in kg/s for parallel flow\n",
    "mhc = (tc2-tc1)/(th1-th2c) # mass flow rate of hot water in kg/s for counter flow\n",
    "# At 300 K\n",
    "h0 = 113.2 # ENthalpy in kJ/kg\n",
    "s0 = 0.395 # ENtropy in kJ/kgK\n",
    "T0 = 300.0 # temperature in K\n",
    "# At 90 degree celsius\n",
    "h1 = 376.92 # Enthalpy in kJ/kg \n",
    "s1 = 1.1925 # Entropy in kJ/kgK\n",
    "af1 = mhp*((h1-h0)-T0*(s1-s0)) # Availability\n",
    "# Parallel Flow\n",
    "# At 60 degree\n",
    "h2 = 251.13 # Enthalpy in kJ/kg \n",
    "s2 =0.8312  # Entropy in kJ/kgK\n",
    " # At 25 degree\n",
    "h3 = 104.89 # Enthalpy in kJ/kg \n",
    "s3 = 0.3674 # Entropy in kJ/kgK\n",
    "# At 50 degree\n",
    "h4 = 209.33 # Enthalpy in kJ/kg \n",
    "s4 = 0.7038 # Entropy in kJ/kgK\n",
    "REG = mc*((h4-h3)-T0*(s4-s3)) # Rate of energy gain\n",
    "REL = mhp*((h1-h2)-T0*(s1-s2)) # Rate of energy loss\n",
    "Ia = REL-REG # Energy destruction\n",
    "n2a = REG/REL # Second law efficiency\n",
    "\n",
    "print \"\\n Example 9.17\"\n",
    "print \"\\n In parallel flow\"\n",
    "print \"\\n The rate of irreversibility is \",Ia ,\" kW\"\n",
    "print \"\\n The Second law efficiency is \",n2a*100 ,\" percent\"\n",
    "#The answers vary due to round off error\n",
    "\n",
    "\n",
    "# Counter flow\n",
    "h2_ = 146.68 \n",
    "sp = 0.5053 # At 35 degree\n",
    "REG_b = REG # Rate of energy gain by hot water is same in both flows\n",
    "REL_b = mhc*((h1-h2_)-T0*(s1-sp))\n",
    "Ib = mhc*((h1-h2_)-(T0*(s1-sp))) # Energy destruction\n",
    "n2b = REG_b/Ib # Second law efficiency\n",
    "print \"\\n\\n In counter flow\"\n",
    "print \"\\n The rate of irreversibility is \",Ib ,\" kW\"\n",
    "print \"\\n The Second law efficiency is \",n2b*100 ,\" percent\"\n",
    "#The answers vary due to round off error\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex9.18:pg-320"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 9.18\n",
      "\n",
      " The maximum cooling rate is  106.207042424  kW\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "m = 50.0# mass flow rate in kg/h\n",
    "Th = 23.0 # Home temperature in degree Celsius\n",
    "# State 1\n",
    "T1 = 150.0 # Saturated vapor temperature in degree Celsius\n",
    "h1 = 2746.4 # Saturated vapor enthalpy in kJ/kg\n",
    "s1 = 6.8387 #Saturated vapor entropy in kJ/kgK\n",
    "# State 2\n",
    "h2 = 419.0 # Saturated liquid enthalpy in kJ/kg\n",
    "s2 = 1.3071 #Saturated liquid entropy in kJ/kg \n",
    "T0 = 45.0 #  Atmospheric temperature in degree Celsius\n",
    "#\n",
    "b1 = h1-((T0+273)*s1) # Availability at point 1\n",
    "b2 = h2-((T0+273)*s2) # Availability at point 2\n",
    "Q_max = m*(b1-b2)/((T0+273)/(Th+273)-1) # maximum cooling rate\n",
    "\n",
    "print \"\\n Example 9.18\"\n",
    "print \"\\n The maximum cooling rate is \",Q_max/3600 ,\" kW\"\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}