Пример #1
0
 def _calcCellDistAndVec(self):
     tmp = numerix.take(self._cellCenters, self.faceCellIDs, axis=1)
     tmp = tmp[...,1,:] - tmp[...,0,:]
     tmp = MA.filled(MA.where(MA.getmaskarray(tmp), self._cellToFaceDistanceVectors[:,0], tmp))
     cellDistanceVectors = tmp
     cellDistances = MA.filled(MA.sqrt(MA.sum(tmp * tmp, 0)))
     return cellDistances, cellDistanceVectors
Пример #2
0
 def _cellToCellIDsFilled(self):
     N = self.numberOfCells
     M = self._maxFacesPerCell
     cellIDs = numerix.repeat(numerix.arange(N)[numerix.newaxis, ...],
                              M,
                              axis=0)
     cellToCellIDs = self._cellToCellIDs
     return MA.where(MA.getmaskarray(cellToCellIDs), cellIDs, cellToCellIDs)
Пример #3
0
    def _calcFaceCellToCellNormals(self):
        faceCellCentersUp = numerix.take(self._cellCenters, self.faceCellIDs[1], axis=1)
        faceCellCentersDown = numerix.take(self._cellCenters, self.faceCellIDs[0], axis=1)
        faceCellCentersUp = numerix.where(MA.getmaskarray(faceCellCentersUp),
                                          self._faceCenters,
                                          faceCellCentersUp)

        diff = faceCellCentersDown - faceCellCentersUp
        mag = numerix.sqrt(numerix.sum(diff**2))
        faceCellToCellNormals = diff / numerix.resize(mag, (self.dim, len(mag)))

        orientation = 1 - 2 * (numerix.dot(self.faceNormals, faceCellToCellNormals) < 0)
        return faceCellToCellNormals * orientation
Пример #4
0
Файл: mesh.py Проект: regmi/fipy
 def _calcFaceAreas(self):
     faceVertexIDs = MA.filled(self.faceVertexIDs, -1)
     substitute = numerix.repeat(faceVertexIDs[numerix.newaxis, 0], 
                                 faceVertexIDs.shape[0], axis=0)
     faceVertexIDs = numerix.where(MA.getmaskarray(self.faceVertexIDs), substitute, faceVertexIDs)
     faceVertexCoords = numerix.take(self.vertexCoords, faceVertexIDs, axis=1)
     faceOrigins = numerix.repeat(faceVertexCoords[:,0], faceVertexIDs.shape[0], axis=0)
     faceOrigins = numerix.reshape(faceOrigins, MA.shape(faceVertexCoords))
     faceVertexCoords = faceVertexCoords - faceOrigins
     left = range(faceVertexIDs.shape[0])
     right = left[1:] + [left[0]]
     cross = numerix.sum(numerix.cross(faceVertexCoords, numerix.take(faceVertexCoords, right, 1), axis=0), 1)
     self.faceAreas = numerix.sqrtDot(cross, cross) / 2.
Пример #5
0
    def _calcFaceCenters(self):
        maskedFaceVertexIDs = MA.filled(self.faceVertexIDs, 0)

        faceVertexCoords = numerix.take(self.vertexCoords, maskedFaceVertexIDs, axis=1)

        if MA.getmask(self.faceVertexIDs) is False:
            faceVertexCoordsMask = numerix.zeros(numerix.shape(faceVertexCoords), 'l')
        else:
            faceVertexCoordsMask = \
              numerix.repeat(MA.getmaskarray(self.faceVertexIDs)[numerix.newaxis,...], 
                             self.dim, axis=0)
            
        faceVertexCoords = MA.array(data=faceVertexCoords, mask=faceVertexCoordsMask)

        return MA.filled(MA.average(faceVertexCoords, axis=1))
