summaryrefslogtreecommitdiff
path: root/Machine_Design-I_by_Dr._Sadhu_Singh/chapter8.ipynb
blob: f1479e25cdc6389d73a1655dde51618e1b5985b4 (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
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 8 - Mechanical Springs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## exa 8.1 Pg 227"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Wahl's correction factor = 1.184 \n",
      " \n",
      " Wire diameter = 4.15 mm. Use 4.25 mm.\n",
      " \n",
      " Mean coil diameter = 34 mm.\n",
      " \n",
      " no. of active turns = 14\n",
      " \n",
      " total no. of turns for squared and ground ends = 16\n",
      " \n",
      " Free length of spring = 123.0 mm Use 124 mm\n",
      " \n",
      " Pitch of coils = 8.30 mm\n",
      " \n",
      " Check for buckling - \n",
      " \n",
      " ratio lf/Dm = 3.647 > 2.6. So, Providing guide is necessary.\n",
      " \n",
      " Critical load for buckling - \n",
      " \n",
      " Fcr = 170.5 N for hinged ends < Fmax\n",
      " \n",
      " Fcr = 480.5 N for fixed ends > Fmax\n",
      " \n",
      " From above two calculatio, it can be seen that spring is safe in buckling for fixed ends.\n",
      " \n",
      "\n",
      " Lowest natural frequency for both ends fixed, fn = 3.079 Hz\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "# Given Data\n",
    "Fmin=250## N\n",
    "Fmax=300## N\n",
    "Del=8## mm\n",
    "C=8## spring index\n",
    "tau_d=420## MPa\n",
    "G=84## GPa\n",
    "\n",
    "# 1. Wahl's correction factor\n",
    "Kw=(4*C-1)/(4*C-4)+0.615/C## Wahl's correction factor\n",
    "print \"\\n Wahl's correction factor = %.3f \"%(Kw)\n",
    "# 2. Wire diameter\n",
    "# tau_d=Kw*8*Fmax*C/pi/d**2\n",
    "d=sqrt(Kw*8*Fmax*C/pi/tau_d)## mm\n",
    "print ' \\n Wire diameter = %.2f mm. Use 4.25 mm.'%(d)\n",
    "d=4.25## mm\n",
    "# 3. Mean coil diameter\n",
    "Dm=8*d## mm\n",
    "print ' \\n Mean coil diameter = %.f mm.'%(Dm)\n",
    "# 4. Stiffness of spring\n",
    "k=(Fmax-Fmin)/Del## N/mm\n",
    "# 5. no. of active turns\n",
    "n = G*10**3*d/8/C**3/k ## no. of active turns\n",
    "print ' \\n no. of active turns = %.f'%(n)\n",
    "# 6. total no. of turns for squared and ground ends\n",
    "nt=n+2## total no. of turns for squared and ground ends\n",
    "print ' \\n total no. of turns for squared and ground ends = %.f'%(nt)\n",
    "# 7. Free length of spring\n",
    "#lf=l_s+del_max+clashallowance(=0.15*del_max)\n",
    "del_max=Del*Fmax/(Fmax-Fmin)##mm\n",
    "l_s=nt*d## mm\n",
    "lf=l_s+del_max+0.15*del_max## mm\n",
    "print ' \\n Free length of spring = %.1f mm Use 124 mm'%(lf)\n",
    "lf=124##mm\n",
    "# 8. Pitch of coils\n",
    "p=lf/(nt-1)##mm\n",
    "print ' \\n Pitch of coils = %.2f mm'%(p)\n",
    "# 9. Check for buckling\n",
    "print ' \\n Check for buckling - '\n",
    "m=lf/Dm## > 2.6 provided guide\n",
    "print ' \\n ratio lf/Dm = %.3f > 2.6. So, Providing guide is necessary.'%(m)\n",
    "kl_1=0.22## for hinged ends\n",
    "kl_2=0.62## for fixed ends\n",
    "Fcr_1=k*kl_1*lf##N (for hinged ends)\n",
    "Fcr_2=k*kl_2*lf##N (for fixed ends)\n",
    "print ' \\n Critical load for buckling - '\n",
    "print ' \\n Fcr = %.1f N for hinged ends < Fmax'%(Fcr_1)\n",
    "print ' \\n Fcr = %.1f N for fixed ends > Fmax'%(Fcr_2)\n",
    "print ' \\n From above two calculatio, it can be seen that spring is safe in buckling for fixed ends.'\n",
    "# 10. Lowest natural frequency for both ends fixed\n",
    "rau=7800## N/mm.cube. (Density of spring material)\n",
    "fn=d/(pi*n*Dm**2)*sqrt(G*10**3/8/(rau*10**-9))##\n",
    "print ' \\n\\n Lowest natural frequency for both ends fixed, fn = %.3f Hz'%(fn)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## exa 8.2 Pg 228"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \n",
      " factor of safety = 1.44\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "# Given Data\n",
    "Fmin=60## N\n",
    "Fmax=140## N\n",
    "d=3## mm\n",
    "Dm=18## mm\n",
    "Sut=1430## MPa\n",
    "\n",
    "C=Dm/d## spring index\n",
    "Kw=(4*C-1)/(4*C-4)+0.615/C## Wahl's correction factor\n",
    "Ks=1+0.5/C## Shear Stress factor\n",
    "Fm=(Fmax+Fmin)/2## N\n",
    "Fa=(Fmax-Fmin)/2## N\n",
    "tau_m=Ks*(8*Fm*C)/(pi*d**2)## MPa\n",
    "tau_a=Kw*(8*Fa*C)/(pi*d**2)## MPa\n",
    "Ses_dash=0.22*Sut## MPa\n",
    "Sys=0.45*Sut## MPa\n",
    "#tau_m/Sys+tua_a/Ses_dash*(2-Ses_dash/Sys)=1/n\n",
    "n=1/(tau_m/Sys+tau_a/Ses_dash*(2-Ses_dash/Sys))## factor of safety\n",
    "print ' \\n factor of safety = %.2f'%(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## exa 8.3 Pg 229"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Wahl's correction factor = 1.2525 \n",
      " \n",
      " Initial tortional shear stress = 85.05 MPa\n",
      " \n",
      " spring stiffness = 9.72 N/mm\n",
      " \n",
      " Spring load to cause yielding = 305.7 N\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "# Given Data\n",
    "Fi=40## N\n",
    "d=3## mm\n",
    "C=6## spring index\n",
    "n=15## factor of safety\n",
    "tau=650## N/mm.sq.\n",
    "G=84## kN/mm.sq.\n",
    "\n",
    "# Wahl's correction factor\n",
    "Kw=(4*C-1)/(4*C-4)+0.615/C## Wahl's correction factor\n",
    "print \"\\n Wahl's correction factor = %.4f \"%Kw\n",
    "\n",
    "# Initial tortional shear stress\n",
    "tau_i=Kw*(8*Fi*C)/(pi*d**2)## MPa\n",
    "print ' \\n Initial tortional shear stress = %.2f MPa'%(tau_i)\n",
    "k=G*10**3*d/(8*C**3*n)## spring stiffness\n",
    "print ' \\n spring stiffness = %.2f N/mm'%(k)\n",
    "# Spring load to cause yielding\n",
    "#tau=Kw*(8*Fi*C)/(pi*d**2)\n",
    "F=tau/(Kw*(8*C)/(pi*d**2))\n",
    "print ' \\n Spring load to cause yielding = %.1f N'%(F)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## exa 8.4 Pg 230"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \n",
      " diameter of spring wire = 8.48 mm or 9 mm\n",
      " \n",
      " Mean coil diameter = 54 mm\n",
      " \n",
      " no. of active coils = 9\n",
      " \n",
      " free length of spring = 127.75 mm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,ceil\n",
    "# Given Data\n",
    "Fmin=500## N\n",
    "Fmax=1200## N\n",
    "C=6## spring index\n",
    "n=1.5## factor of safety\n",
    "Sys=760## MPa\n",
    "Ses_dash=350## MPa\n",
    "Del=25## mm\n",
    "G=82## kN/mm.sq.\n",
    "\n",
    "Kw=(4*C-1)/(4*C-4)+0.615/C## Wahl's correction factor\n",
    "Ks=1+0.5/C## Shear stress factor\n",
    "Fm=(Fmax+Fmin)/2## N\n",
    "Fa=(Fmax-Fmin)/2## N\n",
    "tau_m_into_d_sq=Ks*(8*Fm*C)/(pi)## where tau_m_into_d_sq = tau_m*d**2\n",
    "tau_a_into_d_sq=Kw*(8*Fa*C)/(pi)## where tau_a_into_d_sq = tau_a*d**2\n",
    "\n",
    "#(tau_m-tau_a)/Sys+2*tua_a/Ses_dash=1/n\n",
    "d=sqrt(n)*sqrt((tau_m_into_d_sq-tau_a_into_d_sq)/Sys+2*tau_a_into_d_sq/Ses_dash)## mm\n",
    "print ' \\n diameter of spring wire = %.2f mm or %.f mm'%(d, ceil(d))\n",
    "d=ceil(d)## mm\n",
    "Dm=C*d## mm\n",
    "print ' \\n Mean coil diameter = %.f mm'%( Dm)\n",
    "#del=8*Fmax*Ci**3/(G*d)\n",
    "i=(Del/(8*Fmax*C**3/(G*10**3*d)))## no. of active coils\n",
    "i=ceil(i)## no. of active coils\n",
    "print ' \\n no. of active coils = %.f'%(i)\n",
    "nt=i+2## no. of active coils (for square & ground ends)\n",
    "lf=nt*d+1.15*Del## mm\n",
    "print ' \\n free length of spring = %.2f mm'%(lf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## exa 8.5 Pg 231"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \n",
      " Force on the valve = 3534.3 N\n",
      " \n",
      " Maximum deflection = 60 mm\n",
      " \n",
      " Maximum force = 5301.4 N\n",
      " \n",
      " Wahls correction factor = 1.2525 \n",
      " \n",
      " Diameter of spring wire = 13 mm\n",
      " \n",
      " Mean coil diameter = 78 mm\n",
      " \n",
      " number of turns = 8 \n",
      " \n",
      " Total number of turns for square & ground ends = 10 \n",
      " \n",
      " Free length = 199 mm. Use 200 mm\n",
      " \n",
      " Pitch of coil = 22.1 mm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,ceil\n",
    "# Given Data\n",
    "p=125## MPa\n",
    "dv=60## mm\n",
    "del1=40## mm\n",
    "del2=20## mm\n",
    "tau_max=600## MPa\n",
    "G=85## kN/mm.sq.\n",
    "C=6## spring index\n",
    "\n",
    "Fv=(pi/4)*dv**2*p/100## N (Force on the valve)\n",
    "del_max=del1+del2## mm (Max. deflection)\n",
    "Fmax=Fv*dv/del1## N (Max. force)\n",
    "Kw=(4*C-1)/(4*C-4)+0.615/C## Wahl's correction factor\n",
    "# tau = 8*Fmax*C*Kw/(pi*d**2)\n",
    "d=sqrt((8*Fmax*C*Kw/(pi))/tau_max)## mm (Diameter of spring wire)\n",
    "Dm=6*d## mm (Mean coil diameter)\n",
    "n=G*10**3*d*del_max/(8*Fmax*C**3)## no. of turns\n",
    "n = ceil(n)## no. of turns\n",
    "nt=n+2## total no. of turns\n",
    "lf=nt*d+1.15*del_max## mm (Free length)\n",
    "p=lf/(nt-1)## mm (Pitch of coil)\n",
    "print ' \\n Force on the valve = %.1f N'%(Fv)\n",
    "print ' \\n Maximum deflection = %.f mm'%( del_max)\n",
    "print ' \\n Maximum force = %.1f N'%( Fmax)\n",
    "print ' \\n Wahl''s correction factor = %.4f '%(Kw)\n",
    "print ' \\n Diameter of spring wire = %.f mm'%(d)\n",
    "print ' \\n Mean coil diameter = %.f mm'%( Dm)\n",
    "print ' \\n number of turns = %.f '%(n)\n",
    "print ' \\n Total number of turns for square & ground ends = %.f '%(nt)\n",
    "print ' \\n Free length = %.f mm. Use 200 mm'%(lf)\n",
    "print ' \\n Pitch of coil = %.1f mm'%(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## exa 8.7 Pg 232"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \n",
      " Spring force when valve is lifted = 1484.4 N\n",
      " \n",
      "\n",
      " Design of spring - \n",
      " \n",
      " Spring stiffness = 61.85 N/mm\n",
      " \n",
      " Wahl's correction factor = 1.2525\n",
      " \n",
      " spring diameter = 7.54 mm or 8 mm\n",
      " \n",
      " no. of active coils = 6.29. Use n=7\n",
      " \n",
      " total no. of active coils = 8\n",
      " \n",
      " pitch of coils = 16.67 mm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,ceil\n",
    "from numpy.linalg import solve\n",
    "# Given Data\n",
    "dv=30## mm\n",
    "Wv=10## N\n",
    "Wl=25## N\n",
    "lf=100## mm\n",
    "del1=20## mm\n",
    "p=3.5## N/mm.sq.\n",
    "valve_lift=2## mm\n",
    "C=6## spring index\n",
    "tau=500## N/mm.sq.\n",
    "G=0.84*10**5## N/mm.sq.\n",
    "\n",
    "W=(pi/4)*dv**2*p## N (load on the valve at operating condition)\n",
    "W1=W-Wv##N (Net load on the valve at operating condition)\n",
    "#W1*100=Wl*150+S1*200+P*300 # taking momens about the fulcrum\n",
    "#S1*200+P*300=W1*100-Wl*150 ...eqn(1)\n",
    "valve_lift=20*100/200## mm #from figure (when spring is extended by 20 mm)\n",
    "spring_extension=2*200/100## mm # from figure (when valve is lifted 2 mm)\n",
    "valve_load=W*12/10## N # (when valve is lifted 2 mm)\n",
    "W2=valve_load-Wv## N # (when valve is lifted 2 mm)\n",
    "del2=del1+4## mm (when valve is lifted)\n",
    "#S2=S1*del2/del1## spring force when valve is lifted\n",
    "#S1*del2/del1-s2=0 ... eqn(1)\n",
    "#W2*100=Wl*150+S2*200+P*300 # taking momens about the fulcrum\n",
    "#S2*200+P*300 =W2*100-Wl*150 ... eqn(2)\n",
    "#S1*200+P*300=W1*100-Wl*150 ...eqn(3)\n",
    "# solving above 3 eqn. by matrix method\n",
    "A=[[del2/del1, -1, 0],[200, 0, 300],[0, 200, 300]]\n",
    "B=[[0],[W1*100-Wl*150],[W2*100-Wl*150]]\n",
    "X=solve(A,B)## solution matrix\n",
    "S1=X[0]## N\n",
    "S2=X[1]## N\n",
    "print ' \\n Spring force when valve is lifted = %.1f N'%(S2)\n",
    "print ' \\n\\n Design of spring - '\n",
    "k=(S2-S1)/(del2-del1)## N/mm (Spring stiffness)\n",
    "print ' \\n Spring stiffness = %.2f N/mm'%(k)\n",
    "Kw=(4*C-1)/(4*C-4)+0.615/C## Wahl's correction factor\n",
    "print \" \\n Wahl's correction factor = %.4f\"%(Kw)\n",
    "# tau=Kw*8*S2*C/pi/d**2 max. shear stress\n",
    "d=sqrt(Kw*8*S2*C/pi/tau)## mm (spring diameter)\n",
    "print ' \\n spring diameter = %.2f mm or %.f mm'%(d,d)\n",
    "d=ceil(d)## mm\n",
    "# k=G*d/(8*C**3*n) (Spring stiffness)\n",
    "n=G*d/(8*C**3*k)## no. of active coils\n",
    "print ' \\n no. of active coils = %.2f. Use n=7'%(n)\n",
    "n=ceil(n)## rounding\n",
    "nt=n+1## total no. of active coils\n",
    "print ' \\n total no. of active coils = %.f'%(nt)\n",
    "p=lf/(n-1)## mm (pitch of coils)\n",
    "print ' \\n pitch of coils = %.2f mm'%(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## exa 8.8 Pg 234"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \n",
      " Spring stiffness = 12.5 N/mm\n",
      " \n",
      " By hit and trial method and using value of C**3/d -\n",
      " \n",
      " value of Spring Index, C = 4.8 \n",
      " \n",
      " value of wire diameter, d = 3.9 mm\n",
      " \n",
      " But we adopt d=4 mm.\n",
      " Hence, Spring Index = 4.84 \n",
      " \n",
      " Mean coil diameter = 19.36 mm\n",
      " \n",
      " Outside coil diameter = 23.36 mm < 25 mm. Hence design is ok.\n",
      " \n",
      " Wahls correction factor = 1.322 \n",
      " \n",
      " Maximum shear stress = 1018.54 N/mm.sq.\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "\n",
    "# Given Data\n",
    "Fmin=0## N\n",
    "Fmax=1000## N\n",
    "Del=80## mm\n",
    "Do=25## mm\n",
    "n=30## no. of turns\n",
    "G=85## kN/mm.sq.\n",
    "\n",
    "k=(Fmax-Fmin)/Del## N/mm (Spring stiffness)\n",
    "print ' \\n Spring stiffness = %.1f N/mm'%(k)\n",
    "# k=G*d/(8*C**3*n) (Spring stiffness)\n",
    "C_cube_BY_d=G*10**3/(k*8*n)## \n",
    "\n",
    "def hitntrial(c3d,Do):\n",
    "    from numpy import arange\n",
    "    for C in arange(5.0,4.5,-0.1):\n",
    "        d=C**3/(c3d)#\n",
    "        Doo=d*C+C#\n",
    "        if Doo<Do :\n",
    "            break\n",
    "        \n",
    "    return [C,d]\n",
    "\n",
    "[C,d]=hitntrial(C_cube_BY_d,Do)\n",
    "print ' \\n By hit and trial method and using value of C**3/d -'\n",
    "print ' \\n value of Spring Index, C = %.1f '%(C)\n",
    "print ' \\n value of wire diameter, d = %.1f mm'%(d)\n",
    "print ' \\n But we adopt d=4 mm.'\n",
    "d=4## mm (adopted for design)\n",
    "C=(C_cube_BY_d*d)**(1/3)## Spring index\n",
    "print ' Hence, Spring Index = %.2f '%(C)\n",
    "Dm=C*d## mm\n",
    "print ' \\n Mean coil diameter = %.2f mm'%( Dm)\n",
    "Do=Dm+d## mm\n",
    "print ' \\n Outside coil diameter = %.2f mm < 25 mm. Hence design is ok.'%( Do)\n",
    "Kw=(4*C-1)/(4*C-4)+0.615/C## Wahl's correction factor\n",
    "print ' \\n Wahl''s correction factor = %.3f '%(Kw)\n",
    "tau=8*Kw*C*Fmax/(pi*d**2)## N/mm.sq.\n",
    "print ' \\n Maximum shear stress = %.2f N/mm.sq.'%(tau)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## exa 8.10 Pg 235"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " wire diameter of spring = 7.28 mm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "# Given Data\n",
    "Fmin=600## N\n",
    "Fmax=1000## N\n",
    "C=6## spring index\n",
    "n=1.5## factor of safety\n",
    "Sys=700## N/mm.sq.\n",
    "Ses_dash=350## N/mm.sq.\n",
    "\n",
    "Kw=(4*C-1)/(4*C-4)+0.615/C## Wahl's correction factor\n",
    "Ks=1+0.5/C## Shear Stress factor\n",
    "Fm=(Fmax+Fmin)/2## N\n",
    "Fa=(Fmax-Fmin)/2## N\n",
    "tau_m_into_d_sq=Ks*(8*Fm*C)/(pi)## where tau_m_into_d_sq = tau_m*d**2\n",
    "tau_a_into_d_sq=Kw*(8*Fa*C)/(pi)## where tau_a_into_d_sq = tau_a*d**2\n",
    "\n",
    "#(tau_m-tau_a)/Sys+2*tua_a/Ses_dash=1/n\n",
    "d=sqrt(n)*sqrt((tau_m_into_d_sq-tau_a_into_d_sq)/Sys+2*tau_a_into_d_sq/Ses_dash)## mm\n",
    "print ' wire diameter of spring = %.2f mm'%(d)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## exa 8.11 Pg 236"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \n",
      " initial tension in spring = 2500 N\n",
      " \n",
      " maximum tension in spring = 2688 N\n",
      " \n",
      " stiffness of spring = 31.25 N/mm\n",
      " \n",
      " diameter of spring = 17.19 mm. Use 18 mm.\n",
      " \n",
      " mean coil diameter = 99 mm\n",
      " \n",
      " outside coil diameter = 117 mm\n",
      " \n",
      " initial coil diameter = 81 mm\n",
      " \n",
      " no. of turns = 35\n",
      " \n",
      " total no. of turns(for extension spring) = 36\n",
      " \n",
      " free length of spring = 676 mm\n",
      " \n",
      " pitch of coils = 19.52 mm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,ceil\n",
    "# Given Data\n",
    "dv=100##mm\n",
    "C=5.5## spring index\n",
    "pi=1## N/mm.sq.\n",
    "p=1.075## N/mm.sq.\n",
    "Del=6## mm\n",
    "tau_max=400## N/mm.sq.\n",
    "G=80## kN/mm.sq.\n",
    "\n",
    "Fi=(pi/4)*dv**2*pi## N (initial tension in spring)\n",
    "print ' \\n initial tension in spring = %.f N'%( Fi)\n",
    "F=(pi/4)*dv**2*p## N (maximum tension in spring)\n",
    "print ' \\n maximum tension in spring = %.f N'%( F)\n",
    "k=(F-Fi)/Del## N/mm (stiffness of spring)\n",
    "print ' \\n stiffness of spring = %.2f N/mm'%(k)\n",
    "#Tmax=F*Dm/2 where Dm=5.5*d\n",
    "Tmax_BY_d=F*5.5/2## calculation\n",
    "#Tmax=(pi/16)*d**3*tau_max\n",
    "d=sqrt(Tmax_BY_d/((pi/16)*tau_max))## mm\n",
    "print ' \\n diameter of spring = %.2f mm. Use 18 mm.'%(d)\n",
    "d=ceil(d)## mm (rounding)\n",
    "Dm=5.5*d##mm\n",
    "print ' \\n mean coil diameter = %.f mm'%(Dm)\n",
    "Do=Dm+d##mm\n",
    "print ' \\n outside coil diameter = %.f mm'%(Do)\n",
    "Di=Dm-d## mm\n",
    "print ' \\n initial coil diameter = %.f mm'%(Di)\n",
    "n=G*10**3*d*Del/8/(F-Fi)/C**3## no. of turns\n",
    "print ' \\n no. of turns = %.f'%(n)\n",
    "nt=n+1## total no. of turns\n",
    "print ' \\n total no. of turns(for extension spring) = %.f'%(nt)\n",
    "gi=1## mm (initial gap)\n",
    "lf=nt*d+(nt-1)*gi## mm\n",
    "print ' \\n free length of spring = %.f mm'%(lf)\n",
    "p=lf/(nt-1)##mm\n",
    "print ' \\n pitch of coils = %.2f mm'%(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## exa 8.12 Pg 236"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \n",
      " (i) neglecting the effect of curvature\n",
      " \n",
      " Axial load = 412.3 N\n",
      " \n",
      " deflection per active turn = 9.954 mm/turn\n",
      " \n",
      "\n",
      " (ii) considering the effect of curvature\n",
      " \n",
      " Axial load = 382.5 N\n",
      " \n",
      " deflection per active turn = 9.234 mm/turn\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,ceil\n",
    "# Given Data\n",
    "d=6##mm\n",
    "Do=75## mm\n",
    "tau=350## N/mm.sq.\n",
    "G=84## kN/mm.sq.\n",
    "\n",
    "print ' \\n (i) neglecting the effect of curvature'\n",
    "dm=Do-d## mm\n",
    "C=dm/d## spring index\n",
    "Ks=1+0.5/C## shear stress factor\n",
    "#tau=Ks*(8*Fmax*C)/(pi*d**2)\n",
    "Fmax=tau/(Ks*(8*C)/(pi*d**2))## N\n",
    "print ' \\n Axial load = %.1f N'%(Fmax)\n",
    "delBYi=8*Fmax*C**3/(G*10**3*d)## mm/turn\n",
    "print ' \\n deflection per active turn = %.3f mm/turn'%(delBYi)\n",
    "print ' \\n\\n (ii) considering the effect of curvature'\n",
    "Kw=(4*C-1)/(4*C-4)+0.615/C## Wahl's correction factor\n",
    "#tau=Kw*(8*Fmax*C)/(G*d)\n",
    "Fmax=tau/(Kw*8*C/(pi*d**2))#\n",
    "print ' \\n Axial load = %.1f N'%(Fmax)\n",
    "delBYn=8*Fmax*C**3/(G*10**3*d)## mm/turn\n",
    "print ' \\n deflection per active turn = %.3f mm/turn'%(delBYn)\n",
    "# Note - answer in the textbook is wrong for last part."
   ]
  }
 ],
 "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
}