/[escript]/trunk/escriptcore/py_src/flows.py
ViewVC logotype

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

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

revision 2719 by gross, Wed Oct 14 06:38:03 2009 UTC revision 2793 by gross, Tue Dec 1 06:10:10 2009 UTC
# Line 381  class StokesProblemCartesian(Homogeneous Line 381  class StokesProblemCartesian(Homogeneous
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.           The approximation spaces used for velocity (=Solution(domain)) and pressure (=ReducedSolution(domain)) must be
385             LBB complient, for instance using quadratic and linear approximation on the same element or using linear approximation
386             with macro elements for the pressure.
387    
388             :param domain: domain of the problem.
389           :type domain: `Domain`           :type domain: `Domain`
          :warning: The apprximation order needs to be two otherwise you may see oscilations in the pressure.  
390           """           """
391           HomogeneousSaddlePointProblem.__init__(self,**kwargs)           HomogeneousSaddlePointProblem.__init__(self,**kwargs)
392           self.domain=domain           self.domain=domain
# Line 446  class StokesProblemCartesian(Homogeneous Line 449  class StokesProblemCartesian(Homogeneous
449       """       """
450       return self.__pde_proj.getSolverOptions()       return self.__pde_proj.getSolverOptions()
451    
452         def updateStokesEquation(self, v, p):
453             """
454             updates the Stokes equation to consider dependencies from ``v`` and ``p``
455             :note: This method can be overwritten by a subclass. Use `setStokesEquation` to set new values.
456             """
457             pass
458         def setStokesEquation(self, f=None,fixed_u_mask=None,eta=None,surface_stress=None,stress=None, restoration_factor=None):
459            """
460            assigns new values to the model parameters.
461    
462            :param f: external force
463            :type f: `Vector` object in `FunctionSpace` `Function` or similar
464            :param fixed_u_mask: mask of locations with fixed velocity.
465            :type fixed_u_mask: `Vector` object on `FunctionSpace` `Solution` or similar
466            :param eta: viscosity
467            :type eta: `Scalar` object on `FunctionSpace` `Function` or similar
468            :param surface_stress: normal surface stress
469            :type surface_stress: `Vector` object on `FunctionSpace` `FunctionOnBoundary` or similar
470            :param stress: initial stress
471        :type stress: `Tensor` object on `FunctionSpace` `Function` or similar
472            """
473            if eta !=None:
474                k=util.kronecker(self.domain.getDim())
475                kk=util.outer(k,k)
476                self.eta=util.interpolate(eta, Function(self.domain))
477            self.__pde_prec.setValue(D=1/self.eta)
478                self.__pde_u.setValue(A=self.eta*(util.swap_axes(kk,0,3)+util.swap_axes(kk,1,3)))
479            if restoration_factor!=None:
480                n=self.domain.getNormal()
481                self.__pde_u.setValue(d=restoration_factor*util.outer(n,n))
482            if fixed_u_mask!=None:
483                self.__pde_u.setValue(q=fixed_u_mask)
484            if f!=None: self.__f=f
485            if surface_stress!=None: self.__surface_stress=surface_stress
486            if stress!=None: self.__stress=stress
487    
488       def initialize(self,f=Data(),fixed_u_mask=Data(),eta=1,surface_stress=Data(),stress=Data(), restoration_factor=0):       def initialize(self,f=Data(),fixed_u_mask=Data(),eta=1,surface_stress=Data(),stress=Data(), restoration_factor=0):
489          """          """
490          assigns values to the model parameters          assigns values to the model parameters
# Line 460  class StokesProblemCartesian(Homogeneous Line 499  class StokesProblemCartesian(Homogeneous
499          :type surface_stress: `Vector` object on `FunctionSpace` `FunctionOnBoundary` or similar          :type surface_stress: `Vector` object on `FunctionSpace` `FunctionOnBoundary` or similar
500          :param stress: initial stress          :param stress: initial stress
501      :type stress: `Tensor` object on `FunctionSpace` `Function` or similar      :type stress: `Tensor` object on `FunctionSpace` `Function` or similar
         :note: All values needs to be set.  
502          """          """
503          self.eta=eta          self.setStokesEquation(f,fixed_u_mask, eta, surface_stress, stress, restoration_factor)
         A =self.__pde_u.createCoefficient("A")  
     self.__pde_u.setValue(A=Data())  
         for i in range(self.domain.getDim()):  
         for j in range(self.domain.getDim()):  
             A[i,j,j,i] += 1.  
             A[i,j,i,j] += 1.  
         n=self.domain.getNormal()  
     self.__pde_prec.setValue(D=1/self.eta)  
         self.__pde_u.setValue(A=A*self.eta,q=fixed_u_mask, d=restoration_factor*util.outer(n,n))  
         self.__f=f  
         self.__surface_stress=surface_stress  
         self.__stress=stress  
504    
505       def Bv(self,v,tol):       def Bv(self,v,tol):
506           """           """
# Line 484  class StokesProblemCartesian(Homogeneous Line 510  class StokesProblemCartesian(Homogeneous
510           :return: inner product of element p and div(v)           :return: inner product of element p and div(v)
511           :rtype: ``float``           :rtype: ``float``
512           """           """
513           self.__pde_proj.setValue(Y=-util.div(v)) # -???           self.__pde_proj.setValue(Y=-util.div(v))
514       self.getSolverOptionsDiv().setTolerance(tol)       self.getSolverOptionsDiv().setTolerance(tol)
515       self.getSolverOptionsDiv().setAbsoluteTolerance(0.)       self.getSolverOptionsDiv().setAbsoluteTolerance(0.)
516           out=self.__pde_proj.getSolution()           out=self.__pde_proj.getSolution()
# Line 524  class StokesProblemCartesian(Homogeneous Line 550  class StokesProblemCartesian(Homogeneous
550           """           """
551           return util.sqrt(util.integrate(util.length(util.grad(v))**2))           return util.sqrt(util.integrate(util.length(util.grad(v))**2))
552    
553    
554       def getDV(self, p, v, tol):       def getDV(self, p, v, tol):
555           """           """
556           return the value for v for a given p (overwrite)           return the value for v for a given p (overwrite)
# Line 532  class StokesProblemCartesian(Homogeneous Line 559  class StokesProblemCartesian(Homogeneous
559           :param v: a initial guess for the value v to return.           :param v: a initial guess for the value v to return.
560           :return: dv given as *Adv=(f-Av-B^*p)*           :return: dv given as *Adv=(f-Av-B^*p)*
561           """           """
562             self.updateStokesEquation(v,p)
563           self.__pde_u.setValue(Y=self.__f, y=self.__surface_stress)           self.__pde_u.setValue(Y=self.__f, y=self.__surface_stress)
564       self.getSolverOptionsVelocity().setTolerance(tol)       self.getSolverOptionsVelocity().setTolerance(tol)
565       self.getSolverOptionsVelocity().setAbsoluteTolerance(0.)       self.getSolverOptionsVelocity().setAbsoluteTolerance(0.)

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

  ViewVC Help
Powered by ViewVC 1.1.26