Пример #6
0
 def _calcFaceAreas(self):
     faceVertexIDs = MA.filled(self.faceVertexIDs, -1)
     substitute = numerix.repeat(faceVertexIDs[numerix.newaxis, 0], 
                                 faceVertexIDs.shape[0], axis=0)
     faceVertexIDs = numerix.where(MA.getmaskarray(self.faceVertexIDs), 
                                   substitute, faceVertexIDs)
     faceVertexCoords = numerix.take(self.vertexCoords, faceVertexIDs, axis=1)
     faceOrigins = numerix.repeat(faceVertexCoords[:,0], faceVertexIDs.shape[0], axis=0)
     faceOrigins = numerix.reshape(faceOrigins, MA.shape(faceVertexCoords))
     faceVertexCoords = faceVertexCoords - faceOrigins
     left = range(faceVertexIDs.shape[0])
     right = left[1:] + [left[0]]
     cross = numerix.sum(numerix.cross(faceVertexCoords, 
                                       numerix.take(faceVertexCoords, right, 1), 
                                       axis=0), 
                         1)
     return numerix.sqrtDot(cross, cross) / 2.
Пример #7
0
    def _cellVertexIDs(self):
        ## Get all the vertices from all the faces for each cell
        cellFaceVertices = numerix.take(self.faceVertexIDs, self.cellFaceIDs, axis=1)

        ## get a sorted list of vertices for each cell 
        cellVertexIDs = numerix.reshape(cellFaceVertices, (-1, self.numberOfCells))
        cellVertexIDs = MA.sort(cellVertexIDs, axis=0, fill_value=-1)

        cellVertexIDs = MA.sort(MA.concatenate((cellVertexIDs[-1, numerix.newaxis], 
                                                MA.masked_where(cellVertexIDs[:-1] 
                                                                == cellVertexIDs[1:], 
                                                                cellVertexIDs[:-1]))), 
                                axis=0, fill_value=-1)
        
        ## resize the array to remove extra masked values
        if cellVertexIDs.shape[-1] == 0:
            length = 0
        else:
            length = min(numerix.sum(MA.getmaskarray(cellVertexIDs), axis=0))
        return cellVertexIDs[length:][::-1]
Пример #8
0
 def _adjacentCellIDs(self):
     faceCellIDs = self.faceCellIDs
     return (MA.where(MA.getmaskarray(faceCellIDs[0]), faceCellIDs[1], faceCellIDs[0]).filled(),
             MA.where(MA.getmaskarray(faceCellIDs[1]), faceCellIDs[0], faceCellIDs[1]).filled())
Пример #9
0
 def _cellToCellIDsFilled(self):
     N = self.numberOfCells
     M = self._maxFacesPerCell
     cellIDs = numerix.repeat(numerix.arange(N)[numerix.newaxis, ...], M, axis=0)
     cellToCellIDs = self._cellToCellIDs
     return MA.where(MA.getmaskarray(cellToCellIDs), cellIDs, cellToCellIDs)
Пример #10
0
 def _adjacentCellIDs(self):
     faceCellIDs = self.faceCellIDs
     return (MA.where(MA.getmaskarray(faceCellIDs[0]), faceCellIDs[1], faceCellIDs[0]).filled(),
             MA.where(MA.getmaskarray(faceCellIDs[1]), faceCellIDs[0], faceCellIDs[1]).filled())
Пример #11
0
 def _calcAdjacentCellIDs(self):
     return (MA.filled(self.faceCellIDs[0]),
             MA.filled(
                 MA.where(MA.getmaskarray(self.faceCellIDs[1]),
                          self.faceCellIDs[0], self.faceCellIDs[1])))
Пример #12
0
 def _calcAdjacentCellIDs(self):
     return (MA.filled(self.faceCellIDs[0]), 
                       MA.filled(MA.where(MA.getmaskarray(self.faceCellIDs[1]), 
                           self.faceCellIDs[0], 
                                          self.faceCellIDs[1])))
Пример #13
0
Файл: mesh.py Проект: regmi/fipy
 def _calcCellToCellIDsFilled(self):
     N = self.getNumberOfCells()
     M = self._getMaxFacesPerCell()
     cellIDs = numerix.repeat(numerix.arange(N)[numerix.newaxis, ...], M, axis=0)
     cellToCellIDs = self._getCellToCellIDs()
     self.cellToCellIDsFilled = MA.where(MA.getmaskarray(cellToCellIDs), cellIDs, cellToCellIDs)