tunnelling1.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """Quantum tunneling using 4th order Runge-Kutta method"""
  2. import numpy as np
  3. from vedo import Plotter, Line
  4. N = 300 # number of points
  5. dt = 0.004 # time step
  6. x0 = 5 # peak initial position
  7. s0 = 0.75 # uncertainty on particle position
  8. k0 = 10 # initial momentum of the wave packet
  9. Vmax = 0.2 # height of the barrier (try 0 for particle in empty box)
  10. size = 20.0 # x span [0, size]
  11. def f(psi):
  12. nabla2psi = np.zeros(N+2, dtype=complex)
  13. dx2 = ((x[-1] - x[0]) / (N+2))**2 * 400 # dx**2 step, scaled
  14. nabla2psi[1 : N+1] = (psi[0:N] + psi[2 : N+2] - 2 * psi[1 : N+1]) / dx2
  15. return 1j * (nabla2psi - V * psi) # this is the RHS of Schroedinger equation
  16. def d_dt(psi): # find Psi(t+dt)-Psi(t) /dt with 4th order Runge-Kutta method
  17. k1 = f(psi)
  18. k2 = f(psi + dt / 2 * k1)
  19. k3 = f(psi + dt / 2 * k2)
  20. k4 = f(psi + dt * k3)
  21. return (k1 + 2 * k2 + 2 * k3 + k4) / 6
  22. x = np.linspace(0, size, N+2) # we will need 2 extra points for the box wall
  23. V = Vmax * (np.abs(x-11) < 0.5) - 0.01 # simple square barrier potential
  24. Psi = np.sqrt(1/s0) * np.exp(-1/2 * ((x-x0)/s0)**2 + 1j * x * k0) # wave packet
  25. zeros = np.zeros_like(x)
  26. plt = Plotter(interactive=False, size=(1000,500))
  27. barrier = Line(np.c_[x, V * 15]).c("red3").lw(3)
  28. wpacket = Line(np.c_[x, zeros]).c('blue4').lw(2)
  29. plt.show(barrier, wpacket, __doc__, zoom=2)
  30. for j in range(150):
  31. for i in range(500):
  32. Psi += d_dt(Psi) * dt # integrate for a while
  33. amp = np.real(Psi * np.conj(Psi)) * 1.5 # psi squared, probability(x)
  34. wpacket.points = np.c_[x, amp, zeros] # update points
  35. plt.render()
  36. plt.interactive().close()