/[escript]/trunk/modellib/py_src/flow.py
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 155 - (show annotations)
Wed Nov 9 02:02:19 2005 UTC (13 years, 10 months ago) by jgs
File MIME type: text/x-python
File size: 4059 byte(s)
move all directories from trunk/esys2 into trunk and remove esys2

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

  ViewVC Help
Powered by ViewVC 1.1.26