/[escript]/trunk/escript/py_src/flows.py
ViewVC logotype

Contents of /trunk/escript/py_src/flows.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1551 - (show annotations)
Wed May 7 23:11:44 2008 UTC (11 years, 5 months ago) by artak
File MIME type: text/x-python
File size: 5427 byte(s)
RILU canged to ILU0 to fix today's test failure
1 # $Id:$
2 #
3 #######################################################
4 #
5 # Copyright 2008 by University of Queensland
6 #
7 # http://esscc.uq.edu.au
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 #######################################################
13 #
14
15 """
16 Some models for flow
17
18 @var __author__: name of author
19 @var __copyright__: copyrights
20 @var __license__: licence agreement
21 @var __url__: url entry point on documentation
22 @var __version__: version
23 @var __date__: date of the version
24 """
25
26 __author__="Lutz Gross, l.gross@uq.edu.au"
27 __copyright__=""" Copyright (c) 2008 by ACcESS MNRF
28 http://www.access.edu.au
29 Primary Business: Queensland, Australia"""
30 __license__="""Licensed under the Open Software License version 3.0
31 http://www.opensource.org/licenses/osl-3.0.php"""
32 __url__="http://www.iservo.edu.au/esys"
33 __version__="$Revision:$"
34 __date__="$Date:$"
35
36 from escript import *
37 import util
38 from linearPDEs import LinearPDE
39 from pdetools import HomogeneousSaddlePointProblem,Projector
40
41 class StokesProblemCartesian(HomogeneousSaddlePointProblem):
42 """
43 solves
44
45 -(eta*(u_{i,j}+u_{j,i}))_j - p_i = f_i
46 u_{i,i}=0
47
48 u=0 where fixed_u_mask>0
49 eta*(u_{i,j}+u_{j,i})*n_j=surface_stress
50
51 if surface_stress is not give 0 is assumed.
52
53 typical usage:
54
55 sp=StokesProblemCartesian(domain)
56 sp.setTolerance()
57 sp.initialize(...)
58 v,p=sp.solve(v0,p0)
59 """
60 def __init__(self,domain,**kwargs):
61 HomogeneousSaddlePointProblem.__init__(self,**kwargs)
62 self.domain=domain
63 self.vol=util.integrate(1.,Function(self.domain))
64 self.__pde_u=LinearPDE(domain,numEquations=self.domain.getDim(),numSolutions=self.domain.getDim())
65 self.__pde_u.setSymmetryOn()
66 self.__pde_u.setSolverMethod(preconditioner=LinearPDE.ILU0)
67
68 self.__pde_prec=LinearPDE(domain)
69 self.__pde_prec.setReducedOrderOn()
70 self.__pde_prec.setSymmetryOn()
71
72 self.__pde_proj=LinearPDE(domain)
73 self.__pde_proj.setReducedOrderOn()
74 self.__pde_proj.setSymmetryOn()
75 self.__pde_proj.setValue(D=1.)
76
77 def initialize(self,f=Data(),fixed_u_mask=Data(),eta=1,surface_stress=Data()):
78 self.eta=eta
79 A =self.__pde_u.createCoefficientOfGeneralPDE("A")
80 self.__pde_u.setValue(A=Data())
81 for i in range(self.domain.getDim()):
82 for j in range(self.domain.getDim()):
83 A[i,j,j,i] += 1.
84 A[i,j,i,j] += 1.
85 self.__pde_prec.setValue(D=1/eta) #1./self.eta
86 self.__pde_u.setValue(A=A*self.eta,q=fixed_u_mask,Y=f,y=surface_stress)
87
88 def B(self,arg):
89 d=util.div(arg)
90 self.__pde_proj.setValue(Y=d)
91 self.__pde_proj.setTolerance(self.getSubProblemTolerance())
92 return self.__pde_proj.getSolution(verbose=self.show_details)
93
94 def inner(self,p0,p1):
95 s0=util.interpolate(p0,Function(self.domain))
96 s1=util.interpolate(p1,Function(self.domain))
97 return util.integrate(s0*s1)
98
99 def inner_a(self,a0,a1):
100 p0=util.interpolate(a0[1],Function(self.domain))
101 p1=util.interpolate(a1[1],Function(self.domain))
102 alfa=(1/self.vol)*util.integrate(p0)
103 beta=(1/self.vol)*util.integrate(p1)
104 v0=util.grad(a0[0])
105 v1=util.grad(a1[0])
106 #print "NORM",alfa,beta,util.integrate((p0-alfa)*(p1-beta))+util.integrate(util.inner(v0,v1))
107 return util.integrate((p0-alfa)*(p1-beta)+((1/self.eta)**2)*util.inner(v0,v1))
108
109
110 def getStress(self,u):
111 mg=util.grad(u)
112 return 2.*self.eta*util.symmetric(mg)
113
114 def solve_A(self,u,p):
115 """
116 solves Av=f-Au-B^*p (v=0 on fixed_u_mask)
117 """
118 self.__pde_u.setTolerance(self.getSubProblemTolerance())
119 self.__pde_u.setValue(X=-self.getStress(u)-p*util.kronecker(self.domain))
120 return self.__pde_u.getSolution(verbose=self.show_details)
121
122
123 def solve_prec(self,p):
124 #proj=Projector(domain=self.domain, reduce = True, fast=False)
125 self.__pde_prec.setTolerance(self.getSubProblemTolerance())
126 self.__pde_prec.setValue(Y=p)
127 q=self.__pde_prec.getSolution(verbose=self.show_details)
128 q0=util.interpolate(q,Function(self.domain))
129 q-=(1/self.vol)*util.integrate(q0)
130 return q
131
132 def stoppingcriterium(self,Bv,v,p):
133 n_r=util.sqrt(self.inner(Bv,Bv))
134 n_v=util.Lsup(v)
135 if self.verbose: print "PCG step %s: L2(div(v)) = %s, Lsup(v)=%s"%(self.iter,n_r,n_v)
136 self.iter+=1
137 if n_r <= self.vol**(1./2.-1./self.domain.getDim())*n_v*self.getTolerance():
138 if self.verbose: print "PCG terminated after %s steps."%self.iter
139 return True
140 else:
141 return False
142 def stoppingcriterium2(self,norm_r,norm_b,solver='GMRES',TOL=None):
143 if TOL==None:
144 TOL=self.getTolerance()
145 if self.verbose: print "%s step %s: L2(r) = %s, L2(b)*TOL=%s"%(solver,self.iter,norm_r,norm_b*TOL)
146 self.iter+=1
147
148 if norm_r <= norm_b*TOL:
149 if self.verbose: print "%s terminated after %s steps."%(solver,self.iter)
150 return True
151 else:
152 return False
153
154

  ViewVC Help
Powered by ViewVC 1.1.26