当前位置: 首页>>代码示例>>Python>>正文


Python solvers.LinearSolver类代码示例

本文整理汇总了Python中sfepy.solvers.solvers.LinearSolver的典型用法代码示例。如果您正苦于以下问题:Python LinearSolver类的具体用法?Python LinearSolver怎么用?Python LinearSolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LinearSolver类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__( self, conf, **kwargs ):
        try:
            import petsc4py
            petsc4py.init([])
            from petsc4py import PETSc
        except ImportError:
            msg = 'cannot import petsc4py!'
            raise ImportError( msg )

        LinearSolver.__init__(self, conf, eps_a=conf.eps_a, eps_r=conf.eps_r,
                              petsc=PETSc, pmtx=None, **kwargs)

        ksp = PETSc.KSP().create()

        ksp.setType( self.conf.method )
        ksp.getPC().setType( self.conf.precond )
        side = self._precond_sides[self.conf.precond_side]
        if side is not None:
            ksp.setPCSide(side)
        self.ksp = ksp

        self.converged_reasons = {}
        for key, val in ksp.ConvergedReason.__dict__.iteritems():
            if isinstance(val, int):
                self.converged_reasons[val] = key
开发者ID:renatocoutinho,项目名称:sfepy,代码行数:25,代码来源:ls.py

示例2: __init__

    def __init__(self, conf, **kwargs):
        LinearSolver.__init__(self, conf, solve=None, **kwargs)
        um = self.sls = None

        aux = try_imports(['import scipy.linsolve as sls',
                           'import scipy.splinalg.dsolve as sls',
                           'import scipy.sparse.linalg.dsolve as sls'],
                          'cannot import scipy sparse direct solvers!')
        self.sls = aux['sls']
        aux = try_imports(['import scipy.linsolve.umfpack as um',
                           'import scipy.splinalg.dsolve.umfpack as um',
                           'import scipy.sparse.linalg.dsolve.umfpack as um',
                           'import scikits.umfpack as um'])
        if 'um' in aux:
            um = aux['um']

        if um is not None:
            is_umfpack = hasattr(um, 'UMFPACK_OK')
        else:
            is_umfpack = False

        method = self.conf.method
        if method == 'superlu':
            self.sls.use_solver(useUmfpack=False)
        elif method == 'umfpack':
            if not is_umfpack and self.conf.warn:
                output('umfpack not available, using superlu!')
        elif method != 'auto':
            raise ValueError('uknown solution method! (%s)' % method)

        if method != 'superlu' and is_umfpack:
            self.sls.use_solver(useUmfpack=True,
                                assumeSortedIndices=True)
开发者ID:lokik,项目名称:sfepy,代码行数:33,代码来源:ls.py

示例3: __init__

    def __init__(self, conf, **kwargs):
        import sfepy.solvers.ls_mumps as mumps

        self.mumps_ls = None
        mumps.load_mumps_libraries()  # try to load MUMPS libraries

        LinearSolver.__init__(self, conf, mumps=mumps, mumps_ls=None,
                              mumps_presolved=False, **kwargs)
开发者ID:rc,项目名称:sfepy,代码行数:8,代码来源:ls.py

示例4: __init__

    def __init__(self, conf, **kwargs):
        LinearSolver.__init__(self, conf, **kwargs)

        self.umfpack = None
        if self._presolve() and hasattr(self, "mtx"):
            if self.mtx is not None:
                family = Umfpack._family[self.mtx.dtype]
                self.umfpack = um.UmfpackContext(family=family)
                self.umfpack.numeric(self.mtx)
开发者ID:certik,项目名称:sfepy,代码行数:9,代码来源:ls.py

示例5: __init__

    def __init__(self, conf, **kwargs):
        try:
            import petsc4py
            petsc4py.init([])
            from petsc4py import PETSc
        except ImportError:
            msg = 'cannot import petsc4py!'
            raise ImportError(msg)

        LinearSolver.__init__(self, conf, petsc=PETSc, pmtx=None,
                              converged_reasons=None, **kwargs)
开发者ID:cheon7886,项目名称:sfepy,代码行数:11,代码来源:ls.py

示例6: __init__

    def __init__(self, conf, **kwargs):
        import scipy.sparse.linalg.isolve as la

        LinearSolver.__init__(self, conf, **kwargs)

        try:
            solver = getattr(la, self.conf.method)
        except AttributeError:
            output("scipy solver %s does not exist!" % self.conf.method)
            output("using cg instead")
            solver = la.cg
        self.solver = solver
        self.converged_reasons = {0: "successful exit", 1: "number of iterations", -1: "illegal input or breakdown"}
