Exemple #1
0
    def test_ray_iterator( self ):

        start = [-2, 0, 0]
        startvol = dagmc.find_volume( start )
        self.assertEqual( startvol, 3 )
        direction = [1, 0, 0]

        expected_vols = [2, 3, 1, 4]
        expected_dists = [1,2,3.156921938,0]

        for i, (vol, dist, surf) in enumerate( dagmc.ray_iterator( startvol, start, direction ) ):
            self.assertEqual( expected_vols[i], vol )
            if expected_dists[i] != 0: 
                self.assertAlmostEqual( expected_dists[i], dist )
        self.assertEqual( i, 3 )

        for i, (vol, dist, surf) in enumerate( dagmc.ray_iterator( startvol, start, direction, dist_limit=4 ) ):
            self.assertEqual( expected_vols[i], vol )
            if expected_dists[i] != 0:
                self.assertAlmostEqual( expected_dists[i], dist )
        self.assertEqual( i, 1 )
Exemple #2
0
    def _alloc_one_ray(self, start_ijk, dim, xyz, uvw, divs, samples):
        """Fire a single ray and store the sampled data to the grid
        
        start_ijk: structured mesh coordinates of the hex from which ray begins
        dim: 0, 1, or 2 depending on whether whether ray is x, y, or z-directed.
        xyz: start position of ray
        uvw: direction of ray
        divs: The structured grid divisions along this dimension.
        samples: 2D array of zeros used to store ray info
        """
        first_vol = self.first_vol
        if not first_vol or not dagmc.point_in_volume(first_vol, xyz, uvw):
            first_vol = dagmc.find_volume(xyz, uvw)

        vol = first_vol
        loc = divs[0]
        div = 0
        for nxtvol, raydist, _ in dagmc.ray_iterator(vol, xyz, uvw):
            mat_idx = get_mat_id(self.materials, vol)
            vol = nxtvol
            for meshdist, meshrat, newloc in self._grid_fragments(
                    divs, div, loc, raydist):
                # The ray fills this voxel for a normalized distance of
                # meshrat = (meshdist / length_of_voxel)
                samples[div, mat_idx] += meshrat
                loc += meshdist
                if (newloc):
                    div += 1

        # Save the first detected volume to speed future queries
        self.first_vol = first_vol

        # prepare an indexing object for self.grid to access the appropriate mesh row.
        # It is important to use a slice object rather than a general sequence
        # because a general sequence will trigger numpy's advanced iteration,
        # which returns copies of data instead of views.
        idx_ijk = start_ijk
        idx_ijk[dim] = slice(self.scdmesh.dims[dim],
                             self.scdmesh.dims[dim + 3])
        for sample, voxel in itertools.izip_longest(samples,
                                                    self.grid[idx_ijk]):
            voxel['mats'] += sample
            voxel['errs'] += sample**2
Exemple #3
0
    def _alloc_one_ray(self, start_ijk, dim, xyz, uvw, divs, samples):
        """Fire a single ray and store the sampled data to the grid
        
        start_ijk: structured mesh coordinates of the hex from which ray begins
        dim: 0, 1, or 2 depending on whether whether ray is x, y, or z-directed.
        xyz: start position of ray
        uvw: direction of ray
        divs: The structured grid divisions along this dimension.
        samples: 2D array of zeros used to store ray info
        """
        first_vol = self.first_vol
        if not first_vol or not dagmc.point_in_volume(first_vol,xyz,uvw):
            first_vol = dagmc.find_volume(xyz,uvw)

        vol = first_vol
        loc = divs[0]
        div = 0
        for nxtvol, raydist, _ in dagmc.ray_iterator( vol, xyz, uvw ):
            mat_idx = get_mat_id( self.materials, vol )
            vol = nxtvol
            for meshdist, meshrat, newloc in self._grid_fragments( divs, div, loc, raydist ):
                # The ray fills this voxel for a normalized distance of
                # meshrat = (meshdist / length_of_voxel)
                samples[div,mat_idx] += meshrat
                loc += meshdist
                if(newloc):
                    div += 1

        # Save the first detected volume to speed future queries
        self.first_vol = first_vol

        # prepare an indexing object for self.grid to access the appropriate mesh row.
        # It is important to use a slice object rather than a general sequence
        # because a general sequence will trigger numpy's advanced iteration,
        # which returns copies of data instead of views.
        idx_ijk = start_ijk
        idx_ijk[dim] = slice(self.scdmesh.dims[dim], self.scdmesh.dims[dim+3])
        for sample, voxel in itertools.izip_longest( samples, self.grid[idx_ijk]):
            voxel['mats'] += sample
            voxel['errs'] += sample**2
        localtime = time.asctime(time.localtime(time.time()))
        print(float(i) / float(nps)) * 100.0, '% complete', localtime
        print 'lost particle fraction = ', (float(num_lost) /
                                            float(nps)) * 100.0, '%'

#  call an isotropic source
    uvw = source_functions.isotropic()

    volumes = list()
    positions = list()

    # set the iterator to produce xyz hit locations
    kw = {"yield_xyz": 'yield_xyz'}

    # intialise the ray iterator with appropriate values
    dagmc.ray_iterator(first_vol, pos, uvw, **kw)

    # loop through the ray history
    for (vol, dist, sur, xyz) in dagmc.ray_iterator(first_vol, pos, uvw, **kw):
        volumes.append(vol)
        positions.append(str(xyz))
#       uvw = source_functions.isotropic()

#       print xyz

    lost = andy_geom_functions.lost_particle(volumes)
    if lost == 0:
        num_lost += 1
        # call dump2vtk, which takes the current ray history and prints it in nice format
        andy_geom_functions.dump_2_vtk(pos, positions, num_lost)
        andy_geom_functions.extrapolate_ray(pos, positoins, num_lost, 200.0)
    if i%(nps/10)==0:
          localtime = time.asctime(time.localtime(time.time()))
          print (float(i)/float(nps))*100.0,'% complete', localtime
          print 'lost particle fraction = ',(float(num_lost)/float(nps))*100.0,'%'

 #  call an isotropic source
    uvw = source_functions.isotropic()

    volumes=list()
    positions=list()

    # set the iterator to produce xyz hit locations
    kw={"yield_xyz":'yield_xyz'}

    # intialise the ray iterator with appropriate values
    dagmc.ray_iterator(first_vol,pos,uvw,**kw)

    # loop through the ray history
    for (vol,dist,sur,xyz) in dagmc.ray_iterator(first_vol,pos,uvw,**kw):
         volumes.append(vol)
         positions.append(str(xyz))
  #       uvw = source_functions.isotropic()

  #       print xyz

    lost = andy_geom_functions.lost_particle(volumes)
    if lost == 0:
         num_lost +=1
# call dump2vtk, which takes the current ray history and prints it in nice format
         andy_geom_functions.dump_2_vtk(pos,positions,num_lost)
         andy_geom_functions.extrapolate_ray(pos,positoins,num_lost,200.0)