/[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 6939 - (show annotations)
Mon Jan 20 03:37:18 2020 UTC (6 months, 2 weeks ago) by uqaeller
File MIME type: text/x-python
File size: 5340 byte(s)
Updated the copyright header.


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