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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#
import os, sys
import time
import random
import numpy
from scipy.sparse import coo_matrix
from scipy.sparse import csr_matrix
from scipy.sparse.linalg import spsolve
#
print "sys.version:", sys.version
#
## nbDof = 120000 # OK
nbDof = 130000 # KO
P = 3 # largeur de bande
print "nbDof:", nbDof
print "P:", P
# time
t0 = time.time()
# Assembly
Arow, Acol, Adata = [], [], []
Brow, Bcol, Bdata = [], [], []
for i in range(nbDof):
x = random.randint(1, 9)
Brow.append(i)
Bcol.append(0)
Bdata.append(x)
for k in range(P+1):
if (k==0):
x = random.randint(1, 9)
Arow.append(i)
Acol.append(i+k)
Adata.append(x)
continue
x = random.randint(1, 9)
if (0 <= i-k):
Arow.append(i)
Acol.append(i-k)
Adata.append(x)
Arow.append(i-k)
Acol.append(i)
Adata.append(x)
print "len(Adata):", len(Adata)
# coo_matrix
A = coo_matrix((Adata, (Arow, Acol)), shape=(nbDof, nbDof), dtype=float)
# coo_matrix
B = coo_matrix((Bdata, (Brow, Bcol)), shape=(nbDof, 1), dtype=float)
#
if (True):
computationTime = time.time() - t0
print "--> matrix construction: computation time: %.2f s"%computationTime
# solve AU = B
t1 = time.time()
A = csr_matrix(A)
B = csr_matrix(B)
U = spsolve(A, B)
#
if (True):
computationTime = time.time() - t1
print "--> solve: computation time: %.2f s"%computationTime |
Partager