Example #1
0
 def _createCells(self):
     ## cells = (f1, f2, f3, f4) going anticlockwise.
     ## f1 etc. refer to the faces
     bottomFaces = numerix.arange(0, self.numberOfHorizontalFaces - self.nx)
     topFaces = numerix.arange(self.nx, self.numberOfHorizontalFaces)
     leftFaces = vector.prune(
         numerix.arange(
             self.numberOfHorizontalFaces,
             self.numberOfHorizontalFaces + self.numberOfVerticalFaces),
         self.nx + 1, self.nx)
     rightFaces = vector.prune(
         numerix.arange(
             self.numberOfHorizontalFaces,
             self.numberOfHorizontalFaces + self.numberOfVerticalFaces),
         self.nx + 1, 0)
     lowerLeftDiagonalFaces = numerix.arange(
         self.numberOfHorizontalFaces + self.numberOfVerticalFaces,
         self.numberOfHorizontalFaces + self.numberOfVerticalFaces +
         self.numberOfEachDiagonalFaces)
     lowerRightDiagonalFaces = lowerLeftDiagonalFaces + self.numberOfEachDiagonalFaces
     upperLeftDiagonalFaces = lowerRightDiagonalFaces + self.numberOfEachDiagonalFaces
     upperRightDiagonalFaces = upperLeftDiagonalFaces + self.numberOfEachDiagonalFaces
     ##faces in arrays, now get the cells
     bottomOfBoxCells = numerix.array(
         [bottomFaces, lowerRightDiagonalFaces, lowerLeftDiagonalFaces])
     rightOfBoxCells = numerix.array(
         [rightFaces, upperRightDiagonalFaces, lowerRightDiagonalFaces])
     topOfBoxCells = numerix.array(
         [topFaces, upperLeftDiagonalFaces, upperRightDiagonalFaces])
     leftOfBoxCells = numerix.array(
         [leftFaces, lowerLeftDiagonalFaces, upperLeftDiagonalFaces])
     return numerix.concatenate(
         (rightOfBoxCells, topOfBoxCells, leftOfBoxCells, bottomOfBoxCells),
         axis=1)
Example #2
0
File: grid2D.py Project: regmi/fipy
    def _createFaces(self):
        """
        v1, v2 refer to the vertices.
        Horizontal faces are first
        """
        v1 = numerix.arange(self.numberOfVertices)
        v2 = v1 + 1

        horizontalFaces = vector.prune(numerix.array((v1, v2)), self.numberOfVerticalColumns, self.nx, axis=1)

        v1 = numerix.arange(self.numberOfVertices - self.numberOfVerticalColumns)
        v2 = v1 + self.numberOfVerticalColumns
        verticalFaces =  numerix.array((v1, v2))

        ## The cell normals must point out of the cell.
        ## The left and bottom faces have only one neighboring cell,
        ## in the 2nd neighbor position (there is nothing in the 1st).
        ## 
        ## reverse some of the face orientations to obtain the correct normals

        tmp = horizontalFaces.copy()
        horizontalFaces[0,:self.nx] = tmp[1,:self.nx]
        horizontalFaces[1,:self.nx] = tmp[0,:self.nx]

        self.numberOfHorizontalFaces = horizontalFaces.shape[-1]

        tmp = verticalFaces.copy()
        verticalFaces[0, :] = tmp[1, :]
        verticalFaces[1, :] = tmp[0, :]
        if self.numberOfVerticalColumns > 0:
            verticalFaces[0, ::self.numberOfVerticalColumns] = tmp[0, ::self.numberOfVerticalColumns]
            verticalFaces[1, ::self.numberOfVerticalColumns] = tmp[1,::self.numberOfVerticalColumns]

        return numerix.concatenate((horizontalFaces, verticalFaces), axis=1)
