本文整理汇总了Python中pyamg.gallery.poisson函数的典型用法代码示例。如果您正苦于以下问题:Python poisson函数的具体用法?Python poisson怎么用?Python poisson使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了poisson函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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'})))
示例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"})))
示例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'})))
示例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))
示例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],)))
示例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())
示例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"})))
示例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)
示例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)
示例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)
示例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
示例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)
示例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
示例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))
示例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))