當前位置: 首頁>>代碼示例>>Python>>正文


Python linalg.spilu方法代碼示例

本文整理匯總了Python中scipy.sparse.linalg.spilu方法的典型用法代碼示例。如果您正苦於以下問題:Python linalg.spilu方法的具體用法?Python linalg.spilu怎麽用?Python linalg.spilu使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.sparse.linalg的用法示例。


在下文中一共展示了linalg.spilu方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: GetPreconditioner

# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import spilu [as 別名]
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() 
開發者ID:romeric,項目名稱:florence,代碼行數:23,代碼來源:LinearSolver.py

示例2: SetSolver

# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import spilu [as 別名]
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 
開發者ID:romeric,項目名稱:florence,代碼行數:38,代碼來源:LinearSolver.py

示例3: __init__

# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import spilu [as 別名]
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) 
開發者ID:team-ocean,項目名稱:veros,代碼行數:12,代碼來源:scipy.py

示例4: __init__

# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import spilu [as 別名]
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 
開發者ID:treverhines,項目名稱:RBF,代碼行數:29,代碼來源:linalg.py

示例5: init_solver

# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import spilu [as 別名]
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) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:8,代碼來源:flow_matrix.py

示例6: init_solver

# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import spilu [as 別名]
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) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:8,代碼來源:flow_matrix.py

示例7: ilu_linsolver

# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import spilu [as 別名]
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) 
開發者ID:SanPen,項目名稱:GridCal,代碼行數:10,代碼來源:sparse_solve.py

示例8: init_solver

# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import spilu [as 別名]
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) 
開發者ID:aws-samples,項目名稱:aws-kube-codesuite,代碼行數:8,代碼來源:flow_matrix.py


注:本文中的scipy.sparse.linalg.spilu方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。