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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4984 - (show annotations)
Mon Jun 2 02:50:34 2014 UTC (5 years, 2 months ago) by sshaw
File MIME type: text/x-python
File size: 14041 byte(s)
revamping testrunners, now uses automated discovery and allows running specific tests without modifying files (see escriptcore/py_src/testing.py for more info/examples)

1 # -*- coding: utf-8 -*-
2
3 ##############################################################################
4 #
5 # Copyright (c) 2003-2014 by University of Queensland
6 # http://www.uq.edu.au
7 #
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 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
13 # Development 2012-2013 by School of Earth Sciences
14 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
15 #
16 ##############################################################################
17
18 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
19 http://www.uq.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 __url__="https://launchpad.net/escript-finley"
24
25 import esys.escriptcore.utestselect as unittest
26 from esys.escriptcore.testing import *
27 import tempfile
28
29
30
31 VERBOSE=False and True
32
33 from esys.escript import *
34 from esys.escript.models import DarcyFlow
35 from esys.finley import Rectangle, Brick
36
37 from math import pi
38 import numpy
39 import sys
40 import os
41 #====================================================================================================================
42 try:
43 FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']
44 except KeyError:
45 FINLEY_WORKDIR='.'
46
47 class Darcy(unittest.TestCase):
48 # this is a simple test for the darcy flux problem
49 #
50 #
51 # p = 1/k * ( 1/2* (fb-f0)/xb* x **2 + f0 * x - ub*x ) + p0
52 #
53 # with f = (fb-f0)/xb* x + f0
54 #
55 # u = f - k * p,x = ub
56 #
57 # we prescribe pressure at x=x0=0 to p0
58 #
59 # if we prescribe the pressure on the bottom x=xb we set
60 #
61 # pb= 1/k * ( 1/2* (fb-f0)* xb + f0 * xb - ub*xb ) + p0 = 1/k * ((fb+f0)/2 - ub ) * xb + p0
62 #
63 # which leads to ub = (fb+f0)/2-k*(pb-p0)/xb
64 #
65 def rescaleDomain(self):
66 x=self.dom.getX().copy()
67 for i in range(self.dom.getDim()):
68 x_inf=inf(x[i])
69 x_sup=sup(x[i])
70 if i == self.dom.getDim()-1:
71 x[i]=-self.WIDTH*(x[i]-x_sup)/(x_inf-x_sup)
72 else:
73 x[i]=self.WIDTH*(x[i]-x_inf)/(x_sup-x_inf)
74 self.dom.setX(x)
75 def getScalarMask(self,include_bottom=True):
76 x=self.dom.getX().copy()
77 x_inf=inf(x[self.dom.getDim()-1])
78 x_sup=sup(x[self.dom.getDim()-1])
79 out=whereZero(x[self.dom.getDim()-1]-x_sup)
80 if include_bottom: out+=whereZero(x[self.dom.getDim()-1]-x_inf)
81 return wherePositive(out)
82 def getVectorMask(self,include_bottom=True):
83 x=self.dom.getX().copy()
84 out=Vector(0.,Solution(self.dom))
85 for i in range(self.dom.getDim()):
86 x_inf=inf(x[i])
87 x_sup=sup(x[i])
88 if i != self.dom.getDim()-1: out[i]+=whereZero(x[i]-x_sup)
89 if i != self.dom.getDim()-1 or include_bottom: out[i]+=whereZero(x[i]-x_inf)
90 return wherePositive(out)
91
92 def setSolutionFixedBottom(self, p0, pb, f0, fb, k):
93 d=self.dom.getDim()
94 x=self.dom.getX()[d-1]
95 xb=inf(x)
96 u=Vector(0.,Solution(self.dom))+kronecker(d)[d-1]*((f0+fb)/2.-k*(pb-p0)/xb)
97 p=1./k*((fb-f0)/(xb*2.)* x**2 - (fb-f0)/2.*x)+(pb-p0)/xb*x + p0
98 f= ((fb-f0)/xb* x + f0)*kronecker(Function(self.dom))[d-1]
99 return u,p,f
100
101 def testConstF_FixedBottom_smallK(self):
102 k=1.e-8
103 mp=self.getScalarMask(include_bottom=True)
104 mv=self.getVectorMask(include_bottom=False)
105 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)
106 p=p_ref*mp
107 u=u_ref*mv
108 df=DarcyFlow(self.dom, verbose=VERBOSE, solver=self.SOLVER)
109 df.setValue(g=f,
110 location_of_fixed_pressure=mp,
111 location_of_fixed_flux=mv,
112 permeability=Scalar(k,Function(self.dom)))
113 v,p=df.solve(u_ref,p)
114
115
116 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
117 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
118 def testConstF_FixedBottom_mediumK(self):
119 k=1.
120 mp=self.getScalarMask(include_bottom=True)
121 mv=self.getVectorMask(include_bottom=False)
122 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)
123 p=p_ref*mp
124 u=u_ref*mv
125 df=DarcyFlow(self.dom, verbose=VERBOSE, solver=self.SOLVER)
126 df.setValue(g=f,
127 location_of_fixed_pressure=mp,
128 location_of_fixed_flux=mv,
129 permeability=Scalar(k,Function(self.dom)))
130 v,p=df.solve(u,p )
131
132
133 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
134 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
135
136 def testConstF_FixedBottom_largeK(self):
137 k=1.e8
138 mp=self.getScalarMask(include_bottom=True)
139 mv=self.getVectorMask(include_bottom=False)
140 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)
141 p=p_ref*mp
142 u=u_ref*mv
143 df=DarcyFlow(self.dom, verbose=VERBOSE, solver=self.SOLVER)
144 df.setValue(g=f,
145 location_of_fixed_pressure=mp,
146 location_of_fixed_flux=mv,
147 permeability=Scalar(k,Function(self.dom)))
148 v,p=df.solve(u,p)
149 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
150 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
151
152 def testVarioF_FixedBottom_smallK(self):
153 k=1.e-8
154 mp=self.getScalarMask(include_bottom=True)
155 mv=self.getVectorMask(include_bottom=False)
156 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)
157 p=p_ref*mp
158 u=u_ref*mv
159 df=DarcyFlow(self.dom, verbose=VERBOSE, solver=self.SOLVER)
160 #df.getSolverOptionsPressure().setVerbosityOn()
161 df.setValue(g=f,
162 location_of_fixed_pressure=mp,
163 location_of_fixed_flux=mv,
164 permeability=Scalar(k,Function(self.dom)))
165 v,p=df.solve(u,p)
166
167 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
168 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
169
170 def testVarioF_FixedBottom_mediumK(self):
171 k=1.
172 mp=self.getScalarMask(include_bottom=True)
173 mv=self.getVectorMask(include_bottom=False)
174 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)
175 p=p_ref *mp
176 u=u_ref *mv
177 df=DarcyFlow(self.dom, verbose=VERBOSE, solver=self.SOLVER)
178 df.setValue(g=f,
179 location_of_fixed_pressure=mp,
180 location_of_fixed_flux=mv,
181 permeability=Scalar(k,Function(self.dom)))
182 v,p=df.solve(u,p)
183
184 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
185 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
186
187 def testVarioF_FixedBottom_largeK(self):
188 k=1.e8
189 mp=self.getScalarMask(include_bottom=True)
190 mv=self.getVectorMask(include_bottom=False)
191 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)
192 p=p_ref*mp
193
194 u=u_ref*mv
195 df=DarcyFlow(self.dom, verbose=VERBOSE, solver=self.SOLVER)
196 df.setValue(g=f,
197 location_of_fixed_pressure=mp,
198 location_of_fixed_flux=mv,
199 permeability=Scalar(k,Function(self.dom)))
200 v,p=df.solve(u,p)
201
202 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
203 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
204
205 def testConstF_FreeBottom_smallK(self):
206 k=1.e-8
207 mp=self.getScalarMask(include_bottom=False)
208 mv=self.getVectorMask(include_bottom=True)
209 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)
210 p=p_ref # *mp
211 u=u_ref*mv
212 df=DarcyFlow(self.dom, verbose=VERBOSE, solver=self.SOLVER)
213 df.setValue(g=f,
214 location_of_fixed_pressure=mp,
215 location_of_fixed_flux=mv,
216 permeability=Scalar(k,Function(self.dom)))
217
218 v,p=df.solve(u,p)
219
220 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
221 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
222
223 def testConstF_FreeBottom_mediumK(self):
224 k=1.
225 mp=self.getScalarMask(include_bottom=False)
226 mv=self.getVectorMask(include_bottom=True)
227 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)
228 p=p_ref *mp
229 u=u_ref*mv
230 df=DarcyFlow(self.dom, verbose=VERBOSE, solver=self.SOLVER)
231 df.setValue(g=f,
232 location_of_fixed_pressure=mp,
233 location_of_fixed_flux=mv,
234 permeability=Scalar(k,Function(self.dom)))
235 v,p=df.solve(u,p)
236
237
238 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
239 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
240
241 def testConstF_FreeBottom_largeK(self):
242 k=1.e8
243 mp=self.getScalarMask(include_bottom=False)
244 mv=self.getVectorMask(include_bottom=True)
245 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)
246 p=p_ref*mp
247 u=u_ref*mv
248 df=DarcyFlow(self.dom, verbose=VERBOSE, solver=self.SOLVER)
249 #df.getSolverOptionsPressure().setVerbosityOn()
250 df.setValue(g=f,
251 location_of_fixed_pressure=mp,
252 location_of_fixed_flux=mv,
253 permeability=Scalar(k,Function(self.dom)))
254 v,p=df.solve(u,p)
255 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
256 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
257
258 def testVarioF_FreeBottom_smallK(self):
259 k=1.e-8
260 mp=self.getScalarMask(include_bottom=False)
261 mv=self.getVectorMask(include_bottom=True)
262 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)
263 p=p_ref*mp
264 u=u_ref*mv
265 df=DarcyFlow(self.dom, verbose=VERBOSE, solver=self.SOLVER)
266 df.setValue(g=f,
267 location_of_fixed_pressure=mp,
268 location_of_fixed_flux=mv,
269 permeability=Scalar(k,Function(self.dom)))
270 v,p=df.solve(u,p)
271
272 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
273 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
274
275 def testVarioF_FreeBottom_mediumK(self):
276 k=1.
277 mp=self.getScalarMask(include_bottom=False)
278 mv=self.getVectorMask(include_bottom=True)
279 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)
280 p=p_ref*mp
281 u=u_ref*mv
282 df=DarcyFlow(self.dom, verbose=VERBOSE, solver=self.SOLVER)
283 df.setValue(g=f,
284 location_of_fixed_pressure=mp,
285 location_of_fixed_flux=mv,
286 permeability=Scalar(k,Function(self.dom)))
287 v,p=df.solve(u,p)
288 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
289 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
290
291 def testVarioF_FreeBottom_largeK(self):
292 k=1.e8
293 mp=self.getScalarMask(include_bottom=False)
294 mv=self.getVectorMask(include_bottom=True)
295 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)
296 p=p_ref*mp
297 u=u_ref*mv
298 df=DarcyFlow(self.dom, verbose=VERBOSE, solver=self.SOLVER)
299 df.setValue(g=f,
300 location_of_fixed_pressure=mp,
301 location_of_fixed_flux=mv,
302 permeability=Scalar(k,Function(self.dom)))
303 v,p=df.solve(u,p)
304 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
305 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
306
307 class Darcy2D(Darcy):
308 TOL=1e-4
309 WIDTH=1.
310 SOLVER=DarcyFlow.POST
311 def setUp(self):
312 NE=40 # wrning smaller NE may case a failure for VarioF tests due to discretization errors.
313 self.dom = Rectangle(NE,NE)
314 self.rescaleDomain()
315 def tearDown(self):
316 del self.dom
317
318 class Test_Darcy2D_EVAL(Darcy2D):
319 TEST_TOL=0.01
320 SOLVER=DarcyFlow.EVAL
321
322 class Test_Darcy2D_POST(Darcy2D):
323 TEST_TOL=1.e-3
324 SOLVER=DarcyFlow.POST
325
326 class Test_Darcy2D_SMOOTH(Darcy2D):
327 TEST_TOL=0.01
328 SOLVER=DarcyFlow.SMOOTH
329
330 class Darcy3D(Darcy):
331 WIDTH=1.
332 SOLVER=DarcyFlow.POST
333 def setUp(self):
334 NE=29 # wrning smaller NE may case a failure for VarioF tests due to discretization errors.
335 self.dom = Brick(NE,NE,NE)
336 self.rescaleDomain()
337 def tearDown(self):
338 del self.dom
339
340 class Test_Darcy3D_EVAL(Darcy3D):
341 TEST_TOL=0.01
342 SOLVER=DarcyFlow.EVAL
343
344 class Test_Darcy3D_POST(Darcy3D):
345 TEST_TOL=1.e-3
346 SOLVER=DarcyFlow.POST
347
348 class Test_Darcy3D_SMOOTH(Darcy3D):
349 TEST_TOL=0.01
350 SOLVER=DarcyFlow.SMOOTH
351
352
353 if __name__ == '__main__':
354 run_tests(__name__, classes=[
355 Test_Darcy3D_EVAL, Test_Darcy3D_POST, Test_Darcy3D_SMOOTH,
356 Test_Darcy2D_EVAL, Test_Darcy2D_POST, Test_Darcy2D_SMOOTH
357 ],exit_on_failure=True)
358
359

  ViewVC Help
Powered by ViewVC 1.1.26