/[escript]/trunk/escript/py_src/pdetools.py
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 872 by gross, Mon Oct 9 06:50:09 2006 UTC revision 873 by gross, Mon Oct 16 04:07:33 2006 UTC
# Line 390  class SaddlePointProblem(object): Line 390  class SaddlePointProblem(object):
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    
# Line 402  class SaddlePointProblem(object): Line 402  class SaddlePointProblem(object):
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}
# Line 410  class SaddlePointProblem(object): Line 410  class SaddlePointProblem(object):
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    
# Line 420  class SaddlePointProblem(object): Line 420  class SaddlePointProblem(object):
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
# Line 434  class SaddlePointProblem(object): Line 436  class SaddlePointProblem(object):
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.872  
changed lines
  Added in v.873

  ViewVC Help
Powered by ViewVC 1.1.26