summaryrefslogtreecommitdiff
path: root/Basic_Engineering_Thermodynamics_by_Rayner_Joel/Chapter4.ipynb
blob: 72f198755027b1baf16be48e58b149bd7902bc17 (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
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 4: Steam and two phase systems"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1: pg 61"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.1\n",
      "The specific liquid enthalpy (kJ/kg) =  640.1\n",
      "The specific enthalpy of evaporation (kJ/kg) =  2107.4\n",
      "The specific enthalpy of dry saturated steam (kJ/kg) =  2747.5\n"
     ]
    }
   ],
   "source": [
    "#pg 61\n",
    "#calculate the specific liquid enthalpy of evaporation and dry saturated steam\n",
    "print('Example 4.1');\n",
    "\n",
    "#  aim : To determine\n",
    "#  the enthalpy\n",
    "\n",
    "#  Given values\n",
    "P = .50;# Pressure, [MN/m^2]\n",
    "\n",
    "#  solution\n",
    "\n",
    "#  From steam tables, at given pressure\n",
    "hf = 640.1;#  specific liquid enthalpy ,[kJ/kg]\n",
    "hfg = 2107.4;#  specific enthalpy of evaporation ,[kJ/kg]\n",
    "hg = 2747.5; #  specific enthalpy of dry saturated steam ,[kJ/kg]\n",
    "tf = 151.8; #  saturation temperature,[C]\n",
    "#results\n",
    "print 'The specific liquid enthalpy (kJ/kg) = ',hf\n",
    "print 'The specific enthalpy of evaporation (kJ/kg) = ',hfg\n",
    "print 'The specific enthalpy of dry saturated steam (kJ/kg) = ',hg\n",
    "\t\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2: pg 61"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.2\n",
      "The Saturation temperature (C) =  212.4\n",
      "The Specific liquid enthalpy (kJ/kg) =  908.6\n",
      "The Specific enthalpy of evaporation (kJ/kg) =  1888.6\n",
      "The Specific enthalpy of dry saturated steam (kJ/kg) =  2797.2\n",
      "The answers in the textbook are a bit different due to rounding off error\n"
     ]
    }
   ],
   "source": [
    "#pg 61\n",
    "#calculate the saturation temperature, specific enthalpy\n",
    "print('Example 4.2');\n",
    "import numpy\n",
    "#  aim : To determine \n",
    "#  saturation temperature and enthalpy\n",
    "\n",
    "#  Given values\n",
    "P = 2.04;# pressure, [MN/m^2]\n",
    "\n",
    "#  solution\n",
    "#  since in the steam table values of enthalpy and saturation temperature at 2 and 2.1 MN?m^2 are   given, so for knowing required values at given pressure,there is need to do interpolation\n",
    "\n",
    "#  calculation of saturation temperature and results\n",
    "#  from steam table\n",
    "#  P in [MN/m^2] and tf in [C]\n",
    "Table_P_tf_x=[2.1,2.0]\n",
    "Table_P_tf_y=[214.9,212.4]\n",
    "# using interpolation\n",
    "tf = numpy.interp(P,Table_P_tf_x,Table_P_tf_y);#  saturation temperature at given condition\n",
    "print 'The Saturation temperature (C) = ',tf\n",
    "\n",
    "# calculation of specific liquid enthalpy\n",
    "#  from steam table\n",
    "Table_P_hf_y = [920.0,908.6];#  P in [MN/m^2] and hf in [kJ/kg]\n",
    "Table_P_hf_x=[2.1,2.0]\n",
    "# using interpolation\n",
    "hf = numpy.interp(P,Table_P_hf_x,Table_P_hf_y); #  enthalpy at given condition, [kJ/kg]\n",
    "print 'The Specific liquid enthalpy (kJ/kg) = ',hf\n",
    "\n",
    "# calculation of specific enthalpy of evaporation\n",
    "#  from steam table\n",
    "Table_P_hfg_x = [2.1,2.0];#  P in [MN/m^2] and hfg in [kJ/kg]\n",
    "Table_P_hfg_y=[1878.2,1888.6]\n",
    "# using interpolation \n",
    "hfg = numpy.interp(P,Table_P_hfg_x,Table_P_hfg_y); #  enthalpy at given condition, [kJ/kg]\n",
    "print 'The Specific enthalpy of evaporation (kJ/kg) = ',hfg\n",
    "\n",
    "#  calculation of specific enthalpy of dry saturated steam\n",
    "#  from steam table\n",
    "Table_P_hg_y = [2798.2,2797.2];#P in [MN/m^2] and hg in [kJ/kg]\n",
    "Table_P_hg_x=[2.1,2.0]\n",
    "# using interpolation\n",
    "hg = numpy.interp(P,Table_P_hg_x,Table_P_hg_y); #  enthalpy at given condition, [kJ/kg]\n",
    "print 'The Specific enthalpy of dry saturated steam (kJ/kg) = ',hg\n",
    "\n",
    "print'The answers in the textbook are a bit different due to rounding off error'\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3: pg 63"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.3\n",
      "The specific enthalpy of steam at 2 MN/m^2 with temperature 250 C (kJ/kg) =  2902\n",
      "The specific enthalpy at given T and P by alternative path (kJ/kg) =  2875.9\n"
     ]
    }
   ],
   "source": [
    "#pg 63\n",
    "#calculate the specific enthalpy\n",
    "print('Example 4.3');\n",
    "\n",
    "#  aim : To determine\n",
    "#  the specific enthalpy\n",
    "\n",
    "#  given values\n",
    "P = 2; #  pressure ,[MN/m^2]\n",
    "t = 250; #  Temperature, [C]\n",
    "cp = 2.0934; #  average value of specific heat capacity, [kJ/kg K]\n",
    "\n",
    "#  solution\n",
    "\n",
    "#  looking up steam table it shows that at given pressure saturation temperature is 212.4 C,so\n",
    "tf = 212.4; #  [C]\n",
    "#  hence,\n",
    "Degree_of_superheat = t-tf;#  [C]\n",
    "#  from table at given temperature 250 C\n",
    "h = 2902; #  specific enthalpy of steam at 250 C ,[kJ/kg]\n",
    "\n",
    "#  Also from steam table enthalpy at saturation temperature is\n",
    "hf = 2797.2 ;#  [kJ/kg]\n",
    "#  so enthalpy at given temperature is\n",
    "h2 = hf+cp*(t-tf);#  [kJ/kg]\n",
    "#results\n",
    "print 'The specific enthalpy of steam at 2 MN/m^2 with temperature 250 C (kJ/kg) = ',h\n",
    "print 'The specific enthalpy at given T and P by alternative path (kJ/kg) = ',round(h2,1)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4: pg 63"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.4\n",
      " The estimated specific enthalpy (kJ/kg) =  3002.08\n",
      " The accurate specific enthalpy of steam at pressure of 2.5 MN/m^2 and with a temperature 320 C (kJ/kg) =  3025.0\n",
      " The answer is a bit different from textbook due to rounding off error\n"
     ]
    }
   ],
   "source": [
    "#pg 63\n",
    "#calculate the estimated and accurate specific enthalpy\n",
    "print('Example 4.4');\n",
    "import numpy\n",
    "#  aim : To determine\n",
    "#  the specific enthalpy of steam\n",
    "\n",
    "#  Given values\n",
    "P = 2.5;#  pressure, [MN/m^2]\n",
    "t = 320; #  temperature, [C]\n",
    "\n",
    "#  solution\n",
    "#  from steam table at given condition the saturation temperature of steam is 223.9 C, therefore steam is superheated\n",
    "tf = 223.9;#  [C]\n",
    "\n",
    "#  first let's calculate estimated enthalpy\n",
    "#  again from steam table \n",
    "\n",
    "hg = 2800.9;#  enthalpy at saturation temp, [kJ/kg]\n",
    "cp =2.0934;#  specific heat capacity of steam,[kJ/kg K]\n",
    "\n",
    "#  so enthalpy at given condition is\n",
    "h = hg+cp*(t-tf);#  [kJ/kg]\n",
    "print ' The estimated specific enthalpy (kJ/kg) = ',round(h,2)\n",
    "\n",
    "#  calculation of accurate specific enthalpy\n",
    "#  we need double interpolation for this\n",
    "\n",
    "#  first interpolation w.r.t. to temperature\n",
    "#  At 2 MN/m^2\n",
    "Table_t_h_x = [325.,300.];# where, t in [C] and h in [kJ/kg]\n",
    "Table_t_h_y=[3083.,3025.]\n",
    "h1 = numpy.interp(320.,Table_t_h_x,Table_t_h_y); #  [kJ/kg]\n",
    "\n",
    "#  at 4 MN/m^2\n",
    "Table_t_h_x = [325.,300.]; #  t in [C] and h in [kJ/kg]\n",
    "Table_t_h_y=[3031.,2962.]\n",
    "h2 = numpy.interp(320.,Table_t_h_x,Table_t_h_y); #  [kJ/kg]\n",
    "\n",
    "#  now interpolation w.r.t. pressure\n",
    "Table_P_h_x = [4.,2.]; #  where P in NM/m^2 and h1,h2 in kJ/kg\n",
    "Table_P_h_y=[h2,h1]\n",
    "h = numpy.interp(2.5,Table_P_h_x,Table_P_h_y);#  [kJ/kg]\n",
    "print ' The accurate specific enthalpy of steam at pressure of 2.5 MN/m^2 and with a temperature 320 C (kJ/kg) = ',h\n",
    "\n",
    "#  End\n",
    "print ' The answer is a bit different from textbook due to rounding off error'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5: pg 65"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.5\n",
      " The specific enthalpy of wet steam (kJ/kg) =  2317.605\n"
     ]
    }
   ],
   "source": [
    "#pg 65\n",
    "#calculate the specific enthalpy\n",
    "print('Example 4.5');\n",
    "\n",
    "# aim : To determine \n",
    "#  the specific enthalpy \n",
    "\n",
    "#  Given values\n",
    "P = 70; #  pressure, [kn/m^2]\n",
    "x = .85; #  Dryness fraction\n",
    "\n",
    "# solution\n",
    "\n",
    "#  from steam table, at given pressure \n",
    "hf = 376.8;#  [kJ/kg]\n",
    "hfg = 2283.3;#  [kJ/kg]\n",
    "\n",
    "# now using equation [2]\n",
    "h = hf+x*hfg;#  specific enthalpy of wet steam,[kJ/kg]\n",
    "\n",
    "#results\n",
    "print ' The specific enthalpy of wet steam (kJ/kg) = ',h\n",
    "\n",
    "# There is minor variation in the book's answer\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8: pg 68"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.8\n",
      "The specific volume of wet steam (m^3/kg) =  0.14121\n"
     ]
    }
   ],
   "source": [
    "#pg 68\n",
    "#calculate the specific volume\n",
    "print('Example 4.8');\n",
    "\n",
    "#  aim : To determine \n",
    "#  the specific volume of wet steam\n",
    "\n",
    "#  Given values\n",
    "P = 1.25; #  pressure, [MN/m^2]\n",
    "x = .9; #  dry fraction\n",
    "\n",
    "#  solution\n",
    "#  from steam table at given pressure\n",
    "vg = .1569;#  [m^3/kg]\n",
    "#  hence\n",
    "v = x*vg; #  [m^3/kg]\n",
    "#results\n",
    "print 'The specific volume of wet steam (m^3/kg) = ',v\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 9: pg 69"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.9\n",
      " The specific volume of steam at pressure of 2 MN/m^2 and with temperature 325 C (m^3/kg) =  0.1321\n",
      " The degree of superheat (C) =  112.6\n"
     ]
    }
   ],
   "source": [
    "#pg 69\n",
    "#calculate the specific volume and degree of superheat\n",
    "print('Example 4.9');\n",
    "\n",
    "#  aim : To determine\n",
    "#  the specific volume \n",
    "\n",
    "#  Given values\n",
    "t = 325; #  temperature, [C]\n",
    "P = 2; #  pressure, [MN/m^2]\n",
    "\n",
    "#  solution\n",
    "# from steam table at given t and P\n",
    "vf = .1321; #  [m^3/kg]\n",
    "tf = 212.4; #  saturation temperature, [C]\n",
    "doh= t-tf; #  degree of superheat, [C]\n",
    "#results\n",
    "print ' The specific volume of steam at pressure of 2 MN/m^2 and with temperature 325 C (m^3/kg) = ',vf\n",
    "print ' The degree of superheat (C) = ',doh\n",
    "\n",
    "# End \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10: pg 69"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example .10\n",
      " (a) The mass of steam entering the heater (kg/h) =  81.8\n",
      " (b) The mass of water entering the heater (kg/h) =  628.23\n"
     ]
    }
   ],
   "source": [
    "#pg 69\n",
    "#calculate the mass of steam and water\n",
    "print('Example .10');\n",
    "import math\n",
    "# aim : To determine\n",
    "# (a) the mass of steam entering the heater\n",
    "# (b) the mass of water entering the heater\n",
    "\n",
    "#  Given values\n",
    "x = .95;#  Dryness fraction\n",
    "P = .7;#  pressure,[MN/m**2]\n",
    "d = 25;#  internal diameter of heater,[mm]\n",
    "C = 12; #  steam velocity in the pipe,[m/s]\n",
    "\n",
    "#  solution\n",
    "#  from steam table at .7 MN/m**2 pressure\n",
    "hf = 697.1;#  [kJ/kg]\n",
    "hfg = 2064.9;#  [kJ/kg]\n",
    "hg = 2762.0; #  [kJ/kg]\n",
    "vg = .273; #  [m**3/kg]\n",
    "\n",
    "#  (a)\n",
    "v = x*vg; #  [m**3/kg]\n",
    "ms_dot = math.pi*(d*10**-3)**2*C*3600/(4*v);#  mass of steam entering, [kg/h]\n",
    "\n",
    "#  (b)\n",
    "h = hf+x*hfg;#  specific enthalpy of steam entering heater,[kJ/kg]\n",
    "#  again from steam tables\n",
    "hf1 = 376.8;#  [kJ/kg] at 90 C\n",
    "hf2 = 79.8;#  [kJ/kg] at 19 C\n",
    "\n",
    "#  using energy balance,mw_dot*(hf1-hf2)=ms_dot*(h-hf1)\n",
    "mw_dot = ms_dot*(h-hf1)/(hf1-hf2);#  mass of water entering to heater,[kg/h]\n",
    "#results\n",
    "print ' (a) The mass of steam entering the heater (kg/h) = ',round(ms_dot,1)\n",
    "print ' (b) The mass of water entering the heater (kg/h) = ',round(mw_dot,2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11: pg 72"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.11\n",
      " The change in internal energy (kJ) =  -486.753\n"
     ]
    }
   ],
   "source": [
    "#pg 72\n",
    "#calculate the change in internal energy\n",
    "print('Example 4.11');\n",
    "\n",
    "# aim: To determine\n",
    "#  the change of internal energy\n",
    "\n",
    "#  Given values\n",
    "m = 1.5;#  mass of steam,[kg]\n",
    "P1 = 1;#  initial pressure, [MN/m**2]\n",
    "t = 225;#  temperature, [C]\n",
    "P2 = .28;#  final pressure, [MN/m**2]\n",
    "x = .9;#  dryness fraction of steam at P2\n",
    "\n",
    "#  solution\n",
    "\n",
    "# from steam table at P1\n",
    "h1 = 2886;#  [kJ/kg]\n",
    "v1 = .2198; #  [m**3/kg]\n",
    "#  hence\n",
    "u1 = h1-P1*v1*10**3;# internal energy [kJ/kg]\n",
    "\n",
    "# at P2\n",
    "hf2 = 551.4;# [kJ/kg]\n",
    "hfg2 = 2170.1;# [kJ/kg]\n",
    "vg2 = .646; #  [m**3/kg]\n",
    "#  so\n",
    "h2 = hf2+x*hfg2;#  [kj/kg]\n",
    "v2 = x*vg2;#   [m**3/kg]\n",
    "\n",
    "# now\n",
    "u2 = h2-P2*v2*10**3;#  [kJ/kg]\n",
    "\n",
    "#  hence change in specific internal energy is\n",
    "del_u = u2-u1;#  [kJ/kg]\n",
    "\n",
    "del_u = m*del_u;#  [kJ];\n",
    "#results\n",
    "print ' The change in internal energy (kJ) = ',del_u\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 12: pg 74"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.12\n",
      " Dryness fraction of steam after throttling is  =  0.787\n"
     ]
    }
   ],
   "source": [
    "#pg 74\n",
    "#calculate the dryness fraction\n",
    "print('Example 4.12');\n",
    "\n",
    "#  aim : To determine \n",
    "#  the dryness fraction of steam after throttling\n",
    "\n",
    "#  given values\n",
    "P1 = 1.4;#  pressure before throttling, [MN/m^2]\n",
    "x1 = .7;#  dryness fraction before throttling\n",
    "P2 = .11;#  pressure after throttling, [MN/m^2]\n",
    "\n",
    "#  solution\n",
    "#  from steam table\n",
    "hf1 = 830.1;#  [kJ/kg]\n",
    "hfg1 = 1957.7;#  [kJ/kg]\n",
    "h1 = hf1 + x1*hfg1; #  [kJ/kg]\n",
    "\n",
    "hf2 = 428.8;#  [kJ/kg]\n",
    "hfg2 = 2250.8;#  [kJ/kg]\n",
    "\n",
    "#  now for throttling,\n",
    "#  hf1+x1*hfg1=hf2+x2*hfg2; where x2 is dryness fraction after throttling\n",
    "\n",
    "x2=(h1-hf2)/hfg2; # final dryness fraction\n",
    "#results\n",
    "print ' Dryness fraction of steam after throttling is  = ',round(x2,3)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 13: pg 75"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.13\n",
      " (a) The condition of the resulting mixture is dry with dryness fraction  =   0.965\n",
      " (b) The internal diameter of the pipe (mm) =  145.96\n"
     ]
    }
   ],
   "source": [
    "#pg 75\n",
    "#calculate the dryness fraction and internal diameter\n",
    "print('Example 4.13');\n",
    "import math\n",
    "#  aim : To determine \n",
    "#  the dryness fraction of steam \n",
    "#  and the internal diameter of the pipe\n",
    "\n",
    "#  Given values\n",
    "\n",
    "#  steam1\n",
    "P1 = 2.;# pressure before throttling, [MN/m^2]\n",
    "t = 300.;#  temperature,[C]\n",
    "ms1_dot = 2.;# steam flow rate, [kg/s]\n",
    "P2 = 800.;#  pressure after throttling, [kN/m^2]\n",
    "\n",
    "#  steam2\n",
    "P = 800.;# pressure, [N/m^2]\n",
    "x2 = .9;#  dryness fraction\n",
    "ms2_dot = 5; #  [kg/s]\n",
    "\n",
    "#  solution\n",
    "#  (a)\n",
    "#  from steam table specific enthalpy of steam1 before throttling is\n",
    "hf1 = 3025;#  [kJ/kg]\n",
    "#  for throttling process specific enthalpy will same so final specific enthalpy of steam1 is\n",
    "hf2 = hf1;\n",
    "# hence\n",
    "h1 = ms1_dot*hf2;# [kJ/s]\n",
    "\n",
    "#  calculation of specific enthalpy of steam2\n",
    "hf2 = 720.9;#  [kJ/kg]\n",
    "hfg2 = 2046.5;#  [kJ/kg]\n",
    "#  hence\n",
    "h2 = hf2+x2*hfg2;#  specific enthalpy, [kJ/kg]\n",
    "h2 = ms2_dot*h2;#  total enthalpy, [kJ/s]\n",
    "\n",
    "#  after mixing\n",
    "m_dot = ms1_dot+ms2_dot;#  total mass of mixture,[kg/s]\n",
    "h = h1+h2;#  Total enthalpy of the mixture,[kJ/s]\n",
    "h = h/7;#  [kJ/kg]\n",
    "\n",
    "#  At pressure 800 N/m^2 \n",
    "hf = 720.9;#  [kJ/kg]\n",
    "hfg = 2046.5;#  [kJ/kg]\n",
    "#  so total enthalpy is,hf+x*hfg, where x is dryness fraction of mixture and which is equal to h\n",
    "#  hence\n",
    "x = (h-hf)/hfg;# dryness fraction after mixing\n",
    "\n",
    "#  (b)\n",
    "# Given\n",
    "C = 15;#  velocity, [m/s]\n",
    "#  from steam table\n",
    "v = .1255;#  [m^/kg]\n",
    "A = ms1_dot*v/C;#  area, [m^2]\n",
    "#  using ms1_dot = A*C/v, where A is cross section area in m^2 and\n",
    "#  A = %pi*d^2/4, where d is diameter of the pipe \n",
    "\n",
    "#  calculation of d\n",
    "d = math.sqrt(4*A/math.pi); # diameter, [m]\n",
    "#results\n",
    "print ' (a) The condition of the resulting mixture is dry with dryness fraction  =  ',round(x,3)\n",
    "print ' (b) The internal diameter of the pipe (mm) = ',round(d*1000,2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 14: pg 78"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.14\n",
      " The dryness fraction of the steam entering seprating calorimeter is  =  0.9\n"
     ]
    }
   ],
   "source": [
    "#pg 78\n",
    "#calculate the dryness fraction\n",
    "print('Example 4.14');\n",
    "\n",
    "#  aim : To estimate \n",
    "#  the dryness fraction\n",
    "\n",
    "#  Given values\n",
    "M = 1.8;#  mass of condensate, [kg]\n",
    "m = .2;#  water collected, [kg]\n",
    "\n",
    "#  solution\n",
    "x = M/(M+m);#  formula for calculation of dryness fraction using seprating calorimeter\n",
    "#results\n",
    "print ' The dryness fraction of the steam entering seprating calorimeter is  = ',x\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15: pg 80"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.15\n",
      " The dryness fraction of steam is  =  0.928\n",
      "There is a calculation mistake in book so answer is not matching\n"
     ]
    }
   ],
   "source": [
    "#pg 80\n",
    "#calculate the dryness fraction\n",
    "print('Example 4.15');\n",
    "import numpy\n",
    "#  aim : To determine\n",
    "#  the dryness fraction of the steam at 2.2 MN/m^2\n",
    "\n",
    "#  Given values\n",
    "P1 = 2.2;#  [MN/m^2]\n",
    "P2 = .13;#  [MN/m^2]\n",
    "t2 = 112;#  [C]\n",
    "tf2 = 150;#  temperature, [C]\n",
    "\n",
    "# solution\n",
    "# from steam table, at 2.2 MN/m^2\n",
    "#  saturated steam at 2 MN/m^2 Pressure\n",
    "hf1 = 931;#  [kJ/kg]\n",
    "hfg1 = 1870;#  [kJ/kg]\n",
    "hg1 = 2801;#  [kJ/kg]\n",
    "\n",
    "# for superheated steam\n",
    "#  at .1 MN/m^2\n",
    "hg2 = 2675;#  [kJ/kg]\n",
    "hg2_150 = 2777;# specific enthalpy at 150 C, [kJ/kg]\n",
    "tf2 = 99.6;#  saturation temperature, [C]\n",
    "\n",
    "# at .5 MN/m^2\n",
    "hg3 = 2693;#  [kJ/kg]\n",
    "hg3_150 = 2773;# specific enthalpy at 150 C, [kJ/kg]\n",
    "tf3 = 111.4;#  saturation temperature, [C]\n",
    "\n",
    "Table_P_h1_x = [.1,.5];# where, P in MN/m^2 and h in [kJ/kg]\n",
    "Table_P_h1_y=[hg2,hg3]\n",
    "hg = numpy.interp(.13,Table_P_h1_x,Table_P_h1_y);#  specific entahlpy at .13 MN/m^2, [kJ/kg]\n",
    "\n",
    "Table_P_h2_x = [.1,.5];#  where, P in MN/m^2 and h in [kJ/kg]\n",
    "Table_P_h2_y =[hg2_150,hg3_150];\n",
    "hg_150 = numpy.interp(.13,Table_P_h2_x,Table_P_h2_y);#  specific entahlpy at .13 MN/m^2 and 150 C, [kJ/kg]\n",
    "\n",
    "Table_P_tf_x = [.1,.5];# where, P in MN/m^2 and h in [kJ/kg]\n",
    "Table_P_tf_y = [tf2,tf3]\n",
    "tf = numpy.interp(.13,Table_P_tf_x,Table_P_tf_y);#  saturation temperature, [C]\n",
    "\n",
    "#  hence\n",
    "h2 = hg+(hg_150-hg)/(t2-tf)/(tf2-tf);#  specific enthalpy at .13 MN/m^2 and 112 C, [kJ/kg]\n",
    "\n",
    "# now since process is throttling so h2=h1\n",
    "# and h1 = hf1+x1*hfg1, so\n",
    "x1 = (h2-hf1)/hfg1;# dryness fraction\n",
    "#results\n",
    "print ' The dryness fraction of steam is  = ',round(x1,3)\n",
    "\n",
    "print 'There is a calculation mistake in book so answer is not matching'\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 16: pg 82"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.16\n",
      " The minimum dryness fraction of steam is x  =   0.939\n"
     ]
    }
   ],
   "source": [
    "#pg 82\n",
    "#calculate the minimum dryness fraction\n",
    "print('Example 4.16');\n",
    "\n",
    "#  aim : To determine \n",
    "#  the minimum dryness fraction of steam\n",
    "\n",
    "#  Given values\n",
    "P1 = 1.8;#  testing pressure,[MN/m^2]\n",
    "P2 = .11;#  pressure after throttling,[MN/m^2]\n",
    "\n",
    "#  solution\n",
    "#  from steam table\n",
    "#  at .11 MN/m^2 steam is completely dry and specific enthalpy is\n",
    "hg = 2680;#  [kJ/kg]\n",
    "\n",
    "#  before throttling steam is wet, so specific enthalpy is=hf+x*hfg, where x is dryness fraction\n",
    "#  from steam table\n",
    "hf = 885.;#  [kJ/kg]\n",
    "hfg = 1912.;#  [kJ/kg]\n",
    "\n",
    "#  now for throttling process,specific enthalpy will same before and after\n",
    "#  hence\n",
    "x = (hg-hf)/hfg;\n",
    "#results\n",
    "print ' The minimum dryness fraction of steam is x  =  ',round(x,3)\n",
    "\n",
    "#  End"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 17: pg 83"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.17\n",
      " (a) The mass of steam in the vessel (kg) =  1.569\n",
      " (b) The final dryness fraction of the steam =  0.576\n",
      " (c) The amount of heat transferred during cooling process (kJ) =  -1377.1\n"
     ]
    }
   ],
   "source": [
    "#pg 83\n",
    "#calculate the mass of steam, final dryness and amount of heat\n",
    "print('Example 4.17');\n",
    "\n",
    "#  aim : To determine the\n",
    "#  (a) mass of steam in the vessel\n",
    "#  (b) final dryness of the steam\n",
    "#  (c) amount of heat transferrred during the cooling process\n",
    "\n",
    "#  Given values\n",
    "V1 = .8;#  [m^3]\n",
    "P1 = 360.;#  [kN/m^2]\n",
    "P2 = 200.;#  [kN/m^2]\n",
    "\n",
    "#  solution\n",
    "\n",
    "#  (a)\n",
    "# at 360 kN/m^2\n",
    "vg1 = .510;#  [m^3]\n",
    "m = V1/vg1;#  mass of steam,[kg]\n",
    "\n",
    "#  (b)\n",
    "#  at 200 kN/m^2\n",
    "vg2 = .885;# [m^3/kg]\n",
    "#  the volume remains constant so\n",
    "x = vg1/vg2;# final dryness fraction\n",
    "\n",
    "# (c)\n",
    "#  at 360 kN/m^2\n",
    "h1 = 2732.9;# [kJ/kg]\n",
    "#  hence\n",
    "u1 = h1-P1*vg1;#  [kJ/kg]\n",
    "\n",
    "#  at 200 kN/m^2\n",
    "hf = 504.7;# [kJ/kg]\n",
    "hfg=2201.6;#[kJ/kg]\n",
    "#  hence\n",
    "h2 = hf+x*hfg;# [kJ/kg]\n",
    "#  now\n",
    "u2 = h2-P2*vg1;#  [kJ/kg]\n",
    "#  so\n",
    "del_u = u2-u1;#  [kJ/kg]\n",
    "#  from the first law of thermodynamics del_U+W=Q, \n",
    "W = 0;#  because volume is constant\n",
    "del_U = m*del_u;#  [kJ]\n",
    "#  hence\n",
    "Q = del_U;#  [kJ]\n",
    "#results\n",
    "print ' (a) The mass of steam in the vessel (kg) = ',round(m,3)\n",
    "print ' (b) The final dryness fraction of the steam = ',round(x,3)\n",
    "print ' (c) The amount of heat transferred during cooling process (kJ) = ',round(Q,1)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 18: pg 84"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.18\n",
      " The heat received by the steam (kJ/kg) =  380.3\n"
     ]
    }
   ],
   "source": [
    "#pg 84\n",
    "#calculate the heat received by steam\n",
    "print('Example 4.18');\n",
    "\n",
    "#  aim : To determine\n",
    "#  the heat received by the steam per kilogram\n",
    "\n",
    "# Given values\n",
    "# initial\n",
    "P1 = 4;# pressure, [MN/m^2]\n",
    "x1 = .95; #  dryness fraction\n",
    "\n",
    "#  final\n",
    "t2 = 350;#  temperature,[C]\n",
    "\n",
    "#  solution\n",
    "\n",
    "# from steam table, at 4 MN/m^2 and x1=.95\n",
    "hf = 1087.4;#  [kJ/kg]\n",
    "hfg = 1712.9;#  [kJ/kg]\n",
    "#  hence\n",
    "h1 = hf+x1*hfg;#  [kJ/kg]\n",
    "\n",
    "#  since pressure is kept constant ant temperature is raised so at this condition\n",
    "h2 = 3095;#  [kJ/kg]\n",
    "\n",
    "#  so by energy balance\n",
    "Q = h2-h1;#  Heat received,[kJ/kg]\n",
    "#results\n",
    "print ' The heat received by the steam (kJ/kg) = ',round(Q,1)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 19: pg 85"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.19\n",
      " (a) The Quantity of steam present (kg) =  3.0\n",
      "      Dryness fraction is  =   0.5\n",
      "      The enthalpy (kJ) =  5451.9\n",
      "      The heat loss (kJ) =  2917.8\n",
      " (b) The dryness fraction is  =  0.989\n",
      "     The enthalpy (kJ) =  8346.3\n"
     ]
    }
   ],
   "source": [
    "#pg 85\n",
    "#calculate the condition after the given cases\n",
    "print('Example 4.19');\n",
    "\n",
    "#  aim : To determine the condition of the steam after \n",
    "#  (a) isothermal compression to half its initial volume,heat rejected\n",
    "#  (b) hyperbolic compression to half its initial volume\n",
    "\n",
    "#  Given values\n",
    "V1 = .3951;#  initial volume,[m^3]\n",
    "P1 = 1.5;#  initial pressure,[MN/m^2]\n",
    "\n",
    "#  solution\n",
    "\n",
    "#  (a)\n",
    "#  from steam table, at 1.5 MN/m^2 \n",
    "hf1 = 844.7;#  [kJ/kg]\n",
    "hfg1 = 1945.2;#  [kJ/kg]\n",
    "hg1 = 2789.9;# [kJ/kg]\n",
    "vg1 = .1317;#  [m^3/kg]\n",
    "\n",
    "#  calculation\n",
    "m = V1/vg1;#  mass of steam,[kg]\n",
    "vg2b = vg1/2;# given,[m^3/kg](vg2b is actual specific volume before compression)\n",
    "x1 = vg2b/vg1;#  dryness fraction\n",
    "h1 = m*(hf1+x1*hfg1);#  [kJ]\n",
    "Q = m*x1*hfg1;#  heat loss,[kJ]\n",
    "print ' (a) The Quantity of steam present (kg) = ',m\n",
    "print '      Dryness fraction is  =  ',x1\n",
    "print '      The enthalpy (kJ) = ',h1\n",
    "print '      The heat loss (kJ) = ',Q\n",
    "\n",
    "#  (b)\n",
    "V2 = V1/2;\n",
    "#  Given compression is according to the law PV=Constant,so\n",
    "P2 = P1*V1/V2;#  [MN/m^2]\n",
    "#  from steam table at P2\n",
    "hf2 = 1008.4;# [kJ/kg]\n",
    "hfg2 = 1793.9;#  [kJ/kg]\n",
    "hg2 = 2802.3;#  [kJ/kg]\n",
    "vg2 = .0666;#  [m^3/kg]\n",
    "\n",
    "#  calculation\n",
    "x2 = vg2b/vg2;#  dryness fraction\n",
    "h2 = m*(hf2+x2*hfg2);#  [kJ]\n",
    "\n",
    "print ' (b) The dryness fraction is  = ',round(x2,3)\n",
    "print '     The enthalpy (kJ) = ',round(h2,1)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 20: pg 88"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.20\n",
      " (a) The mass of steam present (kg) =  5.0\n",
      " (b) The work transfer (kJ) =  708.0\n",
      " (c) The change in internal energy (kJ) =  -1611.0\n",
      "since del_U<0,so this is loss of internal energy\n",
      " (d) The heat exchange between the steam and surrounding (kJ) =  -903.0\n",
      "since Q<0,so this is loss of heat energy to surrounding\n",
      "there are minor vairations in the values reported in the book due to rounding off error\n"
     ]
    }
   ],
   "source": [
    "#pg 88\n",
    "#calculate the mass of steam, work transfer, change of internal energy, heat exchange\n",
    "print('Example 4.20');\n",
    "\n",
    "#  aim : To determine the\n",
    "#  (a) mass of steam \n",
    "#  (b) work transfer\n",
    "#  (c) change of internal energy\n",
    "#  (d) heat exchange b/w the steam and surroundings\n",
    "\n",
    "#  Given values\n",
    "P1 = 2.1;#  initial pressure,[MN/m**2]\n",
    "x1 = .9;#  dryness fraction\n",
    "V1 = .427;#  initial volume,[m**3]\n",
    "P2 = .7;#  final pressure,[MN/m**2]\n",
    "#  Given process is polytropic with\n",
    "n = 1.25; # polytropic index\n",
    "\n",
    "#  solution\n",
    "#  from steam table\n",
    "\n",
    "#  at 2.1 MN/m**2\n",
    "hf1 = 920.0;#  [kJ/kg]\n",
    "hfg1=1878.2;#  [kJ/kg]\n",
    "hg1=2798.2;#  [kJ/kg]\n",
    "vg1 = .0949;#  [m**3/kg]\n",
    "\n",
    "#  and at .7 MN/m**2\n",
    "hf2 = 697.1;#  [kJ/kg]\n",
    "hfg2 = 2064.9;#  [kJ/kg]\n",
    "hg2 = 2762.0;# [kJ/kg]\n",
    "vg2 = .273;#  [m**3/kg]\n",
    "\n",
    "#calculations and results\n",
    "#  (a)\n",
    "v1 = x1*vg1;#  [m**3/kg]\n",
    "m = V1/v1;#  [kg]\n",
    "print ' (a) The mass of steam present (kg) = ',round(m)\n",
    "\n",
    "#  (b)\n",
    "#  for polytropic process\n",
    "v2 = v1*(P1/P2)**(1/n);#  [m**3/kg]\n",
    "\n",
    "x2 = v2/vg2;#  final dryness fraction\n",
    "#  work transfer\n",
    "W = m*(P1*v1-P2*v2)*10**3/(n-1);#  [kJ]\n",
    "print ' (b) The work transfer (kJ) = ',round(W)\n",
    "\n",
    "#  (c)\n",
    "#  initial\n",
    "h1 = hf1+x1*hfg1;#  [kJ/kg]\n",
    "u1 = h1-P1*v1*10**3;#  [kJ/kg]\n",
    "\n",
    "#  final\n",
    "h2 = hf2+x2*hfg2;#  [kJ/kg]\n",
    "u2 = h2-P2*v2*10**3;#  [kJ/kg]\n",
    "\n",
    "del_U = m*(u2-u1);#  [kJ]\n",
    "print ' (c) The change in internal energy (kJ) = ',round(del_U)\n",
    "if(del_U<0):\n",
    "    print('since del_U<0,so this is loss of internal energy')\n",
    "else:\n",
    "    print('since del_U>0,so this is gain in internal energy')\n",
    "\n",
    "\n",
    "#  (d)\n",
    "Q = del_U+W;#  [kJ]\n",
    "print ' (d) The heat exchange between the steam and surrounding (kJ) = ',round(Q,1)\n",
    "if(Q<0):\n",
    "    print('since Q<0,so this is loss of heat energy to surrounding')\n",
    "else:\n",
    "    print('since Q>0,so this is gain in heat energy to the steam')\n",
    "\n",
    "print 'there are minor vairations in the values reported in the book due to rounding off error'\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21: pg 91"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 4.21\n",
      " (a) The volume occupied by 1 kg of steam (m^3/kg) =  0.22\n",
      " (b)(1) The final dryness fraction of the steam =  0.887\n",
      "    (2) The change in internal energy of the steam during expansion is  (kJ/kg)  (This is a loss of internal energy) =  -243.0\n",
      " There are minor variation in the answer due to rounding off error\n"
     ]
    }
   ],
   "source": [
    "#pg 91\n",
    "#calculate the volume, dryness fraction and change in internal energy\n",
    "print('Example 4.21');\n",
    "\n",
    "#  aim : To determine the \n",
    "#  (a) volume occupied by steam\n",
    "#  (b)(1) final dryness fraction of steam\n",
    "#       (2) Change of internal energy during expansion\n",
    "\n",
    "#  (a)\n",
    "#  Given values\n",
    "P1 = .85;#  [mN/m**2]\n",
    "x1 = .97;\n",
    "\n",
    "#  solution\n",
    "#  from steam table, at .85 MN/m**2,\n",
    "vg1 = .2268;#  [m**3/kg]\n",
    "#  hence\n",
    "v1 = x1*vg1;#  [m**3/kg]\n",
    "print ' (a) The volume occupied by 1 kg of steam (m^3/kg) = ',round(v1,2)\n",
    "\n",
    "# (b)(1)\n",
    "P2 = .17;#  [MN/m**2]\n",
    "# since process is polytropic process with\n",
    "n = 1.13; #  polytropic index\n",
    "# hence\n",
    "v2 = v1*(P1/P2)**(1/n);# [m**3/kg]\n",
    "\n",
    "# from steam table at .17 MN/m**2\n",
    "vg2 = 1.031;# [m**3/kg]\n",
    "# steam is wet so\n",
    "x2 = v2/vg2;#  final dryness fraction\n",
    "print ' (b)(1) The final dryness fraction of the steam = ',round(x2,3)\n",
    "\n",
    "#  (2)\n",
    "W = (P1*v1-P2*v2)*10**3/(n-1);# [kJ/kg]\n",
    "#  since process is adiabatic, so\n",
    "del_u = -W;# [kJ/kg]\n",
    "print '    (2) The change in internal energy of the steam during expansion is  (kJ/kg)  (This is a loss of internal energy) = ',round(del_u)\n",
    "print' There are minor variation in the answer due to rounding off error'\n",
    "\n",
    "#  End\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.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}