def __buildMatrix(self, var, solver, boundaryConditions, dt): if numerix.sctype2char(var.getsctype()) not in numerix.typecodes['Float']: import warnings warnings.warn("""sweep() or solve() are likely to produce erroneous results when `var` does not contain floats.""", UserWarning, stacklevel=4) self._verifyCoeffType(var) if numerix.getShape(dt) != (): raise TypeError, "`dt` must be a single number, not a " + type(dt).__name__ dt = float(dt) if type(boundaryConditions) not in (type(()), type([])): boundaryConditions = (boundaryConditions,) for bc in boundaryConditions: bc._resetBoundaryConditionApplied() if os.environ.has_key('FIPY_DISPLAY_MATRIX'): if not hasattr(self, "_viewer"): from fipy.viewers.matplotlibViewer.matplotlibSparseMatrixViewer import MatplotlibSparseMatrixViewer Term._viewer = MatplotlibSparseMatrixViewer() matrix, RHSvector = self._buildMatrix(var, solver._getMatrixClass(), boundaryConditions, dt) solver._storeMatrix(var=var, matrix=matrix, RHSvector=RHSvector) if os.environ.has_key('FIPY_DISPLAY_MATRIX'): self._viewer.title = "%s %s" % (var.name, self.__class__.__name__) self._viewer.plot(matrix=matrix, RHSvector=RHSvector) from fipy import raw_input raw_input()
def _implicitBuildMatrix_(self, SparseMatrix, L, id1, id2, b, weight, var, boundaryConditions, interiorFaces, dt): mesh = var.mesh coeffMatrix = self._getCoeffMatrix_(var, weight) id1 = self._reshapeIDs(var, id1) id2 = self._reshapeIDs(var, id2) L.addAt(numerix.take(coeffMatrix['cell 1 diag'], interiorFaces, axis=-1).ravel(), id1.ravel(), id1.swapaxes(0,1).ravel()) L.addAt(numerix.take(coeffMatrix['cell 1 offdiag'], interiorFaces, axis=-1).ravel(), id1.ravel(), id2.swapaxes(0,1).ravel()) L.addAt(numerix.take(coeffMatrix['cell 2 offdiag'], interiorFaces, axis=-1).ravel(), id2.ravel(), id1.swapaxes(0,1).ravel()) L.addAt(numerix.take(coeffMatrix['cell 2 diag'], interiorFaces, axis=-1).ravel(), id2.ravel(), id2.swapaxes(0,1).ravel()) N = mesh.numberOfCells M = mesh._maxFacesPerCell for boundaryCondition in boundaryConditions: LL, bb = boundaryCondition._buildMatrix(SparseMatrix, N, M, coeffMatrix) if 'FIPY_DISPLAY_MATRIX' in os.environ: self._viewer.title = r"%s %s" % (boundaryCondition.__class__.__name__, self.__class__.__name__) self._viewer.plot(matrix=LL, RHSvector=bb) from fipy import raw_input raw_input() L += LL b += bb
def __doBCs(self, SparseMatrix, higherOrderBCs, N, M, coeffs, coefficientMatrix, boundaryB): for boundaryCondition in higherOrderBCs: LL, bb = boundaryCondition._buildMatrix(SparseMatrix, N, M, coeffs) if 'FIPY_DISPLAY_MATRIX' in os.environ: self._viewer.title = r"%s %s" % (boundaryCondition.__class__.__name__, self.__class__.__name__) self._viewer.plot(matrix=LL, RHSvector=bb) from fipy import raw_input raw_input() self.__bcAdd(coefficientMatrix, boundaryB, LL, bb) return coefficientMatrix, boundaryB
def __doBCs(self, SparseMatrix, higherOrderBCs, N, M, coeffs, coefficientMatrix, boundaryB): for boundaryCondition in higherOrderBCs: LL, bb = boundaryCondition._buildMatrix(SparseMatrix, N, M, coeffs) if 'FIPY_DISPLAY_MATRIX' in os.environ: self._viewer.title = r"%s %s" % ( boundaryCondition.__class__.__name__, self.__class__.__name__) self._viewer.plot(matrix=LL, RHSvector=bb) from fipy import raw_input raw_input() self.__bcAdd(coefficientMatrix, boundaryB, LL, bb) return coefficientMatrix, boundaryB
def _prepareLinearSystem(self, var, solver, boundaryConditions, dt): solver = self.getDefaultSolver(var, solver) var = self._verifyVar(var) self._checkVar(var) if type(boundaryConditions) not in (type(()), type([])): boundaryConditions = (boundaryConditions, ) for bc in boundaryConditions: bc._resetBoundaryConditionApplied() if 'FIPY_DISPLAY_MATRIX' in os.environ: if not hasattr(self, "_viewer"): from fipy.viewers.matplotlibViewer.matplotlibSparseMatrixViewer import MatplotlibSparseMatrixViewer Term._viewer = MatplotlibSparseMatrixViewer() var, matrix, RHSvector = self._buildAndAddMatrices( var, self._getMatrixClass(solver, var), boundaryConditions=boundaryConditions, dt=dt, transientGeomCoeff=self._getTransientGeomCoeff(var), diffusionGeomCoeff=self._getDiffusionGeomCoeff(var), buildExplicitIfOther=self._buildExplcitIfOther) self._buildCache(matrix, RHSvector) solver._storeMatrix(var=var, matrix=matrix, RHSvector=RHSvector) if 'FIPY_DISPLAY_MATRIX' in os.environ: if var is None: name = "" else: if not hasattr(var, "name"): name = "" else: name = var.name self._viewer.title = r"%s %s" % (name, repr(self)) from fipy.variables.coupledCellVariable import _CoupledCellVariable if isinstance(solver.RHSvector, _CoupledCellVariable): RHSvector = solver.RHSvector.globalValue else: RHSvector = solver.RHSvector self._viewer.plot(matrix=solver.matrix, RHSvector=RHSvector) from fipy import raw_input raw_input() return solver
def _prepareLinearSystem(self, var, solver, boundaryConditions, dt): solver = self.getDefaultSolver(var, solver) var = self._verifyVar(var) self._checkVar(var) if type(boundaryConditions) not in (type(()), type([])): boundaryConditions = (boundaryConditions,) for bc in boundaryConditions: bc._resetBoundaryConditionApplied() if 'FIPY_DISPLAY_MATRIX' in os.environ: if not hasattr(self, "_viewer"): from fipy.viewers.matplotlibViewer.matplotlibSparseMatrixViewer import MatplotlibSparseMatrixViewer Term._viewer = MatplotlibSparseMatrixViewer() var, matrix, RHSvector = self._buildAndAddMatrices(var, self._getMatrixClass(solver, var), boundaryConditions=boundaryConditions, dt=dt, transientGeomCoeff=self._getTransientGeomCoeff(var), diffusionGeomCoeff=self._getDiffusionGeomCoeff(var), buildExplicitIfOther=self._buildExplcitIfOther) self._buildCache(matrix, RHSvector) solver._storeMatrix(var=var, matrix=matrix, RHSvector=RHSvector) if 'FIPY_DISPLAY_MATRIX' in os.environ: if var is None: name = "" else: if not hasattr(var, "name"): name = "" else: name = var.name self._viewer.title = r"%s %s" % (name, repr(self)) from fipy.variables.coupledCellVariable import _CoupledCellVariable if isinstance(solver.RHSvector, _CoupledCellVariable): RHSvector = solver.RHSvector.globalValue else: RHSvector = solver.RHSvector self._viewer.plot(matrix=solver.matrix, RHSvector=RHSvector) from fipy import raw_input raw_input() return solver
def _implicitBuildMatrix_(self, SparseMatrix, L, id1, id2, b, weight, var, boundaryConditions, interiorFaces, dt): mesh = var.mesh coeffMatrix = self._getCoeffMatrix_(var, weight) id1 = self._reshapeIDs(var, id1) id2 = self._reshapeIDs(var, id2) L.addAt( numerix.take(coeffMatrix['cell 1 diag'], interiorFaces, axis=-1).ravel(), id1.ravel(), id1.swapaxes(0, 1).ravel()) L.addAt( numerix.take(coeffMatrix['cell 1 offdiag'], interiorFaces, axis=-1).ravel(), id1.ravel(), id2.swapaxes(0, 1).ravel()) L.addAt( numerix.take(coeffMatrix['cell 2 offdiag'], interiorFaces, axis=-1).ravel(), id2.ravel(), id1.swapaxes(0, 1).ravel()) L.addAt( numerix.take(coeffMatrix['cell 2 diag'], interiorFaces, axis=-1).ravel(), id2.ravel(), id2.swapaxes(0, 1).ravel()) N = mesh.numberOfCells M = mesh._maxFacesPerCell for boundaryCondition in boundaryConditions: LL, bb = boundaryCondition._buildMatrix(SparseMatrix, N, M, coeffMatrix) if 'FIPY_DISPLAY_MATRIX' in os.environ: self._viewer.title = r"%s %s" % ( boundaryCondition.__class__.__name__, self.__class__.__name__) self._viewer.plot(matrix=LL, RHSvector=bb) from fipy import raw_input raw_input() L += LL b += bb