示例#1
0
def initialize_tile(c, i, j, n, conf):

    # load particle containers
    bucket = pyrad.PhotonContainer()

    #reserve memory for particles
    Nprtcls = conf.ppt
    bucket.reserve(Nprtcls)
    c.push_back(bucket)
示例#2
0
def initialize_tile(tile, indx, n, conf):

    # set parameters
    tile.cfl = conf.cfl

    #--------------------------------------------------
    # particle container

    #ppc = conf.ppc  # / conf.Nspecies

    # load particle containers
    #for sps in range(conf.Nspecies):

    #    if conf.threeD:
    #        container = pypic.threeD.ParticleContainer()
    #    elif conf.twoD:
    #        container = pypic.twoD.ParticleContainer()

    #    # alternate injection between - and + charged prtcls
    #    if sps % 2 == 0:
    #        container.q = -conf.qe
    #    else:
    #        container.q = -conf.qi

    #    # reserve memory for particles
    #    Nprtcls = conf.NxMesh * conf.NyMesh * conf.NzMesh * conf.ppc
    #    container.reserve(Nprtcls)

    #    tile.set_container(container)

    #--------------------------------------------------
    # photon buckets

    # load particle containers
    bucket = pyrad.PhotonContainer()

    #reserve memory for particles
    Nprtcls = conf.ppt
    bucket.reserve(Nprtcls)
    tile.push_back(bucket)

    #--------------------------------------------------

    # set bounding box of the tile
    #mins = ind2loc(indx, (0, 0, 0), conf)
    #maxs = ind2loc(indx, (conf.NxMesh, conf.NyMesh, conf.NzMesh), conf)

    #if conf.threeD:
    #    tile.set_tile_mins(mins[0:3])
    #    tile.set_tile_maxs(maxs[0:3])
    #elif conf.twoD:
    #    tile.set_tile_mins(mins[0:2])
    #    tile.set_tile_maxs(maxs[0:2])

    return
示例#3
0
def initialize_tile(c, indx, n, conf):

    # try 3d unpacking; if not, fallback to 2D
    try:
        i, j, k = indx
    except:
        try:
            i, j = indx
        except:
            i = indx

    # load particle containers
    bucket = pyrad.PhotonContainer()

    #reserve memory for particles
    Nprtcls = conf.ppt
    bucket.reserve(Nprtcls)
    c.push_back(bucket)
示例#4
0
文件: test_rad.py 项目: xihe/runko
    def test_initialization(self):

        #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)
        #
        #axs = []
        #for ai in range(1):
        #    axs.append( plt.subplot(gs[ai]) )

        conf = Conf()
        conf.NxMesh = 3
        conf.NyMesh = 3
        conf.Nx = 3
        conf.Ny = 3
        conf.Ny = 1
        conf.ppc = 1
        conf.update_bbox()

        kT = 1.0  #black body photon field temperature

        Nprtcls = conf.NxMesh * conf.NyMesh * conf.NzMesh * conf.ppc

        container = pyrad.PhotonContainer()
        container.reserve(Nprtcls)

        weight = 1.0

        ene_ref = np.zeros(Nprtcls)
        wgt_ref = np.zeros(Nprtcls)
        x0_ref = np.zeros((Nprtcls, 3))
        u0_ref = np.zeros((Nprtcls, 3))

        for ip in range(Nprtcls):
            ene = bbodySample(kT)

            x0 = rand3Dloc(conf)
            u0 = rand3Dvel(1.0)

            container.add_particle(x0, u0, weight, ene)

            # add also to reference array
            ene_ref[ip] = ene
            wgt_ref[ip] = weight
            x0_ref[ip, :] = x0
            u0_ref[ip, :] = u0

        ene = container.ene()
        wgt = container.wgt()

        loc0 = container.loc(0)
        loc1 = container.loc(1)
        loc2 = container.loc(2)

        vel0 = container.vel(0)
        vel1 = container.vel(1)
        vel2 = container.vel(2)

        for ip in range(Nprtcls):
            self.assertAlmostEqual(container.ene()[ip], ene_ref[ip], places=5)
            self.assertAlmostEqual(container.wgt()[ip], wgt_ref[ip], places=5)

            self.assertAlmostEqual(container.loc(0)[ip],
                                   x0_ref[ip, 0],
                                   places=5)
            self.assertAlmostEqual(container.loc(1)[ip],
                                   x0_ref[ip, 1],
                                   places=5)
            self.assertAlmostEqual(container.loc(2)[ip],
                                   x0_ref[ip, 2],
                                   places=5)

            self.assertAlmostEqual(container.vel(0)[ip],
                                   u0_ref[ip, 0],
                                   places=5)
            self.assertAlmostEqual(container.vel(1)[ip],
                                   u0_ref[ip, 1],
                                   places=5)
            self.assertAlmostEqual(container.vel(2)[ip],
                                   u0_ref[ip, 2],
                                   places=5)
示例#5
0
文件: test_rad.py 项目: xihe/runko
    def test_blackbody(self):

        if do_plots:
            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)

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

        conf = Conf()
        conf.NxMesh = 3
        conf.NyMesh = 3
        conf.ppc = 1
        conf.update_bbox()

        kTbb = 1.5e-2 / 511.0  # Photon blackbody temperature in units of mc^2; 2e-4 = 0.1 keV

        #Nprtcls = conf.NxMesh * conf.NyMesh * conf.NzMesh * conf.ppc
        Nprtcls = int(1e4)

        container = pyrad.PhotonContainer()
        container.reserve(Nprtcls)

        weight = 1.0
        for ip in range(Nprtcls):
            ene = bbodySample(kTbb)

            x0 = rand3Dloc(conf)
            u0 = rand3Dvel(1.0)

            container.add_particle(x0, u0, weight, ene)

        nbins = 100
        emin = 1.0e-3
        emax = 2.0e+3
        #Nph = container.size()
        Nph = Nprtcls
        self.assertEqual(Nprtcls, Nph)

        if do_plots:
            try:
                axs[0].set_xlim(emin, emax)
                #axs[0].set_ylim(1e-4, 1.2e-0)
                axs[0].minorticks_on()
                axs[0].set_xscale('log')
                axs[0].set_yscale('log')
            except:
                pass

        ene = np.array(container.ene())
        phhist, edges = np.histogram(
            ene * 511., np.logspace(np.log10(emin), np.log10(emax), nbins))

        if do_plots:
            try:
                axs[0].bar(edges[:-1],
                           phhist.astype(np.float32) / Nph,
                           width=np.diff(edges),
                           log=True)  # number of photons per log energy
            except:
                pass

        prtcl_sum = np.sum(phhist * edges[:-1]) / Nph
        print("Energy of photons: {}".format(prtcl_sum))

        bbrad_sum = np.sum(3.0e12 * 2. * edges**3 /
                           (np.exp(edges / kTbb) - 1.0))
        print("Blackbody energy: {}".format(bbrad_sum))

        try:
            plt.savefig("blackbody.pdf")
        except:
            pass