flow_over_gaussian.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #print repr(inlet_profile)
  28. fig = Composition({
  29. 'bottom': wall,
  30. 'inlet': inlet_profile,
  31. 'symmetry line': symmetry_line,
  32. 'outlet': outlet,
  33. })
  34. fig.draw() # send all figures to plotting backend
  35. vx, vy = velprofile(H/2.)
  36. symbols = {
  37. 'alpha': Distance_wText((W,0), (W,alpha), r'$\alpha$'),
  38. 'W': Distance_wText((0,-0.5), (W,-0.5), r'$W$',
  39. text_spacing=-1./30),
  40. 'L': Distance_wText((W,-0.5), (W+L,-0.5), r'$L$',
  41. text_spacing=-1./30),
  42. 'v(y)': Text('$v(y)$', (H/2., vx)),
  43. 'dashed line': Line((W-2.5*sigma,0), (W+2.5*sigma,0)).\
  44. set_linestyle('dotted').set_linecolor('black'),
  45. }
  46. symbols = Composition(symbols)
  47. symbols.draw()
  48. drawing_tool.display()
  49. drawing_tool.savefig('tmp1')
  50. raw_input()