# visualize initial condition #try: plotNode(axs[0], grid, conf) #plotXmesh(axs[1], grid, conf, 0, "x") saveVisz(-1, grid, conf) #except: # print() # pass Nsamples = conf.Nt fldprop = pyfld.FDTD2() pusher = pypic.BorisPusher() fintp = pypic.LinearInterpolator() currint = pypic.ZigZag() analyzer = pypic.Analyzator() flt = pytools.Filter(conf.NxMesh, conf.NyMesh) flt.init_gaussian_kernel(2.0, 2.0) #simulation loop time = 0.0 ifile = 0 for lap in range(0, conf.Nt): # Tristan loop #advance B half #move particles #advance B half #advance E #reset current (j=0) #deposit
def test_current_exchange(self): """test that current exchange is producing hand-build array""" #plt.fig = plt.figure(1, figsize=(5,7)) #plt.rc('font', family='serif', size=12) #plt.rc('xtick') #plt.rc('ytick') # #gs = plt.GridSpec(5, 1) # #axs = [] #for ai in range(5): # axs.append( plt.subplot(gs[ai]) ) conf = Conf() conf.Nx = 3 conf.Ny = 3 conf.Nz = 1 conf.NxMesh = 10 conf.NyMesh = 10 conf.NzMesh = 1 conf.ppc = 10 conf.vel = 0.1 conf.Nspecies = 2 conf.me =-1.0 #electron mass-to-charge conf.mi = 1.0 #ion mass-to-charge conf.update_bbox() grid = pycorgi.twoD.Grid(conf.Nx, conf.Ny, conf.Nz) grid.set_grid_lims(conf.xmin, conf.xmax, conf.ymin, conf.ymax) loadTiles(grid, conf) #insert_em(grid, conf, linear_field) insert_em(grid, conf, const_field) inject(grid, filler_xvel, conf) #injecting plasma particles #pusher = pypic.BorisPusher() #fintp = pypic.LinearInterpolator() currint = pypic.ZigZag() analyzer = pypic.Analyzator() for j in range(grid.get_Ny()): for i in range(grid.get_Nx()): c = grid.get_tile(i,j) yee = c.get_yee(0) for l in range(-3, conf.NxMesh+3): for m in range(-3,conf.NyMesh+3): for n in range(-3,conf.NzMesh+3): yee.jx[l,m,n] = 1.0 yee.jy[l,m,n] = 1.0 yee.jz[l,m,n] = 1.0 #deposit current #for j in range(grid.get_Ny()): # for i in range(grid.get_Nx()): #for j in [1]: # for i in [1]: # tile = grid.get_tile(i,j) # currint.solve(tile) #exchange currents for the middle one only for j in [1]: for i in [1]: tile = grid.get_tile(i,j) tile.exchange_currents(grid) #plotNode(axs[0], grid, conf) ##plot2dParticles(axs[0], grid, conf, downsample=0.1) #plot2dYee(axs[1], grid, conf, 'rho') #plot2dYee(axs[2], grid, conf, 'jx') #plot2dYee(axs[3], grid, conf, 'jy') #plot2dYee(axs[4], grid, conf, 'jz') #saveVisz(-1, grid, conf) # create reference 3 halo width array by hand ref = np.ones((conf.NxMesh, conf.NyMesh)) ref[0:3, : ] = 2 ref[-3:10,: ] = 2 ref[:, 0:3, ] = 2 ref[:, -3:10] = 2 ref[0:3, 0:3 ] = 4 ref[7:10, 7:10] = 4 ref[0:3, 7:10] = 4 ref[7:10, 0:3 ] = 4 #print(ref) for j in [1]: for i in [1]: c = grid.get_tile(i,j) yee = c.get_yee(0) for l in range(conf.NxMesh): for m in range(conf.NyMesh): self.assertEqual(ref[l,m], yee.jx[l,m,0] ) self.assertEqual(ref[l,m], yee.jy[l,m,0] ) self.assertEqual(ref[l,m], yee.jz[l,m,0] )
def test_current_deposit(self): """ test that current deposit of + and - particles with same x and v produce zero current in total. """ try: plt.fig = plt.figure(1, figsize=(5,7)) plt.rc('font', family='serif', size=12) plt.rc('xtick') plt.rc('ytick') gs = plt.GridSpec(5, 1) axs = [] for ai in range(5): axs.append( plt.subplot(gs[ai]) ) except: pass conf = Conf() conf.Nx = 3 conf.Ny = 3 conf.Nz = 1 conf.NxMesh = 10 conf.NyMesh = 10 conf.NzMesh = 1 conf.ppc = 1 conf.vel = 0.1 conf.Nspecies = 2 conf.me = -1.0 #electron mass-to-charge conf.mi = 1.0 #ion mass-to-charge conf.update_bbox() grid = pycorgi.twoD.Grid(conf.Nx, conf.Ny, conf.Nz) grid.set_grid_lims(conf.xmin, conf.xmax, conf.ymin, conf.ymax) loadTiles(grid, conf) #insert_em(grid, conf, const_field) inject(grid, filler_xvel, conf) #injecting plasma particles #pusher = pypic.BorisPusher() #fintp = pypic.LinearInterpolator() currint = pypic.ZigZag() analyzer = pypic.Analyzator() #deposit current for j in range(grid.get_Ny()): for i in range(grid.get_Nx()): tile = grid.get_tile(i,j) currint.solve(tile) #exchange currents for the middle one only #for j in [1]: # for i in [1]: for j in range(grid.get_Ny()): for i in range(grid.get_Nx()): tile = grid.get_tile(i,j) tile.exchange_currents(grid) try: #plotNode(axs[0], grid, conf) plot2dParticles(axs[0], grid, conf, downsample=0.1) plot2dYee(axs[1], grid, conf, 'rho') plot2dYee(axs[2], grid, conf, 'jx') plot2dYee(axs[3], grid, conf, 'jy') plot2dYee(axs[4], grid, conf, 'jz') #saveVisz(-2, grid, conf) except: pass for j in range(grid.get_Ny()): for i in range(grid.get_Nx()): c = grid.get_tile(i,j) yee = c.get_yee(0) for l in range(conf.NxMesh): for m in range(conf.NyMesh): self.assertAlmostEqual(yee.jx[l,m,0], 0.0, places=7 ) self.assertAlmostEqual(yee.jy[l,m,0], 0.0, places=7 ) self.assertAlmostEqual(yee.jz[l,m,0], 0.0, places=7 )
def skip_test_filters(self): """ filter integration test with rest of the PIC functions""" try: plt.fig = plt.figure(1, figsize=(5,7)) plt.rc('font', family='serif', size=12) plt.rc('xtick') plt.rc('ytick') gs = plt.GridSpec(8, 1) axs = [] for ai in range(8): axs.append( plt.subplot(gs[ai]) ) except: pass conf = Conf() conf.Nx = 3 conf.Ny = 3 conf.Nz = 1 conf.NxMesh = 3 conf.NyMesh = 3 conf.NzMesh = 1 conf.ppc = 10 conf.vel = 0.1 conf.update_bbox() grid = pycorgi.twoD.Grid(conf.Nx, conf.Ny, conf.Nz) grid.set_grid_lims(conf.xmin, conf.xmax, conf.ymin, conf.ymax) loadTiles(grid, conf) #insert_em(grid, conf, linear_field) insert_em(grid, conf, zero_field) inject(grid, filler, conf) #injecting plasma particles #inject(grid, filler_xvel, conf) #injecting plasma particles #pusher = pypic.BorisPusher() #fintp = pypic.LinearInterpolator() currint = pypic.ZigZag() analyzer = pypic.Analyzator() flt = pytools.Filter(conf.NxMesh, conf.NyMesh) flt.init_gaussian_kernel(1.0, 1.0) #for lap in range(0, conf.Nt): for lap in range(1): #analyze for j in range(grid.get_Ny()): for i in range(grid.get_Nx()): tile = grid.get_tile(i,j) analyzer.analyze2d(tile) #update boundaries for j in range(grid.get_Ny()): for i in range(grid.get_Nx()): tile = grid.get_tile(i,j) tile.update_boundaries(grid) #deposit current for j in range(grid.get_Ny()): for i in range(grid.get_Nx()): tile = grid.get_tile(i,j) currint.solve(tile) #exchange currents for j in range(grid.get_Ny()): for i in range(grid.get_Nx()): tile = grid.get_tile(i,j) tile.exchange_currents(grid) try: plotNode(axs[0], grid, conf) #plot2dParticles(axs[0], grid, conf, downsample=0.1) plot2dYee(axs[1], grid, conf, 'rho') plot2dYee(axs[2], grid, conf, 'jx') plot2dYee(axs[3], grid, conf, 'jy') plot2dYee(axs[4], grid, conf, 'jz') except: pass yee_ref = getYee2D(grid, conf) #filter for j in range(grid.get_Ny()): for i in range(grid.get_Nx()): print(" i j ({},{})".format(i,j)) tile = grid.get_tile(i,j) flt.get_padded_current(tile, grid) # fourier space filtering flt.fft_image_forward() flt.apply_kernel() flt.fft_image_backward() # direct filtering #for fj in range(1): # flt.direct_convolve_3point() flt.set_current(tile) #cycle new and temporary currents for j in range(grid.get_Ny()): for i in range(grid.get_Nx()): tile = grid.get_tile(i,j) tile.cycle_current() yee = getYee2D(grid, conf) try: plot2dYee(axs[5], grid, conf, 'jx') plot2dYee(axs[6], grid, conf, 'jy') plot2dYee(axs[7], grid, conf, 'jz') #saveVisz(lap, grid, conf) except: pass for j in range(conf.Ny*conf.NyMesh): for i in range(conf.Nx*conf.NxMesh): #print("({},{})".format(i,j)) self.assertAlmostEqual( yee_ref['jx'][i,j], yee['jx'][i,j], places=6 ) self.assertAlmostEqual( yee_ref['jy'][i,j], yee['jy'][i,j], places=6 ) self.assertAlmostEqual( yee_ref['jz'][i,j], yee['jz'][i,j], places=6 )