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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4984 - (hide annotations)
Mon Jun 2 02:50:34 2014 UTC (5 years, 3 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 gross 3503 # -*- coding: utf-8 -*-
2    
3 jfenwick 3981 ##############################################################################
4 gross 3503 #
5 jfenwick 4657 # Copyright (c) 2003-2014 by University of Queensland
6 jfenwick 3981 # http://www.uq.edu.au
7 gross 3503 #
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 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
13 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
14     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
15 jfenwick 3981 #
16     ##############################################################################
17 gross 3503
18 jfenwick 4657 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
19 jfenwick 3981 http://www.uq.edu.au
20 gross 3503 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 jfenwick 4938 import esys.escriptcore.utestselect as unittest
26 sshaw 4984 from esys.escriptcore.testing import *
27 gross 3503 import tempfile
28    
29    
30    
31     VERBOSE=False and True
32    
33     from esys.escript import *
34 sshaw 4984 from esys.escript.models import DarcyFlow
35 gross 3503 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 sshaw 4984 class Darcy(unittest.TestCase):
48 gross 3503 # 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 jfenwick 3772 for i in range(self.dom.getDim()):
68 gross 3503 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 jfenwick 3772 for i in range(self.dom.getDim()):
86 gross 3503 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 gross 3569 v,p=df.solve(u_ref,p)
114 gross 3503
115    
116 jfenwick 3551 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 gross 3503 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 gross 3569 v,p=df.solve(u,p )
131 gross 3503
132    
133 jfenwick 3551 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 gross 3503
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 gross 3569 v,p=df.solve(u,p)
149     self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
150 jfenwick 3551 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
151 gross 3503
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 gross 3569 v,p=df.solve(u,p)
166 gross 3503
167 gross 3569 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
168 jfenwick 3551 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
169 gross 3503
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 gross 3569 v,p=df.solve(u,p)
183 gross 3503
184 jfenwick 3551 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 gross 3503
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 gross 3569 v,p=df.solve(u,p)
201 gross 3503
202 jfenwick 3551 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 gross 3503
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 gross 3569 v,p=df.solve(u,p)
219 gross 3503
220 jfenwick 3551 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 gross 3503
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 gross 3569 v,p=df.solve(u,p)
236 gross 3503
237    
238 jfenwick 3551 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 gross 3503
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 gross 3793 #df.getSolverOptionsPressure().setVerbosityOn()
250 gross 3503 df.setValue(g=f,
251     location_of_fixed_pressure=mp,
252     location_of_fixed_flux=mv,
253     permeability=Scalar(k,Function(self.dom)))
254 gross 3569 v,p=df.solve(u,p)
255     self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
256 jfenwick 3551 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
257 gross 3503
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 gross 3569 v,p=df.solve(u,p)
271 gross 3503
272 gross 3569 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
273 jfenwick 3551 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
274 gross 3503
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 gross 3569 v,p=df.solve(u,p)
288 jfenwick 3551 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 gross 3503
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 gross 3569 v,p=df.solve(u,p)
304 jfenwick 3551 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 gross 3503
307 sshaw 4984 class Darcy2D(Darcy):
308 gross 3503 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 jfenwick 3892 self.dom = Rectangle(NE,NE)
314 gross 3503 self.rescaleDomain()
315     def tearDown(self):
316     del self.dom
317 sshaw 4984
318     class Test_Darcy2D_EVAL(Darcy2D):
319 gross 3503 TEST_TOL=0.01
320 gross 3569 SOLVER=DarcyFlow.EVAL
321 gross 3503
322 sshaw 4984 class Test_Darcy2D_POST(Darcy2D):
323 gross 3503 TEST_TOL=1.e-3
324     SOLVER=DarcyFlow.POST
325    
326 sshaw 4984 class Test_Darcy2D_SMOOTH(Darcy2D):
327 gross 3569 TEST_TOL=0.01
328     SOLVER=DarcyFlow.SMOOTH
329 gross 3503
330 sshaw 4984 class Darcy3D(Darcy):
331 gross 3503 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 sshaw 4984 class Test_Darcy3D_EVAL(Darcy3D):
341 gross 3503 TEST_TOL=0.01
342 gross 3569 SOLVER=DarcyFlow.EVAL
343 gross 3503
344 sshaw 4984 class Test_Darcy3D_POST(Darcy3D):
345 gross 3503 TEST_TOL=1.e-3
346     SOLVER=DarcyFlow.POST
347    
348 sshaw 4984 class Test_Darcy3D_SMOOTH(Darcy3D):
349 gross 3569 TEST_TOL=0.01
350     SOLVER=DarcyFlow.SMOOTH
351 gross 3503
352    
353     if __name__ == '__main__':
354 sshaw 4984 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 gross 3503
359    

  ViewVC Help
Powered by ViewVC 1.1.26