3
import spmatrix, itsolvers, jdsym, precon, superlu
8
# Test: compare K=eye with K=None
10
# results are not the same, ritz-value in 2nd iterations differ
12
path = '/local/home/geus/matrices'
13
A = spmatrix.ll_mat_from_mtx(path + 'edge6x3x5_A.mtx')
14
M = spmatrix.ll_mat_from_mtx(path + 'edge6x3x5_B.mtx')
18
I = spmatrix.ll_mat(n, n)
21
Keye = precon.jacobi(I)
23
k_conv, lmbd, Q, it, it_inner = jdsym.jdsym(A.to_sss(), M.to_sss(), None, 5, sigma, 1e-10, 15, itsolvers.qmrs,
24
jmin=5, jmax=10, eps_tr=1e-4, toldecay=2.0, linitmax=200, clvl=1, strategy=1)
26
k_conv, lmbd, Q, it, it_inner = jdsym.jdsym(A.to_sss(), M.to_sss(), Keye, 5, sigma, 1e-10, 15, itsolvers.qmrs,
27
jmin=5, jmax=10, eps_tr=1e-4, toldecay=2.0, linitmax=200, clvl=1, strategy=1)
31
# Test 2: K = diag(A - sigma*M), test diagonal prec using Matlab
34
Asigma.shift(-sigma, M)
35
K = precon.jacobi(Asigma.to_sss())
37
b = numpy.ones(n, 'd')
38
x = numpy.zeros(n, 'd')
40
print 'norm(idiag) = %.16g' % (math.sqrt(numpy.dot(x, x)), )
42
k_conv, lmbd, Q, it, it_inner = jdsym.jdsym(A.to_sss(), M.to_sss(), K, 5, sigma, 1e-10, 150, itsolvers.qmrs,
43
jmin=5, jmax=10, eps_tr=1e-4, toldecay=2.0, linitmax=200, clvl=1, strategy=1)
48
Asigma.shift(-sigma, M)
49
K = precon.ssor(Asigma.to_sss())
50
k_conv, lmbd, Q, it, it_inner = jdsym.jdsym(A.to_sss(), M.to_sss(), K, 5, sigma, 1e-10, 150, itsolvers.qmrs,
51
jmin=5, jmax=10, eps_tr=1e-4, toldecay=2.0, linitmax=200, clvl=1, strategy=1)
56
Asigma.shift(-sigma, M)
57
K = precon.jacobi(Asigma.to_sss())
58
k_conv, lmbd, Q, it, it_inner = jdsym.jdsym(A.to_sss(), M.to_sss(), K, 5, sigma, 1e-10, 150, itsolvers.cgs,
59
jmin=5, jmax=10, eps_tr=1e-4, toldecay=2.0, linitmax=200, clvl=1,
64
# time jdtest -e1 -k1 -o linsolver=QMRS,optype=SYM,jmin=5,jmax=10,linitmax=1000,jdtol=1e-6,strategy=1 1.4 1 ~/matrices/cop18_el5_A.mtx ~/matrices/cop18_el5_M.mtx
66
path = '/home/geus/matrices/'
67
A = spmatrix.ll_mat_from_mtx(path + 'cop18_el5_A.mtx')
68
M = spmatrix.ll_mat_from_mtx(path + 'cop18_el5_M.mtx')
73
Asigma.shift(-sigma, M)
74
K = precon.jacobi(Asigma.to_sss())
76
k_conv, lmbd, Q, it, it_inner = jdsym.jdsym(A.to_sss(), M.to_sss(), K, 1, sigma, 1e-6, 150, itsolvers.qmrs,
77
jmin=5, jmax=10, eps_tr=1e-4, toldecay=2.0, linitmax=1000, clvl=1,
80
print k_conv, lmbd, it, it_inner
85
def __init__(self, A, n11):
88
self.lu11 = superlu.factorize(A[:n11,:n11].to_csr(), diag_pivot_thresh=0)
89
self.K22 = precon.ssor(A[n11:,n11:].to_sss())
91
def precon(self, x, y):
92
self.lu11.solve(x[:n11], y[:n11])
93
self.K22.precon(x[n11:], y[n11:])
95
print 'Loading matrices...'
96
path = '/home/geus/matrices/'
97
A = spmatrix.ll_mat_from_mtx(path + 'cop18_el5_A.mtx')
98
M = spmatrix.ll_mat_from_mtx(path + 'cop18_el5_M.mtx')
103
print 'Constructing preconditioner...'
105
Asigma.shift(-sigma, M)
106
K = prec2lev(Asigma, n11)
108
k_conv, lmbd, Q, it, it_inner = jdsym.jdsym(A.to_sss(), M.to_sss(), K, 2, sigma, 1e-8, 300, itsolvers.qmrs,
109
jmin=10, jmax=25, eps_tr=1e-3, toldecay=1.5, linitmax=3000, clvl=1,
112
print k_conv, lmbd, it, it_inner