def plotOrderParameterSqaure(folderName, n_simulations): plt.figure() start = int(20000 / 200) n = np.linspace(100, 100 * n_simulations, n_simulations) Pi_rt = np.zeros(n_simulations) D_r_values = ['0_0', '0_2', '0_5', '0_8', '1_0'] for D_r_s in D_r_values: for i in range(n_simulations): fileName = '{}Dr{}DensitySweep{}.txt'.format(folderName, D_r_s, str(i)) print(fileName) time, x, y, theta, vx, vy, n_particles, n_steps, D_r, deformation = fileReader.loadFileNew(fileName) v = np.mean(np.sqrt(vx**2 + vy**2), axis=1) Pi_x = vx/v[:, None] Pi_y = vy/v[:, None] #Pi_x = np.mean(vx, axis=1)/v #Pi_y = np.mean(vy, axis=1)/v e_r_x = np.mean(Pi_x, axis=1) e_r_y = np.mean(Pi_y, axis=1) Pi_r = np.mean(Pi_x*e_r_x[:, None] + Pi_y*e_r_y[:, None], axis=1) Pi_rt[i] = np.mean(Pi_r[start:n_steps]) plt.plot(n, Pi_rt, label=r"$D_r$ = {}".format(D_r_s)) plt.legend() plt.xlabel(r'Number of particles $N$') plt.ylabel(r'$\Pi_r$')
def plotDensityFlow(fileName, label): time, x, y, theta, vx, vy, n_particles, n_steps, D_r, deformation = fileReader.loadFileNew( fileName) f_time_interval = 4 x_crossed = np.zeros(n_steps - f_time_interval) for i in range(0, n_steps - f_time_interval): x_temp = ((x[i] > 0) & (x[i + f_time_interval] < 0)) + ( (x[i] < 0) & (x[i + f_time_interval] > 0)) x_crossed[i] = np.sum(x_temp) plt.plot(time[0:n_steps - f_time_interval], x_crossed, label=label)
def plotRelativeErrorEM(fileNameBase, isAB): counter = 0 sigma_pp = 1.5 r_cutoff = np.sqrt(2)*sigma_pp #2*sigma_pp*sigma_pp solverType = "EM" if isAB: solverType = "AB" fileName = fileNameBase + solverType + str(counter) + ".txt" time, x, y, theta, vx, vy, n_particles, n_steps, D_r, deformation = fileReader.loadFileNew(fileName) for i in range(0, 3): counter+=1 fileName = fileNameBase + solverType + str(counter) + ".txt" time_next, x_next, y_next, theta_next, vx_next, vy_next, n_particles_next, n_steps_next, D_r_next, deformation_next = fileReader.loadFileNew(fileName) delta_r_vec = np.sqrt((x_next-x)**2 + (y_next-y)**2) t = np.linspace(0, 1, num=1001) delta_r = np.mean(delta_r_vec/r_cutoff, axis=1) label = r'%s $\Delta t*=10^{%d}$, $\Delta t=10^{%d}$' % (solverType, -counter-3, -counter-2) plt.figure(0) plt.semilogy(t, delta_r, label=label) ''' if (i!=0): step = 40/400 der_delta_r = (delta_r[1:401]-delta_r[0:400])/step plt.figure(1) plt.semilogy(time[1:401], der_delta_r, label=label) ''' x = x_next y = y_next plt.figure(0) plt.legend() plt.xlabel(r'$t$') plt.ylabel(r'$\langle |r*-r|\rangle/r_c$ ') #picName = fileNameBase + solverType + ".png" #plt.savefig(picName, dpi=150) '''
def plotTimeAvgV(folderName, n_simulations): plt.figure() n = np.linspace(100, 100 * n_simulations, n_simulations) v_avg = np.zeros(n_simulations) D_r_values = ['0_0', '0_2', '0_5', '0_8', '1_0'] for D_r_s in D_r_values: for i in range(0, n_simulations): #fileName = folderName + 'Dr' + D_r + 'DensitySweep' + str(i) + '.txt' fileName = '{}Dr{}DensitySweep{}.txt'.format(folderName, D_r_s, str(i)) print(fileName) time, x, y, theta, vx, vy, n_particles, n_steps, D_r, deformation = fileReader.loadFileNew(fileName) start = int(20000/200) v = np.sqrt(vx ** 2 + vy ** 2) v = np.mean(v, axis=1) v_avg[i] = np.mean(v[start:n_steps]) plt.plot(n, v_avg, label=r"$D_r$ = {}".format(D_r_s)) plt.xlabel(r'Number of particles $N$') plt.ylabel(r'$\langle v \rangle_{t, r}/v_0$') plt.legend()
def plotVelocityVsFunnelHigth(fileNameBase): L = 25 H = 25 numPoints = 8 v_avg_vec = np.zeros(numPoints) h_vec = np.zeros(numPoints) for i in range(0, numPoints): fileName = fileNameBase + str(i) + ".txt" time, x, y, theta, vx, vy, n_particles, n_steps, D_r, deformation = fileReader.loadFileNew( fileName) start = int(20000 / 200) vx = vx[start:n_steps, :] vy = vy[start:n_steps, :] #v_avg_vec[i]=np.mean(np.sqrt(vx**2+vy**2)) v_avg_vec[i] = np.mean(np.abs(vx)) f_h = (20 - 2 * i) / 20 #h_vec[i] = np.sqrt(L*H * 2 / (1 + f_h) * H / L) h_vec[i] = f_h plt.plot(h_vec, v_avg_vec) plt.xlabel(r"$H_{f}/H$") plt.ylabel(r"$\langle |v_{x}| \rangle_{r,t}$") plt.show()
import h5py import numpy as np import fileReader from datetime import datetime start1 = datetime.now() f = h5py.File( "/home/edvardst/Documents/NTNU/Programming/Master_Thesis/Master_Thesis_c/results/periodic_2D/phaseDiagram/testHDF50.h5", "r") #dset = f.get("dset").valuE dset = np.array(f["dset"]) #print(dset) #print(dset.shape) #print(dset.dtype) readTimeH5 = datetime.now() - start1 start2 = datetime.now() fileName = "/home/edvardst/Documents/NTNU/Programming/Master_Thesis/Master_Thesis_c/results/periodic_2D/phaseDiagram/testHDF50.txt" time, x, y, theta, vx, vy, n_particles, n_steps, D_r, deformation = fileReader.loadFileNew( fileName) readTimeTXT = datetime.now() - start2 print("Readtime of HDF5: \t {}".format(readTimeH5)) print("Readtime of txt: \t {}".format(readTimeTXT)) print("Speedup, HDF5/txt: \t {}".format(readTimeTXT / readTimeH5))
def calcFPSF(fileName): time, x, y, theta, vx, vy, n_particles, n_steps, D_r, deformation = fileReader.loadFileNew(fileName) start = int(20000 / 200) time = time[start:n_steps]-time[start] x = x[start:n_steps, :] y = y[start:n_steps, :] #dx = x - x[0, :] #dy = y - y[0, :] #dr = np.sqrt(dx**2 + dy**2) #Q_t = np.mean(np.where(dr<delta, 1, 0), axis=1) #plt.plot(time, Q_t) #plt.show() max_steps_tau = 100 n_steps = n_steps - start - max_steps_tau '''dr = np.zeros([max_steps_tau, n_particles]) for k in range(1, max_steps_tau+1): dx = x[k:n_steps, :] - x[0:n_steps-k, :] dy = y[k:n_steps, :] - y[0:n_steps - k, :] dr[k-1] = np.mean(np.sqrt(dx**2+dy**2), axis=0)''' dr = np.zeros([max_steps_tau, n_particles]) Q_t = np.zeros([max_steps_tau, n_steps]) deltas = [0.5, 1, 2, 3, 4, 5, 6, 8, 10] #deltas = [0.5, 1, 2] #factor = 0.02 #deltas = np.arange(1*factor, 15*factor, 2*factor) for delta in deltas: for k in range(1, max_steps_tau+1): dx = x[k:n_steps+k, :] - x[0:n_steps, :] dy = y[k:n_steps+k, :] - y[0:n_steps, :] dr = np.sqrt(dx**2+dy**2) Q_t[k-1, :] = np.mean(np.where(dr<delta,1,0), axis=1) #Q_t[k-1, :] = np.real(np.mean(np.exp(-1j*delta*dr),axis=1)) #Q_t[k-1, :] = np.mean(np.real(np.exp(-1j * delta * dr)), axis=1) Q_t_time_avg = np.mean(Q_t, axis=1) Q_t_squared_time_avg = np.mean(Q_t**2, axis=1) tau = np.linspace(1, max_steps_tau + 1, max_steps_tau) #Should be a distribution with stepsize dt equalt to the time difference between two x values in file. #Should perhaps be logarithmic? c_guess = -np.log(Q_t_time_avg[0]) beta_guess = 1 tau_guess = tau[49]/(-np.log(Q_t_time_avg[49])-c_guess) #popt, pcov = curve_fit(strechedExponential, tau, Q_t_time_avg, p0=(tau_guess,beta_guess,c_guess)) #print(popt) #tau_k, beta_k, c = popt chi_4 = n_particles*(Q_t_squared_time_avg-Q_t_time_avg**2) plt.figure(0) #plt.plot(tau, Q_t_time_avg, label=r"$\delta =$ {}".format(delta)) plt.semilogx(tau, Q_t_time_avg, label=r"$\delta =$ {}".format(delta)) plt.figure(1) plt.semilogx(tau, chi_4, label=r"$\delta =$ {}".format(delta)) plt.figure(2) plt.loglog(tau, chi_4, label=r"$\delta =$ {}".format(delta)) #plt.figure(3) #plt.semilogx(tau, strechedExponential(tau, tau_guess, beta_guess, c_guess)) plt.figure(0) plt.xlabel(r"Time $\tau$") plt.ylabel(r"$Q_t$") plt.legend() plt.figure(1) plt.xlabel(r"Time $\tau$") plt.ylabel(r"$\chi_4$") plt.legend() plt.figure(2) plt.xlabel(r"Time $\tau$") plt.ylabel(r"$\chi_4$") plt.legend() plt.show() '''