## Temperature T=2.4 # variance = 7.80 T = 2.4 doit() bins = [-800+4*i for i in range(401)] ### Now plot things: ## Uniform start filename1 = Filename(1, MCcycles, 'Uniform') filename2 = Filename(2.4, MCcycles, 'Uniform') # T = 1 data1 = lesfil(filename1) plt.figure(1) plt.subplot(211) plt.hist(data1[3][500:], bins=bins, normed=True, label='$T=1$') plt.xlim([-800, -770]) plt.ylabel('$P(E)$') plt.legend() # T = 2.4 data2 = lesfil(filename2) plt.figure(1) plt.subplot(212) plt.hist(data2[3][500:], bins=bins, normed=True, label='$T=2.4$') plt.xlim([-700, -300]) plt.legend() plt.ylabel('$P(E)$')
args = "%f %i %i %s %s" % (T, L, MCcycles, filename, initial_state) run = "%stask_d %s" % (path, args) if runAgain: os.system(run) path = "../../../build-FYS3150-project-4-OpenMPI-Release/task_d/" L = 20 MCcycles = 100000 initial_state = "Random" for T in np.linspace(2, 2.4, 100): doit() data = lesfil(Filename(2, MCcycles, initial_state)) bins = [-800 + 4 * i for i in range(401)] plt.ion() fig = plt.figure() ax = fig.add_subplot(111) hist, bins, patches = ax.hist(data[3][10000:], bins=bins, normed=True, label="$T=2.4$") plt.draw() for T in np.linspace(2, 2.4, 100): filename = Filename(T, MCcycles, initial_state) data = lesfil(filename) n, bins = np.histogram(data[3][10000:], bins, normed=True) for rect, h in zip(patches, n): rect.set_height(h)
path = "../../../build-FYS3150-project-4-OpenMPI-Release/task_e/" T_start = 2.0 T_stop = 2.4 T_step = 0.01 # 0.02 MCcycles = 1000000 initial_state = "Random" for L in [20, 40, 60, 80, 100]: if doItAgain: doit() for L in [20, 40, 60, 80, 100]: filename = Filename(L, T_start, T_stop, T_step, MCcycles, initial_state) data = lesfil(filename) plt.figure(0) plt.subplot(211) plotfil(filename, 0, 1, label="$L=%i$" % L) plt.subplot(212) plotfil(filename, 0, 2, label="$L=%i$" % L) plt.figure(2) plt.subplot(211) plotfil(filename, 0, 3, label="$L=%i$" % L) plt.subplot(212) plotfil(filename, 0, 4, label="$L=%i$" % L) plt.figure(0)
Maverage = 0 M2average = (32.0 * np.exp(8.0 / T_start) + 8.0) / Z C_V = (E2average - Eaverage ** 2) / T_start / T_start / 4.0 chi = 1.0 / T_start * (M2average - Maverage * Maverage) / 4.0 absMaverage = (8.0 * np.exp(8.0 / T_start) + 4) / Z / 4.0 chi = 1.0 / T_start * (M2average - absMaverage * absMaverage) / 4.0 for cycle in np.linspace(0, 100000, 1001): MCcylces = int(cycle) filename = "task_b_T1_%f_T2_%f_NT_%i_MC_%i_%s.txt" % (T_start, T_stop, N_T, MCcylces, Initial_state) args = "%f %f %i %i %s %s" % (T_start, T_stop, N_T, MCcylces, filename, Initial_state) run = "mpirun -n 4 %stask_b %s" % (path, args) if runAgain: os.system(run) Eaverage_numerical = lesfil(filename)[2][0] relerr.append(abs(Eaverage / 4.0 - Eaverage_numerical) / abs(Eaverage / 4.0) * 100) print "" print "\# MC Cycles & $\langle E \\rangle$ & $C_V$ & $\langle |M| \\rangle$ & $\chi$ \\\\ \hline" print "%s & %.5f & %.5f & %.5f & %.5f \\\\" % ("Analytical", Eaverage / 4.0, C_V, absMaverage, chi) for MCcycles in [100, 1000, 10000, 100000, 1000000]: filename = "task_b_T1_%f_T2_%f_NT_%i_MC_%i_%s.txt" % (T_start, T_stop, N_T, MCcycles, Initial_state) fil = lesfil(filename) C_V_numerical = float(fil[3][0]) absMaverage_numerical = float(fil[6][0]) chi_numerical = float(fil[5][0]) Eaverage_numerical = float(fil[2][0]) print "%i & %.5f & %.5f & %.5f & %.5f \\\\" % ( fil[0][0], Eaverage_numerical,
def plotfil(filename, x, y, label=None): data = lesfil(filename) plt.plot(data[x], data[y], label=label)