def calculateNewVels(coords, vels, forces, M, L, delta_t): """ Calculates the velocities of the current time step. Parameters ---------- coords : numpy array Array of the particle coordinates from the current time step. vels : numpy array Array of the particle velocities from the previous time step. forces : numpy array Array of the particle forces from the current time step. M : int Number of particles. L : float Box side length. delta_t : float Time step. Returns ------- newVels : numpy array Array of the particle velocities from the current time step. newForces : numpy array Array of the particle velocities from the next time step. """ newForces = Task2.calculateInitialForces(M, L, coords) newVels = numpy.full_like(vels, 0.0) # numpy array allows updates newVels[:][:] = vels[:][:] + \ 0.5 * (forces[:][:] + newForces[:][:]) * delta_t return newVels, newForces
N : int Number of iterations. Returns ------- None. """ filestring = Task2.createFilestring(M, L, coords, vels, "Time step 0") for k in range(1, N): coords = calculateNewCoords(coords, vels, forces, M, L, delta_t) vels, forces = calculateNewVels(coords, vels, forces, M, L, delta_t) filestring += Task2.createFilestring(M, L, coords, vels, f"Time step {k}") print(f"finished timestep {k}") Task2.writeFile(filestring, "trajectories.txt") if __name__ == "__main__": from time import perf_counter start = perf_counter() path, delta_t, N = readInputArguments(sys.argv) M, C, L, coords, vels = readFile(path) forces = Task2.calculateInitialForces(M, L, coords) VerletAlgorithm(coords, vels, forces, M, delta_t, N) end = perf_counter() print("execution time: ", end - start)
def calculateNewVels(coords, vels, forces, M, L, delta_t): newForces = Task2.calculateInitialForces(M, L, coords) newVels = numpy.full_like(vels, 0.0) # numpy array allows updates newVels[:][:] = vels[:][:] + \ 0.5 * (forces[:][:] + newForces[:][:]) * delta_t return newVels, newForces