Advertisement
nlw

Calculation of the deflection of a stiff beam under gravity

nlw
Apr 27th, 2011
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. #!/usr/bin/python
  2. ##########################################################################
  3. ## Program to (try to) calculate the shape of a stiff paper sheet
  4. ## deflected due to gravity. Some more info in my blog...
  5.  
  6. ## Coded by Nicolau Leal Werneck <nwerneck@gmail.com> in 2011/04/27
  7.  
  8. from pylab import *
  9.  
  10. def pplot(x, args):
  11.     plot(x[:,0], x[:,1], args)
  12.  
  13. def calc_p(p,dp,phi,ds):
  14.     p[0] = array([0,0])
  15.     for n in range(1,len(p)):
  16.         dp[n-1] = ds*array([cos(phi[n-1]),sin(phi[n-1])])
  17.         p[n] = p[n-1] + dp[n-1]
  18.  
  19. ion()
  20.  
  21. Np = 50
  22.  
  23. ## The angles at each point
  24. phi = zeros(Np)
  25.  
  26. # Set initial state
  27. phi[0]=arctan2(10,0.1)
  28. phi[1:]=0
  29.  
  30. ## Gravitational acceleration
  31. Ag = array([0,-9.8])
  32.  
  33. ## "time interval" between updates
  34. dt = 0.1
  35.  
  36. ## line segment length
  37. ds = 1.0/Np
  38.  
  39. ## Paper linear density
  40. mu = 1 #0.01
  41.  
  42. ## This EI is actually EI / mu
  43. EI = 100
  44.  
  45. ## Upper limit on the number of iterations
  46. Nt = 100000
  47.  
  48. ## A unit vector in teh direction of each segment
  49. dp = zeros((len(phi),2))
  50. ## the positions of the weights
  51. p = zeros((len(phi)+1,2))
  52.  
  53. ##
  54. ## The main loop
  55.  
  56. for t in range(Nt):
  57.     ## Calculates the current weights positions.
  58.     calc_p(p,dp,phi,ds)
  59.  
  60.     ## Variable to test if changes are already too small
  61.     maxchange=0
  62.  
  63.     ## Iterate over each weight, and calculate its increment
  64.     for s in range(1,len(phi)):
  65.         ## Bending stiffness acceleration
  66.         if s < len(phi)-1:
  67.             Am = EI * ( -p[s-1]+2*p[s]-p[s+1] )  / (2 * ds * mu)
  68.         else:
  69.             Am = EI * ( -p[s-1]+p[s] )  / (2 * ds * mu)
  70.  
  71.         # Total acceleration
  72.         #At = Am + (Ag if p[s,1]>0 else Ag-1*p[s,1]/mu )
  73.         At = Am + Ag
  74.  
  75.         dM = dot(At, dot(array([[0,-1],[1,0]]), dp[s]))
  76.         phi[s] += dt*dM
  77.         mm=np.max(np.abs(dM))
  78.         maxchange = mm if mm>maxchange else maxchange
  79.  
  80.     if maxchange<1e-10:
  81.         break
  82.  
  83.     if not t%100:
  84.         print t,maxchange
  85.  
  86. print 'Iterations:', t
  87.    
  88. calc_p(p,dp,phi,ds)
  89.  
  90. ## Plot the curve
  91. figure(1, figsize=(6,6))
  92. title('Stiff paper sheet bending under gravity')
  93. pplot(p, 'r-o')
  94.  
  95. plot( [0,10*dp[0,0]], [0,10*dp[0,1]] , 'k--', lw=1)
  96. plot( [0,10*dp[0,0]], [0,10*dp[0,1]] , 'k--', lw=1)
  97. plot([0],[0], 'k-s')
  98.  
  99. axis('equal')
  100.  
  101. ## The peak of the curve
  102. mm=p[find(p[:,1] == p[:,1].max())[0]]
  103.  
  104. ## Plots an approximation by a parabola
  105. xx = mgrid[0:100.] * p[-1,0]/100;
  106. A = 2 * mm[1]/mm[0]
  107. B = - mm[1]/mm[0]**2
  108. plot(xx, A*xx+B*xx**2, 'g:', alpha=0.5)
  109.  
  110. savefig('beam3.png', dpi=100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement