~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to demo/la/eigensolver/python/demo.py

  • Committer: Garth N. Wells
  • Date: 2008-03-29 09:34:25 UTC
  • Revision ID: gnw20@cam.ac.uk-20080329093425-3ea2vhjvccq56zvi
Add some basic build & install instructions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
from dolfin import *
9
9
import numpy
10
10
 
11
 
# Test for PETSc and SLEPc
12
 
try:
13
 
    dolfin.PETScMatrix
14
 
except:
15
 
    print "PyDOLFIN has not been configured with PETSc. Exiting."
16
 
    exit()
17
 
try:
18
 
    dolfin.SLEPcEigenvalueSolver
19
 
except:
20
 
    print "PyDOLFIN has not been configured with SLEPc. Exiting."
21
 
    exit()
22
 
 
23
 
 
24
 
A = dolfin.PETScMatrix(2,2)
25
 
A[0, 0] = 4.0
26
 
A[0, 1] = 1.0
27
 
A[1, 0] = 3.0
28
 
A[1, 1] = 2.0
29
 
 
 
11
# Set up two simple test matrices (2 x 2)
 
12
A_array = numpy.array([[4.0, 1.0], [3.0, 2.0]])
 
13
B_array = numpy.array([[4.0, 0.0], [0.0, 1.0]])
 
14
 
 
15
position = numpy.array([0, 1], 'uint32')
 
16
 
 
17
A = PETScMatrix(2,2)
 
18
A.set(A_array, position, position)
30
19
A.apply()
31
20
print ""
32
21
print "Matrix A:"
33
22
A.disp()
34
23
print ""
35
24
 
36
 
B = dolfin.PETScMatrix(2,2)
37
 
B[0,0] = 4.0
38
 
B[0,1] = 0.0
39
 
B[1,0] = 0.0
40
 
B[1,1] = 1.0
 
25
B = PETScMatrix(2,2)
 
26
B.set(B_array, position, position)
41
27
B.apply()
42
28
print ""
43
29
print "Matrix B:"
51
37
esolver.solve(A, B)
52
38
 
53
39
# Real and imaginary parts of an eigenvector
54
 
rr = dolfin.PETScVector(2)
55
 
cc = dolfin.PETScVector(2)
 
40
rr = PETScVector(2)
 
41
cc = PETScVector(2)
56
42
 
57
43
# Get the first eigenpair from the solver
58
44
emode = 0