parameters: (mesh, hdf5, bounds, num_rays, grid, dg, mat_assigns, unique_names)
return_statement: return zones_formatted, zones_novoid
docstring: Get the minimum zone definitions for the geometry.
docstring_summary: Get the minimum zone definitions for the geometry.
docstring_tokens: Get the minimum zone definitions for the geometry .
function: def _get_zones(mesh, hdf5, bounds, num_rays, grid, dg, mat_assigns, unique_names):
      """Get the minimum zone definitions for the geometry.
      """
  
      # Discretize the geometry and get cell fractions
      if dg is None:
          if not HAVE_DAGMC:
              raise RuntimeError("DAGMC is not available."
                                 "Unable to discretize the geometry.")
          else:
              dagmc.load(hdf5)
              dg = dagmc.discretize_geom(mesh, num_rays=num_rays, grid=grid)
  
      # Reorganize dictionary of each voxel's info with the key the voxel number
      # and values of cell and volume fraction
      voxel = {}
      for i in dg:
          idx = i[0]  # voxel number
          if idx not in voxel:
              voxel[idx] = {}
              voxel[idx]['cell'] = []
              voxel[idx]['vol_frac'] = []
          voxel[idx]['cell'].append(i[1])
          voxel[idx]['vol_frac'].append(i[2])
  
      # get material to cell assignments
      if mat_assigns is None:
          if not HAVE_DAGMC:
              raise RuntimeError("DAGMC is not available."
                                 "Unable to get cell material assignments.")
          else:
              mat_assigns = dagmc.cell_material_assignments(hdf5)
  
      # Replace the names in the material assignments with unique names
      temp = {}
      for i, name in mat_assigns.items():
          if "vacuum" in name.lower() or "graveyard" in name.lower():
              temp[i] = name
          else:
              temp[i] = unique_names[name]
      mat_assigns = temp
  
      # Replace cell numbers with materials, eliminating duplicate materials
      # within single zone definition
      zones = {}
      for z in voxel:
          zones[z] = {}
          zones[z]['vol_frac'] = []
          zones[z]['mat'] = []
          for i, cell in enumerate(voxel[z]['cell']):
              if mat_assigns[cell] not in zones[z]['mat']:
                  # create new entry
                  zones[z]['mat'].append(mat_assigns[cell])
                  zones[z]['vol_frac'].append(voxel[z]['vol_frac'][i])
              else:
                  # update value that already exists with new volume fraction
                  for j, val in enumerate(zones[z]['mat']):
                      if mat_assigns[cell] == val:
                          vol_frac = zones[z]['vol_frac'][j] + \
                              voxel[z]['vol_frac'][i]
                          zones[z]['vol_frac'][j] = vol_frac
  
      # Remove vacuum or graveyard from material definition if not vol_frac of 1.0
      skip_array = [['mat:Vacuum'], ['mat:vacuum'],
                    ['mat:Graveyard'], ['mat:graveyard']]
      skip_list = ['mat:Vacuum', 'mat:vacuum', 'mat:Graveyard', 'mat:graveyard']
      zones_compressed = {}
      for z, info in zones.items():
          # check first if the definition is 100% void, keep same if is
          if zones[z]['mat'] in skip_array and zones[z]['vol_frac'] == [1.0]:
              zones_compressed[z] = info
          else:
              # check for partial void
              zones_compressed[z] = {'mat': [], 'vol_frac': []}
              for i, mat in enumerate(zones[z]['mat']):
                  if mat not in skip_list:
                      zones_compressed[z]['mat'].append(mat)
                      zones_compressed[z]['vol_frac'].append(
                          zones[z]['vol_frac'][i])
  
      # Eliminate duplicate zones and assign each voxel a zone number.
      # Assign zone = 0 if vacuum or graveyard and eliminate material definition.
      voxel_zone = {}
      zones_mats = {}
      z = 0
      match = False
      first = True
      for i, vals in zones_compressed.items():
          # Find if the zone already exists
          for zone, info in zones_mats.items():
              # Iterate through both sets to disregard order
              match_all = np.empty(len(vals['mat']), dtype=bool)
              match_all.fill(False)
              for ii, mat in enumerate(vals['mat']):
                  for jj, mat_info in enumerate(info['mat']):
                      if mat == mat_info and np.allclose(np.array(vals['vol_frac'][ii]),
                                                         np.array(info['vol_frac'][jj]), rtol=1e-5):
                          match_all[ii] = True
                          break
              if match_all.all() == True:
                  match = True
                  y = zone
                  break
              else:
                  match = False
          # Create a new zone if first zone or does not match other zones
          if first or not match:
              # Check that the material is not 100% void (assign zone 0 otherwise)
              if vals['mat'] in skip_array:
                  voxel_zone[i] = 0
              else:
                  z += 1
                  zones_mats[z] = zones_compressed[i]
                  voxel_zone[i] = z
                  first = False
          else:
              if vals['mat'] in skip_array:
                  voxel_zone[i] = 0
              else:
                  voxel_zone[i] = y
  
      # Remove any instances of graveyard or vacuum in zone definitions
      zones_novoid = {}
      for z in zones_mats:
          zones_novoid[z] = {'mat': [], 'vol_frac': []}
          for i, mat in enumerate(zones_mats[z]['mat']):
              if mat not in skip_list:
                  zones_novoid[z]['mat'].append(mat)
                  zones_novoid[z]['vol_frac'].append(
                      zones_mats[z]['vol_frac'][i])
  
      # Put zones into format for PARTISN input
      if 'x' in bounds:
          im = len(bounds['x']) - 1
      else:
          im = 1
  
      if 'y' in bounds:
          jm = len(bounds['y']) - 1
      else:
          jm = 1
  
      if 'z' in bounds:
          km = len(bounds['z']) - 1
      else:
          km = 1
  
      n = 0
      zones_formatted = np.zeros(shape=(jm*km, im), dtype=int)
      for i in range(im):
          temp = np.zeros(shape=(jm*km), dtype=int)
          for jk in range(jm*km):
              temp[jk] = voxel_zone[n]
              n += 1
          temp = np.reshape(temp, (jm, km))
          temp = np.transpose(temp)
          temp = np.reshape(temp, jm*km)
          zones_formatted[:, i] = temp
  
      return zones_formatted, zones_novoid
