def _getNearestCellID(self, points): """ Test cases >>> from fipy import * >>> m = Grid1D(nx=3) >>> print(m._getNearestCellID(([0., .9, 3.],))) [0 0 2] >>> print(m._getNearestCellID(([1.1],))) [1] >>> m0 = Grid1D(nx=2, dx=1.) >>> m1 = Grid1D(nx=4, dx=.5) >>> print(m0._getNearestCellID(m1.cellCenters.globalValue)) [0 0 1 1] """ nx = self.globalNumberOfCells if nx == 0: return numerix.arange(0) x0, = self.cellCenters.globalValue[..., 0] xi, = points dx = self.dx i = numerix.array(numerix.rint(((xi - x0) / dx)), 'l') i[i < 0] = 0 i[i > nx - 1] = nx - 1 return i
def _getNearestCellID(self, points): """ Test cases >>> from fipy import * >>> m = Grid1D(nx=3) >>> print m._getNearestCellID(([0., .9, 3.],)) [0 0 2] >>> print m._getNearestCellID(([1.1],)) [1] >>> m0 = Grid1D(nx=2, dx=1.) >>> m1 = Grid1D(nx=4, dx=.5) >>> print m0._getNearestCellID(m1.getCellCenters().getGlobalValue()) [0 0 1 1] """ nx = self.globalNumberOfCells if nx == 0: return numerix.arange(0) x0, = self.getCellCenters().getGlobalValue()[..., 0] xi, = points dx = self.dx i = numerix.array(numerix.rint(((xi - x0) / dx)), "l") i[i < 0] = 0 i[i > nx - 1] = nx - 1 return i
def _getNearestCellID(self, points): nx = self.args['nx'] ny = self.args['ny'] nz = self.args['nz'] x0, y0, z0 = self.cellCenters[...,0] xi, yi, zi = points nx, ny, nz = self.shape dx, dy, dz = self.dx, self.dy, self.dz i = numerix.array(numerix.rint(((xi - x0) / dx)), 'l') i[i < 0] = 0 i[i > nx - 1] = nx - 1 j = numerix.array(numerix.rint(((yi - y0) / dy)), 'l') j[j < 0] = 0 j[j > ny - 1] = ny - 1 k = numerix.array(numerix.rint(((zi - z0) / dz)), 'l') k[k < 0] = 0 k[k > nz - 1] = nz - 1 return k * ny * nx + j * nx + i
def _getNearestCellID(self, points): nx = self.args['nx'] ny = self.args['ny'] nz = self.args['nz'] x0, y0, z0 = self.cellCenters[..., 0] xi, yi, zi = points nx, ny, nz = self.shape dx, dy, dz = self.dx, self.dy, self.dz i = numerix.array(numerix.rint(((xi - x0) / dx)), 'l') i[i < 0] = 0 i[i > nx - 1] = nx - 1 j = numerix.array(numerix.rint(((yi - y0) / dy)), 'l') j[j < 0] = 0 j[j > ny - 1] = ny - 1 k = numerix.array(numerix.rint(((zi - z0) / dz)), 'l') k[k < 0] = 0 k[k > nz - 1] = nz - 1 return k * ny * nx + j * nx + i
def _getNearestCellID(self, points): """ Test cases >>> from fipy import * >>> m = Grid2D(nx=3, ny=2) >>> eps = numerix.array([[1e-5, 1e-5]]) >>> print(m._getNearestCellID(((0., .9, 3.), (0., 2., 2.)))) [0 3 5] >>> print(m._getNearestCellID(([1.1], [1.5]))) [4] >>> m0 = Grid2D(nx=2, ny=2, dx=1., dy=1.) >>> m1 = Grid2D(nx=4, ny=4, dx=.5, dy=.5) >>> print(m0._getNearestCellID(m1.cellCenters.globalValue)) [0 0 1 1 0 0 1 1 2 2 3 3 2 2 3 3] """ nx = self.args['nx'] ny = self.args['ny'] if nx == 0 or ny == 0: return numerix.arange(0) x0, y0 = self.cellCenters.globalValue[..., 0] xi, yi = points dx, dy = self.dx, self.dy i = numerix.array(numerix.rint(((xi - x0) / dx)), 'l') i[i < 0] = 0 i[i > nx - 1] = nx - 1 j = numerix.array(numerix.rint(((yi - y0) / dy)), 'l') j[j < 0] = 0 j[j > ny - 1] = ny - 1 return j * nx + i