Example #1
0
    def _verifyVar(self, var):
        if var is not None:
            raise SolutionVariableNumberError('The solution variable should not be specified.')

        if len(self._vars) != len(self._uncoupledTerms):
            raise SolutionVariableNumberError

        return _AbstractBinaryTerm._verifyVar(self, _CoupledCellVariable(self._vars))
Example #2
0
    def _verifyVar(self, var):
        if var is not None:
            raise SolutionVariableNumberError('The solution variable should not be specified.')

        if len(self._vars) != len(self._uncoupledTerms):
            raise SolutionVariableNumberError

        return _AbstractBinaryTerm._verifyVar(self, _CoupledCellVariable(self._vars))
    def _buildAndAddMatrices(self,
                             var,
                             SparseMatrix,
                             boundaryConditions=(),
                             dt=None,
                             transientGeomCoeff=None,
                             diffusionGeomCoeff=None,
                             buildExplicitIfOther=False):
        """Build matrices of constituent Terms and collect them

        Only called at top-level by `_prepareLinearSystem()`
        
        """

        from fipy.matrices.offsetSparseMatrix import OffsetSparseMatrix
        SparseMatrix = OffsetSparseMatrix(SparseMatrix=SparseMatrix,
                                          numberOfVariables=len(self._vars),
                                          numberOfEquations=len(
                                              self._uncoupledTerms))
        matrix = SparseMatrix(mesh=var.mesh)
        RHSvectors = []

        for equationIndex, uncoupledTerm in enumerate(self._uncoupledTerms):

            SparseMatrix.equationIndex = equationIndex
            termRHSvector = 0
            termMatrix = SparseMatrix(mesh=var.mesh)

            for varIndex, tmpVar in enumerate(var.vars):

                SparseMatrix.varIndex = varIndex

                tmpVar, tmpMatrix, tmpRHSvector = uncoupledTerm._buildAndAddMatrices(
                    tmpVar,
                    SparseMatrix,
                    boundaryConditions=(),
                    dt=dt,
                    transientGeomCoeff=uncoupledTerm._getTransientGeomCoeff(
                        tmpVar),
                    diffusionGeomCoeff=uncoupledTerm._getDiffusionGeomCoeff(
                        tmpVar),
                    buildExplicitIfOther=buildExplicitIfOther)

                termMatrix += tmpMatrix
                termRHSvector += tmpRHSvector

            uncoupledTerm._buildCache(termMatrix, termRHSvector)
            RHSvectors += [CellVariable(value=termRHSvector, mesh=var.mesh)]
            matrix += termMatrix

        return (var, matrix, _CoupledCellVariable(RHSvectors))
Example #4
0
    def _buildAndAddMatrices(self, var, SparseMatrix,  boundaryConditions=(), dt=None, transientGeomCoeff=None, diffusionGeomCoeff=None, buildExplicitIfOther=False):
        """Build matrices of constituent Terms and collect them

        Only called at top-level by `_prepareLinearSystem()`
        
        """

        from fipy.matrices.offsetSparseMatrix import OffsetSparseMatrix
        SparseMatrix =  OffsetSparseMatrix(SparseMatrix=SparseMatrix,
                                           numberOfVariables=len(self._vars),
                                           numberOfEquations=len(self._uncoupledTerms))        
        matrix = SparseMatrix(mesh=var.mesh)
        RHSvectors = []

        for equationIndex, uncoupledTerm in enumerate(self._uncoupledTerms):

            SparseMatrix.equationIndex = equationIndex
            termRHSvector = 0
            termMatrix = SparseMatrix(mesh=var.mesh)
            
            for varIndex, tmpVar in enumerate(var.vars):

                SparseMatrix.varIndex = varIndex
                
                tmpVar, tmpMatrix, tmpRHSvector = uncoupledTerm._buildAndAddMatrices(tmpVar,
                                                                                     SparseMatrix,
                                                                                     boundaryConditions=(),
                                                                                     dt=dt,
                                                                                     transientGeomCoeff=uncoupledTerm._getTransientGeomCoeff(tmpVar),
                                                                                     diffusionGeomCoeff=uncoupledTerm._getDiffusionGeomCoeff(tmpVar),
                                                                                     buildExplicitIfOther=buildExplicitIfOther)

                termMatrix += tmpMatrix 
                termRHSvector += tmpRHSvector

            uncoupledTerm._buildCache(termMatrix, termRHSvector)
            RHSvectors += [CellVariable(value=termRHSvector, mesh=var.mesh)]
            matrix += termMatrix
            
        return (var, matrix, _CoupledCellVariable(RHSvectors))