Example #3
0
    def _createCells(self):
        """
        cells = (front face, back face, left face, right face, bottom face, top face)
        front and back faces are YZ faces
        left and right faces are XZ faces
        top and bottom faces are XY faces
        """
        self.numberOfCells = self.nx * self.ny * self.nz
        
        ## front and back faces
        frontFaces = numerix.arange(self.numberOfYZFaces)
        frontFaces = vector.prune(frontFaces, self.nx + 1, self.nx)
        frontFaces = frontFaces + self.numberOfXYFaces + self.numberOfXZFaces
        backFaces = frontFaces + 1

        ## left and right faces
        leftFaces = numerix.arange(self.nx * self.ny)
        leftFaces = self._repeatWithOffset(leftFaces, self.nx * (self.ny + 1), self.nz)
        leftFaces = numerix.ravel(leftFaces)
        leftFaces = leftFaces + self.numberOfXYFaces
        rightFaces = leftFaces + self.nx

        ## bottom and top faces
        bottomFaces = numerix.arange(self.nx * self.ny * self.nz)
        topFaces = bottomFaces + (self.nx * self.ny)

        return numerix.array((frontFaces, backFaces, leftFaces, rightFaces, bottomFaces, topFaces))
    def createCells(nx, ny, nz, numXYFaces, numXZFaces, numYZFaces):
        """
        cells = (front face, back face, left face, right face, bottom face, top face)
        front and back faces are YZ faces
        left and right faces are XZ faces
        top and bottom faces are XY faces
        """
        ## front and back faces
        frontFaces = numerix.arange(numYZFaces)
        frontFaces = vector.prune(frontFaces, nx + 1, nx)
        frontFaces = frontFaces + numXYFaces + numXZFaces
        backFaces = frontFaces + 1

        ## left and right faces
        leftFaces = numerix.arange(nx * ny)
        leftFaces = _Grid3DBuilder._repeatWithOffset(leftFaces, nx * (ny + 1),
                                                     nz)
        leftFaces = numerix.ravel(leftFaces)
        leftFaces = leftFaces + numXYFaces
        rightFaces = leftFaces + nx

        ## bottom and top faces
        bottomFaces = numerix.arange(nx * ny * nz)
        topFaces = bottomFaces + (nx * ny)

        return numerix.array((frontFaces, backFaces, leftFaces, rightFaces,
                              bottomFaces, topFaces))
Example #5
0
    def createCells(nx, ny, nz, numXYFaces, numXZFaces, numYZFaces):
        """
        cells = (front face, back face, left face, right face, bottom face, top face)
        front and back faces are YZ faces
        left and right faces are XZ faces
        top and bottom faces are XY faces
        """
        ## front and back faces
        frontFaces = numerix.arange(numYZFaces)
        frontFaces = vector.prune(frontFaces, nx + 1, nx)
        frontFaces = frontFaces + numXYFaces + numXZFaces
        backFaces = frontFaces + 1

        ## left and right faces
        leftFaces = numerix.arange(nx * ny)
        leftFaces = _Grid3DBuilder._repeatWithOffset(leftFaces, nx * (ny + 1), nz)
        leftFaces = numerix.ravel(leftFaces)
        leftFaces = leftFaces + numXYFaces
        rightFaces = leftFaces + nx

        ## bottom and top faces
        bottomFaces = numerix.arange(nx * ny * nz)
        topFaces = bottomFaces + (nx * ny)

        return numerix.array((frontFaces, backFaces, leftFaces, rightFaces, bottomFaces, topFaces))
