/[escript]/branches/3.4.1/modellib/py_src/flow.py
ViewVC logotype

Contents of /branches/3.4.1/modellib/py_src/flow.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4587 - (show annotations)
Wed Dec 11 06:17:09 2013 UTC (5 years, 3 months ago) by jfenwick
File MIME type: text/x-python
File size: 5188 byte(s)
Preparation begins

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