File: poisson_test_eig.py

package info (click to toggle)
pysparse 1.1-1.3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,792 kB
  • ctags: 3,499
  • sloc: ansic: 45,867; python: 2,734; makefile: 102
file content (34 lines) | stat: -rw-r--r-- 904 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import numpy as Numeric
import math
from pysparse import spmatrix
from pysparse import itsolvers
from pysparse import precon
from pysparse import jdsym
import time

def poisson2d_sym_blk(n):
    L = spmatrix.ll_mat_sym(n*n)
    I = spmatrix.ll_mat_sym(n)
    P = spmatrix.ll_mat_sym(n)
    for i in range(n):
        I[i,i] = -1
    for i in range(n):
        P[i,i] = 4
        if i > 0: P[i,i-1] = -1
    for i in range(0, n*n, n):
        L[i:i+n,i:i+n] = P
        if i > 0: L[i:i+n,i-n:i] = I
    return L

n = 200

t1 = time.clock()
L = poisson2d_sym_blk(n)
print 'Time for constructing the matrix: %8.2f sec' % (time.clock() - t1, )

print L.nnz

# ---------------------------------------------------------------------------------------
t1 = time.clock()
jdsym.jdsym(L.to_sss(), None, None, 5, 0.0, 1e-8, 100, itsolvers.qmrs, clvl=1)
print 'Time spend in jdsym: %8.2f sec' % (time.clock() - t1, )