Changeset 435 for inundation/ga/storm_surge/pyvolution/cg_solve.py
- Timestamp:
- Oct 21, 2004, 3:27:05 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/cg_solve.py
r432 r435 1 import exceptions 2 class VectorShapeError(exceptions.Exception): 3 """ 4 Setup Exception for routine conjugate_gradient 5 """ 6 def __init__(self,args=None): 7 self.args = args 8 9 10 11 12 1 13 def conjugate_gradient(A,b,x0,imax=2000,tol=1.0e-8,iprint=0): 2 14 # … … 20 32 #end 21 33 22 from Numeric import dot 34 from Numeric import dot, asarray, Float 23 35 #from operator import mod 24 36 25 print "A shape",A.shape 26 print "b shape",b.shape 27 print "x0 shape",x0.shape 28 i=0 37 b = asarray(b, typecode=Float) 38 x0 = asarray(x0, typecode=Float) 39 40 print "A shape",A.shape[0] 41 print "b shape",len(b.shape) 42 print "x0 shape",x0.shape[0] 43 44 if len(b.shape) != 1 : 45 raise VectorShapeError, 'input vector should consist of only one column' 46 47 if iprint == 0: 48 iprint = imax 49 50 i=1 29 51 x = x0 30 52 r = b - A*x … … 47 69 d = r + bt*d 48 70 i = i+1 49 print "i",i50 #if i%iprint :51 # #print 'i = %g rTr = %20.15e \n': i,rTr 52 # pass71 if i%iprint == 0 : 72 print 'i = %g rTr = %20.15e'% (i,rTr) 73 74 53 75 if i==imax: 54 76 print 'max number of iterations attained'
Note: See TracChangeset
for help on using the changeset viewer.