开发者ID:ZJLi2013,项目名称:sfepy,代码行数:13,代码来源:ls.py

示例7: process_conf

    def process_conf( conf ):
        """
        Missing items are set to default values.
        
        Example configuration, all items::
        
            solver_120 = {
                'name' : 'ls120',
                'kind' : 'ls.petsc',

                'method' : 'cg', # ksp_type
                'precond' : 'icc', # pc_type
                'eps_a' : 1e-12, # abstol
                'eps_r' : 1e-12, # rtol
                'i_max' : 1000, # maxits
            }
        """
        get = conf.get_default_attr

        method = get( 'method', 'cg' )
        precond = get( 'precond', 'icc' )
        eps_a = get( 'eps_a', 1e-8 )
        eps_r = get( 'eps_r', 1e-8 )
        i_max = get( 'i_max', 100 )

        common = LinearSolver.process_conf( conf )
        return Struct( **locals() ) + common
开发者ID:olivierverdier,项目名称:sfepy,代码行数:27,代码来源:ls.py

示例8: process_conf

    def process_conf(conf, kwargs):
        """
        Missing items are set to default values.

        Example configuration, all items::

            solver_1100 = {
                'name' : 'dls1100',
                'kind' : 'ls.scipy_direct',

                'method' : 'superlu',
                'presolve' : False,
                'warn' : True,
            }
        """
        get = make_get_conf(conf, kwargs)
        common = LinearSolver.process_conf(conf)

        return (
            Struct(
                method=get("method", "auto"),
                presolve=get("presolve", False),
                warn=get("warn", True),
                i_max=None,
                eps_a=None,
                eps_r=None,
            )
            + common
        )
开发者ID:ZJLi2013,项目名称:sfepy,代码行数:29,代码来源:ls.py

示例9: process_conf

    def process_conf(conf, kwargs):
        """
        Missing items are set to default values.

        Example configuration, all items::

            solver_110 = {
                'name' : 'ls110',
                'kind' : 'ls.scipy_iterative',

                'method' : 'cg',
                'precond' : None,
                'callback' : None,
                'i_max' : 1000,
                'eps_r' : 1e-12,
            }
        """
        get = make_get_conf(conf, kwargs)
        common = LinearSolver.process_conf(conf)

        return Struct(method=get('method', 'cg'),
                      precond=get('precond', None),
                      callback=get('callback', None),
                      i_max=get('i_max', 100),
                      eps_a=None,
                      eps_r=get('eps_r', 1e-8)) + common
开发者ID:LeiDai,项目名称:sfepy,代码行数:26,代码来源:ls.py

示例10: __init__

    def __init__(self, conf, comm=None, **kwargs):
        if comm is None:
            try:
                import petsc4py
                petsc4py.init([])
            except ImportError:
                msg = 'cannot import petsc4py!'
                raise ImportError(msg)

        from petsc4py import PETSc as petsc

        converged_reasons = {}
        for key, val in petsc.KSP.ConvergedReason.__dict__.iteritems():
            if isinstance(val, int):
                converged_reasons[val] = key

        LinearSolver.__init__(self, conf, petsc=petsc, comm=comm,
                              converged_reasons=converged_reasons, **kwargs)
开发者ID:rosendo100,项目名称:sfepy,代码行数:18,代码来源:ls.py

示例11: __init__

    def __init__( self, conf, **kwargs ):
        if scipy.version.version < '0.7.0.dev3861':
            import scipy.linalg as la
        else:
            if scipy.version.version < '0.7.0.dev3998':
                import scipy.splinalg.isolve as la
            else:
                import scipy.sparse.linalg.isolve as la

        LinearSolver.__init__( self, conf, **kwargs )

        try:
            solver = getattr( la, self.conf.method )
        except AttributeError:
            output( 'scipy solver %s does not exist!' % self.conf.method )
            output( 'using cg instead' )
            solver = la.cg
        self.solver = solver
开发者ID:olivierverdier,项目名称:sfepy,代码行数:18,代码来源:ls.py

示例12: process_conf

    def process_conf(conf):
        """
        Missing items are set to default values.
        
        Example configuration, all items:
        
        solver_102 = {
            'name' : 'ls102',
            'kind' : 'ls.pyamg',

            'method' : 'smoothed_aggregation_solver',
            'eps_a'   : 1e-12,
        }
        """
        get = conf.get_default_attr

        method = get("method", "smoothed_aggregation_solver")
        eps_a = get("eps_a", 1e-8)

        common = LinearSolver.process_conf(conf)
        return Struct(**locals()) + common
开发者ID:certik,项目名称:sfepy,代码行数:21,代码来源:ls.py


注:本文中的sfepy.solvers.solvers.LinearSolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。