Example #6
0
    def _createFaces(self):
        """
        XY faces are first, then XZ faces, then YZ faces
        """
        ## do the XY faces
        v1 = numerix.arange((self.nx + 1) * (self.ny))
        v1 = vector.prune(v1, self.nx + 1, self.nx)
        v1 = self._repeatWithOffset(v1, (self.nx + 1) * (self.ny + 1), self.nz + 1) 
        v2 = v1 + 1
        v3 = v1 + (self.nx + 2)
        v4 = v1 + (self.nx + 1)
        XYFaces = numerix.array((v1, v2, v3, v4))

        ## do the XZ faces
        v1 = numerix.arange((self.nx + 1) * (self.ny + 1))
        v1 = vector.prune(v1, self.nx + 1, self.nx)
        v1 = self._repeatWithOffset(v1, (self.nx + 1) * (self.ny + 1), self.nz)
        v2 = v1 + 1
        v3 = v1 + ((self.nx + 1)*(self.ny + 1)) + 1
        v4 = v1 + ((self.nx + 1)*(self.ny + 1))
        XZFaces = numerix.array((v1, v2, v3, v4))
        
        ## do the YZ faces
        v1 = numerix.arange((self.nx + 1) * self.ny)
        v1 = self._repeatWithOffset(v1, (self.nx + 1) * (self.ny + 1), self.nz)
        v2 = v1 + (self.nx + 1)
        v3 = v1 + ((self.nx + 1)*(self.ny + 1)) + (self.nx + 1)                                  
        v4 = v1 + ((self.nx + 1)*(self.ny + 1))
        YZFaces = numerix.array((v1, v2, v3, v4))

        ## reverse some of the face orientations to obtain the correct normals
        ##tmp = horizontalFaces.copy()
        ##horizontalFaces[:self.nx, 0] = tmp[:self.nx, 1]
        ##horizontalFaces[:self.nx, 1] = tmp[:self.nx, 0]
        ##tmp = verticalFaces.copy()
        ##verticalFaces[:, 0] = tmp[:, 1]
        ##verticalFaces[:, 1] = tmp[:, 0]
        ##verticalFaces[::(self.nx + 1), 0] = tmp[::(self.nx + 1), 0]
        ##verticalFaces[::(self.nx + 1), 1] = tmp[::(self.nx + 1), 1]

        self.numberOfXYFaces = (self.nx * self.ny * (self.nz + 1))
        self.numberOfXZFaces = (self.nx * (self.ny + 1) * self.nz)
        self.numberOfYZFaces = ((self.nx + 1) * self.ny * self.nz)
        self.numberOfFaces = self.numberOfXYFaces + self.numberOfXZFaces + self.numberOfYZFaces
        
        return numerix.concatenate((XYFaces, XZFaces, YZFaces), axis=1)
Example #7
0
    def _createFaces(self):
        """
        v1, v2 refer to the cells.
        Horizontel faces are first
        """
        v1 = numerix.arange(self.numberOfCornerVertices)
        v2 = v1 + 1
        horizontalFaces = vector.prune(numerix.array((v1, v2)),
                                       self.nx + 1,
                                       self.nx,
                                       axis=1)
        v1 = numerix.arange(self.numberOfCornerVertices - (self.nx + 1))
        v2 = v1 + self.nx + 1
        verticalFaces = numerix.array((v1, v2))

        ## reverse some of the face orientations to obtain the correct normals

        tmp = horizontalFaces.copy()
        horizontalFaces[0, :self.nx] = tmp[1, :self.nx]
        horizontalFaces[1, :self.nx] = tmp[0, :self.nx]

        tmp = verticalFaces.copy()
        verticalFaces[0] = tmp[1]
        verticalFaces[1] = tmp[0]
        verticalFaces[0, ::(self.nx + 1)] = tmp[0, ::(self.nx + 1)]
        verticalFaces[1, ::(self.nx + 1)] = tmp[1, ::(self.nx + 1)]

        ## do the center ones now

        cellCenters = numerix.arange(self.numberOfCornerVertices,
                                     self.numberOfTotalVertices)
        lowerLefts = vector.prune(
            numerix.arange(self.numberOfCornerVertices - (self.nx + 1)),
            self.nx + 1, self.nx)
        lowerRights = lowerLefts + 1
        upperLefts = lowerLefts + self.nx + 1
        upperRights = lowerLefts + self.nx + 2
        lowerLeftFaces = numerix.array((cellCenters, lowerLefts))
        lowerRightFaces = numerix.array((lowerRights, cellCenters))
        upperLeftFaces = numerix.array((cellCenters, upperLefts))
        upperRightFaces = numerix.array((cellCenters, upperRights))
        return numerix.concatenate(
            (horizontalFaces, verticalFaces, lowerLeftFaces, lowerRightFaces,
             upperLeftFaces, upperRightFaces),
            axis=1)
Example #8
0
File: grid2D.py Project: regmi/fipy
 def _createCellsPy(self):
     cellFaceIDs = numerix.zeros((4, self.nx * self.ny))
     faceIDs = numerix.arange(self.numberOfFaces)
     if self.numberOfFaces > 0:
         cellFaceIDs[0,:] = faceIDs[:self.numberOfHorizontalFaces - self.nx]
         cellFaceIDs[2,:] = cellFaceIDs[0,:] + self.nx
         cellFaceIDs[1,:] = vector.prune(faceIDs[self.numberOfHorizontalFaces:], self.numberOfVerticalColumns)
         cellFaceIDs[3,:] = cellFaceIDs[1,:] - 1
     return cellFaceIDs
