/[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 5024 - (show annotations)
Tue Jun 10 08:46:07 2014 UTC (5 years, 2 months ago) by jfenwick
File MIME type: text/x-python
File size: 5259 byte(s)
Fixing more == None

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2014 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 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 from esys.escript import Data, kronecker, Lsup, div, inf, sup
25 from esys.escript.modelframe import Model,IterationDivergenceError
26 from esys.escript.linearPDEs import LameEquation, SolverOptions
27
28 class SteadyIncompressibleFlow(Model):
29 """
30
31 *-\left(\eta\left(v_{i,j}+v_{j,i}\right)\right)_{,j}+p_{,i}=F_i*
32
33 *\sigma_{ij}=2\eta D_{ij}-p\,\delta_{ij}*
34
35 *D_{ij}=\frac{1}{2}\left( v_{j,i} + v_{i,j }\right)*
36
37 *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.getSolverOptions().setSolverMethod(SolverOptions.DIRECT)
65 if self.location_prescribed_velocity is None: self.location_prescribed_velocit=Data()
66 if self.prescribed_velocity is 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 is None:
90 if self.__p_very_old is 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.getSolverOptions().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_old<self.__diff:
119 self.trace("Pressure iteration failed!")
120 raise IterationDivergenceError("no improvement in pressure iteration")
121 if self.__iter>self.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 than 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

  ViewVC Help
Powered by ViewVC 1.1.26