/[escript]/temp_trunk_copy/modellib/py_src/flow.py
ViewVC logotype

Annotation of /temp_trunk_copy/modellib/py_src/flow.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1384 - (hide annotations)
Fri Jan 11 02:29:38 2008 UTC (12 years, 1 month ago) by phornby
File MIME type: text/x-python
File size: 4996 byte(s)
Make a temp copy of the trunk before checking in the windows changes


1 ksteube 1312 #
2 jgs 144 # $Id$
3 ksteube 1312 #
4     #######################################################
5     #
6     # Copyright 2003-2007 by ACceSS MNRF
7     # Copyright 2007 by University of Queensland
8     #
9     # http://esscc.uq.edu.au
10     # Primary Business: Queensland, Australia
11     # Licensed under the Open Software License version 3.0
12     # http://www.opensource.org/licenses/osl-3.0.php
13     #
14     #######################################################
15     #
16 jgs 144
17 ksteube 1312
18 elspeth 628 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
19     http://www.access.edu.au
20     Primary Business: Queensland, Australia"""
21     __license__="""Licensed under the Open Software License version 3.0
22     http://www.opensource.org/licenses/osl-3.0.php"""
23    
24 jgs 149 from esys.escript import *
25     from esys.escript.modelframe import Model,IterationDivergenceError
26     from esys.escript.linearPDEs import LameEquation
27 jgs 144
28     class SteadyIncompressibleFlow(Model):
29 jgs 147 """
30 jgs 144
31 jgs 149 M{-\left(\eta\left(v_{i,j}+v_{j,i}\right)\right)_{,j}+p_{,i}=F_i}
32    
33     M{\sigma_{ij}=2\eta D_{ij}-p\,\delta_{ij}}
34 jgs 144
35 jgs 149 M{D_{ij}=\frac{1}{2}\left( v_{j,i} + v_{i,j }\right)}
36    
37     M{v_{k,k} = 0}
38 jgs 144
39     """
40    
41 gross 918 def __init__(self,**kwargs):
42 jgs 149 """
43     set up model
44     """
45 gross 918 Model.__init__(self,**kwargs)
46 jgs 144 self.declareParameter(domain=None, \
47     velocity=0., \
48     pressure=0., \
49 jgs 147 viscosity=1., \
50 jgs 144 internal_force=0., \
51 gross 918 location_prescribed_velocity=None, \
52     prescribed_velocity=None, \
53 gross 820 rel_tol=1.e-3,abs_tol=0.,max_iter=10,relaxation=0.0001)
54 jgs 144 self.__iter=0
55    
56 jgs 147 def doInitialization(self):
57 jgs 149 """
58     initialize model
59     """
60 jgs 147 self.__p_old=None
61     self.__p_very_old=None
62     self.__dt_old=None
63 jgs 144 self.__pde=LameEquation(self.domain)
64 gross 820 self.__pde.setSolverMethod(LameEquation.DIRECT)
65 gross 918 if self.location_prescribed_velocity == None: self.location_prescribed_velocit=Data()
66     if self.prescribed_velocity == None: self.prescribed_velocity=Data()
67 jgs 144
68     def stress(self):
69 jgs 149 """
70     returns current stress"""
71 jgs 147 return 2*self.viscosity*self.stretching-self.pressure*kronecker(self.domain)
72 jgs 144
73     def stretching(self):
74 jgs 149 """
75     returns stertching tensor
76     """
77 jgs 144 g=grad(self.velocity)
78     return (g+transpose(g))/2
79 jgs 147
80     def doStepPreprocessing(self,dt):
81 jgs 144 """
82 jgs 149 step up pressure iteration
83 jgs 144
84 jgs 149 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 jgs 144 """
87 jgs 147 self.__iter=0
88     self.__diff=1.e40
89     if not self.__p_old==None:
90     if self.__p_very_old==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 jgs 144
95 jgs 147 def doStep(self,dt):
96 jgs 144 """
97    
98 jgs 149 performs an iteration step of the penalty method.
99     IterationDivergenceError is raised if pressure error cannot be reduced or max_iter is reached.
100 jgs 144
101     """
102     penalty=self.viscosity/self.relaxation
103 jgs 147 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.setTolerance(self.rel_tol/10.)
110     self.velocity=self.__pde.getSolution()
111 jgs 144 update=penalty*div(self.velocity)
112     self.pressure=self.pressure-update
113 jgs 147 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 jgs 144 raise IterationDivergenceError,"no improvement in pressure iteration"
121 jgs 147 if self.__iter>self.max_iter:
122     raise IterationDivergenceError,"Maximum number of iterations steps reached"
123 jgs 144
124 jgs 147 def terminateIteration(self):
125     """iteration is terminateIterationd if relative pressure change is less then rel_tol"""
126     return self.__diff<=self.rel_tol*Lsup(self.pressure)+self.abs_tol
127 jgs 144
128 jgs 147 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