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

Revision 1387 - (show annotations)
Fri Jan 11 07:45:26 2008 UTC (13 years, 8 months ago) by trankine
File MIME type: text/x-python
File size: 4996 byte(s)
Restore the trunk that existed before the windows changes were committed to the (now moved to branches) old trunk.

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