Beispiel #1
0
    def _buildMatrix(self, var, SparseMatrix, boundaryConditions=(), dt=1., equation=None):
        """Implicit portion considers
        """

        mesh = var.getMesh()
        id1, id2 = mesh._getAdjacentCellIDs()
        interiorFaces = numerix.nonzero(mesh.getInteriorFaces())[0]
        
        id1 = numerix.take(id1, interiorFaces)
        id2 = numerix.take(id2, interiorFaces)
        
        N = len(var)
        b = numerix.zeros((N),'d')
        L = SparseMatrix(size = N)

        if equation is not None:
            from fipy.tools.numerix import sign, add
            self._diagonalSign.setValue(sign(add.reduce(equation.matrix.takeDiagonal())))
        else:
            self._diagonalSign.setValue(1)

        weight = self._getWeight(mesh, equation=equation)

        if weight.has_key('implicit'):
            self._implicitBuildMatrix(SparseMatrix, L, id1, id2, b, weight['implicit'], mesh, boundaryConditions, interiorFaces, dt)

        if weight.has_key('explicit'):
            self._explicitBuildMatrix(SparseMatrix, var.getOld(), id1, id2, b, weight['explicit'], mesh, boundaryConditions, interiorFaces, dt)

        return (L, b)
Beispiel #2
0
    def _buildMatrix(self, var, SparseMatrix, boundaryConditions=(), dt=1., equation=None):
        N = len(var)
        b = numerix.zeros((N),'d')
        L = SparseMatrix(size=N)
        
        # The sign of the matrix diagonal doesn't seem likely to change
        # after initialization, but who knows?
        if equation is not None:
            from fipy.tools.numerix import sign, add
            self._diagonalSign.setValue(sign(add.reduce(equation.matrix.takeDiagonal())))
        else:
            self._diagonalSign.setValue(1)
            
        coeffVectors = self._getCoeffVectors(var=var)

        inline._optionalInline(self._buildMatrixIn, self._buildMatrixPy, L, var.getOld(), b, dt, coeffVectors)
        
        return (L, b)