Ejemplo n.º 1
0
    nabla2psi[1:N + 1] = (psi[0:N] + psi[2:N + 2] - 2 * psi[1:N + 1]) / dx2
    return 1j * (nabla2psi - V * psi
                 )  # this is the RH of Schroedinger equation!


def d_dt(psi):  # find Psi(t+dt)-Psi(t) /dt with 4th order Runge-Kutta method
    k1 = f(psi)
    k2 = f(psi + dt / 2 * k1)
    k3 = f(psi + dt / 2 * k2)
    k4 = f(psi + dt * k3)
    return (k1 + 2 * k2 + 2 * k3 + k4) / 6


vp = Plotter(interactive=0, axes=2, bg=(0.95, 0.95, 1))
vp.xtitle = ""
vp.ytitle = "|\Psi(x,t)|\^2"

bck = vp.load(datadir + "images/schrod.png").alpha(.3).scale(.0255).pos(
    [0, -5, -.1])
barrier = Line(np.stack((x, V * 15, np.zeros_like(x)), axis=1),
               c="black",
               lw=2)

lines = []
for i in range(0, Nsteps):
    for j in range(500):
        Psi += d_dt(Psi) * dt  # integrate for a while before showing things
    A = np.real(Psi * np.conj(Psi)) * 1.5  # psi squared, probability(x)
    coords = np.stack((x, A, np.zeros_like(x)), axis=1)
    Aline = Line(coords, c="db", lw=3)
    vp.show([Aline, barrier, bck])
Ejemplo n.º 2
0
t = 0
pb = ProgressBar(0, Nsteps, c="blue", ETA=0)
for i in pb.range():
    y_eu, v_eu = euler(y_eu, v_eu, t, dt)
    y_rk, v_rk = rk4(y_rk, v_rk, t, dt)
    t += dt
    positions_eu.append(y_eu)  # store result of integration
    positions_rk.append(y_rk)
    pb.print("Integrate: RK-4 and Euler")

####################################################
# Visualize the result
####################################################
settings.useDepthPeeling = False
plt = Plotter(interactive=0, axes=2)  # choose axes type nr.2
plt.ytitle = "u(x,t)"
plt.ztitle = ""  # will not draw z axis

for i in x:
    plt += Point([i, 0, 0], c="green", r=6)
pts_actors_eu = plt.actors  # save a copy of the actors list
pts_actors_eu[0].legend = "Euler method"

plt.actors = []  # clean up the list

for i in x:
    plt += Point([i, 0, 0], c="red", r=6)
pts_actors_rk = plt.actors  # save a copy of the actors list
pts_actors_rk[0].legend = "Runge-Kutta4"

# merge the two lists and set it as the current actors
Ejemplo n.º 3
0
v_eu, v_rk = np.array(v), np.array(v)
t = 0
pb = ProgressBar(0, Nsteps, c="blue", ETA=0)
for i in pb.range():
    y_eu, v_eu = euler(y_eu, v_eu, t, dt)
    y_rk, v_rk = rk4(y_rk, v_rk, t, dt)
    t += dt
    positions_eu.append(y_eu)  # store result of integration
    positions_rk.append(y_rk)
    pb.print("Integrate: RK-4 and Euler")

####################################################
# Visualize the result
####################################################
vp = Plotter(interactive=0, axes=2)  # choose axes type nr.2
vp.ytitle = "u(x,t)"
vp.ztitle = ""  # will not draw z axis

for i in x:
    vp += Point([i, 0, 0], c="green", r=6)
pts_actors_eu = vp.actors  # save a copy of the actors list
pts_actors_eu[0].legend = "Euler method"

vp.actors = []  # clean up the list

for i in x:
    vp += Point([i, 0, 0], c="red", r=6)
pts_actors_rk = vp.actors  # save a copy of the actors list
pts_actors_rk[0].legend = "Runge-Kutta4"

# merge the two lists and set it as the current actors
Ejemplo n.º 4
0
    nabla2psi[1:N + 1] = (psi[0:N] + psi[2:N + 2] - 2 * psi[1:N + 1]) / dx2
    return 1j * (nabla2psi - V * psi
                 )  # this is the RH of Schroedinger equation!


def d_dt(psi):  # find Psi(t+dt)-Psi(t) /dt with 4th order Runge-Kutta method
    k1 = f(psi)
    k2 = f(psi + dt / 2 * k1)
    k3 = f(psi + dt / 2 * k2)
    k4 = f(psi + dt * k3)
    return (k1 + 2 * k2 + 2 * k3 + k4) / 6


vp = Plotter(interactive=0, axes=2, bg=(0.95, 0.95, 1))
vp.xtitle = ""
vp.ytitle = "Psi^2(x,t)"
vp.ztitle = ""

bck = vp.load(datadir + "images/schrod.png").alpha(.3).scale(.0255).pos(
    [0, -5, -.1])
barrier = Line(np.stack((x, V * 15, np.zeros_like(x)), axis=1),
               c="black",
               lw=2)

lines = []
for i in range(0, Nsteps):
    for j in range(500):
        Psi += d_dt(Psi) * dt  # integrate for a while before showing things
    A = np.real(Psi * np.conj(Psi)) * 1.5  # psi squared, probability(x)
    coords = np.stack((x, A, np.zeros_like(x)), axis=1)
    Aline = Line(coords, c="db", lw=3)