Пример #1
0
    def _calcValue(self):

        Nfaces = self.mesh.numberOfFaces
        M = self.mesh._maxFacesPerCell
        dim = self.mesh.dim
        cellFaceIDs = self.mesh.cellFaceIDs

        faceNormalAreas = self.distanceVar._levelSetNormals * self.mesh._faceAreas

        cellFaceNormalAreas = numerix.array(MA.filled(numerix.take(faceNormalAreas, cellFaceIDs, axis=-1), 0))
        norms = numerix.array(MA.filled(MA.array(self.mesh._cellNormals), 0))

        alpha = numerix.dot(cellFaceNormalAreas, norms)
        alpha = numerix.where(alpha > 0, alpha, 0)

        alphasum = numerix.sum(alpha, axis=0)
        alphasum += (alphasum < 1e-100) * 1.0
        alpha = alpha / alphasum

        phi = numerix.repeat(self.distanceVar[numerix.newaxis, ...], M, axis=0)
        alpha = numerix.where(phi > 0., 0, alpha)

        volumes = numerix.array(self.mesh.cellVolumes)
        alpha = alpha * volumes * norms

        value = numerix.zeros((dim, Nfaces), 'd')

        vector._putAdd(value, cellFaceIDs, alpha, mask=MA.getmask(MA.array(cellFaceIDs)))

##         value = numerix.reshape(value, (dim, Nfaces, dim))

        return -value / self.mesh._faceAreas
Пример #2
0
 def _numberOfFacesPerCell(self):
     cellFaceIDs = self.cellFaceIDs
     if isinstance(cellFaceIDs, type(MA.array(0))):
         ## bug in count returns float values when there is no mask
         return numerix.array(cellFaceIDs.count(axis=0), 'l')
     else:
         return self._maxFacesPerCell * numerix.ones(cellFaceIDs.shape[-1], 'l')
Пример #3
0
 def _cellToCellIDs(self):
     c1 = numerix.arange(self.numberOfCells)
     ids = MA.array((c1 - 1, c1 + 1))
     if self.numberOfCells > 0:
         ids[0, 0] = MA.masked
         ids[1, -1] = MA.masked
     return ids
Пример #4
0
 def _numberOfFacesPerCell(self):
     cellFaceIDs = self.cellFaceIDs
     if isinstance(cellFaceIDs, type(MA.array(0))):
         ## bug in count returns float values when there is no mask
         return numerix.array(cellFaceIDs.count(axis=0), 'l')
     else:
         return self._maxFacesPerCell * numerix.ones(cellFaceIDs.shape[-1], 'l')
Пример #5
0
Файл: mesh.py Проект: regmi/fipy
 def _getNumberOfFacesPerCell(self):
     cellFaceIDs = self._getCellFaceIDs()
     if type(cellFaceIDs) is type(MA.array(0)):
         ## bug in count returns float values when there is no mask
         return numerix.array(cellFaceIDs.count(axis=0), 'l')
     else:
         return self._getMaxFacesPerCell() * numerix.ones(cellFaceIDs.shape[-1], 'l')
Пример #6
0
 def _cellFaceIDs(self):
     return MA.array(_Grid3DBuilder.createCells(self.nx,
                                                self.ny,
                                                self.nz,
                                                self.numberOfXYFaces,
                                                self.numberOfXZFaces,
                                                self.numberOfYZFaces))
Пример #7
0
 def _cellFaceIDs(self):
     return MA.array(_Grid3DBuilder.createCells(self.nx,
                                                self.ny,
                                                self.nz,
                                                self.numberOfXYFaces,
                                                self.numberOfXZFaces,
                                                self.numberOfYZFaces))
Пример #8
0
 def _getCellToCellIDs(self):
     c1 = numerix.arange(self.numberOfCells)
     ids = MA.array((c1 - 1, c1 + 1))
     if self.numberOfCells > 0:
         ids[0, 0] = MA.masked
         ids[1, -1] = MA.masked
     return ids
Пример #9
0
 def faceCellIDs(self):
     c1 = numerix.arange(self.numberOfFaces)
     ids = MA.array((c1 - 1, c1))
     if self.numberOfFaces > 0:
         ids[0, 0] = ids[1, 0]
         ids[1, 0] = MA.masked
         ids[1, -1] = MA.masked
     return ids
