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

revision 867 by gross, Mon Oct 9 06:50:09 2006 UTC revision 873 by gross, Mon Oct 16 04:07:33 2006 UTC
390         """         """
391         if self.__verbose: print "%s: %s"%(str(self),text)         if self.__verbose: print "%s: %s"%(str(self),text)
392
393     def solve_f(self,u,p,tol=1.e-7,*args):     def solve_f(self,u,p,tol=1.e-8):
394         """         """
395         solves         solves
396
402         @type u: L{escript.Data}         @type u: L{escript.Data}
403         @param p: current approximation of p         @param p: current approximation of p
404         @type p: L{escript.Data}         @type p: L{escript.Data}
405         @param tol: tolerance for du         @param tol: tolerance expected for du
406         @type tol: C{float}         @type tol: C{float}
407         @return: increment du         @return: increment du
408         @rtype: L{escript.Data}         @rtype: L{escript.Data}
410         """         """
411         pass         pass
412
413     def solve_g(self,u,*args):     def solve_g(self,u,tol=1.e-8):
414         """         """
415         solves         solves
416
420
421         @param u: current approximation of u         @param u: current approximation of u
422         @type u: L{escript.Data}         @type u: L{escript.Data}
423           @param tol: tolerance expected for dp
424           @type tol: C{float}
425         @return: increment dp         @return: increment dp
426         @rtype: L{escript.Data}         @rtype: L{escript.Data}
427         @note: this method has to be overwritten by a particular saddle point problem         @note: this method has to be overwritten by a particular saddle point problem
436         """         """
437         pass         pass
438
439     def solve(self,u0,p0,tolerance=1.e-6,*args):     def solve(self,u0,p0,tolerance=1.e-6,iter_max=10,relaxation=1.):
440         pass        tol=1.e-2
441          iter=0
442          converged=False
443          u=u0*1.
444          p=p0*1.
445          while not converged and iter<iter_max:
446              du=self.solve_f(u,p,tol)
447              u-=du
448              norm_du=util.Lsup(du)
449              norm_u=util.Lsup(u)
450
451              dp=relaxation*self.solve_g(u,tol)
452              p+=dp
453              norm_dp=util.sqrt(self.inner(dp,dp))
454              norm_p=util.sqrt(self.inner(p,p))
455              print iter,"-th step rel. errror u,p= (%s,%s)(%s,%s)"%(norm_du/norm_u,norm_dp/norm_p,norm_u,norm_p)
456              iter+=1
457
458              converged = (norm_du <= tolerance*norm_u) and  (norm_dp <= tolerance*norm_p)
459          if converged:
460              print "convergence after %s steps."%iter
461          else:
462              raise ArithmeticError("no convergence after %s steps."%iter)
463
464          return u,p
465
466  # vim: expandtab shiftwidth=4:  # vim: expandtab shiftwidth=4:

Legend:
 Removed from v.867 changed lines Added in v.873