import pyamg
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
n = 10
x = np.linspace(0,1,n+2)[1:-1]
A = pyamg.gallery.poisson((n,), format='csr')
ml = pyamg.smoothed_aggregation_solver(A, max_coarse=1, improve_candidates=None, keep=True)
ml
T = ml.levels[0].T.toarray()
plt.spy(T, marker='o')
T
T = ml.levels[0].T.toarray()
for i in range(T.shape[1]):
plt.plot(x, T[:, i])
P = ml.levels[0].P.toarray()
plt.spy(P, marker='s')
P = ml.levels[0].P.toarray()
for i in range(P.shape[1]):
plt.plot(x, P[:, i])
B = np.ones((n, 2))
B[:,1] = x
print(B)
ml = pyamg.smoothed_aggregation_solver(A, B=B, max_coarse=1, improve_candidates=None, keep=True)
ml
T = ml.levels[0].T.toarray()
for i in range(T.shape[1]):
plt.plot(x, T[:, i])
plt.spy(T, marker='o')
T = ml.levels[0].P.toarray()
for i in range(T.shape[1]):
plt.plot(x, T[:, i])
A, B = pyamg.gallery.elasticity.linear_elasticity((4, 4))
A
B
A, B = pyamg.gallery.elasticity.linear_elasticity((100, 100), nu=0.4)
ml = pyamg.smoothed_aggregation_solver(A.tocsr(), max_coarse=10)
res=[]
b = np.zeros((A.shape[0],))
x0 = np.random.rand(A.shape[0])
u = ml.solve(b, x0=x0, residuals=res)
print(len(res))
print(ml)
res
usub0 = u[1::2]
usub1 = u[0::2]
print(len(u))
print(len(usub0))
print(len(usub1))
plt.pcolor(usub1.reshape((100,100)))
plt.colorbar()
ml = pyamg.smoothed_aggregation_solver(A, B=B, max_coarse=10)
res=[]
b = np.zeros((A.shape[0],))
x0 = np.random.rand(A.shape[0])
u = ml.solve(b, x0=x0, residuals=res)
len(res)
res
usub0 = u[1::2]
usub1 = u[0::2]
print(len(u))
print(len(usub0))
print(len(usub1))
plt.pcolor(usub1.reshape((100,100)))
A
ml