Example #1
0
def Task4b_iv_avg():
    print("TASK : Task4b_iv_avg")
    maxTime = 0.7
    t, N, T = SetTime(maxTime, increments)
    vac = []
    sampling = 5
    for i in range(0, sampling):
        particles = MDGenerators.PopulateCreateCrystalStructure(
            4, "Ar", 1.7, N, constants.mass, 190)
        MDFunctions.MoveToCentreOfBox(particles)
        MDSolver.solveFaster(MDSolver.velocityVerletFast2, particles, maxTime,
                             N)
        vag, diffu_coeff = MDFunctions.ComputeVelocityAutoCorrelation(
            t, particles)
        vac.append(vag)

    avgVag = vac[0]
    for i in range(0, sampling):
        avgVag += vac[i]

    avgVag[0] /= sampling
    chartName = f"Avg Vel AUtocorrelation {sampling}"
    MDPlot.plot([avgVag], t, N, chartName, ["vac"], "time (s)", "4biv_avg")
    MDFileWriter.WriteXYZFile(particles, "4b_ii", N)
    MDFileWriter.WriteLastFrame(particles, "4b_iiii_lastFrame", N)
def plotVelocityAutoCorrelation(particles,
                                t,
                                N,
                                chartName,
                                includeDiffusionCoefficientSubPlot=False,
                                filename="velocityAutoCorrelation"):

    vac, diffusion_coefficcient = MDFunctions.ComputeVelocityAutoCorrelation(
        t, particles)

    t, timeUnits = MDFunctions.ArgonTimeToSeconds(t)

    plt.subplot(1, 1, 1)
    plt.title(f"{chartName} Velocity correlation")
    plt.plot(t, vac, label=f'Velocity auto correlation')
    plt.xlabel(f"time ({timeUnits})")
    plt.ylabel('Vel. Autocorrelation')
    plt.legend()

    plt.savefig(f'{filename}_velcorr.jpg')
    plt.show()
    if includeDiffusionCoefficientSubPlot:
        plt.subplot(2, 1, 1)
        plt.title(f"{chartName} Diffusion Coefficient")
        plt.plot(t, diffusion_coefficcient, label=f'Diffusion coefficient')
        plt.xlabel('time(s)')
        plt.ylabel('Diffusion coefficient')

    plt.legend()

    plt.savefig(f'{filename}_diffcoeff.jpg')
    plt.show()