beam2.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. from pysketcher import *
  2. def beam():
  3. L = 8.0
  4. a = 3*L/4
  5. b = L - a
  6. H = 1.0
  7. xpos = 0.0
  8. ypos = 3.0
  9. drawing_tool.set_coordinate_system(
  10. xmin=-3, xmax=xpos+1.5*L,
  11. ymin=0, ymax=ypos+5*H,
  12. axis=False)
  13. drawing_tool.set_linecolor('blue')
  14. #drawing_tool.set_grid(True)
  15. drawing_tool.set_fontsize(16)
  16. A = point(xpos,ypos)
  17. beam = Rectangle(A, L, H)
  18. h = L/16 # size of support, clamped wall etc
  19. clamped = Rectangle(A - point(h,0) - point(0,2*h), h,
  20. 6*h).set_filled_curves(pattern='/')
  21. load = ConstantBeamLoad(A + point(0,H), L, H)
  22. load.set_linewidth(1).set_linecolor('black')
  23. load_text = Text('$w$',
  24. load.geometric_features()['mid_top'] +
  25. point(0,h/2.))
  26. B = A + point(a, 0)
  27. C = B + point(b, 0)
  28. support = SimplySupportedBeam(B, h) # pt B is simply supported
  29. R1 = Force(A-point(0,2*H), A, '$R_1$', text_spacing=1./50)
  30. R1.set_linewidth(3).set_linecolor('black')
  31. R2 = Force(B-point(0,2*H),
  32. support.geometric_features()['mid_support'],
  33. '$R_2$', text_spacing=1./50)
  34. R2.set_linewidth(3).set_linecolor('black')
  35. M1 = Moment('$M_1$', center=A + point(-H, H/2), radius=H/2,
  36. left=True, text_spacing=1/30.)
  37. M1.set_linecolor('black')
  38. ab_level = point(0, 3*h)
  39. a_dim = Distance_wText(A - ab_level, B - ab_level, '$a$')
  40. b_dim = Distance_wText(B - ab_level, C - ab_level, '$b$')
  41. dims = Composition({'a': a_dim, 'b': b_dim})
  42. symbols = Composition(
  43. {'R1': R1, 'R2': R2, 'M1': M1,
  44. 'w': load, 'w text': load_text,
  45. 'A': Text('$A$', A+point(0.7*h,-0.9*h)),
  46. 'B': Text('$B$',
  47. support.geometric_features()['mid_support']-
  48. point(1.25*h,0)),
  49. 'C': Text('$C$', C+point(h/2,-h/2))})
  50. x_axis = Axis(A + point(L+h, H/2), 2*H, '$x$',).\
  51. set_linecolor('black')
  52. y_axis = Axis(A + point(0,H/2), 3.5*H, '$y$',
  53. label_alignment='left',
  54. rotation_angle=90).set_linecolor('black')
  55. axes = Composition({'x axis': x_axis, 'y axis': y_axis})
  56. annotations = Composition({'dims': dims, 'symbols': symbols,
  57. 'axes': axes})
  58. beam = Composition({'beam': beam, 'support': support,
  59. 'clamped end': clamped, 'load': load})
  60. def deflection(x, a, b, w):
  61. import numpy as np
  62. R1 = 5./8*w*a - 3*w*b**2/(4*a)
  63. R2 = 3./8*w*a + w*b + 3*w*b**2/(4*a)
  64. M1 = R1*a/3 - w*a**2/12
  65. y = -(M1/2.)*x**2 + 1./6*R1*x**3 - w/24.*x**4 + \
  66. 1./6*R2*np.where(x > a, 1, 0)*(x-a)**3
  67. return y
  68. x = linspace(0, L, 101)
  69. y = deflection(x, a, b, w=1.0)
  70. y /= abs(y.max() - y.min())
  71. y += ypos + H/2
  72. elastic_line = Curve(x, y).\
  73. set_linecolor('red').\
  74. set_linestyle('dashed').\
  75. set_linewidth(3)
  76. beam.draw()
  77. drawing_tool.display()
  78. drawing_tool.savefig('tmp_beam2_1.png')
  79. import time
  80. time.sleep(1.5)
  81. annotations.draw()
  82. drawing_tool.display()
  83. drawing_tool.savefig('tmp_beam2_2.png')
  84. time.sleep(1.5)
  85. elastic_line.draw()
  86. drawing_tool.display()
  87. drawing_tool.savefig('tmp_beam2_3.png')
  88. #beam.draw_dimensions()
  89. #test_Dashpot(xpos+2*W)
  90. beam()
  91. input()