/[escript]/release/5.2/modellib/py_src/flow.py
ViewVC logotype

Contents of /release/5.2/modellib/py_src/flow.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6692 - (show annotations)
Mon Jun 25 02:31:06 2018 UTC (2 years, 11 months ago) by jfenwick
File MIME type: text/x-python
File size: 5270 byte(s)
Fix

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