Beispiel #1
0
    def _buildMatrix(self, var, SparseMatrix, boundaryCondtions=(), dt=None, equation=None):

        oldArray = var.getOld()

        mesh = var.getMesh()
        NCells = mesh.getNumberOfCells()
        NCellFaces = mesh._getMaxFacesPerCell()

        cellValues = numerix.repeat(oldArray[numerix.newaxis, ...], NCellFaces, axis = 0)
        
        cellIDs = numerix.repeat(numerix.arange(NCells)[numerix.newaxis, ...], NCellFaces, axis = 0)
        cellToCellIDs = mesh._getCellToCellIDs()

        if NCells > 0:
            cellToCellIDs = MA.where(MA.getmask(cellToCellIDs), cellIDs, cellToCellIDs) 

            adjacentValues = numerix.take(oldArray, cellToCellIDs)

            differences = self._getDifferences(adjacentValues, cellValues, oldArray, cellToCellIDs, mesh)
            differences = MA.filled(differences, 0)
            
            minsq = numerix.sqrt(numerix.sum(numerix.minimum(differences, numerix.zeros((NCellFaces, NCells)))**2, axis=0))
            maxsq = numerix.sqrt(numerix.sum(numerix.maximum(differences, numerix.zeros((NCellFaces, NCells)))**2, axis=0))

            coeff = numerix.array(self._getGeomCoeff(mesh))

            coeffXdiffereneces = coeff * ((coeff > 0.) * minsq + (coeff < 0.) * maxsq)
        else:
            coeffXdiffereneces = 0.

        return (SparseMatrix(mesh=var.getMesh()), -coeffXdiffereneces * mesh.getCellVolumes())
Beispiel #2
0
 def _calcValue_(self, alpha, id1, id2):
     cell1 = numerix.take(self.var, id1, axis=-1)
     cell2 = numerix.take(self.var, id2, axis=-1)
     return numerix.where((cell1 > 0) & (cell2 > 0),
                          numerix.minimum(cell1, cell2),
                          numerix.where((cell1 < 0) & (cell2 < 0),
                                        numerix.maximum(cell1, cell2), 0))
    def _getOldAdjacentValues(self, oldArray, id1, id2, dt):
        oldArray1, oldArray2 = ExplicitUpwindConvectionTerm._getOldAdjacentValues(self, oldArray, id1, id2, dt)
        
        mesh = oldArray.getMesh()

        interiorIDs = numerix.nonzero(mesh.getInteriorFaces())[0]
        interiorFaceAreas = numerix.take(mesh._getFaceAreas(), interiorIDs)
        interiorFaceNormals = numerix.take(mesh._getOrientedFaceNormals(), interiorIDs, axis=-1)
        
        # Courant-Friedrichs-Levy number
        interiorCFL = abs(numerix.take(self._getGeomCoeff(mesh), interiorIDs)) * dt
        
        gradUpwind = (oldArray2 - oldArray1) / numerix.take(mesh._getCellDistances(), interiorIDs)
        
        vol1 = numerix.take(mesh.getCellVolumes(), id1)
        self.CFL = interiorCFL / vol1
        
        oldArray1 += 0.5 * self._getGradient(numerix.dot(numerix.take(oldArray.getGrad(), id1, axis=-1), interiorFaceNormals), gradUpwind) \
            * (vol1 - interiorCFL) / interiorFaceAreas

        vol2 = numerix.take(mesh.getCellVolumes(), id2)
        
        self.CFL = numerix.maximum(interiorCFL / vol2, self.CFL)

        oldArray2 += 0.5 * self._getGradient(numerix.dot(numerix.take(oldArray.getGrad(), id2, axis=-1), -interiorFaceNormals), -gradUpwind) \
            * (vol2 - interiorCFL) / interiorFaceAreas
        
        return oldArray1, oldArray2
