summaryrefslogtreecommitdiff
path: root/Thermal_Engineering_by_K_K_Ramalingam/Chapter9.ipynb
blob: d492b3997836b10d16269ea2fa4f95b28596fe3b (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
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 9 - Air Compressors"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1 - pg 9.18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)Work required in a isothermal compression is (kJ/kg) =  155.813\n",
      "(b)Work required in a polytropic compression is (kJ/kg) =  181.578\n",
      "(c)Work required in a isentropic compression is (kJ/kg) =  203.47\n"
     ]
    }
   ],
   "source": [
    "#pg 9.18\n",
    "#calculate the Work required in all cases\n",
    "#Input data\n",
    "import math\n",
    "m=1.;#Mass of air that has to be compressed in kg\n",
    "P1=1.;#Initial pressure of a single stage reciprocating air compressor in bar\n",
    "P2=6.;#Final pressure in bar\n",
    "T1=303.;#Initial temperature of air in K\n",
    "n=1.2;#Polytropic index of air\n",
    "R=287.;#Gas constant for air in J/kg K\n",
    "r=1.4;#Isentropic index\n",
    "\n",
    "#Calculations\n",
    "W1=(m*R*T1*math.log(P2/P1))/1000;#Work required for compression in kJ/kg in Isothermal compression process\n",
    "W2=((n/(n-1))*m*R*T1*((P2/P1)**((n-1)/n)-1))/1000;#Work required for compression in a polytropic compression process in kJ/kg\n",
    "W3=((r/(r-1))*m*R*T1*((P2/P1)**((r-1)/r)-1))/1000;#Work required for compression in a Isentropic compression process in kJ/kg\n",
    "\n",
    "#Output\n",
    "print '(a)Work required in a isothermal compression is (kJ/kg) = ',round(W1,3)\n",
    "print '(b)Work required in a polytropic compression is (kJ/kg) = ',round(W2,3)\n",
    "print '(c)Work required in a isentropic compression is (kJ/kg) = ',round(W3,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2 - pg 9.19"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)Length of the cylinder is (m) =  0.625\n",
      "(b)Diameter of the cylinder is (mm) =  351.0\n"
     ]
    }
   ],
   "source": [
    "#pg 9.19\n",
    "#calculate the Length and diameter of the cylinder\n",
    "#Input data\n",
    "Pi=60000.;#Indicated power of a double acting air compressor in W\n",
    "P1=1.;#Initial pressure in bar\n",
    "T1=293.;#Initial temperature in K\n",
    "n=1.2;#Polytropic index of the process\n",
    "P2=8.;#Final pressure in bar\n",
    "N=120.;#Speed at which the cylinder operates in rpm\n",
    "S=150.;#Average piston speed in m/min\n",
    "\n",
    "#Calculations\n",
    "L=S/(2*N);#Length of the stroke in m\n",
    "X=(3.14*L)/4;#X=V/D**2 i.e.,Volume of air before compression/square of the diameter in m\n",
    "Y=((n/(n-1))*P1*10**5*X*(((P2/P1)**((n-1)/n))-1));#Y=W/D**2 Work done by the compressor per cycle in N/m\n",
    "Nw=2*N;#Number of working strokes per minute since it is a double acting cylinder\n",
    "D=(((Pi*60)/(Y*Nw))**(0.5))*1000;#Diameter of the cylinder in mm\n",
    "\n",
    "#Output\n",
    "print '(a)Length of the cylinder is (m) = ',L\n",
    "print '(b)Diameter of the cylinder is (mm) = ',round(D,0)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3 -pg 9.20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The indicated power of the compressor is (kW) =  2.684\n"
     ]
    }
   ],
   "source": [
    "#pg 9.20\n",
    "#calculate the Indicated power of compressor\n",
    "#Input data\n",
    "D=0.15;#Diameter of a cylinder of a single acting reciprocating air compressor in m\n",
    "L=0.2;#Length of the stroke in m\n",
    "P1=1.;#The pressure at which compressor sucks air in bar\n",
    "P2=10.;#Final pressure in bar\n",
    "T1=298.;#Initial Temperature in K\n",
    "N=150.;#Operating speed of the compressor in rpm\n",
    "n=1.3;#Polytropic index of the process\n",
    "\n",
    "#Calculations\n",
    "V1=((3.14*D**2*L)/4);#Volume of air before compression in m**3\n",
    "W=((n/(n-1))*P1*10**5*V1*((P2/P1)**((n-1)/n)-1));#Work done by the compressor for a polytropic compression of air in Nm\n",
    "Pi=((W*N)/60)/1000;#Indicated power of the compressor in kW\n",
    "\n",
    "#Output\n",
    "print 'The indicated power of the compressor is (kW) = ',round(Pi,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4 - pg 9.21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mass of air delivered per minute is (kg/min) =  5.64\n"
     ]
    }
   ],
   "source": [
    "#pg 9.21\n",
    "#calculate the mass of air delivered\n",
    "#Input data\n",
    "D=0.25;#Diameter of the cylinder of a single acting air compressor in m\n",
    "L=0.4;#Length of the stroke in m\n",
    "P1=1.;#Initial Pressure of the compressor in bar\n",
    "T1=303.;#Initial temperature of the compressor in K\n",
    "P2=6.;#Pressure during running in bar\n",
    "N=250.;#Operating speed of the compressor in rpm\n",
    "R=287.;#Gas constant in J/kg K \n",
    "\n",
    "#Calculations\n",
    "V1=(3.14*D**2*L)/4;#Volume of air before compression in m**3\n",
    "m=(P1*10**5*V1)/(R*T1);#Mass of air delivered by the compressor per stroke in kg/stroke\n",
    "Nw=N;#Since single acting cylinder number of working stroke is equal to Operating speed of the compressor in rpm\n",
    "ma=m*Nw;#Mass of air delivered per minute in kg/min\n",
    "\n",
    "#Output\n",
    "print 'Mass of air delivered per minute is (kg/min) = ',round(ma,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5 - pg 9.22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Temperature of air delivered by the compressor is (K) =  546.5\n"
     ]
    }
   ],
   "source": [
    "#pg 9.22\n",
    "#calculate the temperature of air\n",
    "#Input data\n",
    "P1=1.;#Initial pressure of a single acting compressor in bar\n",
    "P2=12.;#Final pressure in bar\n",
    "N=500.;#Operating speed of the compressor in rpm\n",
    "T1=308.;#Inlet air temperature in K\n",
    "n=1.3;#Polytropic index\n",
    "\n",
    "#Calculations\n",
    "T2=T1*(P2/P1)**((n-1)/n);#Temperature of air delivered by the compressor in K\n",
    "\n",
    "#Output\n",
    "print 'Temperature of air delivered by the compressor is (K) = ',round(T2,1)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6 - pg 9.22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)Temperature at the end of isentropic compression is (K) =  555.06\n",
      "(b)Temperature at the end of polytropic compression is (K) =  486.49\n",
      "(c)Temperature at the end of isotropic compression is (K) =  293.0\n"
     ]
    }
   ],
   "source": [
    "#pg 9.22\n",
    "#calculate the temperature in all cases\n",
    "#Input data\n",
    "P1=1.;#Pressure at which air is sucked by a compressor in bar\n",
    "T1=293.;#Initial temperature in K\n",
    "P2=9.;#Delivery pressure after compression in bar\n",
    "r=1.41;#Isentropic index\n",
    "n=1.3;#Polytropic index\n",
    "\n",
    "#Calculations\n",
    "T21=T1*((P2/P1)**((r-1)/r));#Temperature at the end of isentropic compression process in K\n",
    "T22=T1*((P2/P1)**((n-1)/n));#Temperature at the end of isentropic compression process in K\n",
    "T23=T1;#Temperature at the end of isotropic compression process in K (Temperature remains constant)\n",
    "\n",
    "#Output\n",
    "print '(a)Temperature at the end of isentropic compression is (K) = ',round(T21,2)\n",
    "print '(b)Temperature at the end of polytropic compression is (K) = ',round(T22,2)\n",
    "print '(c)Temperature at the end of isotropic compression is (K) = ',T23\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7 - pg 9.23"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)Work done by air during suction is (J) =  7000.0\n",
      "(b)Work done on air during compression is (J) =  -14754.0\n",
      "(c)Work done on air during delivery is (J) =  12902.0\n",
      "(d)Net work done on air during the cycle is (kJ) =  20.656\n"
     ]
    }
   ],
   "source": [
    "#pg 9.23\n",
    "#calculate the work done in all cases\n",
    "#Input data\n",
    "V1=0.07;#Displacement of the piston of a single stage single cylinder air compressor in m**3\n",
    "P1=1;#Initial pressure in bar\n",
    "T1=308;#Initial temperature of air in K\n",
    "P2=8.5;#Pressure after the compression process in bar\n",
    "r=1.4;#Isentropic compression \n",
    "\n",
    "#Calculations\n",
    "V2=V1*((P1/P2)**(1/1.4));#Final volume of the cylinder in m**3\n",
    "W1=P1*10**5*V1;#Work done by air during suction in Nm (or) J\n",
    "W2=(P1*10**5*V1*(1-(P2/P1)**((r-1)/r)))/(r-1);#Work done by air during compression in Nm or J\n",
    "Wa1=P2*10**5*V2;#Work done on air during delivery in Nm or J\n",
    "Wa2=((-W2)+Wa1-W1)/1000;#Net work done on air during the cycle in kJ\n",
    "\n",
    "#Output\n",
    "print '(a)Work done by air during suction is (J) = ',W1\n",
    "print '(b)Work done on air during compression is (J) = ',round(W2,0)\n",
    "print '(c)Work done on air during delivery is (J) = ',round(Wa1,0)\n",
    "print '(d)Net work done on air during the cycle is (kJ) = ',round(Wa2,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8 - pg 9.25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)Work done by air during suction is (Nm) =  5000.0\n",
      "(b)Work done on air during Isothermal compression is (Nm) =  -9730.0\n",
      "(c)Heat transferred during this process is (J) =  9730.0\n",
      "(d)Work done on air during delivery is (Nm) =  5000.0\n",
      "(e)Net work done during the cycle is (Nm) =  9729.0\n"
     ]
    }
   ],
   "source": [
    "#pg 9.25\n",
    "#calculate the work done in all cases\n",
    "import math\n",
    "#Input data\n",
    "V1=0.05;#displacement of a piston of a single cylinder single stage reciprocating compressor in m**3\n",
    "P1=1.;#pressure of air sucked in the compressor in bar\n",
    "T1=300.;#Initial Temperature of air in K\n",
    "P2=7.;#Pressure after the compression process in bar\n",
    "\n",
    "#Calculations\n",
    "V2=(P1*V1)/P2;#Volume after the compression in m**3\n",
    "W1=P1*10**5*V1;#Work done by air during suction in Nm\n",
    "W2=P1*10**5*V1*math.log(V2/V1);#Work done on sir during isothermal compression in Nm\n",
    "H=-W2;#Heat transferred to the cylinder walls in Nm or J\n",
    "W3=P1*10**5*V1;#Work done on air during delivery in Nm\n",
    "Wn=W1+(-W2)-W3;#Net work done during the cycke in N m\n",
    "\n",
    "#Output\n",
    "print '(a)Work done by air during suction is (Nm) = ',W1\n",
    "print '(b)Work done on air during Isothermal compression is (Nm) = ',round(W2,0)\n",
    "print '(c)Heat transferred during this process is (J) = ',round(H,0)\n",
    "print '(d)Work done on air during delivery is (Nm) = ',W3\n",
    "print '(e)Net work done during the cycle is (Nm) = ',math.floor(Wn)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 9 - pg 9.26"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Power required to compress and deliver 2kg of air per minute is (kW) =  7.296\n"
     ]
    }
   ],
   "source": [
    "#pg 9.26\n",
    "#calculate the Power required\n",
    "#Input data\n",
    "m=2.;#Mass of air delivered per second in kg\n",
    "P1=1.;#Initial pressure of a single stage compressor in bar\n",
    "T1=293.;#Initial temperature in K\n",
    "P2=7.;#Final pressure in bar\n",
    "n=1.4;#Polytropic index\n",
    "R=287.;#Gas constant in J/kg K\n",
    "\n",
    "#Calculations\n",
    "W=((n/(n-1))*m*R*T1*(((P2/P1)**((n-1)/n))-1))/(60*1000);#Work done by compressor in kW\n",
    "\n",
    "#Output\n",
    "print 'Power required to compress and deliver 2kg of air per minute is (kW) = ',round(W,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10 - pg 9.27"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Work done by the compressor per cycle is (Nm) =  781.0\n"
     ]
    }
   ],
   "source": [
    "#pg 9.27\n",
    "#calculate the Work done\n",
    "#Input data\n",
    "import math\n",
    "D=0.15;#Diameter of the bore of a single stage single acting reciprocating air compressor in m\n",
    "L=0.225;#Stroke length in m\n",
    "P1=1;#Pressure of air received in bar\n",
    "T1=308.;#Temperature of initial air in K\n",
    "P2=6.5;#Delivery pressure in bar\n",
    "n=1.3;#Polytropic index\n",
    "\n",
    "#Calculations\n",
    "Vs=(math.pi*D**2*L)/4;#Stroke volume of the compressor in m**3\n",
    "Vc=0.05*Vs;#Clearance volume in m**3\n",
    "V1=Vs+Vc;#Initial volume of air in m**3\n",
    "V4=Vc*(P2/P1)**(1/n);#The air in the clearance volume expands during suction stroke in m**3\n",
    "V=V1-V4;#Effective swept volume in m**3\n",
    "W=((n/(n-1))*P1*10**5*(V1-V4)*(((P2/P1)**((n-1)/n))-1));#Work done by the compressor per cycle in Nm\n",
    "\n",
    "#Output\n",
    "print 'Work done by the compressor per cycle is (Nm) = ',round(W,0)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11 - pg 9.28"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)Free air delivered per cycle is (m^3) =  0.000356\n",
      "(b)Free air delivered per minute is (m^3/min) =  0.1424\n"
     ]
    }
   ],
   "source": [
    "#pg 9.28\n",
    "#calculate the free air delivered\n",
    "#Input data\n",
    "D=0.1;#Diameter of the bore of a single acting compressor in m\n",
    "L=0.1;#Length of the stroke in m\n",
    "N=400.;#Operating speed of the compressor in in rpm\n",
    "Vc=0.00008;#Clearance volume in m**3\n",
    "n=1.2;#Polytropic index\n",
    "T1=303.;#Initial temperature in K\n",
    "Tf=293.;#Final temperature in K\n",
    "P1=0.95;#Initial pressure in bar\n",
    "P2=8.;#Final pressure in bar\n",
    "Pf=1.013;#Free air pressure in bar\n",
    "\n",
    "#Calculations\n",
    "Vs=(3.14*D**2*L)/4.;#Stroke volume of the compressors in m**3\n",
    "V1=Vc+Vs;#Initial volume of air is equal to cylinder volume in m**3\n",
    "V4=Vc*(P2/P1)**(1/n);#Air in the clearance volume expands during suction stroke to V4\n",
    "Ve=V1-V4;#Effective swept volume in m**3\n",
    "Vf=(P1*(V1-V4)*Tf)/(T1*Pf);#Free air delivered per cycle can be obtained in m**3\n",
    "A=Vf*N;#Free air delivered per minute in m**3/min\n",
    "\n",
    "#Output\n",
    "print '(a)Free air delivered per cycle is (m^3) = ',round(Vf,6)\n",
    "print '(b)Free air delivered per minute is (m^3/min) = ',round(A,4)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 12 - pg 9.29"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Power of the compressor when it runs at 300 rpm is (kW) =   10.718\n"
     ]
    }
   ],
   "source": [
    "#pg 9.29\n",
    "#calculate the Power of the compressor\n",
    "#Input data\n",
    "P1=1.;#Pressure of air drawn by a two stage single acting reciprocating air compressor in bar\n",
    "T1=293.;#Initial temperature in K\n",
    "P3=60.;#Final pressure after the compression in bar\n",
    "P2=10.;#Pressure after compression in the LP cylinder in bar\n",
    "T2=303.;#Temperature after cooling in K\n",
    "D=0.16;#Diameter of a cylinder in m\n",
    "L=0.2;#Stroke length of the cylinder in m\n",
    "n=1.3;#Polytropic index\n",
    "N=300.;#Operating speed of the compressor in rpm\n",
    "R=287.;#Gas constant in J/kg K\n",
    "\n",
    "#Calculations\n",
    "V1=(3.14*D**2*L)/4;#Volume of the LP cylinder in m**3\n",
    "V2=(P1*V1*T2)/(T1*P2);#Volume of the HP cylinder in m**3\n",
    "W=(n/(n-1))*(P1*10**5*V1*(((P2/P1)**((n-1)/n))-1)+(P2*10**5*V2*(((P3/P2)**((n-1)/n))-1)));#Work done by the compressor per working cycle in N m\n",
    "P=(W*N)/(60.*1000);#Power of the compressor in kW\n",
    "\n",
    "#Output\n",
    "print 'Power of the compressor when it runs at 300 rpm is (kW) =  ',round(P,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 13 - pg 9.30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Percentage saving in the work of compression of air in two stages instead of single stage is (percent) =  12.6\n"
     ]
    }
   ],
   "source": [
    "#pg 9.30\n",
    "#calculate the percentage saving\n",
    "#Input data\n",
    "P1=1.;#Initial pressure in bar\n",
    "P3=9.;#Final pressure in bar\n",
    "n=1.3;#Compression index\n",
    "\n",
    "#Calculations\n",
    "W1=(n/(n-1))*(P1*10**5*(((P3/P1)**((n-1)/n))-1));#Work done in compression in a single stage per unit volume per kg of air in N m \n",
    "P2=(P1*P3)**(0.5);#Intercooler pressure for perfect intercooling in bar\n",
    "W2=2*(n/(n-1))*(P1*10**5*(((P2/P1)**((n-1)/n))-1));#Work done in compression in a two stage compressor per unit volume per kg of air in N m\n",
    "Wc=W1-W2;#Saving in work of compression in N m\n",
    "nw=((W1-W2)/W1)*100;#Percentage saving in work of compression in percentage\n",
    "\n",
    "#Output\n",
    "print 'Percentage saving in the work of compression of air in two stages instead of single stage is (percent) = ',round(nw,1)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 14 - pg 9.31"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Minimum work required to compress 1kg of air for given conditions is (Nm) =  338979.0\n"
     ]
    }
   ],
   "source": [
    "#pg 9.31\n",
    "#calculate the Minimum work required\n",
    "#Input data\n",
    "m=1.;#Mass of air to be compressed in kg\n",
    "P1=1.;#Pressure of air before compression in bar\n",
    "T1=303.;#Initial temperature in K\n",
    "P3=25.;#Final pressure of air after compression in bar\n",
    "n=1.3;#Polytropic index\n",
    "R=287.;#Gas constant in J/kg K\n",
    "\n",
    "#Calculations\n",
    "P2=(P1*P3)**(0.5);#Intermediate pressure in the case of perfect intercooling in bar\n",
    "W=2*(n/(n-1))*(m*R*T1*(((P2/P1)**((n-1)/n))-1));#Work done in compression in a two stage compressor per unit volume per kg of air in N m\n",
    "\n",
    "#Output data\n",
    "print 'Minimum work required to compress 1kg of air for given conditions is (Nm) = ',round(W,0)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15 - pg 9.32"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The minimum power required to drive the compressor is (kW) =  12.524\n"
     ]
    }
   ],
   "source": [
    "#pg 9.32\n",
    "#calculate the minimum power\n",
    "#Input data\n",
    "V1=3;#Volume of air sucked in by a two stage compressor in m**3\n",
    "P1=1.04;#Initial pressure in bar\n",
    "T1=298;#Initial temperature in K\n",
    "P2=9;#Delivery pressure in bar\n",
    "n=1.25;#Polytropic index\n",
    "\n",
    "#Calculations\n",
    "P2=(P1*P2)**(0.5);#Intermediate pressure for perfect intercooling and for minimum work of compression in bar\n",
    "W=2*(n/(n-1))*(P1*10**5*V1*(((P2/P1)**((n-1)/n))-1));#Work done in compression in a two stage compressor per unit volume per kg of air in Nm\n",
    "P=W/(60*1000);#Power required to drive the compressor in kW\n",
    "\n",
    "#Output\n",
    "print 'The minimum power required to drive the compressor is (kW) = ',round(P,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 16 - pg 9.32"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mass of water to circulate in the intercooler for abstracting heat is (kg) =  2.098\n"
     ]
    }
   ],
   "source": [
    "#pg 9.32\n",
    "#calculate the mass of water\n",
    "#Input data\n",
    "P1=1.;#Initial pressure of a two stage air compressor in bar\n",
    "P3=36.;#Final pressure in bar\n",
    "T1=298.;#Initial temperature in K\n",
    "n=1.35;#Polytropic index\n",
    "T3=298.;#Temperature after intercooling in K\n",
    "Tc=20.;#Permissible temperature rise of the cooling water in K\n",
    "R=287.;#Gas constant in J/kg K\n",
    "Cp=1.;#Specific heat of air in kJ/kg K\n",
    "Cw=4.2;#Specific heat of water in kJ/kg K\n",
    "ma=1.;#Mass of air in the compressor in kg\n",
    "\n",
    "#Calculations\n",
    "P2=(P1*P3)**(0.5);#Intercooler pressure for complete intercooling and for minimum work of compression in bar\n",
    "T2=T1*(P2/P1)**((n-1)/n);#Temperature after the compression process in K\n",
    "mw=(ma*Cp*(T2-T3))/(Cw*(Tc));#Mass of water to circulate in the intercooler per kg of air in kg\n",
    "\n",
    "#Output\n",
    "print 'Mass of water to circulate in the intercooler for abstracting heat is (kg) = ',round(mw,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 17 - pg 9.33"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The volume ratio of LP to HP cylinders =  2.83\n"
     ]
    }
   ],
   "source": [
    "#pg 9.33\n",
    "#calculate the volume ratio\n",
    "#Input data\n",
    "V1=0.2;#Volume of air flow per second in a two stage single acting reciprocating compressor in m**3\n",
    "P1=0.1;#Intake pressure of air in MPa\n",
    "T1=293.;#Initial temperature in K\n",
    "P3=0.8;#Final pressure after the air is compressed in MPa\n",
    "N=600.;#Operating speed of the compressor in rpm\n",
    "\n",
    "#Calculations\n",
    "P2=(P1*P3)**(0.5);#Intercooler pressure for perfect intercooling and for minimum work of compression in bar\n",
    "Vl=(V1*60)/600;#Volume of the LP cylinder in m**3\n",
    "Vh=(P1*Vl)/P2;#Volume of the high pressure cylinder in m**3\n",
    "R=Vl/Vh;#Ratio of cylinder volumes\n",
    "\n",
    "#Output\n",
    "print 'The volume ratio of LP to HP cylinders = ',round(R,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 18 - pg 9.34"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The ratio of cylinder diameters for the efficiency of compression to be maximum  =  2.236\n"
     ]
    }
   ],
   "source": [
    "#pg 9.34\n",
    "#calculate the ratio required\n",
    "#Input data\n",
    "P1=1.;#Initial pressure of air entering a two stage air compressor with complete intercooling in bar\n",
    "P3=25.;#Delivery pressure of air toe the mains in bar\n",
    "T1=303.;#Initial temperature in K\n",
    "n=1.35;#Compression index\n",
    "\n",
    "#Calculations\n",
    "P2=(P1*P3)**(0.5);#Inter cooler pressure for perfect intercooling in bar\n",
    "R=(P2/P1)**(0.5);#Ratio of cylindrical diameters\n",
    "\n",
    "#Output\n",
    "print 'The ratio of cylinder diameters for the efficiency of compression to be maximum  = ',round(R,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 19 - pg 9.34"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)Number of stages =  4\n",
      "(b)Intermediate pressures are, P2 =  3.31 bar, P3 =  10.95 bar, P4 = 36.26 bar\n"
     ]
    }
   ],
   "source": [
    "#pg 9.34\n",
    "#calculate the number of stages and Intermediate pressures\n",
    "#Input data\n",
    "import math\n",
    "P1=1.;#Initial pressure of a multistage compression in bar\n",
    "Pn1=120.;#Final pressure in bar\n",
    "r=4;#Permissible pressure ratios per stage\n",
    "\n",
    "#Calculations\n",
    "n=math.log(Pn1/P1)/math.log(r)\n",
    "n1=4;#As n=3.45 say 4 stages\n",
    "P5=Pn1;#Since number of stages is 4\n",
    "P4=P5/(Pn1/P1)**(1./n1);#Pressure after the stage 3 in bar\n",
    "P3=P4/(Pn1/P1)**(1./n1);#Pressure after the stage 2 in bar\n",
    "P2=P3/(Pn1/P1)**(1./n1);#Pressure after the stage 1 in bar\n",
    "\n",
    "#Output\n",
    "print '(a)Number of stages = ',n1\n",
    "print '(b)Intermediate pressures are, P2 = ',round(P2,2),'bar, P3 = ',round(P3,2),'bar, P4 =',round(P4,2),'bar'\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 20 - pg 9.35"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)Power required to deliver 15 m^3/min air at suction condition is (kW) =  106.6\n",
      "(b)Intermediate pressures are P2 =  3.42 bar P3 =  11.696 bar\n"
     ]
    }
   ],
   "source": [
    "#pg 9.35\n",
    "#calculate the Power required and Intermediate pressures\n",
    "#Input data\n",
    "P1=1.;#Initial pressure of a 3 stage compressor in bar\n",
    "P4=40.;#Final pressure in bar\n",
    "T1=293.;#Initial temperature in K\n",
    "n=1.3;#Polytropic index\n",
    "V1=15.;#Air delivered per minute in m**3/min\n",
    "\n",
    "#Calculations\n",
    "W=((3*n)/(n-1))*P1*10**5*V1*(((P4/P1)**((n-1)/(3*n)))-1);#Work done by the compressor in kJ/min\n",
    "P=W/(60*1000.);#Power required to deliver 15 m**3/min air in kW\n",
    "P2=P1*(P4/P1)**(1./3);#Intermediate pressure after stage 1 in bar\n",
    "P3=P2*(P4/P1)**(1./3);#Intermediate pressure after stage 2 in bar\n",
    "\n",
    "#Output\n",
    "print '(a)Power required to deliver 15 m^3/min air at suction condition is (kW) = ',round(P,1)\n",
    "print '(b)Intermediate pressures are P2 = ',round(P2,2),'bar P3 = ',round(P3,3),'bar'\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 21 - pg 9.36"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Amount of heat rejected in each intercooler is (kJ) =  113.0\n"
     ]
    }
   ],
   "source": [
    "#pg 9.36\n",
    "#calculate the Amount of heat rejected\n",
    "#Input data\n",
    "P1=1.;#Atmospheric pressure in bar\n",
    "P4=60.;#Delivery pressure in bar\n",
    "T1=303.;#Initial temperature in K\n",
    "n=1.3;#Index of compression\n",
    "Cp=1.005;#Specific heat of air at constant pressure in kJ/kg K\n",
    "S=3.;#Number of stages\n",
    "\n",
    "#Calculations\n",
    "P2=P1*(P4/P1)**(1./3);#Intermediate pressure in bar\n",
    "T2=T1*(P2/P1)**((n-1)/n);#Temperature of air entering the intercoolers in K\n",
    "H=Cp*(T2-T1);#Heat rejected in each intercooler in kJ\n",
    "\n",
    "#Output\n",
    "print 'Amount of heat rejected in each intercooler is (kJ) = ',round(H,0)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 22 - pg 9.37"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)L.P. and I.P.compressor delivery pressure is P2 =  4.021 bar P3 = 16.17 bar\n",
      "(b)Ratio of cylinder volumes is V1:V2:V3 =  16.17 : 4.021 : 1\n",
      "(c)Total indicated power is (kW) =  72.2\n"
     ]
    }
   ],
   "source": [
    "#pg 9.37\n",
    "#calculate the compressor delivery pressure and Ratio of cylinder volumes\n",
    "#Input data\n",
    "P1=1.;#Pressure at the end of suction stroke in LP cylinder of a 3 stage single acting reciprocating compressor in bar\n",
    "T1=293.;#Temperature at the end of suction stroke in LP cylinder in K\n",
    "V=9.;#Free air delivered by the compressor in m**3\n",
    "P4=65.;#Pressure delivered by the compressor in bar\n",
    "n=1.25;#Polytropic index\n",
    "\n",
    "#Calculations\n",
    "P2=P1*(P4/P1)**(1./3);#Intermediate pressure after stage 1 in bar\n",
    "P3=P2*(P4/P1)**(1./3);#Intermediate pressure after stage 2 in bar\n",
    "V3=1;#The volume of cylinder for the third stage in m**3\n",
    "V2=V3*(P3/P2);#Volume of the cylinder for second stage in m**3\n",
    "V1=(P2/P1)*V2;#Volume of the cylinder for first stage in m**3\n",
    "W=(((3*n)/(n-1))*P1*10**5*V*(((P4/P1)**((n-1)/(3*n)))-1))/1000;#Work done by the compressor in kJ/min\n",
    "Pi=W/60;#Indicated power in kW\n",
    "\n",
    "#Output\n",
    "print '(a)L.P. and I.P.compressor delivery pressure is P2 = ',round(P2,3),'bar P3 =',round(P3,2),'bar'\n",
    "print '(b)Ratio of cylinder volumes is V1:V2:V3 = ',round(V1,2),':',round(V2,3),':',V3\n",
    "print '(c)Total indicated power is (kW) = ',round(Pi,2)\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
}