本文整理汇总了Python中sfepy.solvers.solvers.NonlinearSolver类的典型用法代码示例。如果您正苦于以下问题:Python NonlinearSolver类的具体用法?Python NonlinearSolver怎么用?Python NonlinearSolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NonlinearSolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, conf, pmtx=None, prhs=None, 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.SNES.ConvergedReason.__dict__):
if isinstance(val, int):
converged_reasons[val] = key
ksp_converged_reasons = {}
for key, val in six.iteritems(petsc.KSP.ConvergedReason.__dict__):
if isinstance(val, int):
ksp_converged_reasons[val] = key
NonlinearSolver.__init__(self, conf, petsc=petsc,
pmtx=pmtx, prhs=prhs, comm=comm,
converged_reasons=converged_reasons,
ksp_converged_reasons=ksp_converged_reasons,
**kwargs)
示例2: __init__
def __init__(self, conf, problem, **kwargs):
NonlinearSolver.__init__(self, conf, **kwargs)
conf = self.conf
log = get_logging_conf(conf)
conf.log = log = Struct(name='log_conf', **log)
conf.is_any_log = (log.text is not None) or (log.plot is not None)
conf.problem = problem
conf = self.conf
if conf.is_any_log:
self.log = Log([[r'$||r||$'], ['iteration'],
[r'$\gamma$', r'$\max(\delta)$', r'$\max(\tau)$']],
xlabels=['', '', 'all iterations'],
ylabels=[r'$||r||$', 'iteration', 'stabilization'],
yscales=['log', 'linear', 'log'],
is_plot=conf.log.plot is not None,
log_filename=conf.log.text,
formats=[['%.8e'], ['%d'],
['%.8e', '%.8e', '%.8e']])
else:
self.log = None
示例3: __init__
def __init__(self, conf, pmtx=None, prhs=None, 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
NonlinearSolver.__init__(self, conf, petsc=petsc,
pmtx=pmtx, prhs=prhs, comm=comm, **kwargs)
示例4: __init__
def __init__(self, conf, **kwargs):
NonlinearSolver.__init__(self, conf, **kwargs)
conf = self.conf
if conf.is_any_log:
self.log = Log([[r'$||r||$'], ['iteration']],
xlabels=['', 'all iterations'],
ylabels=[r'$||r||$', 'iteration'],
yscales=['log', 'linear'],
log_filename=conf.log.text,
formats=[['%.8e'], ['%d']])
else:
self.log = None
示例5: process_conf
def process_conf(conf, kwargs):
"""
Missing items are left to scipy defaults. Unused options are ignored.
Example configuration, all items::
solver_1 = {
'name' : 'broyden',
'kind' : 'nls.scipy_broyden_like',
'method' : 'broyden3',
'i_max' : 10,
'alpha' : 0.9,
'M' : 5,
'w0' : 0.1,
'verbose' : True,
}
"""
get = make_get_conf(conf, kwargs)
common = NonlinearSolver.process_conf(conf)
return Struct(method=get('method', 'broyden3'),
i_max=get('i_max', 10),
alpha=get('alpha', 0.9),
M=get('M', 5),
w0=get('w0', 0.1),
verbose=get('verbose', False)) + common
示例6: process_conf
def process_conf( conf ):
"""
Missing items are left to scipy defaults. Unused options are ignored.
Example configuration, all items::
solver_1 = {
'name' : 'broyden',
'kind' : 'nls.scipy_broyden_like',
'method' : 'broyden3',
'i_max' : 10,
'alpha' : 0.9,
'M' : 5,
'w0' : 0.1,
'verbose' : True,
}
"""
get = conf.get_default_attr
method = get( 'method', 'broyden3' )
i_max = get( 'i_max' )
alpha = get( 'alpha' )
M = get( 'M' )
w0 = get( 'w0' )
verbose = get( 'verbose' )
common = NonlinearSolver.process_conf( conf )
return Struct( **locals() ) + common
示例7: process_conf
def process_conf(conf, kwargs):
"""
Missing items are set to default values.
Example configuration, all items::
solver_1 = {
'name' : 'oseen',
'kind' : 'nls.oseen',
'needs_problem_instance' : True,
'stabil_mat' : 'stabil',
'adimensionalize' : False,
'check_navier_stokes_rezidual' : False,
'i_max' : 10,
'eps_a' : 1e-8,
'eps_r' : 1.0,
'macheps' : 1e-16,
'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red).
'log' : {'text' : 'oseen_log.txt',
'plot' : 'oseen_log.png'},
}
"""
get = make_get_conf(conf, kwargs)
common = NonlinearSolver.process_conf(conf)
# Compulsory.
needs_problem_instance = get('needs_problem_instance', True)
if not needs_problem_instance:
msg = 'set solver option "needs_problem_instance" to True!'
raise ValueError(msg)
stabil_mat = get('stabil_mat', None, 'missing "stabil_mat" in options!')
# With defaults.
adimensionalize = get('adimensionalize', False)
if adimensionalize:
raise NotImplementedError
check = get('check_navier_stokes_rezidual', False)
log = get_logging_conf(conf)
log = Struct(name='log_conf', **log)
is_any_log = (log.text is not None) or (log.plot is not None)
return Struct(needs_problem_instance=needs_problem_instance,
stabil_mat=stabil_mat,
adimensionalize=adimensionalize,
check_navier_stokes_rezidual=check,
i_max=get('i_max', 1),
eps_a=get('eps_a', 1e-10),
eps_r=get('eps_r', 1.0),
macheps=get('macheps', nm.finfo(nm.float64).eps),
lin_red=get('lin_red', 1.0),
lin_precision=get('lin_precision', None),
log=log,
is_any_log=is_any_log) + common
示例8: __init__
def __init__(self, conf, **kwargs):
NonlinearSolver.__init__(self, conf, **kwargs)
conf = self.conf
if conf.is_any_log:
self.log = Log(
[[r"$||r||$"], ["iteration"]],
xlabels=["", "all iterations"],
ylabels=[r"$||r||$", "iteration"],
yscales=["log", "linear"],
is_plot=conf.log.plot is not None,
log_filename=conf.log.text,
formats=[["%.8e"], ["%d"]],
)
else:
self.log = None
示例9: process_conf
def process_conf(conf, kwargs):
"""
Missing items are set to default values for a linear problem.
Example configuration, all items::
solver_1 = {
'name' : 'newton',
'kind' : 'nls.newton',
'i_max' : 2,
'eps_a' : 1e-8,
'eps_r' : 1e-2,
'macheps' : 1e-16,
'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red).
'lin_precision' : None,
'ls_red' : 0.1,
'ls_red_warp' : 0.001,
'ls_on' : 0.99999,
'ls_min' : 1e-5,
'give_up_warp' : False,
'check' : 0,
'delta' : 1e-6,
'is_plot' : False,
'log' : None, # 'nonlinear' or 'linear' (ignore i_max)
'problem' : 'nonlinear',
}
"""
get = make_get_conf(conf, kwargs)
common = NonlinearSolver.process_conf(conf)
log = get_logging_conf(conf)
log = Struct(name="log_conf", **log)
is_any_log = (log.text is not None) or (log.plot is not None)
return (
Struct(
i_max=get("i_max", 1),
eps_a=get("eps_a", 1e-10),
eps_r=get("eps_r", 1.0),
macheps=get("macheps", nm.finfo(nm.float64).eps),
lin_red=get("lin_red", 1.0),
lin_precision=get("lin_precision", None),
ls_red=get("ls_red", 0.1),
ls_red_warp=get("ls_red_warp", 0.001),
ls_on=get("ls_on", 0.99999),
ls_min=get("ls_min", 1e-5),
give_up_warp=get("give_up_warp", False),
check=get("check", 0),
delta=get("delta", 1e-6),
is_plot=get("is_plot", False),
problem=get("problem", "nonlinear"),
log=log,
is_any_log=is_any_log,
)
+ common
)
示例10: __init__
def __init__(self, conf, **kwargs):
NonlinearSolver.__init__(self, conf, **kwargs)
conf = self.conf
log = get_logging_conf(conf)
conf.log = log = Struct(name='log_conf', **log)
conf.is_any_log = (log.text is not None) or (log.plot is not None)
if conf.is_any_log:
self.log = Log([[r'$||r||$'], ['iteration']],
xlabels=['', 'all iterations'],
ylabels=[r'$||r||$', 'iteration'],
yscales=['log', 'linear'],
is_plot=conf.log.plot is not None,
log_filename=conf.log.text,
formats=[['%.8e'], ['%d']])
else:
self.log = None
示例11: process_conf
def process_conf( conf ):
"""
Missing items are set to default values.
Example configuration, all items::
solver_1 = {
'name' : 'oseen',
'kind' : 'nls.oseen',
'needs_problem_instance' : True,
'stabilization_hook' : 'create_stabil_mat',
'adimensionalize' : False,
'check_navier_stokes_rezidual' : False,
'i_max' : 10,
'eps_a' : 1e-8,
'eps_r' : 1.0,
'macheps' : 1e-16,
'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red).
'is_plot' : False,
'log' : {'text' : 'oseen_log.txt',
'plot' : 'oseen_log.png'},
}
"""
get = conf.get_default_attr
# Compulsory.
needs_problem_instance = get('needs_problem_instance', True)
if not needs_problem_instance:
msg = 'set solver option "needs_problem_instance" to True!'
raise ValueError(msg)
stabilization_hook = get('stabilization_hook', None,
'missing "stabilization_hook" in options!')
# With defaults.
adimensionalize = get( 'adimensionalize', False )
check_navier_stokes_rezidual = get( 'check_navier_stokes_rezidual',
False )
i_max = get( 'i_max', 1 )
eps_a = get( 'eps_a', 1e-10 )
eps_r = get( 'eps_r', 1.0 )
macheps = get( 'macheps', nm.finfo( nm.float64 ).eps )
lin_red = get( 'lin_red', 1.0 )
is_plot = get( 'is_plot', False )
log = get_logging_conf(conf)
log = Struct(name='log_conf', **log)
is_any_log = (log.text is not None) or (log.plot is not None)
common = NonlinearSolver.process_conf( conf )
return Struct( **locals() ) + common
示例12: process_conf
def process_conf( conf ):
"""
Missing items are set to default values.
Example configuration, all items:
solver_1 = {
'name' : 'oseen',
'kind' : 'nls.oseen',
'adimensionalize' : False,
'check_navier_stokes_rezidual' : False,
'fluid_mat_name' : 'fluid',
'stabil_mat_name' : 'stabil',
'lin_convect_eq_name' : 'balance',
'div_eq_name' : 'incompressibility',
'i_max' : 10,
'eps_a' : 1e-8,
'eps_r' : 1.0,
'macheps' : 1e-16,
'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red).
'is_plot' : False,
}
"""
get = conf.get_default_attr
# Compulsory.
fluid_mat_name = get( 'fluid_mat_name', None,
'missing "fluid_mat_name" in options!' )
stabil_mat_name = get( 'stabil_mat_name', None,
'missing "stabil_mat_name" in options!' )
lin_convect_eq_name = get( 'lin_convect_eq_name', None,
'missing "lin_convect_eq_name" in options!' )
div_eq_name = get( 'div_eq_name', None,
'missing "div_eq_name" in options!' )
# With defaults.
adimensionalize = get( 'adimensionalize', False )
check_navier_stokes_rezidual = get( 'check_navier_stokes_rezidual',
False )
i_max = get( 'i_max', 1 )
eps_a = get( 'eps_a', 1e-10 )
eps_r = get( 'eps_r', 1.0 )
macheps = get( 'macheps', nm.finfo( nm.float64 ).eps )
lin_red = get( 'lin_red', 1.0 )
is_plot = get( 'is_plot', False )
common = NonlinearSolver.process_conf( conf )
return Struct( **locals() ) + common
示例13: process_conf
def process_conf(conf):
"""
Missing items are set to default values.
Example configuration, all items::
solver_1 = {
'name' : 'semismooth_newton',
'kind' : 'nls.semismooth_newton',
'semismooth' : True,
'i_max' : 10,
'eps_a' : 1e-8,
'eps_r' : 1e-2,
'macheps' : 1e-16,
'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red).
'ls_red_reg' : 0.1,
'ls_red_alt' : 0.01,
'ls_red_warp' : 0.001,
'ls_on' : 0.9,
'ls_min' : 1e-10,
'log' : {'plot' : 'convergence.png'},
}
"""
get = conf.get_default_attr
semismooth = get('semismooth', True)
i_max = get('i_max', 1)
eps_a = get('eps_a', 1e-10)
eps_r = get('eps_r', 1.0)
macheps = get('macheps', nm.finfo(nm.float64).eps)
lin_red = get('lin_red', 1.0)
ls_red = {'regular' : get('ls_red_reg', 0.1),
'steepest_descent' : get('ls_red_alt', 0.01)}
ls_red_warp = get('ls_red_warp', 0.001)
ls_on = get('ls_on', 0.99999)
ls_min = get('ls_min', 1e-5)
log = get_logging_conf(conf)
log = Struct(name='log_conf', **log)
is_any_log = (log.text is not None) or (log.plot is not None)
common = NonlinearSolver.process_conf(conf)
return Struct(**locals()) + common
示例14: process_conf
def process_conf(conf, kwargs):
"""
Missing items are set to default values.
Example configuration, all items::
solver_1 = {
'name' : 'semismooth_newton',
'kind' : 'nls.semismooth_newton',
'semismooth' : True,
'i_max' : 10,
'eps_a' : 1e-8,
'eps_r' : 1e-2,
'macheps' : 1e-16,
'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red).
'ls_red_reg' : 0.1,
'ls_red_alt' : 0.01,
'ls_red_warp' : 0.001,
'ls_on' : 0.9,
'ls_min' : 1e-10,
'log' : {'plot' : 'convergence.png'},
}
"""
get = make_get_conf(conf, kwargs)
common = NonlinearSolver.process_conf(conf)
log = get_logging_conf(conf)
log = Struct(name='log_conf', **log)
is_any_log = (log.text is not None) or (log.plot is not None)
return Struct(semismooth=get('semismooth', True),
i_max=get('i_max', 1),
eps_a=get('eps_a', 1e-10),
eps_r=get('eps_r', 1.0),
macheps=get('macheps', nm.finfo(nm.float64).eps),
lin_red=get('lin_red', 1.0),
ls_red=get('ls_red', 0.1),
ls_red_warp=get('ls_red_warp', 0.001),
ls_on=get('ls_on', 0.99999),
ls_min=get('ls_min', 1e-5),
log=log,
is_any_log=is_any_log) + common
示例15: __init__
def __init__( self, conf, **kwargs ):
NonlinearSolver.__init__( self, conf, **kwargs )
self.set_method( self.conf )