summaryrefslogtreecommitdiff
path: root/Engineering_Thermodynamics_by_O._Singh/chapter7_2.ipynb
blob: 8171c9b6feea1376bceeee70b56917fb5f6dfbdb (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
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 7:Availability and General Thermodynamic Relation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.1;page no: 218"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.1, Page:218  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 1\n",
      "let us neglect the potential energy change during the flow.\n",
      "applying S.F.E.E,neglecting inlet velocity and change in potential energy,\n",
      "W_max=(h1-To*s1)-(h2+C2^2/2-To*s2)\n",
      "W_max=(h1-h2)-To*(s1-s2)-C2^2/2\n",
      "from steam tables,\n",
      "h1=h_1.6Mpa_300=3034.8 KJ/kg,s1=s_1.6Mpa_300=6.8844 KJ/kg,h2=h_0.1Mpa_150=2776.4 KJ/kg,s2=s_150Mpa_150=7.6134 KJ/kg\n",
      "given To=288 K\n",
      "so W_max in KJ/kg= 457.1\n",
      "maximum possible work(W_max) in KW= 1142.76\n"
     ]
    }
   ],
   "source": [
    "#cal of maximum possible work\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.1, Page:218  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 1\")\n",
    "C2=150;#leave velocity of steam in m/s\n",
    "m=2.5;#steam mass flow rate in kg/s\n",
    "print(\"let us neglect the potential energy change during the flow.\")\n",
    "print(\"applying S.F.E.E,neglecting inlet velocity and change in potential energy,\")\n",
    "print(\"W_max=(h1-To*s1)-(h2+C2^2/2-To*s2)\")\n",
    "print(\"W_max=(h1-h2)-To*(s1-s2)-C2^2/2\")\n",
    "print(\"from steam tables,\")\n",
    "print(\"h1=h_1.6Mpa_300=3034.8 KJ/kg,s1=s_1.6Mpa_300=6.8844 KJ/kg,h2=h_0.1Mpa_150=2776.4 KJ/kg,s2=s_150Mpa_150=7.6134 KJ/kg\")\n",
    "h1=3034.8;\n",
    "s1=6.8844;\n",
    "h2=2776.4;\n",
    "s2=7.6134;\n",
    "print(\"given To=288 K\")\n",
    "To=288;\n",
    "W_max=(h1-h2)-To*(s1-s2)-(C2**2/2*10**-3)\n",
    "print(\"so W_max in KJ/kg=\"),round(W_max,2)\n",
    "W_max=m*W_max\n",
    "print(\"maximum possible work(W_max) in KW=\"),round(W_max,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.2;page no: 219"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.2, Page:219  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 2\n",
      "In these tanks the air stored is at same temperature of 50 degree celcius.Therefore,for air behaving as perfect gas the internal energy of air in tanks shall be same as it depends upon temperature alone.But the availability shall be different.\n",
      "BOTH THE TANKS HAVE SAME INTERNAL ENERGY\n",
      "availability of air in tank,A\n",
      "A=(E-Uo)+Po*(V-Vo)-To*(S-So)\n",
      "=m*{(e-uo)+Po(v-vo)-To(s-so)}\n",
      "m*{Cv*(T-To)+Po*(R*T/P-R*To/Po)-To(Cp*log(T/To)-R*log(P/Po))}\n",
      "so A=m*{Cv*(T-To)+R*(Po*T/P-To)-To*Cp*log(T/To)+To*R*log(P/Po)}\n",
      "for tank A,P in pa,so availability_A in KJ= 1.98\n",
      "for tank B,P=3*10^5 pa,so availability_B in KJ= 30.98\n",
      "so availability of air in tank B is more than that of tank A\n",
      "availability of air in tank A=1.98 KJ\n",
      "availability of air in tank B=30.98 KJ\n"
     ]
    }
   ],
   "source": [
    "#cal of availability of air in tank A,B\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "import math\n",
    "print\"Example 7.2, Page:219  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 2\")\n",
    "m=1.;#mass of air in kg\n",
    "Po=1.*10**5;#atmospheric pressure in pa\n",
    "To=(15.+273.);#temperature of atmosphere in K\n",
    "Cv=0.717;#specific heat at constant volume in KJ/kg K\n",
    "R=0.287;#gas constant in KJ/kg K\n",
    "Cp=1.004;#specific heat at constant pressure in KJ/kg K\n",
    "T=(50.+273.);#temperature of tanks A and B in K\n",
    "print(\"In these tanks the air stored is at same temperature of 50 degree celcius.Therefore,for air behaving as perfect gas the internal energy of air in tanks shall be same as it depends upon temperature alone.But the availability shall be different.\")\n",
    "print(\"BOTH THE TANKS HAVE SAME INTERNAL ENERGY\")\n",
    "print(\"availability of air in tank,A\")\n",
    "print(\"A=(E-Uo)+Po*(V-Vo)-To*(S-So)\")\n",
    "print(\"=m*{(e-uo)+Po(v-vo)-To(s-so)}\")\n",
    "print(\"m*{Cv*(T-To)+Po*(R*T/P-R*To/Po)-To(Cp*log(T/To)-R*log(P/Po))}\")\n",
    "print(\"so A=m*{Cv*(T-To)+R*(Po*T/P-To)-To*Cp*log(T/To)+To*R*log(P/Po)}\")\n",
    "P=1.*10**5;#pressure in tank A in pa\n",
    "availability_A=m*(Cv*(T-To)+R*(Po*T/P-To)-To*Cp*math.log(T/To)+To*R*math.log(P/Po))\n",
    "print(\"for tank A,P in pa,so availability_A in KJ=\"),round(availability_A,2)\n",
    "P=3.*10**5;#pressure in tank B in pa\n",
    "availability_B=m*(Cv*(T-To)+R*(Po*T/P-To)-To*Cp*math.log(T/To)+To*R*math.log(P/Po))\n",
    "print(\"for tank B,P=3*10^5 pa,so availability_B in KJ=\"),round(availability_B,2)\n",
    "print(\"so availability of air in tank B is more than that of tank A\")\n",
    "print(\"availability of air in tank A=1.98 KJ\")\n",
    "print(\"availability of air in tank B=30.98 KJ\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.3;page no: 221"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.3, Page:221  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 3\n",
      "inlet conditions,\n",
      "from steam tables,,h1=3051.2 KJ/kg,s1=7.1229 KJ/kg K\n",
      "outlet conditions,at 0.05 bar and 0.95 dryness fraction\n",
      "from steam tables,sf=0.4764 KJ/kg K,s_fg=7.9187 KJ/kg K,x=0.95,hf=137.82 KJ/kg,h_fg=2423.7 KJ/kg\n",
      "so s2= in KJ/kg K= 8.0\n",
      "and h2= in KJ/kg= 2440.34\n",
      "neglecting the change in potential energy and velocity at inlet to turbine,the steady flow energy equation may be written as to give work output.\n",
      "w in KJ/kg= 598.06\n",
      "power output in KW= 8970.97\n",
      "maximum work for given end states,\n",
      "w_max=(h1-To*s1)-(h2+V2^2*10^-3/2-To*s2) in KJ/kg 850.43\n",
      "w_max in KW 12755.7\n",
      "so maximum power output=12755.7 KW\n",
      "maximum power that could be obtained from exhaust steam shall depend upon availability with exhaust steam and the dead state.stream availability of exhaust steam,\n",
      "A_exhaust=(h2+V^2/2-To*s2)-(ho-To*so)\n",
      "=(h2-ho)+V2^2/2-To(s2-so)\n",
      "approximately the enthalpy of water at dead state of 1 bar,15 degree celcius can be approximated to saturated liquid at 15 degree celcius\n",
      "from steam tables,at 15 degree celcius,ho=62.99 KJ/kg,so=0.2245 KJ/kg K\n",
      "maximum work available from exhaust steam,A_exhaust in KJ/kg\n",
      "A_exhaust=(h2-ho)+V2^2*10^-3/2-To*(s2-so) 151.1\n",
      "maximum power that could be obtained from exhaust steam in KW= 2266.5\n",
      "so maximum power from exhaust steam=2266.5 KW\n"
     ]
    }
   ],
   "source": [
    "#cal of maximum power output and that could be obtained from exhaust steam\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.3, Page:221  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 3\")\n",
    "m=15;#steam flow rate in kg/s\n",
    "V2=160;#exit velocity of steam in m/s\n",
    "To=(15+273);#pond water temperature in K\n",
    "print(\"inlet conditions,\")\n",
    "print(\"from steam tables,,h1=3051.2 KJ/kg,s1=7.1229 KJ/kg K\")\n",
    "h1=3051.2;\n",
    "s1=7.1229;\n",
    "print(\"outlet conditions,at 0.05 bar and 0.95 dryness fraction\")\n",
    "print(\"from steam tables,sf=0.4764 KJ/kg K,s_fg=7.9187 KJ/kg K,x=0.95,hf=137.82 KJ/kg,h_fg=2423.7 KJ/kg\")\n",
    "sf=0.4764;\n",
    "s_fg=7.9187;\n",
    "x=0.95;\n",
    "hf=137.82;\n",
    "h_fg=2423.7;\n",
    "s2=sf+x*s_fg\n",
    "print(\"so s2= in KJ/kg K=\"),round(s2,2)\n",
    "h2=hf+x*h_fg\n",
    "print(\"and h2= in KJ/kg=\"),round(h2,2)\n",
    "print(\"neglecting the change in potential energy and velocity at inlet to turbine,the steady flow energy equation may be written as to give work output.\")\n",
    "w=(h1-h2)-V2**2*10**-3/2\n",
    "print(\"w in KJ/kg=\"),round(w,2)\n",
    "print(\"power output in KW=\"),round(m*w,2)\n",
    "print(\"maximum work for given end states,\")\n",
    "w_max=(h1-To*s1)-(h2+V2**2*10**-3/2-To*s2)\n",
    "print(\"w_max=(h1-To*s1)-(h2+V2^2*10^-3/2-To*s2) in KJ/kg\"),round(w_max,2)\n",
    "w_max=850.38;#approx.\n",
    "w_max=m*w_max\n",
    "print(\"w_max in KW\"),round(w_max,2)\n",
    "print(\"so maximum power output=12755.7 KW\")\n",
    "print(\"maximum power that could be obtained from exhaust steam shall depend upon availability with exhaust steam and the dead state.stream availability of exhaust steam,\")\n",
    "print(\"A_exhaust=(h2+V^2/2-To*s2)-(ho-To*so)\")\n",
    "print(\"=(h2-ho)+V2^2/2-To(s2-so)\")\n",
    "print(\"approximately the enthalpy of water at dead state of 1 bar,15 degree celcius can be approximated to saturated liquid at 15 degree celcius\")\n",
    "print(\"from steam tables,at 15 degree celcius,ho=62.99 KJ/kg,so=0.2245 KJ/kg K\")\n",
    "ho=62.99;\n",
    "so=0.2245;\n",
    "print(\"maximum work available from exhaust steam,A_exhaust in KJ/kg\")\n",
    "A_exhaust=(h2-ho)+V2**2*10**-3/2-To*(s2-so)\n",
    "A_exhaust=151.1;#approx.\n",
    "print(\"A_exhaust=(h2-ho)+V2^2*10^-3/2-To*(s2-so)\"),round(A_exhaust,2)\n",
    "print(\"maximum power that could be obtained from exhaust steam in KW=\"),round(m*A_exhaust,2)\n",
    "print(\"so maximum power from exhaust steam=2266.5 KW\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.4;page no: 222"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.4, Page:222  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 4\n",
      "for dead state of water,\n",
      "from steam tables,uo=104.86 KJ/kg,vo=1.0029*10^-3 m^3/kg,so=0.3673 KJ/kg K\n",
      "for initial state of water,\n",
      "from steam tables,u1=2550 KJ/kg,v1=0.5089 m^3/kg,s1=6.93 KJ/kg K\n",
      "for final state of water,\n",
      "from steam tables,u2=83.94 KJ/kg,v2=1.0018*10^-3 m^3/kg,s2=0.2966 KJ/kg K\n",
      "availability at any state can be given by\n",
      "A=m*((u-uo)+Po*(v-vo)-To*(s-so)+V^2/2+g*z)\n",
      "so availability at initial state,A1 in KJ\n",
      "A1= 2703.28\n",
      "and availability at final state,A2 in KJ\n",
      "A2= 1.09\n",
      "change in availability,A2-A1 in KJ= -2702.19\n",
      "hence availability decreases by 2702.188 KJ\n",
      "NOTE=>In this question,due to large calculations,answers are approximately correct.\n"
     ]
    }
   ],
   "source": [
    "#cal of availability at initial,final state and also change\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.4, Page:222  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 4\")\n",
    "m=5;#mass of steam in kg\n",
    "z1=10;#initial elevation in m\n",
    "V1=25;#initial velocity of steam in m/s\n",
    "z2=2;#final elevation in m\n",
    "V2=10;#final velocity of steam in m/s\n",
    "Po=100;#environmental pressure in Kpa\n",
    "To=(25+273);#environmental temperature in K\n",
    "g=9.81;#acceleration due to gravity in m/s^2\n",
    "print(\"for dead state of water,\")\n",
    "print(\"from steam tables,uo=104.86 KJ/kg,vo=1.0029*10^-3 m^3/kg,so=0.3673 KJ/kg K\")\n",
    "uo=104.86;\n",
    "vo=1.0029*10**-3;\n",
    "so=0.3673;\n",
    "print(\"for initial state of water,\")\n",
    "print(\"from steam tables,u1=2550 KJ/kg,v1=0.5089 m^3/kg,s1=6.93 KJ/kg K\")\n",
    "u1=2550;\n",
    "v1=0.5089;\n",
    "s1=6.93;\n",
    "print(\"for final state of water,\")\n",
    "print(\"from steam tables,u2=83.94 KJ/kg,v2=1.0018*10^-3 m^3/kg,s2=0.2966 KJ/kg K\")\n",
    "u2=83.94;\n",
    "v2=1.0018*10**-3;\n",
    "s2=0.2966;\n",
    "print(\"availability at any state can be given by\")\n",
    "print(\"A=m*((u-uo)+Po*(v-vo)-To*(s-so)+V^2/2+g*z)\")\n",
    "A1=m*((u1-uo)+Po*(v1-vo)-To*(s1-so)+V1**2*10**-3/2+g*z1*10**-3)\n",
    "print(\"so availability at initial state,A1 in KJ\")\n",
    "print(\"A1=\"),round(A1,2)\n",
    "A2=m*((u2-uo)+Po*(v2-vo)-To*(s2-so)+V2**2*10**-3/2+g*z2*10**-3)\n",
    "print(\"and availability at final state,A2 in KJ\")\n",
    "print(\"A2=\"),round(A2,2)\n",
    "A2-A1\n",
    "print(\"change in availability,A2-A1 in KJ=\"),round(A2-A1,2)\n",
    "print(\"hence availability decreases by 2702.188 KJ\")\n",
    "print(\"NOTE=>In this question,due to large calculations,answers are approximately correct.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.5;page no: 223"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.5, Page:223  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 5\n",
      "In question no. 5 expression I=To*S_gen is derived which cannot be solve using python software.\n"
     ]
    }
   ],
   "source": [
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.5, Page:223  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 5\")\n",
    "print(\"In question no. 5 expression I=To*S_gen is derived which cannot be solve using python software.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.6;pg no: 223"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.6, Page:223  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 6\n",
      "loss of available energy=irreversibility=To*deltaSc\n",
      "deltaSc=deltaSs+deltaSe\n",
      "change in enropy of system(deltaSs)=W/T in KJ/kg K 0.98\n",
      "change in entropy of surrounding(deltaSe)=-Cp*(T-To)/To in KJ/kg K -2.8\n",
      "loss of available energy(E) in KJ/kg= -550.49\n",
      "loss of available energy(E)= -550.49\n",
      "ratio of lost available exhaust gas energy to engine work=E/W= 0.524\n"
     ]
    }
   ],
   "source": [
    "#cal of  available energy and ratio of lost available exhaust gas energy to engine work\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.6, Page:223  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 6\")\n",
    "To=(30.+273.);#temperature of surrounding in K\n",
    "W=1050.;#work done in engine in KJ/kg\n",
    "Cp=1.1;#specific heat at constant pressure in KJ/kg K\n",
    "T=(800.+273.);#temperature of exhaust gas in K\n",
    "print(\"loss of available energy=irreversibility=To*deltaSc\")\n",
    "print(\"deltaSc=deltaSs+deltaSe\")\n",
    "deltaSs=W/T\n",
    "print(\"change in enropy of system(deltaSs)=W/T in KJ/kg K\"),round(deltaSs,2)\n",
    "deltaSe=-Cp*(T-To)/To\n",
    "print(\"change in entropy of surrounding(deltaSe)=-Cp*(T-To)/To in KJ/kg K\"),round(deltaSe,2)\n",
    "E=To*(deltaSs+deltaSe)\n",
    "print(\"loss of available energy(E) in KJ/kg=\"),round(E,2)\n",
    "E=-E\n",
    "print(\"loss of available energy(E)=\"),round(-E,2)\n",
    "print(\"ratio of lost available exhaust gas energy to engine work=E/W=\"),round(E/W,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.7;pg no: 224"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.7, Page:224  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 7\n",
      "let us consider velocities and elevations to be given in reference to environment.Availability is given by\n",
      "A=m*((u-uo)+Po*(v-vo)-To(s-so)+C^2/2+g*z)\n",
      "dead state of water,from steam tables,uo=104.88 KJ/kg,vo=1.003*10^-3 m^3/kg,so=0.3674 KJ/kg K\n",
      "for initial state of saturated vapour at 150 degree celcius\n",
      "from steam tables,u1=2559.5 KJ/kg,v1=0.3928 m^3/kg,s1=6.8379 KJ/kg K\n",
      "for final state of saturated liquid at 20 degree celcius\n",
      "from steam tables,u2=83.95 KJ/kg,v2=0.001002 m^3/kg,s2=0.2966 KJ/kg K\n",
      "substituting in the expression for availability\n",
      "initial state availability,A1 in KJ\n",
      "A1= 5650.31\n",
      "final state availability,A2 in KJ\n",
      "A2= 2.58\n",
      "change in availability,deltaA  in KJ= -5647.72\n",
      "so initial availability =5650.28 KJ\n",
      "final availability=2.58 KJ \n",
      "change in availability=decrease by 5647.70 KJ \n"
     ]
    }
   ],
   "source": [
    "#cal of initial,final and change in availability\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.7, Page:224  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 7\")\n",
    "m=10;#mass of water in kg\n",
    "C1=25;#initial velocity in m/s\n",
    "C2=10;#final velocity in m/s\n",
    "Po=0.1*1000;#environmental pressure in Kpa\n",
    "To=(25+273.15);#environmental temperature in K\n",
    "g=9.8;#acceleration due to gravity in m/s^2\n",
    "z1=10;#initial elevation in m\n",
    "z2=3;#final elevation in m\n",
    "print(\"let us consider velocities and elevations to be given in reference to environment.Availability is given by\")\n",
    "print(\"A=m*((u-uo)+Po*(v-vo)-To(s-so)+C^2/2+g*z)\")\n",
    "print(\"dead state of water,from steam tables,uo=104.88 KJ/kg,vo=1.003*10^-3 m^3/kg,so=0.3674 KJ/kg K\")\n",
    "uo=104.88;\n",
    "vo=1.003*10**-3;\n",
    "so=0.3674;\n",
    "print(\"for initial state of saturated vapour at 150 degree celcius\")\n",
    "print(\"from steam tables,u1=2559.5 KJ/kg,v1=0.3928 m^3/kg,s1=6.8379 KJ/kg K\")\n",
    "u1=2559.5;\n",
    "v1=0.3928;\n",
    "s1=6.8379;\n",
    "print(\"for final state of saturated liquid at 20 degree celcius\")\n",
    "print(\"from steam tables,u2=83.95 KJ/kg,v2=0.001002 m^3/kg,s2=0.2966 KJ/kg K\")\n",
    "u2=83.95;\n",
    "v2=0.001002;\n",
    "s2=0.2966;\n",
    "print(\"substituting in the expression for availability\")\n",
    "A1=m*((u1-uo)+Po*(v1-vo)-To*(s1-so)+C1**2*10**-3/2+g*z1*10**-3)\n",
    "print(\"initial state availability,A1 in KJ\")\n",
    "print(\"A1=\"),round(A1,2)\n",
    "A2=m*((u2-uo)+Po*(v2-vo)-To*(s2-so)+C2**2*10**-3/2+g*z2*10**-3)\n",
    "print(\"final state availability,A2 in KJ\")\n",
    "print(\"A2=\"),round(A2,2)\n",
    "deltaA=A2-A1\n",
    "print(\"change in availability,deltaA  in KJ=\"),round(deltaA,2)\n",
    "print(\"so initial availability =5650.28 KJ\")\n",
    "print(\"final availability=2.58 KJ \")\n",
    "print(\"change in availability=decrease by 5647.70 KJ \")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.8;pg no: 225"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.8, Page:225  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 8\n",
      "let inlet and exit states of turbine be denoted as 1 and 2\n",
      "at inlet to turbine,\n",
      "from steam tables,h1=3433.8 KJ/kg,s1=6.9759 KJ/kg K\n",
      "at exit from turbine,\n",
      "from steam tables,h2=2748 KJ/kg,s2=7.228 KJ/kg K\n",
      "at dead state,\n",
      "from steam tables,ho=104.96 KJ/kg,so=0.3673 KJ/kg K\n",
      "availability of steam at inlet,A1 in KJ= 6792.43\n",
      "so availability of steam at inlet=6792.43 KJ\n",
      "applying first law of thermodynamics,\n",
      "Q+m*h1=m*h2+W\n",
      "so W in KJ/s= 2829.0\n",
      "so turbine output=2829 KW\n",
      "maximum possible turbine output will be available when irreversibility is zero.\n",
      "W_rev=W_max=A1-A2\n",
      "W_max in KJ/s= 3804.82\n",
      "so maximum output=3804.81 KW\n",
      "irreversibility can be estimated by the difference between the maximum output and turbine output.\n",
      "I= in KW= 975.82\n",
      "so irreversibility=975.81807 KW\n",
      "NOTE=>In book,W_max is calculated wrong,so irreversibility also comes wrong,which are corrected above.\n"
     ]
    }
   ],
   "source": [
    "#cal of availability of steam at inlet,turbine output,maximum possible turbine output,irreversibility\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.8, Page:225  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 8\")\n",
    "m=5.;#steam flow rate in kg/s\n",
    "p1=5.*1000.;#initial pressure of steam in Kpa\n",
    "T1=(500.+273.15);#initial temperature of steam in K \n",
    "p2=0.2*1000.;#final pressure of steam in Kpa\n",
    "T1=(140.+273.15);#final temperature of steam in K\n",
    "po=101.3;#pressure of steam at dead state in Kpa\n",
    "To=(25.+273.15);#temperature of steam at dead state in K  \n",
    "Q=600.;#heat loss through turbine in KJ/s\n",
    "print(\"let inlet and exit states of turbine be denoted as 1 and 2\")\n",
    "print(\"at inlet to turbine,\")\n",
    "print(\"from steam tables,h1=3433.8 KJ/kg,s1=6.9759 KJ/kg K\")\n",
    "h1=3433.8;\n",
    "s1=6.9759;\n",
    "print(\"at exit from turbine,\")\n",
    "print(\"from steam tables,h2=2748 KJ/kg,s2=7.228 KJ/kg K\")\n",
    "h2=2748;\n",
    "s2=7.228;\n",
    "print(\"at dead state,\")\n",
    "print(\"from steam tables,ho=104.96 KJ/kg,so=0.3673 KJ/kg K\")\n",
    "ho=104.96;\n",
    "so=0.3673;\n",
    "A1=m*((h1-ho)-To*(s1-so))\n",
    "print(\"availability of steam at inlet,A1 in KJ=\"),round(A1,2)\n",
    "print(\"so availability of steam at inlet=6792.43 KJ\")\n",
    "print(\"applying first law of thermodynamics,\")\n",
    "print(\"Q+m*h1=m*h2+W\")\n",
    "W=m*(h1-h2)-Q\n",
    "print(\"so W in KJ/s=\"),round(W,2)\n",
    "print(\"so turbine output=2829 KW\")\n",
    "print(\"maximum possible turbine output will be available when irreversibility is zero.\")\n",
    "print(\"W_rev=W_max=A1-A2\")\n",
    "W_max=m*((h1-h2)-To*(s1-s2))\n",
    "print(\"W_max in KJ/s=\"),round(W_max,2)\n",
    "print(\"so maximum output=3804.81 KW\")\n",
    "print(\"irreversibility can be estimated by the difference between the maximum output and turbine output.\")\n",
    "I=W_max-W\n",
    "print(\"I= in KW=\"),round(I,2)\n",
    "print(\"so irreversibility=975.81807 KW\")\n",
    "print(\"NOTE=>In book,W_max is calculated wrong,so irreversibility also comes wrong,which are corrected above.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.9;pg no: 226"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.9, Page:226  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 9\n",
      "In question no.9 comparision between sublimation and vaporisation line is made which cannot be solve using python software.\n"
     ]
    }
   ],
   "source": [
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.9, Page:226  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 9\")\n",
    "print(\"In question no.9 comparision between sublimation and vaporisation line is made which cannot be solve using python software.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.10;pg no: 227"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.10, Page:227  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 10\n",
      "In question no. 10 expression for change in internal energy of gas is derive which cannot be solve using python software.\n"
     ]
    }
   ],
   "source": [
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.10, Page:227  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 10\")\n",
    "print(\"In question no. 10 expression for change in internal energy of gas is derive which cannot be solve using python software.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.11;pg no: 227"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.11, Page:227  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 11\n",
      "availability for heat reservoir(A_HR) in KJ/kg K 167.66\n",
      "now availability for system(A_system) in KJ/kg K 194.44\n",
      "net loss of available energy(A) in KJ/kg K= -26.78\n",
      "so loss of available energy=26.77 KJ/kg K\n"
     ]
    }
   ],
   "source": [
    "#cal of loss of available energy\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.11, Page:227  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 11\")\n",
    "To=280.;#surrounding temperature in K\n",
    "Q=500.;#heat removed in KJ\n",
    "T1=835.;#temperature of reservoir in K\n",
    "T2=720.;#temperature of system in K\n",
    "A_HR=To*Q/T1\n",
    "print(\"availability for heat reservoir(A_HR) in KJ/kg K\"),round(A_HR,2)\n",
    "A_system=To*Q/T2\n",
    "print(\"now availability for system(A_system) in KJ/kg K\"),round(A_system,2)\n",
    "A=A_HR-A_system \n",
    "print(\"net loss of available energy(A) in KJ/kg K=\"),round(A,2)\n",
    "print(\"so loss of available energy=26.77 KJ/kg K\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.12;pg no: 228"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.12, Page:228  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 12\n",
      "here dead state is given as 300 K and maximum possible work for given change of state of steam can be estimated by the difference of flow availability as given under:\n",
      "W_max=W1-W2 in KJ/kg 1647.0\n",
      "actual work from turbine,W_actual=h1-h2 in KJ/kg 1557.0\n",
      "so actual work=1557 KJ/kg\n",
      "maximum possible work=1647 KJ/kg\n"
     ]
    }
   ],
   "source": [
    "#cal of actual,maximum possible work\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.12, Page:228  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 12\")\n",
    "h1=4142;#enthalpy at entrance in KJ/kg\n",
    "h2=2585;#enthalpy at exit in KJ/kg\n",
    "W1=1787;#availability of steam at entrance in KJ/kg\n",
    "W2=140;#availability of steam at exit in KJ/kg\n",
    "print(\"here dead state is given as 300 K and maximum possible work for given change of state of steam can be estimated by the difference of flow availability as given under:\")\n",
    "W_max=W1-W2\n",
    "print(\"W_max=W1-W2 in KJ/kg\"),round(W_max,2)\n",
    "W_actual=h1-h2\n",
    "print(\"actual work from turbine,W_actual=h1-h2 in KJ/kg\"),round(W_actual,2)\n",
    "print(\"so actual work=1557 KJ/kg\")\n",
    "print(\"maximum possible work=1647 KJ/kg\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.13;pg no: 228"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.13, Page:228  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 13\n",
      "reversible engine efficiency,n_rev=1-(T_min/T_max) 0.621\n",
      "second law efficiency=n/n_rev 0.4026\n",
      "in % 40.26\n"
     ]
    }
   ],
   "source": [
    "#cal of second law efficiency\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.13, Page:228  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 13\")\n",
    "T_min=(20.+273.);#minimum temperature reservoir temperature in K\n",
    "T_max=(500.+273.);#maximum temperature reservoir temperature in K\n",
    "n=0.25;#efficiency of heat engine\n",
    "n_rev=1-(T_min/T_max)\n",
    "print(\"reversible engine efficiency,n_rev=1-(T_min/T_max)\"),round(n_rev,4)\n",
    "n/n_rev\n",
    "print(\"second law efficiency=n/n_rev\"),round(n/n_rev,4)\n",
    "print(\"in %\"),round(n*100/n_rev,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.14;pg no: 228"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.14, Page:228  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 14\n",
      "expansion occurs in adiabatic conditions.\n",
      "temperature after expansion can be obtained by considering adiabatic expansion\n",
      "T2/T1=(V1/V2)^(y-1)\n",
      "so T2= in K= 489.12\n",
      "mass of air,m in kg= 20.91\n",
      "change in entropy of control system,deltaSs=(S2-S1) in KJ/K= -0.0\n",
      "here,there is no change in entropy of environment,deltaSe=0\n",
      "total entropy change of combined system=deltaSc in KJ/K= -0.0\n",
      "loss of available energy(E)=irreversibility in KJ= -0.603\n",
      "so loss of available energy,E=0.603 KJ\n"
     ]
    }
   ],
   "source": [
    "#cal of loss of available energy\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "import math\n",
    "print\"Example 7.14, Page:228  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 14\")\n",
    "V_A=6.;#volume of compartment A in m^3\n",
    "V_B=4.;#volume of compartment B in m^3\n",
    "To=300.;#temperature of atmosphere in K\n",
    "Po=1.*10**5;#atmospheric pressure in pa\n",
    "P1=6.*10**5;#initial pressure in pa\n",
    "T1=600.;#initial temperature in K\n",
    "V1=V_A;#initial volume in m^3\n",
    "V2=(V_A+V_B);#final volume in m^3\n",
    "y=1.4;#expansion constant \n",
    "R=287.;#gas constant in J/kg K\n",
    "Cv=0.718;#specific heat at constant volume in KJ/kg K\n",
    "print(\"expansion occurs in adiabatic conditions.\")\n",
    "print(\"temperature after expansion can be obtained by considering adiabatic expansion\")\n",
    "T2=T1*(V1/V2)**(y-1)\n",
    "print(\"T2/T1=(V1/V2)^(y-1)\")\n",
    "print(\"so T2= in K=\"),round(T2,2)\n",
    "T2=489.12;#approx.\n",
    "m=(P1*V1)/(R*T1)\n",
    "print(\"mass of air,m in kg=\"),round(m,2)\n",
    "m=20.91;#approx.\n",
    "deltaSs=m*Cv*math.log(T2/T1)+m*R*10**-3*math.log(V2/V1)\n",
    "print(\"change in entropy of control system,deltaSs=(S2-S1) in KJ/K=\"),round(deltaSs,2)\n",
    "print(\"here,there is no change in entropy of environment,deltaSe=0\")\n",
    "deltaSe=0;\n",
    "deltaSc=deltaSs+deltaSe\n",
    "print(\"total entropy change of combined system=deltaSc in KJ/K=\"),round(deltaSc,2)\n",
    "E=To*deltaSc\n",
    "print(\"loss of available energy(E)=irreversibility in KJ=\"),round(E,3)\n",
    "print(\"so loss of available energy,E=0.603 KJ\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.15;pg no: 229"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.15, Page:229  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 15\n",
      "In question no. 15 prove for ideal gas satisfies the cyclic relation is done which cannot be solve using python software.\n"
     ]
    }
   ],
   "source": [
    "#cal of maximum possible work\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.15, Page:229  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 15\")\n",
    "print(\"In question no. 15 prove for ideal gas satisfies the cyclic relation is done which cannot be solve using python software.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.16;pg no: 230"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.16, Page:230  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 16\n",
      "availability or reversible work,W_rev=n_rev*Q1 in KJ/min 229.53\n",
      "rate of irreversibility,I=W_rev-W_useful in KJ/sec 99.53\n",
      "second law efficiency=W_useful/W_rev 0.57\n",
      "in percentage 56.64\n",
      "so availability=1.38*10^4 KJ/min\n",
      "and rate of irreversibility=100 KW,second law efficiency=56.63 %\n",
      "NOTE=>In this question,wrong values are put in expression for W_rev in book,however answer is calculated correctly.\n"
     ]
    }
   ],
   "source": [
    "#cal of availability,rate of irreversibility and second law efficiency\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.16, Page:230  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 16\")\n",
    "To=(17.+273.);#temperature of surrounding in K\n",
    "T1=(700.+273.);#temperature of high temperature reservoir in K\n",
    "T2=(30.+273.);#temperature of low temperature reservoir in K\n",
    "Q1=2.*10**4;#rate of heat receive in KJ/min\n",
    "W_useful=0.13*10**3;#output of engine in KW\n",
    "n_rev=(1-T2/T1);\n",
    "W_rev=n_rev*Q1\n",
    "W_rev=W_rev/60.;#W_rev in KJ/s\n",
    "print(\"availability or reversible work,W_rev=n_rev*Q1 in KJ/min\"),round(W_rev,2)\n",
    "I=W_rev-W_useful\n",
    "print(\"rate of irreversibility,I=W_rev-W_useful in KJ/sec\"),round(I,2)\n",
    "W_useful/W_rev\n",
    "print(\"second law efficiency=W_useful/W_rev\"),round(W_useful/W_rev,2)\n",
    "W_useful*100/W_rev\n",
    "print(\"in percentage\"),round(W_useful*100/W_rev,2)\n",
    "print(\"so availability=1.38*10^4 KJ/min\")\n",
    "print(\"and rate of irreversibility=100 KW,second law efficiency=56.63 %\")\n",
    "print(\"NOTE=>In this question,wrong values are put in expression for W_rev in book,however answer is calculated correctly.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.17;pg no: 230"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.17, Page:230  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 17\n",
      "loss of available energy=irreversibility=To*deltaSc\n",
      "deltaSc=deltaSs+deltaSe\n",
      "change in entropy of system=deltaSs\n",
      "change in entropy of environment/surroundings=deltaSe\n",
      "here heat addition process causing rise in pressure from 1.5 bar to 2.5 bar occurs isochorically.let initial and final states be given by subscript 1 and 2\n",
      "P1/T1=P2/T2\n",
      "so T2 in K= 555.0\n",
      "heat addition to air in tank\n",
      "Q in KJ/kg= 223.11\n",
      "deltaSs in KJ/kg K= 0.67\n",
      "deltaSe in KJ/kg K= -0.33\n",
      "and deltaSc in KJ/kg K= 0.34\n",
      "so loss of available energy(E)in KJ/kg= 101.55\n"
     ]
    }
   ],
   "source": [
    "#cal of loss of available energy\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "import math\n",
    "print\"Example 7.17, Page:230  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 17\")\n",
    "To=(27+273);#temperature of surrounding in K\n",
    "T1=(60+273);#initial temperature of air in K\n",
    "P1=1.5*10**5;#initial pressure of air in pa\n",
    "P2=2.5*10**5;#final pressure of air in pa\n",
    "T_reservoir=(400+273);#temperature of reservoir in K\n",
    "Cp=1.005;#specific heat at constant pressure in KJ/kg K\n",
    "print(\"loss of available energy=irreversibility=To*deltaSc\")\n",
    "print(\"deltaSc=deltaSs+deltaSe\")\n",
    "print(\"change in entropy of system=deltaSs\")\n",
    "print(\"change in entropy of environment/surroundings=deltaSe\")\n",
    "print(\"here heat addition process causing rise in pressure from 1.5 bar to 2.5 bar occurs isochorically.let initial and final states be given by subscript 1 and 2\")\n",
    "print(\"P1/T1=P2/T2\")\n",
    "T2=P2*T1/P1\n",
    "print(\"so T2 in K=\"),round(T2,2)\n",
    "print(\"heat addition to air in tank\")\n",
    "deltaT=T2-T1;\n",
    "Q=Cp*deltaT\n",
    "print(\"Q in KJ/kg=\"),round(Q,2)\n",
    "deltaSs=Q/T1\n",
    "print(\"deltaSs in KJ/kg K=\"),round(deltaSs,2)\n",
    "deltaSe=-Q/T_reservoir\n",
    "print(\"deltaSe in KJ/kg K=\"),round(deltaSe,2)\n",
    "deltaSc=deltaSs+deltaSe\n",
    "print(\"and deltaSc in KJ/kg K=\"),round(deltaSc,2)\n",
    "E=To*deltaSc\n",
    "print(\"so loss of available energy(E)in KJ/kg=\"),round(E,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.18;pg no: 231"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.18, Page:231  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 18\n",
      "In question no. 18,relation for T*ds using maxwell relation is derived which cannot be solve using python software.\n"
     ]
    }
   ],
   "source": [
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "print\"Example 7.18, Page:231  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 18\")\n",
    "print(\"In question no. 18,relation for T*ds using maxwell relation is derived which cannot be solve using python software.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.19;pg no: 232"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.19, Page:232  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 19\n",
      "clapeyron equation says,h_fg=T*v_fg*(dp/dT)_sat\n",
      "from steam tables,vg=0.12736 m^3/kg,vf=0.001157 m^3/kg\n",
      "v_fg in m^3/kg= 0.0\n",
      "let us approximate,\n",
      "(dp/dT)_sat_200oc=(deltaP/deltaT)_200oc=(P_205oc-P_195oc)/(205-195) in Mpa/oc\n",
      "here from steam tables,P_205oc=1.7230 Mpa,P_195oc=1.3978 Mpa\n",
      "substituting in clapeyron equation,\n",
      "h_fg in KJ/kg 1941.25\n",
      "so calculated enthalpy of vaporisation=1941.25 KJ/kg\n",
      "and enthalpy of vaporisation from steam table=1940.7 KJ/kg\n"
     ]
    }
   ],
   "source": [
    "#cal of enthalpy of vaporisation\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "import math\n",
    "print\"Example 7.19, Page:232  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 19\")\n",
    "T=(200+273);#temperature of water in K\n",
    "print(\"clapeyron equation says,h_fg=T*v_fg*(dp/dT)_sat\")\n",
    "print(\"from steam tables,vg=0.12736 m^3/kg,vf=0.001157 m^3/kg\")\n",
    "vg=0.12736;\n",
    "vf=0.001157;\n",
    "v_fg=(vg-vf)\n",
    "print(\"v_fg in m^3/kg=\"),round(v_fg)\n",
    "print(\"let us approximate,\")\n",
    "print(\"(dp/dT)_sat_200oc=(deltaP/deltaT)_200oc=(P_205oc-P_195oc)/(205-195) in Mpa/oc\")\n",
    "print(\"here from steam tables,P_205oc=1.7230 Mpa,P_195oc=1.3978 Mpa\")\n",
    "P_205oc=1.7230;#pressure at 205 degree celcius in Mpa\n",
    "P_195oc=1.3978;#pressure at 195 degree celcius in Mpa\n",
    "(P_205oc-P_195oc)/(205-195)\n",
    "print(\"substituting in clapeyron equation,\")\n",
    "h_fg=T*v_fg*(P_205oc-P_195oc)*1000/(205-195)\n",
    "print(\"h_fg in KJ/kg\"),round(h_fg,2)\n",
    "print(\"so calculated enthalpy of vaporisation=1941.25 KJ/kg\")\n",
    "print(\"and enthalpy of vaporisation from steam table=1940.7 KJ/kg\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.20;pg no: 232"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.20, Page:232  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 20\n",
      "by clapeyron equation\n",
      "h_fg=T2*v_fg*(do/dT)_sat \n",
      "h_fg=T2*(vg-vf)*(deltaP/deltaT)in KJ/kg\n",
      "by clapeyron-clausius equation,\n",
      "log(P2/P1)_sat=(h_fg/R)*((1/T1)-(1/T2))_sat\n",
      "log(P2/P1)=(h_fg/R)*((1/T1)-(1/T2))\n",
      "so h_fg=log(P2/P1)*R/((1/T1)-(1/T2))in KJ/kg\n",
      "% deviation from clapeyron equation in % 6.44\n",
      "h_fg by clapeyron equation=159.49 KJ/kg\n",
      "h_fg by clapeyron-clausius equation=169.76 KJ/kg\n",
      "% deviation in h_fg value by clapeyron-clausius equation from the value from clapeyron equation=6.44%\n"
     ]
    }
   ],
   "source": [
    "#cal of loss of available energy\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "import math\n",
    "print\"Example 7.20, Page:232  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 20\")\n",
    "P2=260.96;#saturation pressure at -5 degree celcius\n",
    "P1=182.60;#saturation pressure at -15 degree celcius\n",
    "vg=0.07665;#specific volume of gas at -10 degree celcius in m^3/kg\n",
    "vf=0.00070#specific volume at -10 degree celcius in m^3/kg\n",
    "R=0.06876;#gas constant in KJ/kg K\n",
    "h_fg=156.3;#enthalpy in KJ/kg K\n",
    "T2=(-5.+273.);#temperature in K\n",
    "T1=(-15.+273.);#temperature in K\n",
    "print(\"by clapeyron equation\")\n",
    "print(\"h_fg=T2*v_fg*(do/dT)_sat \")\n",
    "print(\"h_fg=T2*(vg-vf)*(deltaP/deltaT)in KJ/kg\")\n",
    "h_fg=T2*(vg-vf)*(P1-P2)/(T1-T2)\n",
    "print(\"by clapeyron-clausius equation,\")\n",
    "print(\"log(P2/P1)_sat=(h_fg/R)*((1/T1)-(1/T2))_sat\")\n",
    "print(\"log(P2/P1)=(h_fg/R)*((1/T1)-(1/T2))\")\n",
    "print(\"so h_fg=log(P2/P1)*R/((1/T1)-(1/T2))in KJ/kg\")\n",
    "h_fg=math.log(P2/P1)*R/((1/T1)-(1/T2))\n",
    "print(\"% deviation from clapeyron equation in %\"),round((169.76-159.49)*100/159.49,2)\n",
    "print(\"h_fg by clapeyron equation=159.49 KJ/kg\")\n",
    "print(\"h_fg by clapeyron-clausius equation=169.76 KJ/kg\")\n",
    "print(\"% deviation in h_fg value by clapeyron-clausius equation from the value from clapeyron equation=6.44%\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.21;pg no: 233"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.21, Page:233  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 21\n",
      "volume expansion=(1/v)*(dv/dT)_P\n",
      "isothermal compressibility=-(1/v)*(dv/dp)_T\n",
      "let us write dv/dT=deltav/deltaT and dv/dP=deltav/deltaP.The difference may be taken for small pressure and temperature changes.\n",
      "volume expansivity in K^-1,\n",
      "=(1/v)*(dv/dT)_300Kpa\n",
      "=(1/v_300Kpa_300oc)*((v_350oc-v_250oc)/(350-250))_300Kpa\n",
      "from steam tables,v_300Kpa_300oc=0.8753 in m^3/kg,v_350oc=0.9534 in m^3/kg,v_250oc=0.7964 in m^3/kg\n",
      "volume expansivity=1.7937*10^-3 K^-1\n",
      "isothermal compressibility=k in Kpa^-1\n",
      "k= 0.004\n",
      "from steam tables,v_300Kpa_300oc=0.8753 in m^3/kg,v_350Kpa=0.76505 in m^3/kg,v_250Kpa=1.09575 in m^3/kg\n",
      "so isothermal compressibility=3.778*10^-3 Kpa^-1\n"
     ]
    }
   ],
   "source": [
    "#cal of volume expansivity and isothermal compressibility\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "import math\n",
    "print\"Example 7.21, Page:233  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 21\")\n",
    "print(\"volume expansion=(1/v)*(dv/dT)_P\")\n",
    "print(\"isothermal compressibility=-(1/v)*(dv/dp)_T\")\n",
    "print(\"let us write dv/dT=deltav/deltaT and dv/dP=deltav/deltaP.The difference may be taken for small pressure and temperature changes.\")\n",
    "print(\"volume expansivity in K^-1,\")\n",
    "print(\"=(1/v)*(dv/dT)_300Kpa\")\n",
    "print(\"=(1/v_300Kpa_300oc)*((v_350oc-v_250oc)/(350-250))_300Kpa\")\n",
    "print(\"from steam tables,v_300Kpa_300oc=0.8753 in m^3/kg,v_350oc=0.9534 in m^3/kg,v_250oc=0.7964 in m^3/kg\")\n",
    "v_300Kpa_300oc=0.8753;#specific volume at 300Kpa and 300 degree celcius\n",
    "v_350oc=0.9534;#specific volume 350 degree celcius\n",
    "v_250oc=0.7964;#specific volume 250 degree celcius\n",
    "(1/v_300Kpa_300oc)*(v_350oc-v_250oc)/(350-250)\n",
    "print(\"volume expansivity=1.7937*10^-3 K^-1\")\n",
    "print(\"isothermal compressibility=k in Kpa^-1\")\n",
    "v_350Kpa=0.76505;#specific volume 350 Kpa\n",
    "v_250Kpa=1.09575;#specific volume 250 Kpa\n",
    "k=(-1./v_300Kpa_300oc)*(v_350Kpa-v_250Kpa)/(350.-250.)\n",
    "print(\"k=\"),round((-1./v_300Kpa_300oc)*(v_350Kpa-v_250Kpa)/(350.-250.),3)\n",
    "print(\"from steam tables,v_300Kpa_300oc=0.8753 in m^3/kg,v_350Kpa=0.76505 in m^3/kg,v_250Kpa=1.09575 in m^3/kg\")\n",
    "print(\"so isothermal compressibility=3.778*10^-3 Kpa^-1\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.22;pg no: 234"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.22, Page:234  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 22\n",
      "filling of the tank is a transient flow(unsteady)process.for the transient filling process,considering subscripts i and f for initial and final states,\n",
      "hi=uf\n",
      "Cp*Ti=Cv*Tf\n",
      "so Tf=Cp*Ti/Cv in K 417.33\n",
      "inside final temperature,Tf=417.33 K\n",
      "change in entropy,deltaS_gen=(Sf-Si)+deltaS_surr in KJ/kg K= 0.338\n",
      "Cp*log(Tf/Ti)+0\n",
      "change in entropy,deltaS_gen=0.3379 KJ/kg K\n",
      "irreversibility,I in KJ/kg= 100.76\n",
      "irreversibility,I=100.74 KJ/kg\n"
     ]
    }
   ],
   "source": [
    "#cal of inside final temperature,change in entropy and irreversibility\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "import math\n",
    "print\"Example 7.22, Page:234  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 22\")\n",
    "Cp=1.005;#specific heat at constant pressure in KJ/kg K\n",
    "Cv=0.718;#specific heat at constant volume in KJ/kg K\n",
    "Ti=(25+273.15);#atmospheric temperature in K\n",
    "print(\"filling of the tank is a transient flow(unsteady)process.for the transient filling process,considering subscripts i and f for initial and final states,\")\n",
    "print(\"hi=uf\")\n",
    "print(\"Cp*Ti=Cv*Tf\")\n",
    "Tf=Cp*Ti/Cv\n",
    "print(\"so Tf=Cp*Ti/Cv in K\"),round(Tf,2)\n",
    "print(\"inside final temperature,Tf=417.33 K\")\n",
    "deltaS_gen=Cp*math.log(Tf/Ti)\n",
    "print(\"change in entropy,deltaS_gen=(Sf-Si)+deltaS_surr in KJ/kg K=\"),round(deltaS_gen,4)\n",
    "print(\"Cp*log(Tf/Ti)+0\")\n",
    "print(\"change in entropy,deltaS_gen=0.3379 KJ/kg K\")\n",
    "To=Ti;\n",
    "I=To*deltaS_gen\n",
    "print(\"irreversibility,I in KJ/kg=\"),round(I,2)\n",
    "print(\"irreversibility,I=100.74 KJ/kg\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.23;pg no: 234"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.23, Page:234  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 23\n",
      "here the combined closed system consists of hot water and heat engine.here there is no thermal reservoir in the system under consideration.for the maximum work output,irreversibility=0\n",
      "therefore,d(E-To-S)/dt=W_max\n",
      "or W_max=(E-To-S)1-(E-To-S)2\n",
      "here E1=U1=m*Cp*T1,E2=U2=m*Cp*T2\n",
      "therefore,W_max=m*Cp*(T1-T2)-To*m*Cp*log(T1/T2)in KJ\n",
      "so maximum work in KJ= 40946.6\n"
     ]
    }
   ],
   "source": [
    "#cal of  maximum work\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "import math\n",
    "print\"Example 7.23, Page:234  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 23\")\n",
    "m=75.;#mass of hot water in kg\n",
    "T1=(400.+273.);#temperature of hot water in K\n",
    "T2=(27.+273.);#temperature of environment in K\n",
    "Cp=4.18;#specific heat of water in KJ/kg K\n",
    "print(\"here the combined closed system consists of hot water and heat engine.here there is no thermal reservoir in the system under consideration.for the maximum work output,irreversibility=0\")\n",
    "print(\"therefore,d(E-To-S)/dt=W_max\")\n",
    "print(\"or W_max=(E-To-S)1-(E-To-S)2\")\n",
    "print(\"here E1=U1=m*Cp*T1,E2=U2=m*Cp*T2\")\n",
    "print(\"therefore,W_max=m*Cp*(T1-T2)-To*m*Cp*log(T1/T2)in KJ\")\n",
    "To=T2;\n",
    "W_max=m*Cp*(T1-T2)-To*m*Cp*math.log(T1/T2)\n",
    "print(\"so maximum work in KJ=\"),round(W_max,1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##example 7.24;pg no: 235"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 7.24, Page:235  \n",
      " \n",
      "\n",
      "Engineering Thermodynamics by Onkar Singh Chapter 7 Example 24\n",
      "from steam tables,h1=h_50bar_600oc=3666.5 KJ/kg,s1=s_50bar_600oc=7.2589 KJ/kg K,h2=hg=2584.7 KJ/kg,s2=sg=8.1502 KJ/kg K\n",
      "inlet stream availability in KJ/kg= 1587.19\n",
      "input stream availability is equal to the input absolute availability.\n",
      "exit stream availaability in KJ/kg 238.69\n",
      "exit stream availability is equal to the exit absolute availability.\n",
      "W_rev in KJ/kg\n",
      "irreversibility=W_rev-W in KJ/kg 348.49\n",
      "this irreversibility is in fact the availability loss.\n",
      "inlet stream availability=1587.18 KJ/kg\n",
      "exit stream availability=238.69 KJ/kg\n",
      "irreversibility=348.49 KJ/kg\n",
      "NOTE=>In book this question is solve using dead state temperature 25 degree celcius which is wrong as we have to take dead state temperature 15 degree celcius,now this question is correctly solve above taking dead state temperature 15 degree celcius as mentioned in question. \n"
     ]
    }
   ],
   "source": [
    "#cal of inlet stream availability,exit stream availability and irreversibility\n",
    "#intiation of all variables\n",
    "# Chapter 7\n",
    "import math\n",
    "print\"Example 7.24, Page:235  \\n \\n\"\n",
    "print(\"Engineering Thermodynamics by Onkar Singh Chapter 7 Example 24\")\n",
    "C1=150;#steam entering velocity in m/s\n",
    "C2=50;#steam leaving velocity in m/s\n",
    "To=(15+273);#dead state temperature in K\n",
    "W=1000;#expansion work in KJ/kg\n",
    "print(\"from steam tables,h1=h_50bar_600oc=3666.5 KJ/kg,s1=s_50bar_600oc=7.2589 KJ/kg K,h2=hg=2584.7 KJ/kg,s2=sg=8.1502 KJ/kg K\")\n",
    "h1=3666.5;\n",
    "s1=7.2589;\n",
    "h2=2584.7;\n",
    "s2=8.1502;\n",
    "(h1+C1**2*10**-3/2)-To*s1\n",
    "print(\"inlet stream availability in KJ/kg=\"),round((h1+C1**2*10**-3/2)-To*s1,2)\n",
    "(h2+C2**2*10**-3/2)-To*s2\n",
    "print(\"input stream availability is equal to the input absolute availability.\")\n",
    "print(\"exit stream availaability in KJ/kg\"),round((h2+C2**2*10**-3/2)-To*s2,2)\n",
    "print(\"exit stream availability is equal to the exit absolute availability.\")\n",
    "print(\"W_rev in KJ/kg\")\n",
    "W_rev=1587.18-238.69\n",
    "W_rev-W\n",
    "print(\"irreversibility=W_rev-W in KJ/kg\"),round(W_rev-W,2)\n",
    "print(\"this irreversibility is in fact the availability loss.\")\n",
    "print(\"inlet stream availability=1587.18 KJ/kg\")\n",
    "print(\"exit stream availability=238.69 KJ/kg\")\n",
    "print(\"irreversibility=348.49 KJ/kg\")\n",
    "print(\"NOTE=>In book this question is solve using dead state temperature 25 degree celcius which is wrong as we have to take dead state temperature 15 degree celcius,now this question is correctly solve above taking dead state temperature 15 degree celcius as mentioned in question. \")\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
}