本文整理汇总了Python中pyamg.gallery.poisson函数的典型用法代码示例。如果您正苦于以下问题:Python poisson函数的具体用法?Python poisson怎么用?Python poisson使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了poisson函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.cases = []
A = poisson((5000,), format='csr')
self.cases.append((A, None, 0.4, 'symmetric',
('jacobi', {'omega': 4.0 / 3.0})))
self.cases.append((A, None, 0.4, 'symmetric',
('energy', {'krylov': 'cg'})))
self.cases.append((A, None, 0.5, 'symmetric',
('energy', {'krylov': 'gmres'})))
A = poisson((60, 60), format='csr')
self.cases.append((A, None, 0.42, 'symmetric',
('jacobi', {'omega': 4.0 / 3.0})))
self.cases.append((A, None, 0.42, 'symmetric',
('energy', {'krylov': 'cg'})))
self.cases.append((A, None, 0.42, 'symmetric',
('energy', {'krylov': 'cgnr'})))
A, B = linear_elasticity((50, 50), format='bsr')
self.cases.append((A, B, 0.32, 'symmetric',
('jacobi', {'omega': 4.0 / 3.0})))
self.cases.append((A, B, 0.22, 'symmetric',
('energy', {'krylov': 'cg'})))
self.cases.append((A, B, 0.42, 'symmetric',
('energy', {'krylov': 'cgnr'})))
self.cases.append((A, B, 0.42, 'symmetric',
('energy', {'krylov': 'gmres'})))
开发者ID:ChaliZhg,项目名称:pyamg,代码行数:28,代码来源:test_aggregation.py
示例2: setUp
def setUp(self):
self.cases = []
# Test 1
A = poisson((5000,), format="csr")
Ai = A + 1.0j * scipy.sparse.eye(A.shape[0], A.shape[1])
self.cases.append((Ai, None, 0.12, "symmetric", ("jacobi", {"omega": 4.0 / 3.0})))
self.cases.append((Ai, None, 0.12, "symmetric", ("energy", {"krylov": "gmres"})))
# Test 2
A = poisson((71, 71), format="csr")
Ai = A + (0.625 / 0.01) * 1j * scipy.sparse.eye(A.shape[0], A.shape[1])
self.cases.append((Ai, None, 1e-3, "symmetric", ("jacobi", {"omega": 4.0 / 3.0})))
self.cases.append((Ai, None, 1e-3, "symmetric", ("energy", {"krylov": "cgnr"})))
# Test 3
A = poisson((60, 60), format="csr")
Ai = 1.0j * A
self.cases.append((Ai, None, 0.3, "symmetric", ("jacobi", {"omega": 4.0 / 3.0})))
self.cases.append((Ai, None, 0.6, "symmetric", ("energy", {"krylov": "cgnr", "maxiter": 8})))
self.cases.append((Ai, None, 0.6, "symmetric", ("energy", {"krylov": "gmres", "maxiter": 8})))
# Test 4
# Use an "inherently" imaginary problem, the Gauge Laplacian in 2D from
# Quantum Chromodynamics,
A = gauge_laplacian(70, spacing=1.0, beta=0.41)
self.cases.append((A, None, 0.4, "hermitian", ("jacobi", {"omega": 4.0 / 3.0})))
self.cases.append((A, None, 0.4, "hermitian", ("energy", {"krylov": "cg"})))
开发者ID:JulianCienfuegos,项目名称:pyamg,代码行数:28,代码来源:test_aggregation.py
示例3: setUp
def setUp(self):
self.cases = []
# Test 1
A = poisson((5000,), format='csr')
Ai = A + 1.0j * scipy.sparse.eye(A.shape[0], A.shape[1])
self.cases.append((Ai, None, 0.12, 'symmetric',
('energy', {'krylov': 'gmres'})))
# Test 2
A = poisson((71, 71), format='csr')
Ai = A + (0.625 / 0.01) * 1.0j *\
scipy.sparse.eye(A.shape[0], A.shape[1])
self.cases.append((Ai, None, 1e-3, 'symmetric',
('energy', {'krylov': 'cgnr'})))
# Test 3
A = poisson((60, 60), format='csr')
Ai = 1.0j * A
self.cases.append((Ai, None, 0.35, 'symmetric',
('energy', {'krylov': 'cgnr', 'maxiter': 8})))
self.cases.append((Ai, None, 0.35, 'symmetric',
('energy', {'krylov': 'gmres', 'maxiter': 8})))
# Test 4 Use an "inherently" imaginary problem, the Gauge Laplacian in
# 2D from Quantum Chromodynamics,
A = gauge_laplacian(70, spacing=1.0, beta=0.41)
self.cases.append((A, None, 0.25, 'hermitian',
('energy', {'krylov': 'cg'})))
开发者ID:GaZ3ll3,项目名称:pyamg,代码行数:29,代码来源:test_rootnode.py
示例4: setUp
def setUp(self):
self.cases = []
# Consider "Helmholtz" like problems with an imaginary shift so that the operator
# should still be SPD in a sense and SA should perform well.
# There are better near nullspace vectors than the default,
# but a constant should give a convergent solver, nonetheless.
A = poisson( (100,), format='csr'); A = A + 1.0j*scipy.sparse.eye(A.shape[0], A.shape[1])
self.cases.append((A, None))
A = poisson( (10,10), format='csr'); A = A + 1.0j*scipy.sparse.eye(A.shape[0], A.shape[1])
self.cases.append((A, None))
开发者ID:gaussWu,项目名称:pyamg,代码行数:11,代码来源:test_aggregation.py
示例5: setUp
def setUp(self):
self.cases = []
# Poisson problems in 1D and 2D
N = 20
self.cases.append((poisson((2*N,), format='csr'), rand(2*N,))) # 0
self.cases.append((poisson((N, N), format='csr'), rand(N*N,))) # 1
# Boxed examples
A = load_example('recirc_flow')['A'].tocsr() # 2
self.cases.append((A, rand(A.shape[0],)))
A = load_example('bar')['A'].tobsr(blocksize=(3, 3)) # 3
self.cases.append((A, rand(A.shape[0],)))
开发者ID:ChaliZhg,项目名称:pyamg,代码行数:12,代码来源:test_blackbox.py
示例6: setUp
def setUp(self):
self.cases = []
# Poisson problems in 1D and 2D
for N in [2, 3, 5, 7, 10, 11, 19]:
self.cases.append(poisson((N,), format='csr'))
for N in [2, 3, 7, 9]:
self.cases.append(poisson((N, N), format='csr'))
for name in ['knot', 'airfoil', 'bar']:
ex = load_example(name)
self.cases.append(ex['A'].tocsr())
开发者ID:ben-s-southworth,项目名称:pyamg,代码行数:12,代码来源:test_complexity.py
示例7: setUp
def setUp(self):
self.cases = []
A = poisson((5000,), format="csr")
self.cases.append((A, None, 0.4, "symmetric", ("energy", {"krylov": "cg"})))
self.cases.append((A, None, 0.4, "symmetric", ("energy", {"krylov": "gmres"})))
A = poisson((75, 75), format="csr")
self.cases.append((A, None, 0.26, "symmetric", ("energy", {"krylov": "cg"})))
self.cases.append((A, None, 0.30, "symmetric", ("energy", {"krylov": "cgnr"})))
A, B = linear_elasticity((50, 50), format="bsr")
self.cases.append((A, B, 0.3, "symmetric", ("energy", {"krylov": "cg"})))
self.cases.append((A, B, 0.3, "symmetric", ("energy", {"krylov": "cgnr"})))
self.cases.append((A, B, 0.3, "symmetric", ("energy", {"krylov": "gmres"})))
开发者ID:czielinski,项目名称:pyamg,代码行数:15,代码来源:test_rootnode.py
示例8: setUp
def setUp(self):
self.cases = []
# Poisson problems in 2D
for N in [2,3,5,7,8]:
A = poisson( (N,N), format='csr'); A.data = A.data + 0.001j*rand(A.nnz)
self.cases.append(A)
开发者ID:GaZ3ll3,项目名称:pyamg,代码行数:7,代码来源:test_aggregate.py
示例9: test_DAD
def test_DAD(self):
A = poisson((50, 50), format='csr')
x = rand(A.shape[0])
b = rand(A.shape[0])
D = diag_sparse(1.0 / sqrt(10 ** (12 * rand(A.shape[0]) - 6))).tocsr()
D_inv = diag_sparse(1.0 / D.data)
DAD = D * A * D
B = ones((A.shape[0], 1))
# TODO force 2 level method and check that result is the same
kwargs = {'max_coarse': 1, 'max_levels': 2, 'coarse_solver': 'splu'}
sa = rootnode_solver(D * A * D, D_inv * B, **kwargs)
residuals = []
x_sol = sa.solve(b, x0=x, maxiter=10, tol=1e-12, residuals=residuals)
avg_convergence_ratio =\
(residuals[-1] / residuals[0]) ** (1.0 / len(residuals))
# print "Diagonal Scaling Test: %1.3e, %1.3e" %
# (avg_convergence_ratio, 0.4)
assert(avg_convergence_ratio < 0.4)
开发者ID:GaZ3ll3,项目名称:pyamg,代码行数:27,代码来源:test_rootnode.py
示例10: test_solver_parameters
def test_solver_parameters(self):
A = poisson((50, 50), format='csr')
for method in methods:
# method = ('richardson', {'omega':4.0/3.0})
ml = smoothed_aggregation_solver(A, presmoother=method,
postsmoother=method,
max_coarse=10)
residuals = profile_solver(ml)
assert((residuals[-1]/residuals[0])**(1.0/len(residuals)) < 0.95)
assert(ml.symmetric_smoothing)
for method in methods2:
ml = smoothed_aggregation_solver(A, max_coarse=10)
change_smoothers(ml, presmoother=method[0], postsmoother=method[1])
residuals = profile_solver(ml)
assert((residuals[-1]/residuals[0])**(1.0/len(residuals)) < 0.95)
assert(not ml.symmetric_smoothing)
for method in methods3:
ml = smoothed_aggregation_solver(A, max_coarse=10)
change_smoothers(ml, presmoother=method[0], postsmoother=method[1])
assert(ml.symmetric_smoothing)
for method in methods4:
ml = smoothed_aggregation_solver(A, max_coarse=10)
change_smoothers(ml, presmoother=method[0], postsmoother=method[1])
assert(not ml.symmetric_smoothing)
开发者ID:pyamg,项目名称:pyamg,代码行数:30,代码来源:test_smoothing.py
示例11: test_DAD
def test_DAD(self):
A = poisson((50, 50), format="csr")
x = rand(A.shape[0])
b = rand(A.shape[0])
D = diag_sparse(1.0 / sqrt(10 ** (12 * rand(A.shape[0]) - 6))).tocsr()
D_inv = diag_sparse(1.0 / D.data)
DAD = D * A * D
B = ones((A.shape[0], 1))
# TODO force 2 level method and check that result is the same
kwargs = {"max_coarse": 1, "max_levels": 2, "coarse_solver": "splu"}
sa = smoothed_aggregation_solver(D * A * D, D_inv * B, **kwargs)
residuals = []
x_sol = sa.solve(b, x0=x, maxiter=10, tol=1e-12, residuals=residuals)
avg_convergence_ratio = (residuals[-1] / residuals[0]) ** (1.0 / len(residuals))
# print "Diagonal Scaling Test: %1.3e, %1.3e" %
# (avg_convergence_ratio, 0.25)
assert avg_convergence_ratio < 0.25
开发者ID:JulianCienfuegos,项目名称:pyamg,代码行数:26,代码来源:test_aggregation.py
示例12: test_poisson
def test_poisson(self):
cases = []
cases.append((500,))
cases.append((250, 250))
cases.append((25, 25, 25))
for case in cases:
A = poisson(case, format='csr')
np.random.seed(0) # make tests repeatable
x = sp.rand(A.shape[0])
b = A*sp.rand(A.shape[0]) # zeros_like(x)
ml = ruge_stuben_solver(A, max_coarse=50)
res = []
x_sol = ml.solve(b, x0=x, maxiter=20, tol=1e-12,
residuals=res)
del x_sol
avg_convergence_ratio = (res[-1]/res[0])**(1.0/len(res))
assert(avg_convergence_ratio < 0.20)
开发者ID:pyamg,项目名称:pyamg,代码行数:25,代码来源:test_classical.py
示例13: test_improve_candidates
def test_improve_candidates(self):
##
# test improve_candidates for the Poisson problem and elasticity, where rho_scale is
# the amount that each successive improve_candidates option should improve convergence
# over the previous improve_candidates option.
improve_candidates_list = [None, [('block_gauss_seidel', {'iterations' : 4, 'sweep':'symmetric'})] ]
# make tests repeatable
numpy.random.seed(0)
cases = []
A_elas,B_elas = linear_elasticity( (60,60), format='bsr')
# Matrix Candidates rho_scale
cases.append( (poisson( (61,61), format='csr'), ones((61*61,1)), 0.9 ) )
cases.append( (A_elas, B_elas, 0.9 ) )
for (A,B,rho_scale) in cases:
last_rho = -1.0
x0 = rand(A.shape[0],1)
b = rand(A.shape[0],1)
for improve_candidates in improve_candidates_list:
ml = smoothed_aggregation_solver(A, B, max_coarse=10, improve_candidates=improve_candidates)
residuals=[]
x_sol = ml.solve(b,x0=x0,maxiter=20,tol=1e-10, residuals=residuals)
rho = (residuals[-1]/residuals[0])**(1.0/len(residuals))
if last_rho == -1.0:
last_rho = rho
else:
# each successive improve_candidates option should be an improvement on the previous
# print "\nimprove_candidates Test: %1.3e, %1.3e, %d\n"%(rho,rho_scale*last_rho,A.shape[0])
assert(rho < rho_scale*last_rho)
last_rho = rho
开发者ID:gaussWu,项目名称:pyamg,代码行数:30,代码来源:test_aggregation.py
示例14: test_symmetry
def test_symmetry(self):
# Test that a basic V-cycle yields a symmetric linear operator. Common
# reasons for failure are problems with using the same rho for the
# pres/post-smoothers and using the same block_D_inv for
# pre/post-smoothers.
n = 500
A = poisson((n,), format="csr")
smoothers = [
("gauss_seidel", {"sweep": "symmetric"}),
("schwarz", {"sweep": "symmetric"}),
("block_gauss_seidel", {"sweep": "symmetric"}),
"jacobi",
"block_jacobi",
]
rng = arange(1, n + 1, dtype="float").reshape(-1, 1)
Bs = [ones((n, 1)), hstack((ones((n, 1)), rng))]
for smoother in smoothers:
for B in Bs:
ml = smoothed_aggregation_solver(A, B, max_coarse=10, presmoother=smoother, postsmoother=smoother)
P = ml.aspreconditioner()
x = rand(n)
y = rand(n)
assert_approx_equal(dot(P * x, y), dot(x, P * y))
开发者ID:JulianCienfuegos,项目名称:pyamg,代码行数:25,代码来源:test_aggregation.py
示例15: test_symmetry
def test_symmetry(self):
# Test that a basic V-cycle yields a symmetric linear operator. Common
# reasons for failure are problems with using the same rho for the
# pres/post-smoothers and using the same block_D_inv for
# pre/post-smoothers.
n = 500
A = poisson((n,), format='csr')
smoothers = [('gauss_seidel', {'sweep': 'symmetric'}),
('schwarz', {'sweep': 'symmetric'}),
('block_gauss_seidel', {'sweep': 'symmetric'}),
'jacobi', 'block_jacobi']
Bs = [ones((n, 1)),
hstack((ones((n, 1)),
arange(1, n + 1, dtype='float').reshape(-1, 1)))]
for smoother in smoothers:
for B in Bs:
ml = rootnode_solver(A, B, max_coarse=10,
presmoother=smoother,
postsmoother=smoother)
P = ml.aspreconditioner()
x = rand(n,)
y = rand(n,)
assert_approx_equal(dot(P * x, y), dot(x, P * y))
开发者ID:GaZ3ll3,项目名称:pyamg,代码行数:25,代码来源:test_rootnode.py
示例16: test_coarse_solver_opts
def test_coarse_solver_opts(self):
# these tests are meant to test whether coarse solvers are correctly
# passed parameters
A = poisson((30, 30), format='csr')
b = sp.rand(A.shape[0], 1)
# for each pair, the first entry should yield an SA solver that
# converges in fewer iterations for a basic Poisson problem
coarse_solver_pairs = [(('jacobi', {'iterations': 30}), 'jacobi')]
coarse_solver_pairs.append((('gauss_seidel',
{'iterations': 30}), 'gauss_seidel'))
coarse_solver_pairs.append(('gauss_seidel', 'jacobi'))
coarse_solver_pairs.append(('cg', ('cg', {'tol': 10.0})))
coarse_solver_pairs.append(('pinv2', ('pinv2', {'cond': 1.0})))
for coarse1, coarse2 in coarse_solver_pairs:
r1 = []
r2 = []
sa1 = rootnode_solver(A, coarse_solver=coarse1)
sa2 = rootnode_solver(A, coarse_solver=coarse2)
x1 = sa1.solve(b, residuals=r1)
x2 = sa2.solve(b, residuals=r2)
del x1, x2
assert((len(r1) + 5) < len(r2))
开发者ID:karthicks123,项目名称:pyamg,代码行数:25,代码来源:test_rootnode.py
示例17: test_improve_candidates
def test_improve_candidates(self):
# test improve_candidates for the Poisson problem and elasticity, where
# rho_scale is the amount that each successive improve_candidates
# option should improve convergence over the previous
# improve_candidates option.
improve_candidates_list = [None, [("block_gauss_seidel", {"iterations": 4, "sweep": "symmetric"})]]
# make tests repeatable
numpy.random.seed(0)
cases = []
A_elas, B_elas = linear_elasticity((60, 60), format="bsr")
# Matrix Candidates rho_scale
cases.append((poisson((75, 75), format="csr"), ones((75 * 75, 1)), 0.9))
cases.append((A_elas, B_elas, 0.9))
for (A, B, rho_scale) in cases:
last_rho = -1.0
x0 = rand(A.shape[0], 1)
b = rand(A.shape[0], 1)
for improve_candidates in improve_candidates_list:
ml = rootnode_solver(A, B, max_coarse=10, improve_candidates=improve_candidates)
residuals = []
x_sol = ml.solve(b, x0=x0, maxiter=20, tol=1e-10, residuals=residuals)
del x_sol
rho = (residuals[-1] / residuals[0]) ** (1.0 / len(residuals))
if last_rho == -1.0:
last_rho = rho
else:
# each successive improve_candidates option should be an
# improvement on the previous print "\nimprove_candidates
# Test: %1.3e, %1.3e,
# %d\n"%(rho,rho_scale*last_rho,A.shape[0])
assert rho < rho_scale * last_rho
last_rho = rho
开发者ID:czielinski,项目名称:pyamg,代码行数:33,代码来源:test_rootnode.py
示例18: test_nonsymmetric
def test_nonsymmetric(self):
# problem data
data = load_example('recirc_flow')
A = data['A'].tocsr()
B = data['B']
numpy.random.seed(625)
x0 = scipy.rand(A.shape[0])
b = A * scipy.rand(A.shape[0])
# solver parameters
smooth = ('energy', {'krylov': 'gmres'})
SA_build_args = {'max_coarse': 25, 'coarse_solver': 'pinv2',
'symmetry': 'nonsymmetric'}
SA_solve_args = {'cycle': 'V', 'maxiter': 20, 'tol': 1e-8}
strength = [('evolution', {'k': 2, 'epsilon': 8.0})]
smoother = ('gauss_seidel_nr', {'sweep': 'symmetric', 'iterations': 1})
improve_candidates = [('gauss_seidel_nr', {'sweep': 'symmetric',
'iterations': 4}), None]
# Construct solver with nonsymmetric parameters
sa = rootnode_solver(A, B=B, smooth=smooth,
improve_candidates=improve_candidates,
strength=strength,
presmoother=smoother,
postsmoother=smoother, **SA_build_args)
residuals = []
# stand-alone solve
x = sa.solve(b, x0=x0, residuals=residuals, **SA_solve_args)
residuals = array(residuals)
avg_convergence_ratio =\
(residuals[-1] / residuals[0]) ** (1.0 / len(residuals))
# print "Test 1 %1.3e, %1.3e" % (avg_convergence_ratio, 0.7)
assert(avg_convergence_ratio < 0.7)
# accelerated solve
residuals = []
x = sa.solve(b, x0=x0, residuals=residuals, accel='gmres',
**SA_solve_args)
residuals = array(residuals)
avg_convergence_ratio =\
(residuals[-1] / residuals[0]) ** (1.0 / len(residuals))
# print "Test 2 %1.3e, %1.3e" % (avg_convergence_ratio, 0.45)
assert(avg_convergence_ratio < 0.45)
# test that nonsymmetric parameters give the same result as symmetric
# parameters for Poisson problem
A = poisson((15, 15), format='csr')
strength = 'symmetric'
SA_build_args['symmetry'] = 'nonsymmetric'
sa_nonsymm = rootnode_solver(A, B=ones((A.shape[0], 1)), smooth=smooth,
strength=strength,
presmoother=smoother,
postsmoother=smoother,
improve_candidates=None, **SA_build_args)
SA_build_args['symmetry'] = 'symmetric'
sa_symm = rootnode_solver(A, B=ones((A.shape[0], 1)), smooth=smooth,
strength=strength, presmoother=smoother,
postsmoother=smoother,
improve_candidates=None, **SA_build_args)
for (symm_lvl, nonsymm_lvl) in zip(sa_nonsymm.levels, sa_symm.levels):
assert_array_almost_equal(symm_lvl.A.todense(),
nonsymm_lvl.A.todense())
开发者ID:GaZ3ll3,项目名称:pyamg,代码行数:59,代码来源:test_rootnode.py
示例19: setUp
def setUp(self):
self.cases = []
# random matrices
np.random.seed(0)
for N in [2, 3, 5]:
self.cases.append(csr_matrix(np.random.rand(N, N)))
# Poisson problems in 1D and 2D
for N in [2, 3, 5, 7, 10, 11, 19]:
self.cases.append(poisson((N,), format='csr'))
for N in [2, 3, 5, 7, 8]:
self.cases.append(poisson((N, N), format='csr'))
for name in ['knot', 'airfoil', 'bar']:
ex = load_example(name)
self.cases.append(ex['A'].tocsr())
开发者ID:pyamg,项目名称:pyamg,代码行数:17,代码来源:test_aggregate.py
示例20: setUp
def setUp(self):
self.cases = []
# random matrices
numpy.random.seed(0)
for N in [2,3,5]:
self.cases.append( csr_matrix(rand(N,N)) + csr_matrix(1.0j*rand(N,N)))
# Poisson problems in 1D and 2D
for N in [2,3,5,7,10,11,19]:
A = poisson( (N,), format='csr'); A.data = A.data + 1.0j*A.data;
self.cases.append(A)
for N in [2,3,7,9]:
A = poisson( (N,N), format='csr'); A.data = A.data + 1.0j*rand(A.data.shape[0],);
self.cases.append(A)
for name in ['knot','airfoil','bar']:
ex = load_example(name)
A = ex['A'].tocsr(); A.data = A.data + 0.5j*rand(A.data.shape[0],);
self.cases.append(A)
开发者ID:GaZ3ll3,项目名称:pyamg,代码行数:20,代码来源:test_strength.py
注:本文中的pyamg.gallery.poisson函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论