Exemplo n.º 1
0
# Create an array with all the radius and a list with all the masses
Radius = np.concatenate((np.array([Rb]), np.array([Rs] * (Nsp - 1))))
Mass = [1.0] + [Ms] * (Nsp - 1)

# Create the initial array of velocities at random with big sphere at rest
ListVel = [(0., 0.)]
for s in range(1, Nsp):
    ListVel.append((Rb * random.uniform(-1, 1), Rb * random.uniform(-1, 1)))
Vel = np.array(ListVel)

# Create the spheres
Spheres = [vp.sphere(pos=(Pos[0][0], Pos[0][1], 0), r=Radius[0], c='red')]
for s in range(1, Nsp):
    a = vp.sphere(pos=(Pos[s][0], Pos[s][1], 0), r=Radius[s], c='blue')
    Spheres.append(a)
vp.grid(sx=screen_w, sy=screen_w)

# Auxiliary variables
Id = np.identity(Nsp)
Dij = (Radius + Radius[:, np.newaxis])**2  # Matrix Dij=(Ri+Rj)**2

# The main loop
pb = ProgressBar(0, 2000, c='r')
for i in pb.range():
    # Update all positions
    np.add(Pos, Vel * Dt, Pos)  # Fast version of Pos = Pos + Vel*Dt

    # Impose the bouncing at the walls
    if Pos[0, 0] <= -Lb0:
        Pos[0, 0] = -Lb0
        Vel[0, 0] = -Vel[0, 0]
Exemplo n.º 2
0
width   = 10e-6    # slit width in m
D       = 0.1      # screen distance in m
#########################################

# create the slits as a set of individual coherent point-like sources
n = 10 # nr of elementary sources in slit (to control precision).
slit1 = list(zip([0]*n, arange(0,n)*width/n, [0]*n)) # source points inside slit 1
slit2 = list(slit1 + array([1e-5, 0,0]))             # a shifted copy of slit 1
slits = slit1 + slit2  
#slits += list(slit1 + array([-2e-5, 1e-5, 0]))      # add an other copy of slit 1
#slits = [(cos(x)*4e-5, sin(x)*4e-5, 0) for x in arange(0,2*pi, .1)] # Arago spot
#slits = grid(sx=1e-4, sy=1e-4, resx=9, resy=9).coordinates() # a square lattice

vp = Plotter(title='The Double Slit Experiment', axes=0, verbose=0, bg='black')

screen = vp.grid(pos=[0,0,-D], sx=0.1, sy=0.1, resx=200, resy=50)
screen.wire(False) # show it as a solid plane (not as wireframe)

k  = 0.0 + 1j * 2*pi/lambda1 # complex wave number
norm = len(slits)*5e+5
amplitudes = []

for i, x in enumerate(screen.coordinates()):
    psi = 0
    for s in slits:
        r = mag(x-s)
        psi += exp( k * r )/r
    psi2 = real( psi * conj(psi) ) # psi squared
    amplitudes.append(psi2)
    screen.point(i, x+[0,0, psi2/norm]) # elevate grid in z