Ignore:
Timestamp:
Oct 21, 2004, 3:27:05 PM (20 years ago)
Author:
steve
Message:

Cleaned up conjugate_gradient

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/cg_solve.py

    r432 r435  
     1import exceptions
     2class 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
    113def conjugate_gradient(A,b,x0,imax=2000,tol=1.0e-8,iprint=0):
    214   #
     
    2032   #end
    2133
    22    from Numeric import dot
     34   from Numeric import dot, asarray, Float
    2335   #from operator import mod
    2436
    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
    2951   x = x0
    3052   r = b - A*x
     
    4769       d = r + bt*d
    4870       i = i+1
    49        print "i",i
    50        #if i%iprint :
    51        #   #print 'i = %g rTr = %20.15e \n': i,rTr
    52        #   pass
     71       if i%iprint == 0 :
     72          print 'i = %g rTr = %20.15e'% (i,rTr)
     73
     74          
    5375   if i==imax:
    5476     print 'max number of iterations attained'
Note: See TracChangeset for help on using the changeset viewer.