Esempio n. 1
0
def plot2dParticles(ax, n, conf, downsample=0):

    #ax.clear()
    #ax.cla()
    plotNode(ax, n, conf)
    #plotTileBoundaries(ax, n, conf)

    prtcl = get_particles(n, conf, 0)
    Np = len(prtcl.xs)
    #print("particles to plot: {}".format(Np))

    if downsample > 0:
        rindxs = random.sample(range(0, Np - 1), int(downsample * Np))

        prtcl.xs = np.array(prtcl.xs)
        prtcl.ys = np.array(prtcl.ys)
        prtcl.zs = np.array(prtcl.zs)

        prtcl.xs = prtcl.xs[rindxs]
        prtcl.ys = prtcl.ys[rindxs]
        prtcl.zs = prtcl.zs[rindxs]

    ax.plot(prtcl.xs, prtcl.ys, ".", color='red')
Esempio n. 2
0
    def test_boundary_construction(self):

        conf = Conf()

        # set up plotting and figure
        try:
            plt.fig = plt.figure(1, figsize=(3, 3))
            plt.rc('font', family='serif', size=12)
            plt.rc('xtick')
            plt.rc('ytick')

            gs = plt.GridSpec(1, 1)
            gs.update(hspace=0.5)

            axs = []
            for ai in range(1):
                axs.append(plt.subplot(gs[ai]))

            if not os.path.exists(conf.outdir):
                os.makedirs(conf.outdir)
        except:
            pass

        grid = pycorgi.twoD.Grid(conf.Nx, conf.Ny)
        grid.set_grid_lims(conf.xmin, conf.xmax, conf.ymin, conf.ymax)

        # one tile surrounded by other rank
        refGrid = np.ones((conf.Nx, conf.Ny), np.int)
        refGrid[1, 1] = 0

        #setup grid configuration
        if grid.master():
            for j in range(grid.get_Ny()):
                for i in range(grid.get_Nx()):
                    val = refGrid[i, j]
                    grid.set_mpi_grid(i, j, val)
        grid.bcast_mpi_grid()

        # add tiles
        rank = grid.rank()
        for i in range(grid.get_Nx()):
            for j in range(grid.get_Ny()):
                if rank == refGrid[i, j]:
                    c = pycorgi.twoD.Tile()
                    grid.add_tile(c, (i, j))

        try:
            plotNode(axs[0], grid, conf)
            saveVisz(0, grid, conf)
        except:
            pass

        if grid.size() > 1:
            grid.analyze_boundaries()
            #print(grid.rank(), ":sq ", grid.send_queue)
            #print(grid.rank(), ":sqa", grid.send_queue_address)

        if grid.size() > 1:
            grid.send_tiles()
            grid.recv_tiles()

        try:
            plotNode(axs[0], grid, conf)
            saveVisz(1, grid, conf)
        except:
            pass

        cur = readGrid(grid, conf)
        #print(cur)

        if grid.size() > 1:
            for i in range(grid.get_Nx()):
                for j in range(grid.get_Ny()):
                    self.assertEqual(refGrid[i, j], cur[i, j])
Esempio n. 3
0
    #initialize node
    conf = Conf()

    node = plasma.Grid(conf.Nx, conf.Ny)
    node.setGridLims(conf.xmin, conf.xmax, conf.ymin, conf.ymax)

    #node.initMpi()
    #loadMpiXStrides(node)
    loadCells(node, conf)

    #insert initial current into the grid
    injectRingCurrent(node, conf)
    updateBoundaries(node)

    #plot initial condition
    plotNode(axs[0], node, conf)
    plotEfield(axs[1], node, conf)
    saveVisz(0, node, conf)

    #main loop
    for lap in range(1, 51):
        print("---lap: {}".format(lap))

        #B field
        updateBoundaries(node)
        for cid in node.getCellIds():
            c = node.getCellPtr(cid)
            c.pushHalfB()
            c.pushHalfB()

        #E field
Esempio n. 4
0
    #insert_em(grid, conf, linear_field)

    #static setup; communicate neighbor info once
    grid.analyze_boundaries()
    grid.send_tiles()
    grid.recv_tiles()
    initialize_virtuals(grid, conf)

    timer.stop("init")
    timer.stats("init")
    # end of initialization
    ##################################################

    # 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)
Esempio n. 5
0
    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 )