# Integrate 5,000,000 steps. This can be done in one go as well. for i in range(SAMP_STEPS): if (i + 1) % 100 == 0: print('\rrun %i: %.0f%%' % (run + 1, (i + 1) * 100. / SAMP_STEPS), end='', flush=True) system.integrator.run(SAMP_LENGTH) print() # Finalize the accumulators and write to disk system.auto_update_accumulators.remove(msd) msd.finalize() np.savetxt( "{}/msd_{}_{}.dat".format(outdir, vel, run), np.column_stack( (msd.lag_times(), msd.sample_sizes(), msd.result().reshape([-1, 3])))) system.auto_update_accumulators.remove(vacf) vacf.finalize() np.savetxt( "{}/vacf_{}_{}.dat".format(outdir, vel, run), np.column_stack((vacf.lag_times(), vacf.sample_sizes(), vacf.result().reshape([-1, 1])))) system.auto_update_accumulators.remove(avacf) avacf.finalize() np.savetxt( "{}/avacf_{}_{}.dat".format(outdir, vel, run), np.column_stack((avacf.lag_times(), avacf.sample_sizes(), avacf.result().reshape([-1, 1]))))
c_vel = Correlator(obs1=vel_obs, tau_lin=16, tau_max=20., delta_N=1, corr_operation="scalar_product", compress1="discard1") system.auto_update_accumulators.add(c_pos) system.auto_update_accumulators.add(c_vel) system.integrator.run(1000000) c_pos.finalize() c_vel.finalize() msd = np.column_stack( (c_pos.lag_times(), c_pos.sample_sizes(), c_pos.result().reshape([-1, 3]))) vacf = np.column_stack( (c_vel.lag_times(), c_vel.sample_sizes(), c_vel.result().reshape([-1, 1]))) np.savetxt("msd.dat", msd) np.savetxt("vacf.dat", vacf) # Integral of vacf via Green-Kubo # D= 1/3 int_0^infty <v(t_0)v(t_0+t)> dt # Integrate with trapezoidal rule I = np.trapz(vacf[:, 2], vacf[:, 0]) ratio = 1. / 3. * I / (kT / gamma) print("Ratio of measured and expected diffusion coefficients from Green-Kubo:", ratio)