Example #1
0
    def __init__(self, x, y, cells, **kwargs):

        self.__dict__.update(kwargs)

        #Triangulation.__init__(self,x,y,cells)
        HybridGrid.__init__(self,x,y,cells,nfaces=self.nfaces,edges=self.edges,\
            mark=self.mark,grad=self.grad,neigh=self.neigh,xv=self.xv,yv=self.yv)

        self.maxfaces = self.nfaces.max()

        self.Nc = cells.shape[0]

        # Create the polygons for searching
        self.init_polygons()
Example #2
0
    def __init__(self, x, y, cells,**kwargs):
        
        self.__dict__.update(kwargs)

        #Triangulation.__init__(self,x,y,cells)
        HybridGrid.__init__(self,x,y,cells,nfaces=self.nfaces,edges=self.edges,\
            mark=self.mark,grad=self.grad,neigh=self.neigh,xv=self.xv,yv=self.yv)

        self.maxfaces = self.nfaces.max()
        
        self.Nc = cells.shape[0]

        # Create the polygons for searching
        self.init_polygons()
Example #3
0
def curv_ugrid_gen(X,Y,suntanspath=None,maskpoly=None):
    """
    Creates a curvilinear mesh from grid corners points stored
    in arrays X and Y.
    """

    ny,nx = X.shape

    XY = np.vstack((X.ravel(),Y.ravel())).T
    if not maskpoly is None:
        mask = inpolygon(XY,maskpoly)
        mask = mask.reshape((ny,nx))
    else:
        mask = np.ones((ny,nx),dtype=np.bool) # all false

    cells=[]
    xp = []
    yp = []

    def pntindx(j,i,nrows):
        return j*nrows + i

    for jj in range(ny):
        for ii in range(nx):
            #if mask[jj,ii]:
            #xp.append(xgrd[ii])
            #yp.append(ygrd[jj])
            xp.append(X[jj,ii])
            yp.append(Y[jj,ii])

    for jj in range(ny-1):
        for ii in range(nx-1):
            if mask[jj,ii] and mask[jj+1,ii] and mask[jj+1,ii+1] and mask[jj,ii+1]:
                cells.append([pntindx(jj,ii,nx), pntindx(jj+1,ii,nx),\
                    pntindx(jj+1,ii+1,nx),pntindx(jj,ii+1,nx)])
            
    Nc = len(cells)
    nfaces = 4*np.ones((Nc,),np.int)

    cells = np.array(cells,dtype=np.int32)
    # Convert to a suntans grid
    grd = HybridGrid(np.array(xp),np.array(yp),cells,nfaces=nfaces)

    if not suntanspath is None:
        grd.write2suntans(suntanspath)

    return grd
Example #4
0
def curv_ugrid_gen(X,Y,suntanspath=None,maskpoly=None):
    """
    Creates a curvilinear mesh from grid corners points stored
    in arrays X and Y.
    """

    ny,nx = X.shape

    XY = np.vstack((X.ravel(),Y.ravel())).T
    if not maskpoly is None:
        mask = inpolygon(XY,maskpoly)
        mask = mask.reshape((ny,nx))
    else:
        mask = np.ones((ny,nx),dtype=np.bool) # all false

    cells=[]
    xp = []
    yp = []

    def pntindx(j,i,nrows):
        return j*nrows + i

    for jj in range(ny):
        for ii in range(nx):
            #if mask[jj,ii]:
            #xp.append(xgrd[ii])
            #yp.append(ygrd[jj])
            xp.append(X[jj,ii])
            yp.append(Y[jj,ii])

    for jj in range(ny-1):
        for ii in range(nx-1):
            if mask[jj,ii] and mask[jj+1,ii] and mask[jj+1,ii+1] and mask[jj,ii+1]:
                cells.append([pntindx(jj,ii,nx), pntindx(jj+1,ii,nx),\
                    pntindx(jj+1,ii+1,nx),pntindx(jj,ii+1,nx)])

    Nc = len(cells)
    nfaces = 4*np.ones((Nc,),np.int)

    cells = np.array(cells,dtype=np.int32)
    # Convert to a suntans grid
    grd = HybridGrid(np.array(xp),np.array(yp),cells,nfaces=nfaces)

    if not suntanspath is None:
        grd.write2suntans(suntanspath)

    return grd
Example #5
0
def reorder_ugrid(grd):
    """
    Re-order grid cells using METIS

    Input:
        grd - HybridGrid object

    Returns:
        a reordered HybridGrid object
    """
    import cymetis

    # Error check
    assert isinstance(grd, HybridGrid)

    # Create the graph for cymetis
    xadj, adjncy = grd.create_graph()

    # Find the new cell ordering
    perm, iperm = cymetis.reorder_graph(xadj, adjncy)

    # Create a new grid with this ordering
    return HybridGrid(grd.xp, grd.yp, grd.cells[perm, ...])