/[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 918 - (hide annotations)
Wed Jan 3 06:30:00 2007 UTC (13 years, 1 month ago) by gross
Original Path: trunk/modellib/py_src/flow.py
File MIME type: text/x-python
File size: 4575 byte(s)
fixes on ESySXML to get runmodel going.

    * object ids are now local for read and write of XML
    * ParameterSets are now written with class name
    * ParameterSets linked by other ParameterSets (previously only Models) are written now 
    * list are now lists of str (rather than bools), lists with bool, int or float are mapped to numarray
    * numarray are writen with generic types Bool, Int, Float (portability!)


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