Beispiel #4
0
    def _buildMatrix(self, var, SparseMatrix, boundaryConditions=(), dt=None, equation=None, transientGeomCoeff=None, diffusionGeomCoeff=None):

        oldArray = var.old

        mesh = var.mesh
        NCells = mesh.numberOfCells
        NCellFaces = mesh._maxFacesPerCell

        cellValues = numerix.repeat(oldArray[numerix.newaxis, ...], NCellFaces, axis = 0)

        cellIDs = numerix.repeat(numerix.arange(NCells)[numerix.newaxis, ...], NCellFaces, axis = 0)
        cellToCellIDs = mesh._cellToCellIDs

        if NCells > 0:
            cellToCellIDs = MA.where(MA.getmask(cellToCellIDs), cellIDs, cellToCellIDs) 

            adjacentValues = numerix.take(oldArray, cellToCellIDs)

            differences = self._getDifferences(adjacentValues, cellValues, oldArray, cellToCellIDs, mesh)
            differences = MA.filled(differences, 0)

            minsq = numerix.sqrt(numerix.sum(numerix.minimum(differences, numerix.zeros((NCellFaces, NCells), 'l'))**2, axis=0))
            maxsq = numerix.sqrt(numerix.sum(numerix.maximum(differences, numerix.zeros((NCellFaces, NCells), 'l'))**2, axis=0))

            coeff = numerix.array(self._getGeomCoeff(var))

            coeffXdiffereneces = coeff * ((coeff > 0.) * minsq + (coeff < 0.) * maxsq)
        else:
            coeffXdiffereneces = 0.

        return (var, SparseMatrix(mesh=var.mesh), -coeffXdiffereneces * mesh.cellVolumes)
    def _buildMatrix(self, var, SparseMatrix, boundaryConditions=(), dt=None, equation=None, transientGeomCoeff=None, diffusionGeomCoeff=None):

        oldArray = var.old

        mesh = var.mesh
        NCells = mesh.numberOfCells
        NCellFaces = mesh._maxFacesPerCell

        cellValues = numerix.repeat(oldArray[numerix.newaxis, ...], NCellFaces, axis = 0)

        cellIDs = numerix.repeat(numerix.arange(NCells)[numerix.newaxis, ...], NCellFaces, axis = 0)
        cellToCellIDs = mesh._cellToCellIDs

        if NCells > 0:
            cellToCellIDs = MA.where(MA.getmask(cellToCellIDs), cellIDs, cellToCellIDs)

            adjacentValues = numerix.take(oldArray, cellToCellIDs)

            differences = self._getDifferences(adjacentValues, cellValues, oldArray, cellToCellIDs, mesh)
            differences = MA.filled(differences, 0)

            minsq = numerix.sqrt(numerix.sum(numerix.minimum(differences, numerix.zeros((NCellFaces, NCells), 'l'))**2, axis=0))
            maxsq = numerix.sqrt(numerix.sum(numerix.maximum(differences, numerix.zeros((NCellFaces, NCells), 'l'))**2, axis=0))

            coeff = numerix.array(self._getGeomCoeff(var))

            coeffXdifferences = coeff * ((coeff > 0.) * minsq + (coeff < 0.) * maxsq)
        else:
            coeffXdifferences = 0.

        return (var, SparseMatrix(mesh=var.mesh), -coeffXdifferences * mesh.cellVolumes)
 def _calcValue_(self, alpha, id1, id2):
     cell1 = numerix.take(self.var,id1, axis=-1)
     cell2 = numerix.take(self.var,id2, axis=-1)
     return numerix.where((cell1 > 0) & (cell2 > 0),
                          numerix.minimum(cell1, cell2),
                          numerix.where((cell1 < 0) & (cell2 < 0),
                                        numerix.maximum(cell1, cell2),
                                        0))
