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

revision 2718 by artak, Tue Sep 29 05:22:51 2009 UTC revision 2719 by gross, Wed Oct 14 06:38:03 2009 UTC
# Line 377  class StokesProblemCartesian(Homogeneous Line 377  class StokesProblemCartesian(Homogeneous
377              sp.initialize(...)              sp.initialize(...)
378              v,p=sp.solve(v0,p0)              v,p=sp.solve(v0,p0)
379       """       """
380       def __init__(self,domain,adaptSubTolerance=True, **kwargs):       def __init__(self,domain,**kwargs):
381           """           """
382           initialize the Stokes Problem           initialize the Stokes Problem
383
384           :param domain: domain of the problem. The approximation order needs to be two.           :param domain: domain of the problem. The approximation order needs to be two.
385           :type domain: `Domain`           :type domain: `Domain`
:param adaptSubTolerance: If True the tolerance for subproblem is set automatically.
386           :warning: The apprximation order needs to be two otherwise you may see oscilations in the pressure.           :warning: The apprximation order needs to be two otherwise you may see oscilations in the pressure.
387           """           """
389           self.domain=domain           self.domain=domain
self.vol=util.integrate(1.,Function(self.domain))
390           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())
391           self.__pde_u.setSymmetryOn()           self.__pde_u.setSymmetryOn()
392
# Line 448  class StokesProblemCartesian(Homogeneous Line 445  class StokesProblemCartesian(Homogeneous
445       :rtype: `SolverOptions`       :rtype: `SolverOptions`
446       """       """
447       return self.__pde_proj.getSolverOptions()       return self.__pde_proj.getSolverOptions()
def setSubProblemTolerance(self):
"""
"""
sub_tol=self.getSubProblemTolerance()
self.getSolverOptionsDiv().setTolerance(sub_tol)
self.getSolverOptionsDiv().setAbsoluteTolerance(0.)
self.getSolverOptionsPressure().setTolerance(sub_tol)
self.getSolverOptionsPressure().setAbsoluteTolerance(0.)
self.getSolverOptionsVelocity().setTolerance(sub_tol)
self.getSolverOptionsVelocity().setAbsoluteTolerance(0.)

448
450          """          """
# Line 492  class StokesProblemCartesian(Homogeneous Line 476  class StokesProblemCartesian(Homogeneous
476          self.__surface_stress=surface_stress          self.__surface_stress=surface_stress
477          self.__stress=stress          self.__stress=stress
478
479       def Bv(self,v):       def Bv(self,v,tol):
480           """           """
481           returns inner product of element p and div(v)           returns inner product of element p and div(v)
482
# Line 500  class StokesProblemCartesian(Homogeneous Line 484  class StokesProblemCartesian(Homogeneous
484           :return: inner product of element p and div(v)           :return: inner product of element p and div(v)
485           :rtype: ``float``           :rtype: ``float``
486           """           """
487           self.__pde_proj.setValue(Y=-util.div(v))           self.__pde_proj.setValue(Y=-util.div(v)) # -???
488           return self.__pde_proj.getSolution()       self.getSolverOptionsDiv().setTolerance(tol)
489         self.getSolverOptionsDiv().setAbsoluteTolerance(0.)
490             out=self.__pde_proj.getSolution()
491             return out
492
493       def inner_pBv(self,p,Bv):       def inner_pBv(self,p,Bv):
494           """           """
# Line 523  class StokesProblemCartesian(Homogeneous Line 510  class StokesProblemCartesian(Homogeneous
510           :return: inner product of p0 and p1           :return: inner product of p0 and p1
511           :rtype: ``float``           :rtype: ``float``
512           """           """
513           s0=util.interpolate(p0/self.eta,Function(self.domain))           s0=util.interpolate(p0,Function(self.domain))
514           s1=util.interpolate(p1/self.eta,Function(self.domain))           s1=util.interpolate(p1,Function(self.domain))
515           return util.integrate(s0*s1)           return util.integrate(s0*s1)
516
517       def norm_v(self,v):       def norm_v(self,v):
# Line 535  class StokesProblemCartesian(Homogeneous Line 522  class StokesProblemCartesian(Homogeneous
522           :return: norm of v           :return: norm of v
523           :rtype: non-negative ``float``           :rtype: non-negative ``float``
524           """           """
526
527       def getV(self, p, v0):       def getDV(self, p, v, tol):
528           """           """
529           return the value for v for a given p (overwrite)           return the value for v for a given p (overwrite)
530
531           :param p: a pressure           :param p: a pressure
532           :param v0: a initial guess for the value v to return.           :param v: a initial guess for the value v to return.
533           :return: v given as *v= A^{-1} (f-B^*p)*           :return: dv given as *Adv=(f-Av-B^*p)*
534           """           """
535           self.__pde_u.setValue(Y=self.__f, y=self.__surface_stress, r=v0)           self.__pde_u.setValue(Y=self.__f, y=self.__surface_stress)
536         self.getSolverOptionsVelocity().setTolerance(tol)
537         self.getSolverOptionsVelocity().setAbsoluteTolerance(0.)
538           if self.__stress.isEmpty():           if self.__stress.isEmpty():
540           else:           else:
542           out=self.__pde_u.getSolution()           out=self.__pde_u.getSolution()
543           return  out           return  out
544
# Line 562  class StokesProblemCartesian(Homogeneous Line 551  class StokesProblemCartesian(Homogeneous
551          """          """
552          return util.sqrt(util.integrate(util.interpolate(Bv,Function(self.domain))**2))          return util.sqrt(util.integrate(util.interpolate(Bv,Function(self.domain))**2))
553
554       def solve_AinvBt(self,p):       def solve_AinvBt(self,p, tol):
555           """           """
556           Solves *Av=B^*p* with accuracy `self.getSubProblemTolerance()`           Solves *Av=B^*p* with accuracy `tol`
557
558           :param p: a pressure increment           :param p: a pressure increment
559           :return: the solution of *Av=B^*p*           :return: the solution of *Av=B^*p*
560           :note: boundary conditions on v should be zero!           :note: boundary conditions on v should be zero!
561           """           """
562           self.__pde_u.setValue(Y=Data(), y=Data(), r=Data(),X=-p*util.kronecker(self.domain))           self.__pde_u.setValue(Y=Data(), y=Data(), X=-p*util.kronecker(self.domain))
563           out=self.__pde_u.getSolution()           out=self.__pde_u.getSolution()
564           return  out           return  out
565
566       def solve_prec(self,Bv):       def solve_prec(self,Bv, tol):
567           """           """
568           applies preconditioner for for *BA^{-1}B^** to *Bv*           applies preconditioner for for *BA^{-1}B^** to *Bv*
569           with accuracy `self.getSubProblemTolerance()`           with accuracy `self.getSubProblemTolerance()`
# Line 584  class StokesProblemCartesian(Homogeneous Line 573  class StokesProblemCartesian(Homogeneous
573           :note: boundary conditions on p are zero.           :note: boundary conditions on p are zero.
574           """           """
575           self.__pde_prec.setValue(Y=Bv)           self.__pde_prec.setValue(Y=Bv)
576           return self.__pde_prec.getSolution()       self.getSolverOptionsPressure().setTolerance(tol)
577         self.getSolverOptionsPressure().setAbsoluteTolerance(0.)
578             out=self.__pde_prec.getSolution()
579             return out

Legend:
 Removed from v.2718 changed lines Added in v.2719