# Diff of /trunk/escript/py_src/pdetools.py

revision 1468 by gross, Wed Apr 2 08:10:37 2008 UTC revision 1469 by gross, Thu Apr 3 05:16:56 2008 UTC
# Line 477  class IterationHistory(object): Line 477  class IterationHistory(object):
477         if self.verbose: print "iter: %s:  inner(rhat,r) = %e"%(len(self.history)-1, self.history[-1])         if self.verbose: print "iter: %s:  inner(rhat,r) = %e"%(len(self.history)-1, self.history[-1])
478         return self.history[-1]<=self.tolerance * self.history[0]         return self.history[-1]<=self.tolerance * self.history[0]
479
480       def stoppingcriterium2(self,norm_r,norm_b):
481           """
482           returns True if the C{norm_r} is C{tolerance}*C{norm_b}
483
484
485           @param norm_r: current residual norm
486           @type norm_r: non-negative C{float}
487           @param norm_b: norm of right hand side
488           @type norm_b: non-negative C{float}
489           @return: C{True} is the stopping criterium is fullfilled. Otherwise C{False} is returned.
490           @rtype: C{bool}
491
492           """
493           self.history.append(norm_r)
494           if self.verbose: print "iter: %s:  norm(r) = %e"%(len(self.history)-1, self.history[-1])
495           return self.history[-1]<=self.tolerance * norm_b
496
497  def PCG(b, Aprod, Msolve, bilinearform, stoppingcriterium, x=None, iter_max=100):  def PCG(b, Aprod, Msolve, bilinearform, stoppingcriterium, x=None, iter_max=100):
498     """     """
499     Solver for     Solver for
# Line 872  class HomogeneousSaddlePointProblem(obje Line 889  class HomogeneousSaddlePointProblem(obje
889                self.verbose=verbose                self.verbose=verbose
890                self.show_details=show_details and self.verbose                self.show_details=show_details and self.verbose
891
892                  # assume p is known: then v=A^-1(f-B^*p)
893                  # which leads to BA^-1B^*p = BA^-1f
894
895            # Az=f is solved as A(z-v)=f-Av (z-v = 0 on fixed_u_mask)                  # Az=f is solved as A(z-v)=f-Av (z-v = 0 on fixed_u_mask)
896
897
# Line 899  class HomogeneousSaddlePointProblem(obje Line 919  class HomogeneousSaddlePointProblem(obje
919                  if self.verbose: print "enter PCG method (iter_max=%s)"%max_iter                  if self.verbose: print "enter PCG method (iter_max=%s)"%max_iter
920                  p,r=PCG(ArithmeticTuple(self.__z*1.,Bz),self.__Aprod,self.__Msolve,self.__inner,self.__stoppingcriterium,iter_max=max_iter, x=p)                  p,r=PCG(ArithmeticTuple(self.__z*1.,Bz),self.__Aprod,self.__Msolve,self.__inner,self.__stoppingcriterium,iter_max=max_iter, x=p)
921              u=r[0]                u=r[0]
922                  print "div(u)=",util.Lsup(self.B(u)),util.Lsup(u)
923
924            return u,p            return u,p
925
# Line 912  class HomogeneousSaddlePointProblem(obje Line 933  class HomogeneousSaddlePointProblem(obje
933        def __Aprod(self,p):        def __Aprod(self,p):
934            # return BA^-1B*p            # return BA^-1B*p
935            #solve Av =-B^*p as Av =f-Az-B^*p            #solve Av =-B^*p as Av =f-Az-B^*p
936            v=self.solve_A(self.__z,p)            v=self.solve_A(self.__z,-p)
937            return ArithmeticTuple(v, -self.B(v))            return ArithmeticTuple(v, self.B(v))
938
939        def __Aprod_GMRES(self,p):        def __Aprod_GMRES(self,p):
940            # return BA^-1B*p            # return BA^-1B*p
941            #solve Av =-B^*p as Av =f-Az-B^*p            #solve Av =-B^*p as Av =f-Az-B^*p
942        v=self.solve_A(self.__z,p)        v=self.solve_A(self.__z,-p)
943            return -self.B(v)            return self.B(v)
944