Exemple #1
0
    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)
Exemple #2
0
    def __init__(self, conf, context=None, **kwargs):
        try:
            import pyamg.krylov as krylov
        except ImportError:
            msg = 'cannot import pyamg.krylov!'
            raise ImportError(msg)

        LinearSolver.__init__(self,
                              conf,
                              mtx_id=None,
                              mg=None,
                              context=context,
                              **kwargs)

        try:
            solver = getattr(krylov, self.conf.method)
        except AttributeError:
            output('pyamg.krylov.%s does not exist!' % self.conf.method)
            raise

        self.solver = solver
        self.converged_reasons = {
            0: 'successful exit',
            1: 'number of iterations',
            -1: 'illegal input or breakdown',
        }
Exemple #3
0
    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
Exemple #4
0
    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
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
Fichier : ls.py Projet : rc/sfepy
    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)
Exemple #8
0
    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)
Exemple #9
0
    def __init__(self, conf, **kwargs):
        import multiprocessing
        import sfepy.solvers.ls_mumps as mumps

        mumps.load_mumps_libraries()  # try to load MUMPS libraries

        LinearSolver.__init__(self, conf, mumps=mumps, mumps_ls=None,
                              number_of_cpu=multiprocessing.cpu_count(),
                              mumps_presolved=False, **kwargs)
Exemple #10
0
Fichier : ls.py Projet : rc/sfepy
    def __init__(self, conf, **kwargs):
        import multiprocessing
        import sfepy.solvers.ls_mumps as mumps

        mumps.load_mumps_libraries()  # try to load MUMPS libraries

        LinearSolver.__init__(self, conf, mumps=mumps, mumps_ls=None,
                              number_of_cpu=multiprocessing.cpu_count(),
                              mumps_presolved=False, **kwargs)
Exemple #11
0
    def __init__(self, conf, **kwargs):
        try:
            from mumps import DMumpsContext
        except ImportError:
            self.mumps = None
            msg = 'cannot import MUMPS!'
            raise ImportError(msg)

        LinearSolver.__init__(self, conf, **kwargs)
        self.mumps = DMumpsContext()
        self.mumps_presolved = False
Exemple #12
0
    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)
Exemple #13
0
    def __init__(self, conf, **kwargs):
        try:
            from mumps import DMumpsContext
        except ImportError:
            self.mumps = None
            msg = 'cannot import MUMPS!'
            raise ImportError(msg)

        LinearSolver.__init__(self, conf, **kwargs)
        self.mumps = DMumpsContext()
        self.mumps_presolved = False
Exemple #14
0
    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"}
Exemple #15
0
    def __init__(self, conf, comm=None, context=None, **kwargs):
        if comm is None:
            from sfepy.parallel.parallel import init_petsc_args; init_petsc_args

        from petsc4py import PETSc as petsc

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

        LinearSolver.__init__(self, conf, petsc=petsc, comm=comm,
                              converged_reasons=converged_reasons,
                              fields=None, ksp=None, pmtx=None,
                              context=context, **kwargs)
Exemple #16
0
    def __init__(self, conf, comm=None, context=None, **kwargs):
        if comm is None:
            from sfepy.parallel.parallel import init_petsc_args; init_petsc_args

        from petsc4py import PETSc as petsc

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

        LinearSolver.__init__(self, conf, petsc=petsc, comm=comm,
                              converged_reasons=converged_reasons,
                              fields=None, ksp=None, pmtx=None,
                              context=context, **kwargs)
Exemple #17
0
    def __init__(self, conf, **kwargs):
        try:
            import pyamg
        except ImportError:
            msg =  'cannot import pyamg!'
            raise ImportError(msg)

        LinearSolver.__init__(self, conf, mg=None, **kwargs)

        try:
            solver = getattr(pyamg, self.conf.method)
        except AttributeError:
            output('pyamg.%s does not exist!' % self.conf.method)
            output('using pyamg.smoothed_aggregation_solver instead')
            solver = pyamg.smoothed_aggregation_solver
        self.solver = solver
Exemple #18
0
    def __init__(self, conf, **kwargs):
        try:
            import pyamg
        except ImportError:
            msg = 'cannot import pyamg!'
            raise ImportError(msg)

        LinearSolver.__init__(self, conf, mg=None, **kwargs)

        try:
            solver = getattr(pyamg, self.conf.method)
        except AttributeError:
            output('pyamg.%s does not exist!' % self.conf.method)
            output('using pyamg.smoothed_aggregation_solver instead')
            solver = pyamg.smoothed_aggregation_solver
        self.solver = solver
