Sf=Sf) #%% Lax-Friedrich scheme not working... t, Xl, Yl, Hl, Q1l, Q2l = dressler.solvePDE('lf') #%% t, Xr, Yr, Hr, Q1r, Q2r = dressler.solvePDE('rs') #%% n = 5 plot3D(Xl, Yl, Hl[n]) #%% #plot2D(x, t, H[1]) n = -1 plot2D(Xr, Yr, Hr[n]) #%% n = -1 plot3D(Xr, Yr, Hr[n]) #%% quiver(Xr, Yr, Q1r[n], Q2r[n]) #%%Save data DIR = 'data/3/3/' # Directory name pathlib.Path(DIR).mkdir(parents=True, exist_ok=True) # Create Folder #%% Save experiment n = {0, 125, 250, 375, -1} M, N = Hr[0].shape
ymin = 0 ymax = 1 dx = (xmax-xmin)/(nx-1) dy = (ymax-ymin)/(ny-1) p = numpy.zeros((ny,nx)) pd = numpy.zeros((ny,nx)) b = numpy.zeros((ny,nx)) x = numpy.linspace(xmin,xmax,nx) y = numpy.linspace(ymin,ymax,ny) b[int(ny/4),int(nx/4)] = 100 b[int(3*ny/4),int(3*nx/4)] = -100 plot2D(x, y, b) def poisson(l1norm_target): l1norm = 1 it = 0 while l1norm>l1norm_target: pd = p.copy() p[1:-1,1:-1] = ((pd[1:-1,2:]+pd[1:-1,0:-2])*(dy**2) + (pd[2:,1:-1]+pd[0:-2,1:-1])*(dx**2) - b[1:-1,1:-1]*(dx**2)*(dy**2))/(2*((dx**2)+(dy**2))) p[0,:] = 0 p[-1,:] = 0 p[:,0] = 0 p[:,-1] = 0 if numpy.sum(numpy.abs(pd[:])) != 0: l1norm = numpy.sum(numpy.abs(p[:])-numpy.abs(pd[:]))/numpy.sum(numpy.abs(pd[:])) it = it + 1
t_i, t_f = 0, 40 Nx = 201 Nt = 201 x = np.linspace(x_i, x_f, Nx) t = np.linspace(t_i, t_f, Nt) X, T = np.meshgrid(x, t) #%% Ritter HR = h(X, T) UR = u(X, T) #%% Initial condition plot1D(x, HR[-1]) #%% Evolution plot2D(x, t, HR) #%% 3D plot3D(X, T, HR) #%% Initial condition plot1D(x, UR[0]) #%% Evolution plot2D(x, t, UR) #%% 3D plot3D(X, T, UR) #%% Numerical Ritter h_0 = 40
def OnPlot2D(self, event): if (not self.IsXmlRead): wx.MessageBox("No xml file loaded!", "Warning!", wx.OK | wx.ICON_EXCLAMATION, self) return try: # Create the Plot1D Dialog and get the x0,e1,nx values dlg = Plot2DDialog() result = dlg.ShowModal() dlg.Destroy() if result == wx.ID_OK: selection = int(dlg.radiobox.GetSelection()) x0 = np.array([float(dlg.x0_0.GetValue()), float(dlg.x0_1.GetValue()), float(dlg.x0_2.GetValue())]) e1 = np.array([float(dlg.e1_0.GetValue()), float(dlg.e1_1.GetValue()),float(dlg.e1_2.GetValue())]) nx = int(dlg.nx.GetValue()) e2 = np.array([float(dlg.e2_0.GetValue()), float(dlg.e2_1.GetValue()),float(dlg.e2_2.GetValue())]) ny = int(dlg.ny.GetValue()) dlg.Destroy() # Compute the G vectors if needed self.SetStatusText("Generating the g vectors...") try: self.G except: self.G, discard = compute_Gs(self.b,self.charge.shape,self.ecutrho,self.alat) if (selection==0): try: toplot = self.charge except: wx.MessageBox("No charge file loaded!", "Warning!", wx.OK | wx.ICON_EXCLAMATION, self) return elif (selection==1): try: toplot = self.v_bare except: wx.MessageBox("No Vbare calculated!", "Warning!", wx.OK | wx.ICON_EXCLAMATION, self) return elif (selection==2): try: toplot = self.v_bare + self.v_h except: wx.MessageBox("No Vbare+VH calculated!", "Warning!", wx.OK | wx.ICON_EXCLAMATION, self) return elif (selection==3): try: toplot = self.v_bare + self.v_h + self.v_xc except: wx.MessageBox("No Vbare+VH calculated!", "Warning!", wx.OK | wx.ICON_EXCLAMATION, self) return self.SetStatusText("Plotting...") self.plot2D = plot2D(toplot,self.G,self.a,x0,e1,e2,nx,ny,selection) self.plot2D.show() self.SetStatusText("Plotting... done!") except: wx.MessageBox("Something wrong while plotting the charge...", "", wx.OK | wx.ICON_EXCLAMATION, self) self.SetStatusText("")
if (pars.iplot==1): # Read the charge and write it in filpl x0 = [pars.x0_1,pars.x0_2,pars.x0_3] e1 = [pars.e1_1,pars.e1_2,pars.e1_3] nx = pars.nx G = compute_G(b,charge.shape,ecutrho,alat) fig = plot1D(charge,G,a,x0,e1,nx) fig.show() elif (pars.iplot==2): x0 = [pars.x0_1,pars.x0_2,pars.x0_3] e1 = [pars.e1_1,pars.e1_2,pars.e1_3] nx = pars.nx e2 = [pars.e2_1,pars.e2_2,pars.e2_3] ny = pars.ny G = compute_G(b,charge.shape,ecutrho,alat) fig = plot2D(charge,G,a,x0,e1,e2,nx,ny) fig.show() else: print ("Not implemented yet.") end_time = time.time() elapsed_time = end_time - start_time print ("Finished. Elapsed time: "+str(elapsed_time)+" s.") input("Enter to exit")
#%% Plot exp 3 plot1D(t3, H3[:, Ny // 2, Nx // 2]) #%% Exp 4 exp.H = 2 t4, X4, Y4, H4, U4, V4 = exp.solvePDE() #%% Plot exp 1 plot1D(t4, H4[:, Ny // 2, Nx // 2]) #%% # for k in range(len(t1)): # if k % 100 == 0: k = -1 plot2D(X1, Y1, H1[k]) #%% plot3D(X1, Y1, H1[40]) #%% N = 500 x = np.linspace(0, xf, N) t = np.linspace(0, tf, N) l = .475 T = .115 #1.055 k = 2 * np.pi / l w = 2 * np.pi / T eta = 1 + airy(0.5, t, .2, k, w) T2 = .05