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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 155 - (hide annotations)
Wed Nov 9 02:02:19 2005 UTC (15 years 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 jgs 144 # $Id$
2    
3 jgs 149 from esys.escript import *
4     from esys.escript.modelframe import Model,IterationDivergenceError
5     from esys.escript.linearPDEs import LameEquation
6 jgs 144
7     class SteadyIncompressibleFlow(Model):
8 jgs 147 """
9 jgs 144
10 jgs 149 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 jgs 144
14 jgs 149 M{D_{ij}=\frac{1}{2}\left( v_{j,i} + v_{i,j }\right)}
15    
16     M{v_{k,k} = 0}
17 jgs 144
18     """
19    
20     def __init__(self,debug=False):
21 jgs 149 """
22     set up model
23     """
24 jgs 144 Model.__init__(self,debug=debug)
25     self.declareParameter(domain=None, \
26     velocity=0., \
27     pressure=0., \
28 jgs 147 viscosity=1., \
29 jgs 144 internal_force=0., \
30 jgs 147 location_prescribed_velocity=Data(), \
31     prescribed_velocity=Data(), \
32     rel_tol=1.e-3,abs_tol=0.,max_iter=10,relaxation=0.001)
33 jgs 144 self.__iter=0
34    
35 jgs 147 def doInitialization(self):
36 jgs 149 """
37     initialize model
38     """
39 jgs 147 self.__p_old=None
40     self.__p_very_old=None
41     self.__dt_old=None
42 jgs 144 self.__pde=LameEquation(self.domain)
43    
44     def stress(self):
45 jgs 149 """
46     returns current stress"""
47 jgs 147 return 2*self.viscosity*self.stretching-self.pressure*kronecker(self.domain)
48 jgs 144
49     def stretching(self):
50 jgs 149 """
51     returns stertching tensor
52     """
53 jgs 144 g=grad(self.velocity)
54     return (g+transpose(g))/2
55 jgs 147
56     def doStepPreprocessing(self,dt):
57 jgs 144 """
58 jgs 149 step up pressure iteration
59 jgs 144
60 jgs 149 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 jgs 144 """
63 jgs 147 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 jgs 144
71 jgs 147 def doStep(self,dt):
72 jgs 144 """
73    
74 jgs 149 performs an iteration step of the penalty method.
75     IterationDivergenceError is raised if pressure error cannot be reduced or max_iter is reached.
76 jgs 144
77     """
78     penalty=self.viscosity/self.relaxation
79 jgs 147 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 jgs 144 update=penalty*div(self.velocity)
88     self.pressure=self.pressure-update
89 jgs 147 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 jgs 144 raise IterationDivergenceError,"no improvement in pressure iteration"
97 jgs 147 if self.__iter>self.max_iter:
98     raise IterationDivergenceError,"Maximum number of iterations steps reached"
99 jgs 144
100 jgs 147 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 jgs 144
104 jgs 147 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