Example #9
0
 def _createCells(self):
     """
     cells = (f1, f2, f3, f4) going anticlockwise.
     f1 etc. refer to the faces
     """
     bottomFaces = numerix.arange(0, self.numberOfHorizontalFaces - self.nx)
     topFaces = numerix.arange(self.nx, self.numberOfHorizontalFaces)
     leftFaces = vector.prune(numerix.arange(self.numberOfHorizontalFaces, self.numberOfHorizontalFaces + self.numberOfVerticalFaces), self.nx + 1, self.nx)
     rightFaces = vector.prune(numerix.arange(self.numberOfHorizontalFaces, self.numberOfHorizontalFaces + self.numberOfVerticalFaces), self.nx + 1, 0)
     lowerLeftDiagonalFaces = numerix.arange(self.numberOfHorizontalFaces + self.numberOfVerticalFaces, self.numberOfHorizontalFaces + self.numberOfVerticalFaces + self.numberOfEachDiagonalFaces)
     lowerRightDiagonalFaces = lowerLeftDiagonalFaces + self.numberOfEachDiagonalFaces
     upperLeftDiagonalFaces = lowerRightDiagonalFaces + self.numberOfEachDiagonalFaces
     upperRightDiagonalFaces = upperLeftDiagonalFaces + self.numberOfEachDiagonalFaces
     ##faces in arrays, now get the cells
     bottomOfBoxCells = numerix.array([bottomFaces, lowerRightDiagonalFaces, lowerLeftDiagonalFaces])
     rightOfBoxCells = numerix.array([rightFaces, upperRightDiagonalFaces, lowerRightDiagonalFaces])
     topOfBoxCells = numerix.array([topFaces, upperLeftDiagonalFaces, upperRightDiagonalFaces])
     leftOfBoxCells = numerix.array([leftFaces, lowerLeftDiagonalFaces, upperLeftDiagonalFaces])
     return numerix.concatenate((rightOfBoxCells, topOfBoxCells, leftOfBoxCells, bottomOfBoxCells), axis=1)
Example #10
0
    def createFaces(nx, ny, nz):
        """
        XY faces are first, then XZ faces, then YZ faces
        """
        ## do the XY faces
        v1 = numerix.arange((nx + 1) * (ny))
        v1 = vector.prune(v1, nx + 1, nx)
        v1 = _Grid3DBuilder._repeatWithOffset(v1, (nx + 1) * (ny + 1), nz + 1)
        v2 = v1 + 1
        v3 = v1 + (nx + 2)
        v4 = v1 + (nx + 1)
        XYFaces = numerix.array((v1, v2, v3, v4))

        ## do the XZ faces
        v1 = numerix.arange((nx + 1) * (ny + 1))
        v1 = vector.prune(v1, nx + 1, nx)
        v1 = _Grid3DBuilder._repeatWithOffset(v1, (nx + 1) * (ny + 1), nz)
        v2 = v1 + 1
        v3 = v1 + ((nx + 1) * (ny + 1)) + 1
        v4 = v1 + ((nx + 1) * (ny + 1))
        XZFaces = numerix.array((v1, v2, v3, v4))

        ## do the YZ faces
        v1 = numerix.arange((nx + 1) * ny)
        v1 = _Grid3DBuilder._repeatWithOffset(v1, (nx + 1) * (ny + 1), nz)
        v2 = v1 + (nx + 1)
        v3 = v1 + ((nx + 1) * (ny + 1)) + (nx + 1)
        v4 = v1 + ((nx + 1) * (ny + 1))
        YZFaces = numerix.array((v1, v2, v3, v4))

        numberOfXYFaces = nx * ny * (nz + 1)
        numberOfXZFaces = nx * (ny + 1) * nz
        numberOfYZFaces = (nx + 1) * ny * nz
        numberOfFaces = numberOfXYFaces + numberOfXZFaces + numberOfYZFaces

        return (
            [numberOfXYFaces, numberOfXZFaces, numberOfYZFaces, numberOfFaces],
            numerix.concatenate((XYFaces, XZFaces, YZFaces), axis=1),
        )
    def createFaces(nx, ny, nz):
        """
        XY faces are first, then XZ faces, then YZ faces
        """
        ## do the XY faces
        v1 = numerix.arange((nx + 1) * (ny))
        v1 = vector.prune(v1, nx + 1, nx)
        v1 = _Grid3DBuilder._repeatWithOffset(v1, (nx + 1) * (ny + 1), nz + 1)
        v2 = v1 + 1
        v3 = v1 + (nx + 2)
        v4 = v1 + (nx + 1)
        XYFaces = numerix.array((v1, v2, v3, v4))

        ## do the XZ faces
        v1 = numerix.arange((nx + 1) * (ny + 1))
        v1 = vector.prune(v1, nx + 1, nx)
        v1 = _Grid3DBuilder._repeatWithOffset(v1, (nx + 1) * (ny + 1), nz)
        v2 = v1 + 1
        v3 = v1 + ((nx + 1) * (ny + 1)) + 1
        v4 = v1 + ((nx + 1) * (ny + 1))
        XZFaces = numerix.array((v1, v2, v3, v4))

        ## do the YZ faces
        v1 = numerix.arange((nx + 1) * ny)
        v1 = _Grid3DBuilder._repeatWithOffset(v1, (nx + 1) * (ny + 1), nz)
        v2 = v1 + (nx + 1)
        v3 = v1 + ((nx + 1) * (ny + 1)) + (nx + 1)
        v4 = v1 + ((nx + 1) * (ny + 1))
        YZFaces = numerix.array((v1, v2, v3, v4))

        numberOfXYFaces = (nx * ny * (nz + 1))
        numberOfXZFaces = (nx * (ny + 1) * nz)
        numberOfYZFaces = ((nx + 1) * ny * nz)
        numberOfFaces = numberOfXYFaces + numberOfXZFaces + numberOfYZFaces

        return ([
            numberOfXYFaces, numberOfXZFaces, numberOfYZFaces, numberOfFaces
        ], numerix.concatenate((XYFaces, XZFaces, YZFaces), axis=1))
