Ejemplo n.º 1
0
def step_vv(x, v, f, dt, xup):
    global rcut, skin

    # update positions
    x += v*dt + 0.5*f * dt*dt

    # compute maximal position update
    # vectorial
    dx = x - xup
    # square
    dx *= dx
    # sum up 
    dx = dx.sum(axis=0)
    # test whether the neighbor list needs to be rebuilt
    if max(dx) > (0.5*skin)**2:
        lj.rebuild_neighbor_lists(x, rcut+skin)
        xup = x.copy()
    
    # half update of the velocity
    v += 0.5*f * dt
        
    # compute new forces
    f = compute_forces(x)

    # second half update of the velocity
    v += 0.5*f * dt

    return x, v, f, xup
Ejemplo n.º 2
0
    vtffile = open(vtffilename, 'a')

    # write the structure of the system into the file: 
    # N particles ("atoms") with a radius of 0.5
    vtffile.write('atom 0:{} radius 0.5\n'.format(N-1))
    vtffile.write('pbc {} {} {}\n'.format(L, L, L))
    
    # write out that a new timestep starts
    vtffile.write('timestep\n')
    # write out the coordinates of the particles
    for i in range(N):
        vtffile.write("{} {} {}\n".format(x[0,i], x[1,i], x[2,i]))

# main loop
lj.set_globals(L, N, rcut, shift)
lj.rebuild_neighbor_lists(x, rcut+skin)
xup = x.copy()
f = compute_forces(x)
tmax = t+trun
if warmup_on:
    print("Warmup simulation...")
    warmup_finished = False
else:
    print("Simulating until tmax={}...".format(tmax))

while (not warmup_on and t < tmax) or (warmup_on and not warmup_finished):
    x, v, f, xup = step_vv(x, v, f, dt, xup)
    t += dt
    step += 1
    if warmup_on: 
        Tm = compute_temperature(v)