def get_point_materials(materials, coords): """Query DAGMC for materials at a list of points Parameters ---------- materials : dictionary ... coords : list of (x, y, z) float triplets Point coordinates; typically for voxel centers. Returns ------- mats : list of integers List of integers corresponding material at each point in coords. Notes ----- Requires that DagMC geometry has already been loaded via dagmc.load(). """ mats = list() for coord in coords: vol_id = dagmc.find_volume(coord) mats.append(get_mat_id(materials, vol_id)) return mats
def get_center_materials(materials, coords): """ """ mats = list() for coord in coords: vol_id = dagmc.find_volume(coord) mats.append(get_mat_id(materials, vol_id)) return mats
def test_find_volume( self ): vol = dagmc.find_volume( [0,0,0] ) self.assertEqual( vol, 2 ) vol = dagmc.find_volume( [.9,.9,.9] ) self.assertEqual( vol, 2 ) # boundary case -- point [1,.1,.1] is on surface between vols 2 and 3 # the behavior on boundaries will vary with uvw, but ensure that # only the two volumes the touch the location are ever returned. for uvw in [(1,0,0),(-1,0,0),(0,1,0),(0,-1,0)]: vol = dagmc.find_volume( [1,.1,.1], uvw ) self.assertTrue( vol in (2,3) ) # boundary case-- exiting volume 3 => in volume 3 vol = dagmc.find_volume( [1,.1,.1], [-1,0,0] ) self.assertEqual( vol, 3 ) vol = dagmc.find_volume( [1.1,0,0] ) self.assertEqual( vol, 3 )
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
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 )
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
with open(input_file) as f: pass except IOError as e: print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' print 'File ', input_file, ' does not exist' print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' exit() dagmc.load(input_file) #load geometry file #dagmc.load('divertor_merged.h5m') # find out where pos is pos = (625.0, -43.4, 0.0) dir = (1.0, 0.0, 0.0) first_vol = dagmc.find_volume(pos, dir) # open output file for ray story file = open("output.txt", "a") num_lost = 0 nps = 10000000 for i in range(1, nps): 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, '%'
except IOError as e: print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' print 'File ',input_file,' does not exist' print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' exit() dagmc.load(input_file) #load geometry file #dagmc.load('divertor_merged.h5m') # find out where pos is pos=(625.0,-43.4,0.0) dir=(1.0,0.0,0.0) first_vol=dagmc.find_volume(pos,dir) # open output file for ray story file = open("output.txt","a") num_lost=0 nps = 10000000 for i in range(1,nps): 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