Example #12
0
 def createCells(nx, ny, numFaces, numHorizFaces, numVertCols):
     """
     cells = (f1, f2, f3, f4) going anticlock wise.
     f1 etc. refer to the faces
     """ 
     cellFaceIDs = numerix.zeros((4, nx * ny), 'l')
     faceIDs = numerix.arange(numFaces)
     if numFaces > 0:
         cellFaceIDs[0,:] = faceIDs[:numHorizFaces - nx]
         cellFaceIDs[2,:] = cellFaceIDs[0,:] + nx
         cellFaceIDs[1,:] = vector.prune(faceIDs[numHorizFaces:], 
                                         numVertCols)
         cellFaceIDs[3,:] = cellFaceIDs[1,:] - 1
     return cellFaceIDs
Example #13
0
 def createCells(nx, ny, numFaces, numHorizFaces, numVertCols):
     """
     cells = (f1, f2, f3, f4) going anticlock wise.
     f1 etc. refer to the faces
     """
     cellFaceIDs = numerix.zeros((4, nx * ny), 'l')
     faceIDs = numerix.arange(numFaces)
     if numFaces > 0:
         cellFaceIDs[0, :] = faceIDs[:numHorizFaces - nx]
         cellFaceIDs[2, :] = cellFaceIDs[0, :] + nx
         cellFaceIDs[1, :] = vector.prune(faceIDs[numHorizFaces:],
                                          numVertCols)
         cellFaceIDs[3, :] = cellFaceIDs[1, :] - 1
     return cellFaceIDs