Пример #10
0
 def getFaceCellIDs(self):
     c1 = numerix.arange(self.numberOfFaces)
     ids = MA.array((c1 - 1, c1))
     if self.numberOfFaces > 0:
         ids[0, 0] = ids[1, 0]
         ids[1, 0] = MA.masked
         ids[1, -1] = MA.masked
     return ids
Пример #11
0
    def _calcFaceCellIDs(self):
        array = MA.array(MA.indices(self.cellFaceIDs.shape, 'l')[1],
                         mask=MA.getmask(self.cellFaceIDs))
        faceCellIDs = MA.zeros((2, self.numberOfFaces), 'l')

        ## Nasty bug: MA.put(arr, ids, values) fills its ids and
        ## values arguments when masked!  This was not the behavior
        ## that was assumed when used below.  It was only working
        ## because the old fill value was 0 and the first element of
        ## the array needed to be 0 since the cell's face was
        ## 0. numerix.put() has been changed to deal with this
        ## properly.

        ##         MA.put(firstRow, cellFaceIDsFlat[::-1], array[::-1])
        ##         MA.put(secondRow, cellFaceIDsFlat, array)
        firstRow = faceCellIDs[0]
        secondRow = faceCellIDs[1]

        numerix.put(firstRow, self.cellFaceIDs[::-1, ::-1], array[::-1, ::-1])
        numerix.put(secondRow, self.cellFaceIDs, array)

        mask = ((False, ) * self.numberOfFaces, (firstRow == secondRow))
        return MA.sort(MA.array(faceCellIDs, mask=mask), axis=0)
Пример #12
0
Файл: mesh.py Проект: regmi/fipy
    def _calcFaceCellIDs(self):
        array = MA.array(MA.indices(self.cellFaceIDs.shape, 'l')[1], 
                         mask=MA.getmask(self.cellFaceIDs))
        self.faceCellIDs = MA.zeros((2, self.numberOfFaces), 'l')

        ## Nasty bug: MA.put(arr, ids, values) fills its ids and
        ## values arguments when masked!  This was not the behavior
        ## that was assumed when used below.  It was only working
        ## because the old fill value was 0 and the first element of
        ## the array needed to be 0 since the cell's face was
        ## 0. numerix.put() has been changed to deal with this
        ## properly.

##         MA.put(firstRow, cellFaceIDsFlat[::-1], array[::-1])
##         MA.put(secondRow, cellFaceIDsFlat, array)
        firstRow = self.faceCellIDs[0]
        secondRow = self.faceCellIDs[1]
        numerix.put(firstRow, self.cellFaceIDs[::-1,::-1], array[::-1,::-1])
        numerix.put(secondRow, self.cellFaceIDs, array)
        
        mask = ((False,) * self.numberOfFaces, (firstRow == secondRow))
        self.faceCellIDs = MA.sort(MA.array(self.faceCellIDs, mask = mask),
                                   axis=0)
Пример #13
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))
Пример #14
0
 def _cellAreaProjections(self):
     return MA.array(self.cellNormals) * self.cellAreas
Пример #15
0
 def _cellAreaProjections(self):
     return MA.array(self.cellNormals) * self.cellAreas
Пример #16
0
Файл: mesh.py Проект: regmi/fipy
    def _getAddedMeshValues(self, other, smallNumber):
        """
        Returns a `dictionary` with 3 elements: the new mesh vertexCoords, faceVertexIDs, and cellFaceIDs.
        """

        other = other._getConcatenableMesh()

        selfNumFaces = self.faceVertexIDs.shape[-1]
        selfNumVertices = self.vertexCoords.shape[-1]
        otherNumFaces = other.faceVertexIDs.shape[-1]
        otherNumVertices = other.vertexCoords.shape[-1]
        ## check dimensions
        if(self.vertexCoords.shape[0] != other.vertexCoords.shape[0]):
            raise MeshAdditionError, "Dimensions do not match"
        ## compute vertex correlates
        vertexCorrelates = {}
        for i in range(selfNumVertices):
            for j in range(otherNumVertices):
                diff = self.vertexCoords[...,i] - other.vertexCoords[...,j]
                diff = numerix.array(diff)
                if (sum(diff ** 2) < smallNumber):
                    vertexCorrelates[j] = i
        if (self._getNumberOfVertices() > 0 and other._getNumberOfVertices() > 0 and vertexCorrelates == {}):
            raise MeshAdditionError, "Vertices are not aligned"

        
         
        ## compute face correlates
        faceCorrelates = {}
        for i in range(otherNumFaces):
