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

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