コード例 #1
0
X, Y, Vx, Vy = initialize_particles(n_particles)

plot_particles(X, Y, 'coordinates_start.png')

# The main loop
for n in range(n_step):

    X, Y, Vx, Vy = simulate_step(X, Y, Vx, Vy, dt)

    # Print status every 100th step
    if n % 100 == 0:
        print "Step %5i" % (n)

    # Save frame for video every 10th step
    if n % 10 == 0:
        video.add_frame(X, Y)

    # Count the particles
    if n % 5 == 0:
        no_part = 0

        for i in range(n_particles):
            # No need to check for x_positions < 1 or y_positions since we are ALWAYS
            # within the box.
            if( X[i] > 0.0 ):
                no_part += 1


        if( n < n_step / 2 ):
            particle_dist.append( no_part )
        if( n > n_step / 2 ):
コード例 #2
0
ファイル: solution_week1.py プロジェクト: KPLauritzen/molstat
    # for every step
    for i in range(n_particles):
        # if the particle is exiting the box in the x-direction, change the
        # velocity
        if abs(pos_x[i] + vel_x[i] * dt) > 1.0:
            vel_x[i] = -vel_x[i]

        if abs(pos_y[i] + vel_y[i] * dt) > 1.0:
            vel_y[i] = -vel_y[i]

        # make a step in time dt
        pos_x[i] = pos_x[i] + vel_x[i] * dt
        pos_y[i] = pos_y[i] + vel_y[i] * dt

    # save a 'frame' for the video every 10 step
    if n % 10 == 0:
        video.add_frame(pos_x, y_pos)


# Plot the x- and y- coordinates
pylab.clf()  # clear figure
pylab.plot(pos_x, pos_y, "ro")
pylab.axis((-1, 1, -1, 1))
pylab.savefig("coordinates_end.eps")
pylab.savefig("coordinates_end.png")


# Save video
pylab.clf()
video.save(1.0, "non_interacting_particles")