本文整理汇总了Python中sfepy.solvers.solvers.LinearSolver.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python LinearSolver.__init__方法的具体用法?Python LinearSolver.__init__怎么用?Python LinearSolver.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfepy.solvers.solvers.LinearSolver
的用法示例。
在下文中一共展示了LinearSolver.__init__方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sfepy.solvers.solvers import LinearSolver [as 别名]
# 或者: from sfepy.solvers.solvers.LinearSolver import __init__ [as 别名]
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
示例2: __init__
# 需要导入模块: from sfepy.solvers.solvers import LinearSolver [as 别名]
# 或者: from sfepy.solvers.solvers.LinearSolver import __init__ [as 别名]
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)
示例3: __init__
# 需要导入模块: from sfepy.solvers.solvers import LinearSolver [as 别名]
# 或者: from sfepy.solvers.solvers.LinearSolver import __init__ [as 别名]
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)
示例4: __init__
# 需要导入模块: from sfepy.solvers.solvers import LinearSolver [as 别名]
# 或者: from sfepy.solvers.solvers.LinearSolver import __init__ [as 别名]
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)
示例5: __init__
# 需要导入模块: from sfepy.solvers.solvers import LinearSolver [as 别名]
# 或者: from sfepy.solvers.solvers.LinearSolver import __init__ [as 别名]
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)
示例6: __init__
# 需要导入模块: from sfepy.solvers.solvers import LinearSolver [as 别名]
# 或者: from sfepy.solvers.solvers.LinearSolver import __init__ [as 别名]
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"}
示例7: __init__
# 需要导入模块: from sfepy.solvers.solvers import LinearSolver [as 别名]
# 或者: from sfepy.solvers.solvers.LinearSolver import __init__ [as 别名]
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)
示例8: __init__
# 需要导入模块: from sfepy.solvers.solvers import LinearSolver [as 别名]
# 或者: from sfepy.solvers.solvers.LinearSolver import __init__ [as 别名]
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