Ejemplo n.º 1
0
positions = np.array(positions)
velocites = np.array(velocites)
pot_energies = np.array(pot_energies)
kin_energies = np.array(kin_energies)
tot_energies = np.array(tot_energies)

positions_analytical = amplitude * np.cos(angular_freq * times + phi)
velocites_analytical = -angular_freq * amplitude * np.sin(angular_freq *
                                                          times + phi)

writeDataToFile(fn_out, [
    times, positions, velocites, pot_energies, kin_energies, tot_energies,
    positions_analytical, velocites_analytical
], ['time', 'pos', 'vel', 'pot_ene', 'kin_ene', 'tot_ene', 'pos_an', 'vel_an'],
                constantsNames=[
                    'time_step', 'period', 'amplitude', 'k', 'm', 'phi',
                    'conserved_energy'
                ],
                constantsValues=[
                    time_step, period, amplitude, k, m, phi, conserved_energy
                ],
                dataFormat='%15.8f')

if showPlots:
    plt.figure(1)
    plt.plot(times, tot_energies)
    plt.plot(times, pot_energies)
    plt.plot(times, kin_energies)
    plt.show()

    plt.figure(2)
    plt.plot(times, pot_energies)
Ejemplo n.º 2
0
    if (i + 1) % stride_rescale_vel == 0: rescaleVeloctites(v, T, dof)
    if (i + 1) % stride_traj == 0:
        writePostionsToFileXYZ(fn_traj, p, ['Ar'], header.format(times[i + 1]),
                               cell, True)
    kinetic_energy[i + 1] = getKineticEnergy(v)
    potential_energy[i + 1] = pot_new
    F = Fnew

writePostionsToFileXYZ('postions_final.xyz', p, ['Ar'], '', cell, False)
writePostionsToFileXYZ('velocites_final.xyz', v, ['Ar'], '', None, False)

total_energy = potential_energy + kinetic_energy
temperature = 2.0 * kinetic_energy / (dof * kB)

writeDataToFile(
    fn_data,
    [times, potential_energy, kinetic_energy, total_energy, temperature],
    ['time', 'pot', 'kin', 'total', 'T'],
    dataFormat='%15.8f')

plt.figure(3)
plt.plot(times, potential_energy)
plt.figure(4)
plt.plot(times, kinetic_energy)
plt.figure(5)
plt.ylim(np.min(total_energy) * 1.1, 0.0)
plt.plot(times, total_energy)
plt.figure(6)
plt.plot(times, temperature)
plt.show()