def getLocalMaxLevel(self, dup, levels, indices, grid): gp = HashGridPoint(self.numDims) for idim, (level, index) in enumerate(zip(levels, indices)): gp.set(idim, level, index) # up in direction d to the root node diffLevels = np.zeros(self.numDims) for idim in range(self.numDims): # search for children # as long as the corresponding grid point exist in the grid gp.set(idim, 1, 1) if self.verbose: print(" %i: root (%i) = %s" % (dup, idim, (tuple(getLevel(gp)), tuple(getIndex(gp)), tuple([gp.getCoord(i) for i in range(self.numDims)])))) currentgp = HashGridPoint(gp) diffLevels[idim] = self.getMaxLevelOfChildrenUpToMaxLevel( currentgp, grid, idim) return diffLevels
def getLocalFullGridLevel(self, levels, indices, grid, gpk=None, gpl=None): localMaxLevels = np.zeros(self.numDims, dtype="int") # + self.maxLevel - levels + 1 if False and self.numDims == 2 and self.plot: levelouter, indexouter = self.findOuterIntersection(gpk, gpl) levelinner, indexinner = self.findInnerIntersection(gpk, gpl) fig = plt.figure() plotGrid2d(grid) if gpk is not None: plt.plot(gpk.getCoord(0), gpk.getCoord(1), "v", color="orange") if gpl is not None: plt.plot(gpl.getCoord(0), gpl.getCoord(1), "v", color="orange") plt.plot(2**-levelinner[0] * indexinner[0], 2**-levelinner[1] * indexinner[1], "o ", color="yellow") plt.plot(2**-levelouter[0] * indexouter[0], 2**-levelouter[1] * indexouter[1], "o ", color="yellow") plt.xlim(0, 1) plt.ylim(0, 1) fig.show() gpInnerIntersection = HashGridPoint(self.numDims) gpi = HashGridPoint(self.numDims) gpj = HashGridPoint(self.numDims) gs = grid.getStorage() for idim, jdim in combinations(list(range(self.numDims)), 2): # find neighbors in direction idim iright, ileft = getGridPointsOnBoundary(levels[idim], indices[idim]) # find neighbors in direction idim jright, jleft = getGridPointsOnBoundary(levels[jdim], indices[jdim]) for left, right in product((iright, ileft), (jright, jleft)): if left is not None and right is not None: (llevel, lindex), (rlevel, rindex) = left, right for i in range(self.numDims): # compute intersection i if i == idim: gpi.set(i, int(llevel), int(lindex)) else: gpi.set(i, levels[i], indices[i]) # compute intersection j if i == jdim: gpj.set(i, int(rlevel), int(rindex)) else: gpj.set(i, levels[i], indices[i]) # compute inner intersection levelInner, indexInner = self.findInnerIntersection( gpi, gpj) for i in range(self.numDims): gpInnerIntersection.set(i, levelInner[i], indexInner[i]) if gs.isContaining(gpj): localMaxLevels[idim] = max( localMaxLevels[idim], self.getMaxLevelOfChildrenUpToMaxLevel( gpj, grid, idim)) if gs.isContaining(gpi): localMaxLevels[jdim] = max( localMaxLevels[jdim], self.getMaxLevelOfChildrenUpToMaxLevel( gpi, grid, jdim)) if gs.isContaining(gpInnerIntersection): xdim = np.array([ i for i in range(self.numDims) if i != idim and i != jdim ], dtype="int") for i in xdim: localMaxLevels[i] = max( localMaxLevels[i], self.getMaxLevelOfChildrenUpToMaxLevel( gpInnerIntersection, grid, i)) # plot result if False and self.plot: levelouter, indexouter = self.findOuterIntersection( gpi, gpj) fig = plt.figure() plotGrid2d(grid) plt.plot(gpi.getCoord(0), gpi.getCoord(1), "v", color="orange") plt.plot(gpj.getCoord(0), gpj.getCoord(1), "v", color="orange") plt.plot(gpInnerIntersection.getCoord(0), gpInnerIntersection.getCoord(1), "v ", color="red") plt.plot(2**-levelouter[0] * indexouter[0], 2**-levelouter[1] * indexouter[1], "o ", color="yellow") plt.xlim(0, 1) plt.ylim(0, 1) plt.title(localMaxLevels) fig.show() if False and self.plot: plt.show() return localMaxLevels + 1