Exemple #19
0
    def __init__(self, conf, context=None, **kwargs):
        import scipy.sparse.linalg.isolve as la

        LinearSolver.__init__(self, conf, context=context, **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',
        }
Exemple #20
0
    def __init__(self, conf, context=None, **kwargs):
        import scipy.sparse.linalg.isolve as la

        LinearSolver.__init__(self, conf, context=context, **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',
        }
Exemple #21
0
    def __init__(self, conf, **kwargs):
        LinearSolver.__init__(self, conf, **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)

        self.solve = None
        if self._presolve() and hasattr(self, "mtx"):
            if self.mtx is not None:
                self.solve = self.sls.factorized(self.mtx)
Exemple #22
0
    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
Exemple #23
0
    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)
Exemple #24
0
    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 six.iteritems(petsc.KSP.ConvergedReason.__dict__):
            if isinstance(val, int):
                converged_reasons[val] = key

        LinearSolver.__init__(self, conf, petsc=petsc, comm=comm,
                              converged_reasons=converged_reasons,
                              fields=None, **kwargs)
Exemple #25
0
    def __init__(self, conf, **kwargs):
        try:
            import pyamg
        except ImportError:
            msg = "cannot import pyamg!"
            raise ImportError(msg)

        LinearSolver.__init__(self, conf, mg=None, **kwargs)

        try:
            solver = getattr(pyamg, self.conf.method)
        except AttributeError:
            output("pyamg.%s does not exist!" % self.conf.method)
            output("using pyamg.smoothed_aggregation_solver instead")
            solver = pyamg.smoothed_aggregation_solver
        self.solver = solver

        if hasattr(self, "mtx"):
            if self.mtx is not None:
                self.mg = self.solver(self.mtx)
Exemple #26
0
    def __init__(self, conf, context=None, **kwargs):
        try:
            import pyamg.krylov as krylov
        except ImportError:
            msg =  'cannot import pyamg.krylov!'
            raise ImportError(msg)

        LinearSolver.__init__(self, conf, mg=None,
                              context=context, **kwargs)

        try:
            solver = getattr(krylov, self.conf.method)
        except AttributeError:
            output('pyamg.krylov.%s does not exist!' % self.conf.method)
            raise

        self.solver = solver
        self.converged_reasons = {
            0 : 'successful exit',
            1 : 'number of iterations',
            -1 : 'illegal input or breakdown',
        }
Exemple #27
0
    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, **kwargs )

        ksp = PETSc.KSP().create()

        ksp.setType( self.conf.method )
        ksp.getPC().setType( self.conf.precond )

        if hasattr( self, 'mtx' ):
            if self.mtx is not None:
                self.pmtx, self.sol, self.rhs = self.set_matrix( self.mtx )
                ksp.setOperators( self.pmtx ) # set the matrix
                ksp.setFromOptions()

        self.ksp = ksp
Exemple #28
0
    def __init__(self, conf, method=None, **kwargs):
        LinearSolver.__init__(self, conf, solve=None, **kwargs)
        um = self.sls = None
        if method is None:
            method = self.conf.method

        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!')
        if 'sls' in aux:
            self.sls = aux['sls']
        else:
            raise ValueError('SuperLU not available!')

        if method in ['auto', 'umfpack']:
            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'
            ])

            is_umfpack = True if 'um' in aux\
                and hasattr(aux['um'], 'UMFPACK_OK') else False
            if method == 'umfpack' and not is_umfpack:
                raise ValueError('UMFPACK not available!')
        elif method == 'superlu':
            is_umfpack = False
        else:
            raise ValueError('uknown solution method! (%s)' % method)

        if is_umfpack:
            self.sls.use_solver(useUmfpack=True, assumeSortedIndices=True)
        else:
            self.sls.use_solver(useUmfpack=False)
Exemple #29
0
Fichier : ls.py Projet : rc/sfepy
    def __init__(self, conf, method=None, **kwargs):
        LinearSolver.__init__(self, conf, solve=None, **kwargs)
        um = self.sls = None
        if method is None:
            method = self.conf.method

        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!')
        if 'sls' in aux:
            self.sls = aux['sls']
        else:
            raise ValueError('SuperLU not available!')

        if method in ['auto', 'umfpack']:
            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'])

            is_umfpack = True if 'um' in aux\
                and hasattr(aux['um'], 'UMFPACK_OK') else False
            if method == 'umfpack' and not is_umfpack:
                raise ValueError('UMFPACK not available!')
        elif method == 'superlu':
            is_umfpack = False
        else:
            raise ValueError('uknown solution method! (%s)' % method)

        if is_umfpack:
            self.sls.use_solver(useUmfpack=True,
                                assumeSortedIndices=True)
        else:
            self.sls.use_solver(useUmfpack=False)