Example #14
0
    def _createFaces(self):
        """
        v1, v2 refer to the cells.
        Horizontal faces are first
        """
        v1 = numerix.arange(self.numberOfCornerVertices)
        v2 = v1 + 1
        horizontalFaces = vector.prune(numerix.array((v1, v2)), self.nx + 1, self.nx, axis=1)
        v1 = numerix.arange(self.numberOfCornerVertices - (self.nx + 1))
        v2 = v1 + self.nx + 1
        verticalFaces =  numerix.array((v1, v2))

        ## reverse some of the face orientations to obtain the correct normals

        tmp = horizontalFaces.copy()
        horizontalFaces[0, :self.nx] = tmp[1, :self.nx]
        horizontalFaces[1, :self.nx] = tmp[0, :self.nx]

        tmp = verticalFaces.copy()
        verticalFaces[0] = tmp[1]
        verticalFaces[1] = tmp[0]
        verticalFaces[0, ::(self.nx + 1)] = tmp[0, ::(self.nx + 1)]
        verticalFaces[1, ::(self.nx + 1)] = tmp[1, ::(self.nx + 1)]

        ## do the center ones now

        cellCenters = numerix.arange(self.numberOfCornerVertices, self.numberOfTotalVertices)
        lowerLefts = vector.prune(numerix.arange(self.numberOfCornerVertices - (self.nx + 1)), self.nx + 1, self.nx)
        lowerRights = lowerLefts + 1
        upperLefts = lowerLefts + self.nx + 1
        upperRights = lowerLefts + self.nx + 2
        lowerLeftFaces = numerix.array((cellCenters, lowerLefts))
        lowerRightFaces = numerix.array((lowerRights, cellCenters))
        upperLeftFaces = numerix.array((cellCenters, upperLefts))
        upperRightFaces = numerix.array((cellCenters, upperRights))
        return numerix.concatenate((horizontalFaces, verticalFaces, lowerLeftFaces, lowerRightFaces, upperLeftFaces, upperRightFaces), axis=1)
Example #15
0
    def createFaces(nx, numVerts, numVertCols):
        """
        v1, v2 refer to the vertices.
        Horizontal faces are first

        Ugly return to avoid side-effects.
        """
        v1 = numerix.arange(numVerts)
        v2 = v1 + 1

        horizontalFaces = vector.prune(numerix.array((v1, v2)),
                                       numVertCols,
                                       nx,
                                       axis=1)

        v1 = numerix.arange(numVerts - numVertCols)
        v2 = v1 + numVertCols
        verticalFaces = numerix.array((v1, v2))

        ## The cell normals must point out of the cell.
        ## The left and bottom faces have only one neighboring cell,
        ## in the 2nd neighbor position (there is nothing in the 1st).
        ##
        ## reverse some of the face orientations to obtain the correct normals

        tmp = horizontalFaces.copy()
        horizontalFaces[0, :nx] = tmp[1, :nx]
        horizontalFaces[1, :nx] = tmp[0, :nx]

        numberOfHorizontalFaces = horizontalFaces.shape[-1]

        tmp = verticalFaces.copy()
        verticalFaces[0, :] = tmp[1, :]
        verticalFaces[1, :] = tmp[0, :]
        if numVertCols > 0:
            verticalFaces[0, ::numVertCols] = tmp[0, ::numVertCols]
            verticalFaces[1, ::numVertCols] = tmp[1, ::numVertCols]

        return (numerix.concatenate((horizontalFaces, verticalFaces),
                                    axis=1), numberOfHorizontalFaces)
Example #16
0
    def createFaces(nx, numVerts, numVertCols):
        """
        v1, v2 refer to the vertices.
        Horizontal faces are first

        Ugly return to avoid side-effects.
        """
        v1 = numerix.arange(numVerts)
        v2 = v1 + 1

        horizontalFaces = vector.prune(numerix.array((v1, v2)), numVertCols, nx, axis=1)

        v1 = numerix.arange(numVerts - numVertCols)
        v2 = v1 + numVertCols
        verticalFaces =  numerix.array((v1, v2))

        ## The cell normals must point out of the cell.
        ## The left and bottom faces have only one neighboring cell,
        ## in the 2nd neighbor position (there is nothing in the 1st).
        ## 
        ## reverse some of the face orientations to obtain the correct normals

        tmp = horizontalFaces.copy()
        horizontalFaces[0,:nx] = tmp[1,:nx]
        horizontalFaces[1,:nx] = tmp[0,:nx]

        numberOfHorizontalFaces = horizontalFaces.shape[-1]

        tmp = verticalFaces.copy()
        verticalFaces[0, :] = tmp[1, :]
        verticalFaces[1, :] = tmp[0, :]
        if numVertCols > 0:
            verticalFaces[0, ::numVertCols] = tmp[0, ::numVertCols]
            verticalFaces[1, ::numVertCols] = tmp[1,::numVertCols]

        return (numerix.concatenate((horizontalFaces, verticalFaces), axis=1),
                numberOfHorizontalFaces)