# Contents of /trunk/modellib/py_src/flow.py

Revision 3432 - (show annotations)
Fri Jan 7 01:32:07 2011 UTC (9 years, 9 months ago) by jfenwick
File MIME type: text/x-python
File size: 5124 byte(s)
Made import statements a bit more specific to clean up the epydoc

 1 2 ######################################################## 3 # 4 # Copyright (c) 2003-2010 by University of Queensland 5 # Earth Systems Science Computational Center (ESSCC) 6 7 # 8 # Primary Business: Queensland, Australia 9 # Licensed under the Open Software License version 3.0 10 11 # 12 ######################################################## 13 14 __copyright__="""Copyright (c) 2003-2010 by University of Queensland 15 Earth Systems Science Computational Center (ESSCC) 16 http://www.uq.edu.au/esscc 17 Primary Business: Queensland, Australia""" 18 __license__="""Licensed under the Open Software License version 3.0 19 20 __url__= 21 22 from esys.escript import Data, kronecker, Lsup, div, inf, sup 23 from esys.escript.modelframe import Model,IterationDivergenceError 24 from esys.escript.linearPDEs import LameEquation 25 26 class SteadyIncompressibleFlow(Model): 27 """ 28 29 *-\left(\eta\left(v_{i,j}+v_{j,i}\right)\right)_{,j}+p_{,i}=F_i* 30 31 *\sigma_{ij}=2\eta D_{ij}-p\,\delta_{ij}* 32 33 *D_{ij}=\frac{1}{2}\left( v_{j,i} + v_{i,j }\right)* 34 35 *v_{k,k} = 0* 36 37 """ 38 39 def __init__(self,**kwargs): 40 """ 41 set up model 42 """ 43 Model.__init__(self,**kwargs) 44 self.declareParameter(domain=None, \ 45 velocity=0., \ 46 pressure=0., \ 47 viscosity=1., \ 48 internal_force=0., \ 49 location_prescribed_velocity=None, \ 50 prescribed_velocity=None, \ 51 rel_tol=1.e-3,abs_tol=0.,max_iter=10,relaxation=0.0001) 52 self.__iter=0 53 54 def doInitialization(self): 55 """ 56 initialize model 57 """ 58 self.__p_old=None 59 self.__p_very_old=None 60 self.__dt_old=None 61 self.__pde=LameEquation(self.domain) 62 self.__pde.getSolverOptions().setSolverMethod(self.__pde.getSolverOptions().DIRECT) 63 if self.location_prescribed_velocity == None: self.location_prescribed_velocit=Data() 64 if self.prescribed_velocity == None: self.prescribed_velocity=Data() 65 66 def stress(self): 67 """ 68 returns current stress""" 69 return 2*self.viscosity*self.stretching-self.pressure*kronecker(self.domain) 70 71 def stretching(self): 72 """ 73 returns stertching tensor 74 """ 75 g=grad(self.velocity) 76 return (g+transpose(g))/2 77 78 def doStepPreprocessing(self,dt): 79 """ 80 step up pressure iteration 81 82 if run within a time dependend problem extrapolation of pressure from previous time steps is used to 83 get an initial guess (that needs some work!!!!!!!) 84 """ 85 self.__iter=0 86 self.__diff=1.e40 87 if not self.__p_old==None: 88 if self.__p_very_old==None: 89 self.pressure=self.__p_old 90 else: 91 self.pressure=(1.+dt/self.__dt_old)*self.__p_old-dt/self.__dt_old*self.__p_very_old 92 93 def doStep(self,dt): 94 """ 95 96 performs an iteration step of the penalty method. 97 IterationDivergenceError is raised if pressure error cannot be reduced or max_iter is reached. 98 99 """ 100 penalty=self.viscosity/self.relaxation 101 self.__pde.setValue(lame_mu=self.viscosity, \ 102 lame_lambda=penalty, \ 103 F=self.internal_force, \ 104 sigma=self.pressure*kronecker(self.__pde.getDomain()), \ 105 r=self.prescribed_velocity, \ 106 q=self.location_prescribed_velocity) 107 self.__pde.getSolverOptions().setTolerance(self.rel_tol/10.) 108 self.velocity=self.__pde.getSolution() 109 update=penalty*div(self.velocity) 110 self.pressure=self.pressure-update 111 self.__diff,diff_old=Lsup(update),self.__diff 112 self.__iter+=1 113 self.trace("velocity range %e:%e"%(inf(self.velocity),sup(self.velocity))) 114 self.trace("pressure range %e:%e"%(inf(self.pressure),sup(self.pressure))) 115 self.trace("pressure correction: %e"%self.__diff) 116 if self.__iter>2 and diff_oldself.max_iter: 120 raise IterationDivergenceError,"Maximum number of iterations steps reached" 121 122 def terminateIteration(self): 123 """iteration is terminateIterationd if relative pressure change is less then rel_tol""" 124 return self.__diff<=self.rel_tol*Lsup(self.pressure)+self.abs_tol 125 126 def doStepPostprocessing(self,dt): 127 self.__dt_old=dt 128 self.__p_old,self.__p_very_old=self.pressure,self.__p_old

## Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision