def allPositionsInThird(self, ring, includeEdgeAssems=False): """ Returns a list of all the positions in a ring (in the first third) Parameters ---------- ring : int The ring to check includeEdgeAssems : bool, optional If True, include repeated positions in odd ring numbers. Default: False Notes ----- Rings start at 1, positions start at 1 Returns ------- positions : int """ positions = [] for pos in range(1, hexagon.numPositionsInRing(ring) + 1): i, j = self.getIndicesFromRingAndPos(ring, pos) loc = IndexLocation(i, j, 0, None) if self.isInFirstThird(loc, includeEdgeAssems): positions.append(pos) return positions
def generateSortedHexLocationList(self, nLocs): """ Generate a list IndexLocations, sorted based on their distance from the center. IndexLocation are taken from a full core. Ties between locations with the same distance (e.g. A3001 and A3003) are broken by ring number then position number. """ # first, roughly calculate how many rings need to be created to cover nLocs worth of assemblies nLocs = int(nLocs) # need to make this an integer # next, generate a list of locations and corresponding distances locList = [] for ring in range(1, hexagon.numRingsToHoldNumCells(nLocs) + 1): positions = hexagon.numPositionsInRing(ring) for position in range(1, positions + 1): i, j = getIndicesFromRingAndPos(ring, position) locList.append(self[(i, j, 0)]) # round to avoid differences due to floating point math locList.sort(key=lambda loc: ( round(numpy.linalg.norm(loc.getGlobalCoordinates()), 6), loc.i, # loc.i=ring loc.j, )) # loc.j= pos return locList[:nLocs]
def addRing(self, ring, p0=None, p1=None): """ Adds a section of a ring (or a whole ring) to the zone Parameters ---------- ring : int The ring to add p0 : int, optional beginning position within ring. Default: None (full ring) p1 : int, optional Ending position within ring. """ grid = grids.HexGrid.fromPitch(1.0) if p0 is None or p1 is None: if self.symmetry == 3: posList = grid.allPositionsInThird(ring) elif self.symmetry == 1: posList = range(1, hexagon.numPositionsInRing(ring) + 1) else: raise RuntimeError( "Zones are not written to handle {0}-fold symmetry yet" "".format(self.symmetry)) else: posList = range(p0, p1 + 1) for pos in posList: newLoc = grid.getLabel( grid.getLocatorFromRingAndPos(ring, pos).getCompleteIndices()[:2]) if newLoc not in self.locList: self.append(newLoc)
def isInFirstThird(self, locator, includeTopEdge=False): """True if locator is in first third of hex grid. """ ring, pos = self.getRingPos(locator.indices) if ring == 1: return True maxPosTotal = hexagon.numPositionsInRing(ring) maxPos1 = ring + ring // 2 - 1 maxPos2 = maxPosTotal - ring // 2 + 1 if ring % 2: # odd ring. Upper edge assem typically not included. if includeTopEdge: maxPos1 += 1 else: maxPos2 += 1 # make a table to understand this. if pos <= maxPos1 or pos >= maxPos2: return True return False