Example #1
0
    def setUp(self):
        self.n = 200
        self.A = PysparseMatrix(matrix=poisson.poisson2d_sym_blk(self.n))
        
        self.x_exact = numpy.ones(self.n*self.n)/self.n
        self.normx = 1.0/self.n
        self.b = self.A * self.x_exact

        h = 1.0 / self.n
        lmbd_min = 4.0/h/h * (math.sin(math.pi*h/2.0) ** 2 +
                              math.sin(math.pi*h/2.0) ** 2)
        lmbd_max = 4.0/h/h * (math.sin((self.n - 1)*math.pi*h/2.0) ** 2 +
                              math.sin((self.n - 1)*math.pi*h/2.0) ** 2)
        cond = lmbd_max/lmbd_min
        self.tol = cond * macheps()
        self.LU = None
        self.relerr = 0.0
        self.descr = ''
        self.fmt = '\t%10s  %8.2e  %8.2e  %8d  %8d  %6.2f  %6.2f\n'
Example #2
0
 def setUp(self):
     self.n = 20
     self.A = poisson.poisson2d(self.n)
     self.S = poisson.poisson2d_sym(self.n)
     self.B = poisson.poisson2d_sym_blk(self.n)
Example #3
0
import math, time
import Numeric
from pysparse import spmatrix, itsolvers, precon, poisson

N = 200
TOL = 1e-8
MAXIT = 800
SSOR_STEPS = 2

L = poisson.poisson2d_sym_blk(N)
S = L.to_sss()

b = Numeric.ones(N*N, 'd')

print 'Solving 2D-Laplace equation using PCG and SSOR preconditioner with variable omega'
print
print 'omega    nit    time       resid' 
print '--------------------------------' 

for omega in [0.1*(i+1) for i in range(20)]:

    K_ssor = precon.ssor(S, omega, SSOR_STEPS)
    t1 = time.clock()

    x = Numeric.zeros(N*N, 'd')
    info, iter, relres = itsolvers.pcg(S, b, x, TOL, MAXIT, K_ssor)

    elapsed_time = time.clock() - t1

    r = Numeric.zeros(N*N, 'd')
    S.matvec(x, r)