function_tokens: def _get_zones ( mesh , hdf5 , bounds , num_rays , grid , dg , mat_assigns , unique_names ) : # Discretize the geometry and get cell fractions if dg is None : if not HAVE_DAGMC : raise RuntimeError ( "DAGMC is not available." "Unable to discretize the geometry." ) else : dagmc . load ( hdf5 ) dg = dagmc . discretize_geom ( mesh , num_rays = num_rays , grid = grid ) # Reorganize dictionary of each voxel's info with the key the voxel number # and values of cell and volume fraction voxel = { } for i in dg : idx = i [ 0 ] # voxel number if idx not in voxel : voxel [ idx ] = { } voxel [ idx ] [ 'cell' ] = [ ] voxel [ idx ] [ 'vol_frac' ] = [ ] voxel [ idx ] [ 'cell' ] . append ( i [ 1 ] ) voxel [ idx ] [ 'vol_frac' ] . append ( i [ 2 ] ) # get material to cell assignments if mat_assigns is None : if not HAVE_DAGMC : raise RuntimeError ( "DAGMC is not available." "Unable to get cell material assignments." ) else : mat_assigns = dagmc . cell_material_assignments ( hdf5 ) # Replace the names in the material assignments with unique names temp = { } for i , name in mat_assigns . items ( ) : if "vacuum" in name . lower ( ) or "graveyard" in name . lower ( ) : temp [ i ] = name else : temp [ i ] = unique_names [ name ] mat_assigns = temp # Replace cell numbers with materials, eliminating duplicate materials # within single zone definition zones = { } for z in voxel : zones [ z ] = { } zones [ z ] [ 'vol_frac' ] = [ ] zones [ z ] [ 'mat' ] = [ ] for i , cell in enumerate ( voxel [ z ] [ 'cell' ] ) : if mat_assigns [ cell ] not in zones [ z ] [ 'mat' ] : # create new entry zones [ z ] [ 'mat' ] . append ( mat_assigns [ cell ] ) zones [ z ] [ 'vol_frac' ] . append ( voxel [ z ] [ 'vol_frac' ] [ i ] ) else : # update value that already exists with new volume fraction for j , val in enumerate ( zones [ z ] [ 'mat' ] ) : if mat_assigns [ cell ] == val : vol_frac = zones [ z ] [ 'vol_frac' ] [ j ] + voxel [ z ] [ 'vol_frac' ] [ i ] zones [ z ] [ 'vol_frac' ] [ j ] = vol_frac # Remove vacuum or graveyard from material definition if not vol_frac of 1.0 skip_array = [ [ 'mat:Vacuum' ] , [ 'mat:vacuum' ] , [ 'mat:Graveyard' ] , [ 'mat:graveyard' ] ] skip_list = [ 'mat:Vacuum' , 'mat:vacuum' , 'mat:Graveyard' , 'mat:graveyard' ] zones_compressed = { } for z , info in zones . items ( ) : # check first if the definition is 100% void, keep same if is if zones [ z ] [ 'mat' ] in skip_array and zones [ z ] [ 'vol_frac' ] == [ 1.0 ] : zones_compressed [ z ] = info else : # check for partial void zones_compressed [ z ] = { 'mat' : [ ] , 'vol_frac' : [ ] } for i , mat in enumerate ( zones [ z ] [ 'mat' ] ) : if mat not in skip_list : zones_compressed [ z ] [ 'mat' ] . append ( mat ) zones_compressed [ z ] [ 'vol_frac' ] . append ( zones [ z ] [ 'vol_frac' ] [ i ] ) # Eliminate duplicate zones and assign each voxel a zone number. # Assign zone = 0 if vacuum or graveyard and eliminate material definition. voxel_zone = { } zones_mats = { } z = 0 match = False first = True for i , vals in zones_compressed . items ( ) : # Find if the zone already exists for zone , info in zones_mats . items ( ) : # Iterate through both sets to disregard order match_all = np . empty ( len ( vals [ 'mat' ] ) , dtype = bool ) match_all . fill ( False ) for ii , mat in enumerate ( vals [ 'mat' ] ) : for jj , mat_info in enumerate ( info [ 'mat' ] ) : if mat == mat_info and np . allclose ( np . array ( vals [ 'vol_frac' ] [ ii ] ) , np . array ( info [ 'vol_frac' ] [ jj ] ) , rtol = 1e-5 ) : match_all [ ii ] = True break if match_all . all ( ) == True : match = True y = zone break else : match = False # Create a new zone if first zone or does not match other zones if first or not match : # Check that the material is not 100% void (assign zone 0 otherwise) if vals [ 'mat' ] in skip_array : voxel_zone [ i ] = 0 else : z += 1 zones_mats [ z ] = zones_compressed [ i ] voxel_zone [ i ] = z first = False else : if vals [ 'mat' ] in skip_array : voxel_zone [ i ] = 0 else : voxel_zone [ i ] = y # Remove any instances of graveyard or vacuum in zone definitions zones_novoid = { } for z in zones_mats : zones_novoid [ z ] = { 'mat' : [ ] , 'vol_frac' : [ ] } for i , mat in enumerate ( zones_mats [ z ] [ 'mat' ] ) : if mat not in skip_list : zones_novoid [ z ] [ 'mat' ] . append ( mat ) zones_novoid [ z ] [ 'vol_frac' ] . append ( zones_mats [ z ] [ 'vol_frac' ] [ i ] ) # Put zones into format for PARTISN input if 'x' in bounds : im = len ( bounds [ 'x' ] ) - 1 else : im = 1 if 'y' in bounds : jm = len ( bounds [ 'y' ] ) - 1 else : jm = 1 if 'z' in bounds : km = len ( bounds [ 'z' ] ) - 1 else : km = 1 n = 0 zones_formatted = np . zeros ( shape = ( jm * km , im ) , dtype = int ) for i in range ( im ) : temp = np . zeros ( shape = ( jm * km ) , dtype = int ) for jk in range ( jm * km ) : temp [ jk ] = voxel_zone [ n ] n += 1 temp = np . reshape ( temp , ( jm , km ) ) temp = np . transpose ( temp ) temp = np . reshape ( temp , jm * km ) zones_formatted [ : , i ] = temp return zones_formatted , zones_novoid