def restricted(self, dofs): source_dofs = np.setdiff1d(np.union1d(self.grid.neighbours(0, 0)[dofs].ravel(), dofs), np.array([-1], dtype=np.int32), assume_unique=True) sub_grid = SubGrid(self.grid, entities=source_dofs) sub_boundary_info = SubGridBoundaryInfo(sub_grid, self.grid, self.boundary_info) op = self.with_(grid=sub_grid, boundary_info=sub_boundary_info, name='{}_restricted'.format(self.name)) sub_grid_indices = sub_grid.indices_from_parent_indices(dofs, codim=0) proj = ComponentProjection(sub_grid_indices, op.range) return Concatenation(proj, op), sub_grid.parent_indices(0)
def subgrid_factory(grid_generator, neq, seed): np.random.seed(seed) g = grid_generator() if neq == 0: return SubGrid(g, np.arange(g.size(0), dtype=np.int32)) else: return SubGrid( g, np.array( random.sample(range(g.size(0)), max(int(m.floor(g.size(0) / neq)), 1))))
def restricted(self, dofs): source_dofs = np.setdiff1d(np.union1d( self.grid.neighbours(0, 0)[dofs].ravel(), dofs), np.array([-1], dtype=np.int32), assume_unique=True) sub_grid = SubGrid(self.grid, source_dofs) sub_boundary_info = make_sub_grid_boundary_info( sub_grid, self.grid, self.boundary_info) op = self.with_(grid=sub_grid, boundary_info=sub_boundary_info, space_id=None, name=f'{self.name}_restricted') sub_grid_indices = sub_grid.indices_from_parent_indices(dofs, codim=0) proj = ComponentProjection(sub_grid_indices, op.range) return proj @ op, sub_grid.parent_indices(0)
def getsubgrid(grid, xpos, ypos, coarse_grid_resolution, xsize=2, ysize=2): assert 0 <= xpos <= coarse_grid_resolution - 2 assert 0 <= ypos <= coarse_grid_resolution - 2 xstep = float(grid.domain[1][0] - grid.domain[0][0]) / coarse_grid_resolution ystep = float(grid.domain[1][1] - grid.domain[0][1]) / coarse_grid_resolution xmin = grid.domain[0][0] + xpos * xstep xmax = xmin + xsize * xstep ymin = grid.domain[0][1] + ypos * ystep ymax = ymin + ysize * ystep def filter(elem): return (xmin <= elem[0] <= xmax) and (ymin <= elem[1] <= ymax) mask = [filter(e) for e in grid.centers(0)] indices = np.nonzero(mask)[0] return SubGrid(grid, indices)