def find_eq(n_lattice, N, T, h, n_max, typ, graphs): """Runs two lattices side by side to check for the number of steps required to reach equillibrium""" lattices = [] lines = [] leg = [] spin_fig = plt.figure() for i in range(n_lattice): lattice = main.lattice(N, T, field=h, exch_energy=main.J_e, mag_moment=main.mu_e) lattices.append(lattice) lines.append(lattice.progress_n(n_max, graphs=graphs)) plt.title("Lattice" + str(i)) plt.rcParams.update({'font.size': 16}) plt.figure(spin_fig.number) add_to_plot(lines[i], energy=False) leg.append("Lattice" + str(i)) plt.title("Evolution of Spin for N = " + str(N) + ", T = " + str(T) + ", h = " + str(h)) plt.rcParams.update({'font.size': 22}) plt.legend(leg) return lattices
def run(result_file, temp_list, h, Num, n_eq_N, n_eq_T, n_prog, graphs) : if temp_list[0] > 2.27 : typ = 'r' else : typ = 'a+' lattice = main.lattice(Num, temp_list[0], field = h, exch_energy = J, mag_moment = main.mu_e, typ=typ) print("\nProgressing for initial eq") lattice.progress_n(n_eq_N) temp_track = 0 Xs, Cs, result_lines = [], [], [] for temp in temp_list : these_ens, these_mags = [], [] temp_track += 1 print("\nTemp =", temp, "-", temp_track, "/", len(temp_list)) #Init lattice lattice.new_run(temp, h, exch_energy = J) if temp != temp_list[0] : print("Progressing for T_eq") lattice.progress_n(n_eq_T) print("Progressing for heat capacity data") lines = lattice.progress_n(n_prog, graphs=graphs) for l in lines : splt = l.split(",") l_en, l_mag = float(splt[1].strip()), float(splt[2].strip()) these_ens.append(l_en/Num ** 2) these_mags.append(l_mag) var_e = get_var(these_ens) var_m = get_var(these_mags) C = var_e/(main.k_b*temp**2) X = main.mu * var_m/(main.k_b*temp) Cs.append(C) Xs.append(X) result_lines.append(str(Num) +"," + str(n_prog)+"," + str(temp) +"," + str(C) + "," +str(X) + "\n") append_result_to_file(result_file, [str(Num) +"," + str(n_prog)+"," + str(temp) +"," + str(C) + "," +str(X) + "\n"]) print("Appended this run to", result_file) return result_lines
temp_list = [x for x in np.linspace(T_i, T_f, num=10)] #steps - whole lattice progressions n = 100 #graphing #number of graphs to display graphs = 6 #Plot of all the energies i = 0 all_plot = plt.figure() leg = [] #initial lattice lat = main.lattice(N, temp_list[0], field=h, typ=typ) #iterate through temps, Temp in J_e/k_b (set = 1) for temp in temp_list: #Preserve spin state, regen random numbers and reset temp lat.new_run(temp) print() i += 1 print("Running for temp =", ("%.2f" % temp), ":", i, "/", len(temp_list)) print() #Progress the lattice n times lines = lat.progress_n(n, graphs=graphs)
rev = copy.copy(hs) rev.reverse() temp = 2 #steps - whole lattice progressions - use data after j (e.g. j steps to eq) n = 200 n_T_eq = 400 #graphing #number of graphs to display graphs = 0 #initial lattice lat = main.lattice(N, temp, field=hs[0], typ=typ) #Progress from 0 to max #iterate through temps, Temp in J_e/k_b (set = 1) init_count = 0 for h in hs_init: init_count += 1 print("h =", h, "-", init_count, "/", len(hs_init)) these_ens, these_mags = [], [] #Preserve spin state, regen random numbers and reset temp lat.new_run(temp, h) lat.progress_n(n_T_eq) """
n_eq_N = 600 n_eq_T = 200 n_prog = 200 #number of graphs to display graphs = 0 N = 30 ################# #simulate n times until smallest + stdev < 2nd smallest - stdev #Initialise lattice = main.lattice(N, T_range[0], field = h, exch_energy = main.J_e, mag_moment = main.mu_e, typ=typ) acc_range = 0.1 first = True #While the T range is too large, chop the range while abs(T_range[0] - T_range[1] ) > acc_range : print("T_dict so far") print(T_dict) #Simulate for each temperature twice and get a list - initial run only if first : print("\n***INITIALISING ***\n") print("Simulating for all temps twice- initial range")
#Get the new lattice to equillibrium - check and manually accept not_accepted = True while not_accepted: print("Initialising lattice from random") if temp_list[0] > 2: typ = 'r' else: typ = 'a+' lattice = main.lattice(N, temp_list[0], field=h, exch_energy=main.J_e, mag_moment=main.mu_e, typ=typ) check_N = plt.figure() lattice.progress_n(n_eq_N, 4) plt.show(check_N.number) inp = input("Do you want to keep this lattice? (y/n)\n") if inp.lower() == "y": not_accepted = False for temp in temp_list: