beam2.py 3.4 KB

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