Beispiel #7
0
   def _getNonOrthogonality(self):
       
       exteriorFaceArray = numerix.zeros((self.faceCellIDs.shape[1],))
       numerix.put(exteriorFaceArray, numerix.nonzero(self.getExteriorFaces()), 1)
       unmaskedFaceCellIDs = MA.filled(self.faceCellIDs, 0) ## what we put in for the "fill" doesn't matter because only exterior faces have anything masked, and exterior faces have their displacement vectors set to zero.
       ## if it's an exterior face, make the "displacement vector" equal to zero so the cross product will be zero.
   
       faceDisplacementVectors = numerix.where(numerix.array(zip(exteriorFaceArray, exteriorFaceArray)), 0.0, numerix.take(self._getCellCenters().swapaxes(0,1), unmaskedFaceCellIDs[1, :]) - numerix.take(self._getCellCenters().swapaxes(0,1), unmaskedFaceCellIDs[0, :])).swapaxes(0,1)
       faceCrossProducts = (faceDisplacementVectors[0, :] * self.faceNormals[1, :]) - (faceDisplacementVectors[1, :] * self.faceNormals[0, :])
       faceDisplacementVectorLengths = numerix.maximum(((faceDisplacementVectors[0, :] ** 2) + (faceDisplacementVectors[1, :] ** 2)) ** 0.5, 1.e-100)
       faceWeightedNonOrthogonalities = abs(faceCrossProducts / faceDisplacementVectorLengths) * self.faceAreas
       cellFaceWeightedNonOrthogonalities = numerix.take(faceWeightedNonOrthogonalities, self.cellFaceIDs)
       cellFaceAreas = numerix.take(self.faceAreas, self.cellFaceIDs)
       cellTotalWeightedValues = numerix.add.reduce(cellFaceWeightedNonOrthogonalities, axis = 0)  
       cellTotalFaceAreas = numerix.add.reduce(cellFaceAreas, axis = 0)
 
       return (cellTotalWeightedValues / cellTotalFaceAreas)
Beispiel #8
0
    def _nonOrthogonality(self):

        exteriorFaceArray = numerix.zeros((self.faceCellIDs.shape[1], ), 'l')
        numerix.put(exteriorFaceArray, numerix.nonzero(self.exteriorFaces), 1)
        unmaskedFaceCellIDs = MA.filled(self.faceCellIDs, 0)
        # what we put in for the "fill" doesn't matter because only exterior
        # faces have anything masked, and exterior faces have their displacement
        # vectors set to zero.
        #
        # if it's an exterior face, make the "displacement vector" equal to zero
        # so the cross product will be zero.

        faceDisplacementVectors = \
          numerix.where(numerix.array(zip(exteriorFaceArray, exteriorFaceArray)),
                        0.0,
                        numerix.take(self._scaledCellCenters.swapaxes(0,1),
                                     unmaskedFaceCellIDs[1, :]) \
                          - numerix.take(self._scaledCellCenters.swapaxes(0,1),
                        unmaskedFaceCellIDs[0, :]))

        faceDisplacementVectors = faceDisplacementVectors.swapaxes(0, 1)

        faceCrossProducts = (faceDisplacementVectors[0, :] * self.faceNormals[1,:]) \
          - (faceDisplacementVectors[1, :] * self.faceNormals[0, :])

        faceDisplacementVectorLengths = numerix.maximum(((faceDisplacementVectors[0, :] ** 2) \
          + (faceDisplacementVectors[1, :] ** 2)) ** 0.5, 1.e-100)

        faceWeightedNonOrthogonalities = abs(
            faceCrossProducts /
            faceDisplacementVectorLengths) * self._faceAreas

        cellFaceWeightedNonOrthogonalities = numerix.take(
            faceWeightedNonOrthogonalities, self.cellFaceIDs)

        cellFaceAreas = numerix.take(self._faceAreas, self.cellFaceIDs)
        cellTotalWeightedValues = numerix.add.reduce(
            cellFaceWeightedNonOrthogonalities, axis=0)
        cellTotalFaceAreas = numerix.add.reduce(cellFaceAreas, axis=0)

        return (cellTotalWeightedValues / cellTotalFaceAreas)