Advertisement
bolverk

richtmyer_meshkov_instability

Feb 19th, 2022
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. import numpy
  2. from numba import jit
  3. import matplotlib.pyplot as plt
  4. from tqdm import tqdm
  5.  
  6. @jit(nopython=True)
  7. def calc_vel(p):
  8.  
  9.     x = p[0]
  10.     y = p[1]
  11.     vx = numpy.sign(y)*numpy.sin(x)*numpy.exp(-numpy.abs(y))
  12.     vy = numpy.cos(x)*numpy.exp(-numpy.abs(y))
  13.     return numpy.array([vx,vy])
  14.  
  15. @jit(nopython=True)
  16. def calc_all_vel(p_list):
  17.  
  18.     res = numpy.zeros_like(p_list)
  19.     for i in range(len(res)):
  20.         res[i] = calc_vel(p_list[i])
  21.     return res
  22.  
  23. x0_list = numpy.linspace(0,20,2000)
  24. y0_list = 1e-3*numpy.sin(x0_list)
  25. p_list = numpy.vstack((x0_list, y0_list)).T
  26.  
  27. fig, ax = plt.subplots()
  28. ax.set_ylim((-1,1))
  29. image, = ax.plot(x0_list, y0_list)
  30. plt.draw()
  31.  
  32. dt = 0.2e-2
  33. v_list = numpy.zeros_like(p_list)
  34. counter = 0
  35. for n in tqdm(range(800)):
  36.     p_list = p_list + calc_all_vel(p_list)*dt
  37.     if n%2 == 0:
  38.         image.set_data(p_list.T[0],
  39.                        p_list.T[1])
  40.         plt.draw()
  41.         fig.savefig('output/snapshot_'+str(counter).zfill(3)+'.png')
  42.         counter += 1
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement