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


1 ksteube 1809
2 jfenwick 3981 ##############################################################################
3 ksteube 1312 #
4 uqaeller 6939 # Copyright (c) 2003-2020 by The University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 ksteube 1312 #
7 ksteube 1809 # Primary Business: Queensland, Australia
8 jfenwick 6112 # Licensed under the Apache License, version 2.0
9     # http://www.apache.org/licenses/LICENSE-2.0
10 ksteube 1312 #
11 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 uqaeller 6939 # Development from 2019 by School of Earth and Environmental Sciences
15 jfenwick 3981 #
16     ##############################################################################
17 jgs 144
18 sshaw 5706 from __future__ import print_function, division
19    
20 uqaeller 6939 __copyright__="""Copyright (c) 2003-2020 by The University of Queensland
21 jfenwick 3981 http://www.uq.edu.au
22 ksteube 1809 Primary Business: Queensland, Australia"""
23 jfenwick 6112 __license__="""Licensed under the Apache License, version 2.0
24     http://www.apache.org/licenses/LICENSE-2.0"""
25 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
26 elspeth 628
27 jfenwick 6638 import esys.escript as es
28     import esys.escript.modelframe as esmf
29     import esys.escript.linearPDEs as lpde
30 jgs 144
31 jfenwick 6638 class SteadyIncompressibleFlow(esmf.Model):
32 jgs 147 """
33 jgs 144
34 jfenwick 2625 *-\left(\eta\left(v_{i,j}+v_{j,i}\right)\right)_{,j}+p_{,i}=F_i*
35 jgs 149
36 jfenwick 2625 *\sigma_{ij}=2\eta D_{ij}-p\,\delta_{ij}*
37 jgs 144
38 jfenwick 2625 *D_{ij}=\frac{1}{2}\left( v_{j,i} + v_{i,j }\right)*
39 jgs 149
40 jfenwick 2625 *v_{k,k} = 0*
41 jgs 144
42     """
43    
44 gross 918 def __init__(self,**kwargs):
45 jgs 149 """
46     set up model
47     """
48 jfenwick 6638 esmf.Model.__init__(self,**kwargs)
49 jgs 144 self.declareParameter(domain=None, \
50     velocity=0., \
51     pressure=0., \
52 jgs 147 viscosity=1., \
53 jgs 144 internal_force=0., \
54 gross 918 location_prescribed_velocity=None, \
55     prescribed_velocity=None, \
56 gross 820 rel_tol=1.e-3,abs_tol=0.,max_iter=10,relaxation=0.0001)
57 jgs 144 self.__iter=0
58    
59 jgs 147 def doInitialization(self):
60 jgs 149 """
61     initialize model
62     """
63 jgs 147 self.__p_old=None
64     self.__p_very_old=None
65     self.__dt_old=None
66 jfenwick 6638 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 jgs 144
71     def stress(self):
72 jgs 149 """
73     returns current stress"""
74 jfenwick 6638 return 2*self.viscosity*self.stretching-self.pressure*es.kronecker(self.domain)
75 jgs 144
76     def stretching(self):
77 jgs 149 """
78     returns stertching tensor
79     """
80 jgs 144 g=grad(self.velocity)
81     return (g+transpose(g))/2
82 jgs 147
83     def doStepPreprocessing(self,dt):
84 jgs 144 """
85 jgs 149 step up pressure iteration
86 jgs 144
87 jgs 149 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 jgs 144 """
90 jgs 147 self.__iter=0
91     self.__diff=1.e40
92 jfenwick 5024 if not self.__p_old is None:
93     if self.__p_very_old is None:
94 jgs 147 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 jgs 144
98 jgs 147 def doStep(self,dt):
99 jgs 144 """
100    
101 jgs 149 performs an iteration step of the penalty method.
102     IterationDivergenceError is raised if pressure error cannot be reduced or max_iter is reached.
103 jgs 144
104     """
105     penalty=self.viscosity/self.relaxation
106 jgs 147 self.__pde.setValue(lame_mu=self.viscosity, \
107     lame_lambda=penalty, \
108     F=self.internal_force, \
109 jfenwick 6638 sigma=self.pressure*es.kronecker(self.__pde.getDomain()), \
110 jgs 147 r=self.prescribed_velocity, \
111     q=self.location_prescribed_velocity)
112 gross 2474 self.__pde.getSolverOptions().setTolerance(self.rel_tol/10.)
113 jgs 147 self.velocity=self.__pde.getSolution()
114 jfenwick 6638 update=penalty*es.div(self.velocity)
115 jgs 144 self.pressure=self.pressure-update
116 jfenwick 6638 self.__diff,diff_old=es.Lsup(update),self.__diff
117 jgs 147 self.__iter+=1
118 jfenwick 6638 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 jgs 147 self.trace("pressure correction: %e"%self.__diff)
121     if self.__iter>2 and diff_old<self.__diff:
122     self.trace("Pressure iteration failed!")
123 jfenwick 6638 raise esmf.IterationDivergenceError("no improvement in pressure iteration")
124 jgs 147 if self.__iter>self.max_iter:
125 jfenwick 6638 raise esmf.IterationDivergenceError("Maximum number of iterations steps reached")
126 jgs 144
127 jgs 147 def terminateIteration(self):
128 caltinay 4285 """iteration is terminateIterationd if relative pressure change is less than rel_tol"""
129 jfenwick 6638 return self.__diff<=self.rel_tol*es.Lsup(self.pressure)+self.abs_tol
130 jgs 144
131 jgs 147 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