示例#1
0
def VerletAlgorithm(coords, vels, forces, M, delta_t, N):
    """
    Algorithm to integrate Newtons equations of motion. Writes the results 
    of the calulcations in the requested format into an output file.

    Parameters
    ----------
    coords : numpy array
        Array of the particle coordinates from the previous 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 previous time step.
    M : int
        Number of particles.
    delta_t : float
        Time step.
    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")
示例#2
0
def VerletAlgorithm(coords, vels, forces, M, delta_t, N):
    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")