Esempio n. 1
0
    def _initInterp(self):
        """
        Initialise the interpolant

        Finds the horizontal indices of the slice points and
        constructs the 3D mask array
        """

        # Find the cell index of each point along the slice
        self.Tri = GridSearch(self.xp, self.yp, self.cells)

        self.cellind = self.Tri(self.xslice, self.yslice)

        klayer, Nkmax = self.get_klayer()

        # Construct the 3D coordinate arrays
        self.xslice = np.repeat(self.xslice.reshape((1, self.Npt)),
                                self.Nkmax,
                                axis=0)
        self.yslice = np.repeat(self.yslice.reshape((1, self.Npt)),
                                self.Nkmax,
                                axis=0)
        self.distslice = np.repeat(self.distslice.reshape((1, self.Npt)),
                                   self.Nkmax,
                                   axis=0)
        self.zslice = np.repeat(-self.z_r[klayer].reshape((self.Nkmax, 1)),
                                self.Npt,
                                axis=1)

        # Construct the mask array
        self.calc_mask()

        # Get the bathymetry along the slice
        self.hslice = -self.dv[self.cellind]
Esempio n. 2
0
    def __init__(self,
                 ncfile,
                 xpt=None,
                 ypt=None,
                 Npt=100,
                 klayer=[-99],
                 **kwargs):

        self.Npt = Npt

        Spatial.__init__(self, ncfile, klayer=klayer, **kwargs)

        # Load the grid as a hybridgrid
        self.grd = GridSearch(self.xp,self.yp,self.cells,nfaces=self.nfaces,\
            edges=self.edges,mark=self.mark,grad=self.grad,neigh=self.neigh,\
                xv=self.xv,yv=self.yv)

        # Find the edge indices along the line
        self.update_xy(xpt, ypt)
Esempio n. 3
0
def GridParticles(grdfile,dx,dy,nz,xypoly=None,splitvec=1):
    """
    Returns the locations of particles on a regular grid inside of suntans grid

    Inputs:
        grdfile - netcdf filename containing the suntans grid
        dx,dy - resolution in x and y component respectively.
        nz - number of particles in the vertical. Particles are arranged in sigma layers.
        xypoly - [optional] coordinates of an additional bounding polygon [Nx2 array]
    """

    # Load the suntans grid
    sun = Grid(grdfile)

    # Load a trisearch object
    tri = GridSearch(sun.xp,sun.yp,sun.cells,nfaces=sun.nfaces,verbose=False)

    if xypoly == None:
        xlims = [sun.xlims[0],sun.xlims[1]]
        ylims = [sun.ylims[0],sun.ylims[1]]
    else:
        xlims = [xypoly[:,0].min(),xypoly[:,0].max()]
        ylims = [xypoly[:,1].min(),xypoly[:,1].max()]

    # Construct a 2D mesh of particles
    x = np.arange(xlims[0],xlims[1],dx)
    y = np.arange(ylims[0],ylims[1],dy)

    X,Y = np.meshgrid(x,y)

    X=X.ravel()
    Y=Y.ravel()
    # Check which particles are inside the grid
    cellind = tri(X,Y)
    mask = cellind!=-1

    # Check which particles are also inside of the polygon
    if not xypoly == None:
        inpoly = inpolygon(np.vstack((X,Y)).T,xypoly)
        mask = operator.and_(mask,inpoly)

    xout = X[mask]
    yout = Y[mask]

    nx = xout.shape[0]

    # Construct the 3D mesh
    xout = np.repeat(xout.reshape((nx,1)),nz,axis=1)
    yout = np.repeat(yout.reshape((nx,1)),nz,axis=1)

    zout = np.linspace(0.05,0.95,nz)
    zout = np.repeat(zout.reshape((nz,1)),nx,axis=1)

    zout *= -sun.dv[cellind[mask]]
    zout = zout.T

    xout = xout.ravel()
    yout = yout.ravel()
    zout = zout.ravel()

    # Rearrange the vectors to avoid clustering (this helps even the MPI workload)
    #xout_split=[]
    #yout_split=[]
    #zout_split=[]
    #for start in range(splitvec):
    #    xout_split.append(xout[start::splitvec])
    #    yout_split.append(yout[start::splitvec])
    #    zout_split.append(zout[start::splitvec])

    #xout = np.hstack(xout_split)
    #yout = np.hstack(yout_split)
    #zout = np.hstack(zout_split)


    return xout, yout, zout