flow_over_gaussian-checkpoint.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from pysketcher import *
  2. from numpy import exp, linspace
  3. W = 5 # upstream area
  4. L = 10 # downstread area
  5. H = 4 # height
  6. sigma = 2
  7. alpha = 2
  8. drawing_tool.set_coordinate_system(xmin=0, xmax=W+L+1,
  9. ymin=-2, ymax=H+1,
  10. axis=True)
  11. drawing_tool.set_linecolor('blue')
  12. # Create bottom
  13. def gaussian(x):
  14. return alpha*exp(-(x-W)**2/(0.5*sigma**2))
  15. x = linspace(0, W+L, 51)
  16. y = gaussian(x)
  17. wall = Wall(x, y, thickness=-0.3, pattern='|', transparent=True).\
  18. set_linecolor('brown')
  19. wall['eraser'].set_linecolor('white')
  20. def velprofile(y):
  21. return [2*y*(2*H-y)/H**2, 0]
  22. inlet_profile = VelocityProfile((0,0), H, velprofile, 5)
  23. symmetry_line = Line((0,H), (W+L,H))
  24. symmetry_line.set_linestyle('dashed')
  25. outlet = Line((W+L,0), (W+L,H))
  26. outlet.set_linestyle('dashed')
  27. fig = Composition({
  28. 'bottom': wall,
  29. 'inlet': inlet_profile,
  30. 'symmetry line': symmetry_line,
  31. 'outlet': outlet,
  32. })
  33. fig.draw() # send all figures to plotting backend
  34. vx, vy = velprofile(H/2.)
  35. symbols = {
  36. 'alpha': Distance_wText((W,0), (W,alpha), r'$\alpha$'),
  37. 'W': Distance_wText((0,-0.5), (W,-0.5), r'$W$',
  38. text_spacing=-1./30),
  39. 'L': Distance_wText((W,-0.5), (W+L,-0.5), r'$L$',
  40. text_spacing=-1./30),
  41. 'v(y)': Text('$v(y)$', (H/2., vx)),
  42. 'dashed line': Line((W-2.5*sigma,0), (W+2.5*sigma,0)).\
  43. set_linestyle('dotted').set_linecolor('black'),
  44. }
  45. symbols = Composition(symbols)
  46. symbols.draw()
  47. drawing_tool.display()
  48. drawing_tool.savefig('tmp1')
  49. input()