##          Seems to be overwriting other.faceVertexIDs with new numpy
##            currFace = other.faceVertexIDs[i]
##            currFace = other.faceVertexIDs[...,i].copy()
##          Changed this again as numpy 1.0.4 seems to have no copy method for
##          masked arrays.
            try:
                currFace = other.faceVertexIDs[...,i].copy()
            except:
                currFace = MA.array(other.faceVertexIDs[...,i], mask=MA.getmask(other.faceVertexIDs[...,i]))

            keepGoing = 1
            currIndex = 0 
            for item in currFace:
                if(vertexCorrelates.has_key(item)):
                    currFace[currIndex] = vertexCorrelates[item]
                    currIndex = currIndex + 1
                else:
                    keepGoing = 0
            if(keepGoing == 1):
                for j in range(selfNumFaces):
                    if (self._equalExceptOrder(currFace, self.faceVertexIDs[...,j])):
                        faceCorrelates[i] = j
        if (self._getNumberOfFaces() > 0 and other._getNumberOfFaces() > 0 and faceCorrelates == {}):
            raise MeshAdditionError, "Faces are not aligned"
        
        faceIndicesToAdd = ()
        for i in range(otherNumFaces):
            if(not faceCorrelates.has_key(i)):
                faceIndicesToAdd = faceIndicesToAdd + (i,)
        vertexIndicesToAdd = ()
        for i in range(otherNumVertices):
            if(not vertexCorrelates.has_key(i)):
                vertexIndicesToAdd = vertexIndicesToAdd + (i,)

        ##compute the full face and vertex correlation list
        a = selfNumFaces
        for i in faceIndicesToAdd:
            faceCorrelates[i] = a
            a = a + 1
        b = selfNumVertices
        for i in vertexIndicesToAdd:
            vertexCorrelates[i] = b
            b = b + 1

        ## compute what the cells are that we need to add
        cellsToAdd = numerix.ones((self.cellFaceIDs.shape[0], other.cellFaceIDs.shape[-1]))
        cellsToAdd = -1 * cellsToAdd

        for j in range(other.cellFaceIDs.shape[-1]):
            for i in range(other.cellFaceIDs.shape[0]):
                cellsToAdd[i, j] = faceCorrelates[other.cellFaceIDs[i, j]]

        cellsToAdd = MA.masked_values(cellsToAdd, -1)


        ## compute what the faces are that we need to add
        facesToAdd = numerix.take(other.faceVertexIDs, faceIndicesToAdd, axis=1)

        for j in range(facesToAdd.shape[-1]):
            for i in range(facesToAdd.shape[0]):
                facesToAdd[i, j] = vertexCorrelates[facesToAdd[i, j]]

        ## compute what the vertices are that we need to add
        verticesToAdd = numerix.take(other.vertexCoords, vertexIndicesToAdd, axis=1)

        return {
            'vertexCoords': numerix.concatenate((self.vertexCoords, verticesToAdd), axis=1), 
            'faceVertexIDs': numerix.concatenate((self.faceVertexIDs, facesToAdd), axis=1), 
            'cellFaceIDs': MA.concatenate((self.cellFaceIDs, cellsToAdd), axis=1)
            }
Пример #17
0
 def _cellFaceIDs(self):
     return MA.array(_Grid1DBuilder.createCells(self.nx))
Пример #18
0
 def _cellFaceIDs(self):
     return MA.array(_Grid1DBuilder.createCells(self.nx))
Пример #19
0
 def _getCellAreaProjections(self):
     return MA.array(self._getCellNormals())
Пример #20
0
 def _getCellFaceIDs(self):
     return MA.array(self._createCells())