/[escript]/trunk/finley/test/python/stokes_problems.py
ViewVC logotype

Contents of /trunk/finley/test/python/stokes_problems.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4154 - (show annotations)
Tue Jan 22 09:30:23 2013 UTC (6 years, 9 months ago) by jfenwick
File MIME type: text/x-python
File size: 4553 byte(s)
Round 1 of copyright fixes
1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2013 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development since 2012 by School of Earth Sciences
13 #
14 ##############################################################################
15
16 __copyright__="""Copyright (c) 2003-2013 by University of Queensland
17 http://www.uq.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __url__="https://launchpad.net/escript-finley"
22
23 """
24 solvers for the stokes problem
25
26 :var __author__: name of author
27 :var __copyright__: copyrights
28 :var __license__: licence agreement
29 :var __url__: url entry point on documentation
30 :var __version__: version
31 :var __date__: date of the version
32 """
33
34 __author__="Lutz Gross, l.gross@uq.edu.au"
35
36 from esys.escript import *
37 from esys.escript.pdetools import SaddlePointProblem
38 from esys.escript.linearPDEs import LinearPDE
39 from esys.finley import Rectangle
40 from esys.weipa import saveVTK
41
42 class SimpleStokesProblem(SaddlePointProblem):
43 """
44 simple example of saddle point problem
45 """
46 def __init__(self,domain):
47 super(SimpleStokesProblem, self).__init__(self)
48
49 self.__pde_u=LinearPDE(domain)
50 self.__pde_u.setSymmetryOn()
51 self.__pde_u.setValue(A=identityTensor4(dom))
52
53 self.__pde_p=LinearPDE(domain)
54 self.__pde_p.setReducedOrderOn()
55 self.__pde_p.setSymmetryOn()
56 self.__pde_p.setValue(D=1.)
57
58 def initialize(self,f=Data(),fixed_u_mask=Data()):
59 self.__pde_u.setValue(q=fixed_u_mask,Y=f)
60 def inner(self,p0,p1):
61 return integrate(p0*p1,Function(self.__pde_p.getDomain()))
62
63 def solve_f(self,u,p,tol=1.e-8):
64 self.__pde_u.setTolerance(tol)
65 self.__pde_u.setValue(X=grad(u)+p*kronecker(self.__pde_u.getDomain()))
66 return self.__pde_u.getSolution()
67 def solve_g(self,u,tol=1.e-8):
68 self.__pde_p.setTolerance(tol)
69 self.__pde_p.setValue(X=-u)
70 dp=self.__pde_p.getSolution()
71 return dp
72
73 class StokesProblem(SaddlePointProblem):
74 """
75 simple example of saddle point problem
76 """
77 def __init__(self,domain):
78 super(StokesProblem, self).__init__(self)
79 self.domain=domain
80 self.__pde_u=LinearPDE(domain,numEquations=self.domain.getDim(),numSolutions=self.domain.getDim())
81 self.__pde_u.setSymmetryOn()
82
83 self.__pde_p=LinearPDE(domain)
84 self.__pde_p.setReducedOrderOn()
85 self.__pde_p.setSymmetryOn()
86
87 def initialize(self,f=Data(),fixed_u_mask=Data(),eta=1):
88 self.eta=eta
89 A =self.__pde_u.createCoefficientOfGeneralPDE("A")
90 for i in range(self.domain.getDim()):
91 for j in range(self.domain.getDim()):
92 A[i,j,j,i] += self.eta
93 A[i,j,i,j] += self.eta
94 self.__pde_p.setValue(D=1./self.eta)
95 self.__pde_u.setValue(A=A,q=fixed_u_mask,Y=f)
96
97 def inner(self,p0,p1):
98 return integrate(p0*p1,Function(self.__pde_p.getDomain()))
99
100 def solve_f(self,u,p,tol=1.e-8):
101 self.__pde_u.setTolerance(tol)
102 g=grad(u)
103 self.__pde_u.setValue(X=self.eta*symmetric(g)+p*kronecker(self.__pde_u.getDomain()))
104 return self.__pde_u.getSolution()
105
106 def solve_g(self,u,tol=1.e-8):
107 self.__pde_p.setTolerance(tol)
108 self.__pde_p.setValue(X=-u)
109 dp=self.__pde_p.getSolution()
110 return dp
111
112 NE=50
113 dom=Rectangle(NE,NE,order=2)
114 # prop=SimpleStokesProblem(dom)
115 prop=StokesProblem(dom)
116 x=dom.getX()
117 mask=(whereZero(x[0])+whereZero(x[0]-1.)+whereZero(x[1]-1.))*unitVector(0,dom)+(whereZero(x[1]-1.)+whereZero(x[1]))*unitVector(1,dom)
118 u0=Vector(0.,Solution(dom))
119 u0[0]=x[1]*whereZero(x[1]-1.)
120 p0=Scalar(0,ReducedSolution(dom))
121 # prop.initialize(fixed_u_mask=mask)
122 prop.initialize(fixed_u_mask=mask,eta=10.)
123 u,p=prop.solve(u0,p0,tolerance=0.01)
124 # saveVTK("stokes.vtu",u=u,p=p,m=mask,u0=u0)
125
126 eta=whereNegative(x[1]-0.5)*1.e6+whereNonNegative(x[1]-0.5)
127 prop.initialize(fixed_u_mask=mask,eta=eta)
128 u,p=prop.solve(u0,p0,tolerance=0.01,tolerance_u=0.1,accepted_reduction=0.8)
129 saveVTK("stokes.vtu",u=u,p=p,m=mask,u0=u0)
130
131 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26