예제 #1
0
파일: fv.py 프로젝트: JuliaBru/pymor
 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)
예제 #2
0
 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)
예제 #3
0
파일: grid.py 프로젝트: mahgadalla/pymor
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))))
예제 #4
0
 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)
예제 #5
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)