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

revision 2344 by jfenwick, Mon Mar 30 02:13:58 2009 UTC revision 2370 by gross, Mon Apr 6 06:41:49 2009 UTC
# Line 48  class DarcyFlow(object): Line 48  class DarcyFlow(object):
48      @note: The problem is solved in a least squares formulation.      @note: The problem is solved in a least squares formulation.
49      """      """
50
51      def __init__(self, domain,useReduced=False):      def __init__(self, domain, weight=None, useReduced=False):
52          """          """
53          initializes the Darcy flux problem          initializes the Darcy flux problem
54          @param domain: domain of the problem          @param domain: domain of the problem
55          @type domain: L{Domain}          @type domain: L{Domain}
56          """          """
57          self.domain=domain          self.domain=domain
58          self.__l=util.longestEdge(self.domain)**2          if weight == None:
59               s=self.domain.getSize()
60               self.__l=(3.*util.longestEdge(self.domain)*s/util.sup(s))**2
61            else:
62               self.__l=weight
63          self.__pde_v=LinearPDESystem(domain)          self.__pde_v=LinearPDESystem(domain)
64          if useReduced: self.__pde_v.setReducedOrderOn()          if useReduced: self.__pde_v.setReducedOrderOn()
65          self.__pde_v.setSymmetryOn()          self.__pde_v.setSymmetryOn()
66          self.__pde_v.setValue(D=util.kronecker(domain), A=self.__l*util.outer(util.kronecker(domain),util.kronecker(domain)))          self.__pde_v.setValue(D=util.kronecker(domain), A=self.__l*util.outer(util.kronecker(domain),util.kronecker(domain)))
67            # self.__pde_v.setSolverMethod(preconditioner=self.__pde_v.ILU0)
68          self.__pde_p=LinearSinglePDE(domain)          self.__pde_p=LinearSinglePDE(domain)
69          self.__pde_p.setSymmetryOn()          self.__pde_p.setSymmetryOn()
70          if useReduced: self.__pde_p.setReducedOrderOn()          if useReduced: self.__pde_p.setReducedOrderOn()
# Line 263  class DarcyFlow(object): Line 268  class DarcyFlow(object):
268                 if norm_r == None or norm_r>ATOL:                 if norm_r == None or norm_r>ATOL:
269                     if num_corrections>max_num_corrections:                     if num_corrections>max_num_corrections:
270                           raise ValueError,"maximum number of correction steps reached."                           raise ValueError,"maximum number of correction steps reached."
271                     p,r, norm_r=PCG(self.__g-util.interpolate(v,Function(self.domain))-Qp,self.__Aprod,p,self.__Msolve_PCG,self.__inner_PCG,atol=0.1*ATOL, rtol=0.,iter_max=max_iter, verbose=self.verbose)                     p,r, norm_r=PCG(self.__g-util.interpolate(v,Function(self.domain))-Qp,self.__Aprod,p,self.__Msolve_PCG,self.__inner_PCG,atol=0.5*ATOL, rtol=0.,iter_max=max_iter, verbose=self.verbose)
272                     num_corrections+=1                     num_corrections+=1
273                 else:                 else:
274                     converged=True                     converged=True
# Line 327  class DarcyFlow(object): Line 332  class DarcyFlow(object):
332            if self.show_details: print "DarcyFlux: Applying operator"            if self.show_details: print "DarcyFlux: Applying operator"
333            Qdp=self.__Q(dp)            Qdp=self.__Q(dp)
334            self.__pde_v.setValue(Y=-Qdp,X=Data(), r=Data())            self.__pde_v.setValue(Y=-Qdp,X=Data(), r=Data())
335            du=self.__pde_v.getSolution(verbose=self.show_details)            du=self.__pde_v.getSolution(verbose=self.show_details, iter_max = 100000)
336              # self.__pde_v.getOperator().saveMM("proj.mm")
337            return Qdp+du            return Qdp+du
338      def __inner_GMRES(self,r,s):      def __inner_GMRES(self,r,s):
339           return util.integrate(util.inner(r,s))           return util.integrate(util.inner(r,s))
# Line 339  class DarcyFlow(object): Line 345  class DarcyFlow(object):
345            self.__pde_p.setTolerance(self.getSubProblemTolerance())            self.__pde_p.setTolerance(self.getSubProblemTolerance())
346            if self.show_details: print "DarcyFlux: Applying preconditioner"            if self.show_details: print "DarcyFlux: Applying preconditioner"
347            self.__pde_p.setValue(X=util.transposed_tensor_mult(self.__permeability,r), Y=Data(), r=Data())            self.__pde_p.setValue(X=util.transposed_tensor_mult(self.__permeability,r), Y=Data(), r=Data())
348            return self.__pde_p.getSolution(verbose=self.show_details)            # self.__pde_p.getOperator().saveMM("prec.mm")
349              return self.__pde_p.getSolution(verbose=self.show_details, iter_max = 100000)
350
351      def getFlux(self,p=None, fixed_flux=Data(), show_details=False):      def getFlux(self,p=None, fixed_flux=Data(), show_details=False):
352          """          """
# Line 366  class DarcyFlow(object): Line 373  class DarcyFlow(object):
373             self.__pde_v.setValue(Y=g)             self.__pde_v.setValue(Y=g)
374          else:          else:
375             self.__pde_v.setValue(Y=g-self.__Q(p))             self.__pde_v.setValue(Y=g-self.__Q(p))
376          return self.__pde_v.getSolution(verbose=show_details)          return self.__pde_v.getSolution(verbose=show_details, iter_max=100000)
377
379       """       """
# Line 401  class StokesProblemCartesian(Homogeneous Line 408  class StokesProblemCartesian(Homogeneous
408           self.__pde_u=LinearPDE(domain,numEquations=self.domain.getDim(),numSolutions=self.domain.getDim())           self.__pde_u=LinearPDE(domain,numEquations=self.domain.getDim(),numSolutions=self.domain.getDim())
409           self.__pde_u.setSymmetryOn()           self.__pde_u.setSymmetryOn()
410           # self.__pde_u.setSolverMethod(self.__pde_u.DIRECT)           # self.__pde_u.setSolverMethod(self.__pde_u.DIRECT)
411           # self.__pde_u.setSolverMethod(preconditioner=LinearPDE.RILU)           # self.__pde_u.setSolverMethod(preconditioner=LinearPDE.ILU0)
412
413           self.__pde_prec=LinearPDE(domain)           self.__pde_prec=LinearPDE(domain)
414           self.__pde_prec.setReducedOrderOn()           self.__pde_prec.setReducedOrderOn()

Legend:
 Removed from v.2344 changed lines Added in v.2370