Python scipy.sparse.linalg.spilu() Examples
The following are 8
code examples of scipy.sparse.linalg.spilu().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy.sparse.linalg
, or try the search function
.
Example #1
Source File: LinearSolver.py From florence with MIT License | 6 votes |
def GetPreconditioner(self,A, type="amg_smoothed_aggregation"): """Applies a suitable preconditioner to sparse matrix A based on algebraic multigrid of incomplete LU/Cholesky factorisation input: A: [csc_matrix or csc_matrix] type: [str] either "amg_smoothed_aggregation" for a preconditioner based on algebraic multigrid or "incomplete_lu" for scipy's spilu linear operator returns: A preconditioner that can be used in conjunction with scipy's sparse linear iterative solvers (the M keyword in scipy's iterative solver) """ if not (isspmatrix_csc(A) or isspmatrix_csr(A)): raise TypeError("Matrix must be in CSC or CSR sparse format for preconditioning") ml = smoothed_aggregation_solver(A) return ml.aspreconditioner()
Example #2
Source File: LinearSolver.py From florence with MIT License | 5 votes |
def SetSolver(self,linear_solver="direct", linear_solver_type="umfpack", apply_preconditioner=False, preconditioner="amg_smoothed_aggregation", iterative_solver_tolerance=1.0e-12, reduce_matrix_bandwidth=False, geometric_discretisation=None): """ input: linear_solver: [str] type of solver either "direct", "iterative", "petsc" or "amg" linear_solver_type [str] type of direct or linear solver to use, for instance "umfpack", "superlu" or "mumps" for direct solvers, or "cg", "gmres" etc for iterative solvers or "amg" for algebraic multigrid solver. See WhichSolvers method for the complete set of available linear solvers preconditioner: [str] either "smoothed_aggregation", or "ruge_stuben" or "rootnode" for a preconditioner based on algebraic multigrid or "ilu" for scipy's spilu linear operator geometric_discretisation: [str] type of geometric discretisation used, for instance for FEM discretisations this would correspond to "tri", "quad", "tet", "hex" etc """ self.solver_type = linear_solver self.solver_subtype = "umfpack" self.iterative_solver_tolerance = iterative_solver_tolerance self.apply_preconditioner = apply_preconditioner self.requires_cuthill_mckee = reduce_matrix_bandwidth self.geometric_discretisation = geometric_discretisation
Example #3
Source File: scipy.py From veros with MIT License | 5 votes |
def __init__(self, vs): self._matrix = self._assemble_poisson_matrix(vs) jacobi_precon = self._jacobi_preconditioner(vs, self._matrix) self._matrix = jacobi_precon * self._matrix self._rhs_scale = jacobi_precon.diagonal() self._extra_args = {} logger.info('Computing ILU preconditioner...') ilu_preconditioner = spalg.spilu(self._matrix.tocsc(), drop_tol=1e-6, fill_factor=100) self._extra_args['M'] = spalg.LinearOperator(self._matrix.shape, ilu_preconditioner.solve)
Example #4
Source File: linalg.py From RBF with MIT License | 5 votes |
def __init__(self, A, drop_tol=0.005, fill_factor=2.0, normalize_inplace=False): # the spilu and gmres functions are most efficient with csc sparse. If the # matrix is already csc then this will do nothing A = sp.csc_matrix(A) n = row_norms(A) if normalize_inplace: divide_rows(A, n, inplace=True) else: A = divide_rows(A, n, inplace=False).tocsc() LOGGER.debug( 'computing the ILU decomposition of a %s by %s sparse matrix with %s ' 'nonzeros ' % (A.shape + (A.nnz,))) ilu = spla.spilu( A, drop_rule='basic', drop_tol=drop_tol, fill_factor=fill_factor) LOGGER.debug('done') M = spla.LinearOperator(A.shape, ilu.solve) self.A = A self.M = M self.n = n
Example #5
Source File: flow_matrix.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def init_solver(self,L): global linalg from scipy.sparse import linalg ilu= linalg.spilu(self.L1.tocsc()) n=self.n-1 self.M = linalg.LinearOperator(shape=(n,n), matvec=ilu.solve)
Example #6
Source File: flow_matrix.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def init_solver(self, L): global linalg from scipy.sparse import linalg ilu = linalg.spilu(self.L1.tocsc()) n = self.n - 1 self.M = linalg.LinearOperator(shape=(n, n), matvec=ilu.solve)
Example #7
Source File: sparse_solve.py From GridCal with GNU General Public License v3.0 | 5 votes |
def ilu_linsolver(A, b): """ ILU wrapper function for linear system solve A x = b :param A: System matrix :param b: right hand side :return: solution """ return spilu(A).solve(b)
Example #8
Source File: flow_matrix.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def init_solver(self, L): global linalg from scipy.sparse import linalg ilu = linalg.spilu(self.L1.tocsc()) n = self.n-1 self.M = linalg.LinearOperator(shape=(n, n), matvec=ilu.solve)