def _getDefaultSolver(self, var, solver, *args, **kwargs): solver = solver or super(UpwindConvectionTerm, self)._getDefaultSolver( var, solver, *args, **kwargs) if solver and not solver._canSolveAsymmetric(): import warnings warnings.warn("%s cannot solve asymmetric matrices" % solver) from fipy.solvers import DefaultAsymmetricSolver return solver or DefaultAsymmetricSolver(*args, **kwargs)
def _getDefaultSolver(self, var, solver, *args, **kwargs): if solver and not solver._canSolveAsymmetric(): import warnings warnings.warn("%s cannot solve assymetric matrices" % solver) if self._vectorSize(var) > 1: from fipy.solvers import DefaultAsymmetricSolver return solver or DefaultAsymmetricSolver(*args, **kwargs) else: return solver
def _getDefaultSolver(self, var, solver, *args, **kwargs): r""" Make sure the method actually does something. >>> print(_AsymmetricConvectionTerm((1,)).getDefaultSolver().__repr__()[:6]) Linear """ solver = solver or super(_AsymmetricConvectionTerm, self)._getDefaultSolver( var, solver, *args, **kwargs) if solver and not solver._canSolveAsymmetric(): import warnings warnings.warn("%s cannot solve asymmetric matrices" % solver) from fipy.solvers import DefaultAsymmetricSolver return solver or DefaultAsymmetricSolver(*args, **kwargs)
def _getDefaultSolver(self, var, solver, *args, **kwargs): solver = solver or super(FirstOrderAdvectionTerm, self)._getDefaultSolver(var, solver, *args, **kwargs) if solver and not solver._canSolveAsymmetric(): import warnings warnings.warn("%s cannot solve assymetric matrices" % solver) import fipy.solvers.solver if fipy.solvers.solver == 'trilinos' or fipy.solvers.solver == 'no-pysparse': from fipy.solvers.trilinos.preconditioners.jacobiPreconditioner import JacobiPreconditioner from fipy.solvers.trilinos.linearGMRESSolver import LinearGMRESSolver return solver or LinearGMRESSolver(precon=JacobiPreconditioner(), *args, **kwargs) elif fipy.solvers.solver == 'pyamg': from fipy.solvers.pyAMG.linearGeneralSolver import LinearGeneralSolver return solver or LinearGeneralSolver(tolerance=1e-15, iterations=2000, *args, **kwargs) else: from fipy.solvers import DefaultAsymmetricSolver return solver or DefaultAsymmetricSolver(*args, **kwargs)
def sweep(self, var, solver=None, boundaryConditions=(), dt=None, underRelaxation=None, residualFn=None): r"""Builds and solves the linear system once This method also recalculates and returns the residual as well as applying under-relaxation. Parameters ---------- var : ~fipy.variables.cellVariable.CellVariable The `Variable` to be solved for. Provides the initial condition, the old value and holds the solution on completion. solver : ~fipy.solvers.solver.Solver The iterative solver to be used to solve the linear system of equations. boundaryConditions : :obj`tuple` of ~fipy.boundaryConditions.boundaryCondition.BoundaryCondition dt : float The time step size. underRelaxation : float Usually a value between `0` and `1` or `None` in the case of no under-relaxation """ self.dt.setValue(dt) if solver is None: from fipy.solvers import DefaultAsymmetricSolver solver = DefaultAsymmetricSolver() if type(boundaryConditions) not in (type(()), type([])): boundaryConditions = (boundaryConditions, ) var.constrain(0, var.mesh.exteriorFaces) return self.eq.sweep(var, solver=solver, boundaryConditions=boundaryConditions, underRelaxation=underRelaxation, residualFn=residualFn, dt=1.)
def sweep(self, var, solver=None, boundaryConditions=(), dt=None, underRelaxation=None, residualFn=None): r""" Builds and solves the `AdsorbingSurfactantEquation`'s linear system once. This method also recalculates and returns the residual as well as applying under-relaxation. :Parameters: - `var`: The variable to be solved for. Provides the initial condition, the old value and holds the solution on completion. - `solver`: The iterative solver to be used to solve the linear system of equations. - `boundaryConditions`: A tuple of boundaryConditions. - `dt`: The time step size. - `underRelaxation`: Usually a value between `0` and `1` or `None` in the case of no under-relaxation """ self.dt.setValue(dt) if solver is None: from fipy.solvers import DefaultAsymmetricSolver solver = DefaultAsymmetricSolver() if type(boundaryConditions) not in (type(()), type([])): boundaryConditions = (boundaryConditions, ) var.constrain(0, var.mesh.exteriorFaces) return self.eq.sweep(var, solver=solver, boundaryConditions=boundaryConditions, underRelaxation=underRelaxation, residualFn=residualFn, dt=1.)
def _getDefaultSolver(self, var, solver, *args, **kwargs): if solver and not solver._canSolveAsymmetric(): import warnings warnings.warn("%s cannot solve asymmetric matrices" % solver) from fipy.solvers import DefaultAsymmetricSolver return solver or DefaultAsymmetricSolver(*args, **kwargs)