/[escript]/trunk/downunder/test/python/run_forward.py
ViewVC logotype

Contents of /trunk/downunder/test/python/run_forward.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5262 - (show annotations)
Thu Nov 13 08:11:40 2014 UTC (4 years, 5 months ago) by gross
File MIME type: text/x-python
File size: 20748 byte(s)
Some fixes to the dcresitivity forward model. simple test added. 
1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2014 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 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 import logging
25 import esys.escriptcore.utestselect as unittest
26 from esys.escriptcore.testing import *
27 import numpy as np
28 import os
29 import sys
30 import cmath
31 from esys.downunder import *
32 from esys.escript import unitsSI as U
33 from esys.escript import *
34 from esys.weipa import saveSilo
35 from esys.escript.linearPDEs import LinearSinglePDE, LinearPDE
36 from esys.escript import getEscriptParamInt
37 from esys.escript.pdetools import Locator
38
39 mpisize = getMPISizeWorld()
40 # this is mainly to avoid warning messages
41 logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)
42
43 try:
44 TEST_DATA_ROOT=os.environ['DOWNUNDER_TEST_DATA_ROOT']
45 except KeyError:
46 TEST_DATA_ROOT='ref_data'
47
48 try:
49 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
50 except KeyError:
51 WORKDIR='.'
52
53
54 have_direct=getEscriptParamInt("PASO_DIRECT")
55
56
57 @unittest.skipIf(mpisize>1 or have_direct!=1, "more than 1 MPI rank or missing direct solver")
58 class TestAcousticInversion(unittest.TestCase):
59 def test_API(self):
60 from esys.ripley import Rectangle
61 domain=Rectangle(20,20, diracPoints=[(0.5,1.)], diracTags=['sss'])
62 omega=2.
63
64
65 data=Data([1,2], FunctionOnBoundary(domain))
66 F=Data([2,3], Function(domain))
67 w=1.
68 self.assertRaises(ValueError, AcousticWaveForm, domain, omega, w, data, 1.) # F is a scalar
69 self.assertRaises(ValueError, AcousticWaveForm, domain, omega, w, [1,2], F) # data is not Data
70 self.assertRaises(ValueError, AcousticWaveForm, domain, omega, w, Data([1,2], Function(domain)), F) # data is not on boundary
71 self.assertRaises(ValueError, AcousticWaveForm, domain, omega, w, Scalar(1, Function(domain)), F) # data is not of shape (2,)
72 self.assertRaises(ValueError, AcousticWaveForm, domain, omega, [1,2], data, F) # w is not a scalar
73 self.assertRaises(ValueError, AcousticWaveForm, domain, omega, Scalar(1, Function(domain)), data, F) # w is not a scalar
74
75 # now we do a real one
76 acw=AcousticWaveForm(domain, omega, w, data, F)
77 self.assertEqual(acw.getDomain(), domain)
78 pde=acw.setUpPDE()
79 self.assertIsInstance(pde, LinearPDE)
80 self.assertEqual(pde.getNumEquations(), 2)
81 self.assertEqual(pde.getNumSolutions(), 2)
82 self.assertEqual(pde.getDomain(), domain)
83
84
85 def test_numeric2DscaleF(self):
86
87 from esys.ripley import Rectangle
88 domain=Rectangle(100,100, diracPoints=[(0.5,1.)], diracTags=['sss'])
89 omega=2.
90
91 # test solution is u = a * z where a is complex
92 a=complex(3.45, 0.56)
93 sigma=complex(1e-3, 0.056)
94
95
96 data=Data([a.real, a.imag], FunctionOnBoundary(domain))
97 mydata=data.copy()
98
99 z=FunctionOnBoundary(domain).getX()[1]
100 w=whereZero(z-1.)
101 # source:
102 F=Data( [1,0],Function(domain))
103 #
104 acw=AcousticWaveForm(domain, omega, w, data, F, coordinates=None, fixAtBottom=False, tol=1e-8, saveMemory=True, scaleF=True)
105 # check rescaled data
106 surv=acw.getSurvey()
107 self.assertAlmostEqual( integrate(length(surv[0])**2 * surv[1]), 1.)
108
109 mydata_scale=sqrt( integrate(w*length(mydata)**2) )
110 self.assertAlmostEqual( acw.getSourceScaling(z*[1, 0.]) , a/mydata_scale )
111 self.assertAlmostEqual( acw.getSourceScaling(mydata) , 1./mydata_scale )
112
113 # this should be zero:
114 sigma_comps=[sigma.real, sigma.imag]
115 args=acw.getArguments(sigma_comps)
116 d=acw.getDefect(sigma_comps, *args)
117 self.assertTrue(isinstance(d, float))
118 self.assertLess(abs(d), 1e-10)
119
120 dg=acw.getGradient(sigma_comps, *args)
121 self.assertTrue(isinstance(dg, Data))
122 self.assertTrue(dg.getShape()==(2,))
123 self.assertTrue(dg.getFunctionSpace()==Solution(domain))
124 self.assertTrue(Lsup(dg) < 1e-10)
125
126 # this shuld be zero' too
127 sigma_comps=[2*sigma.real, sigma.imag/2.]
128 args=acw.getArguments(sigma_comps)
129 d=acw.getDefect(sigma_comps, *args)
130 self.assertTrue(isinstance(d, float))
131 self.assertTrue(abs(d)< 1e-10)
132
133 dg=acw.getGradient(sigma_comps, *args)
134 self.assertTrue(isinstance(dg, Data))
135 self.assertTrue(dg.getShape()==(2,))
136 self.assertTrue(dg.getFunctionSpace()==Solution(domain))
137 self.assertTrue(Lsup(dg) < 1e-10)
138
139 # this shouldn't be zero:
140 sigma0=[2*sigma.real, 10*a.imag]*(27*Function(domain).getX()[0]-Function(domain).getX()[1])
141 args=acw.getArguments(sigma0)
142 d0=acw.getDefect(sigma0, *args)
143 self.assertTrue(isinstance(d0, float))
144 self.assertTrue(d0 >= 0)
145 self.assertTrue(d0 > 1e-10)
146
147 dg0=acw.getGradient(sigma0, *args)
148 self.assertTrue(isinstance(dg0, Data))
149 self.assertTrue(dg0.getShape()==(2,))
150 self.assertTrue(dg0.getFunctionSpace()==Solution(domain))
151 self.assertTrue(Lsup(dg0) > 1e-10)
152
153 # test the gradient numerrically:
154 h=0.002
155 X=Function(domain).getX()
156 # .. increment:
157 p=h*exp(-(length(X-[0.6,0.6])/10)**2)*Lsup(length(sigma0))
158
159
160 sigma1=sigma0+p*[1,0]
161 args=acw.getArguments(sigma1)
162 d1=acw.getDefect(sigma1, *args)
163 self.assertTrue( abs( d1-d0-integrate(dg0[0]*p) ) < 1e-2 * abs(d1-d0) )
164
165 sigma2=sigma0+p*[0,1]
166 args=acw.getArguments(sigma2)
167 d2=acw.getDefect(sigma2, *args)
168 self.assertTrue( abs(d2-d0-integrate(dg0[1]*p)) < 1e-2 * abs(d2-d0) )
169
170 def test_numeric2DnoscaleF(self):
171
172 from esys.ripley import Rectangle
173 domain=Rectangle(10,20, diracPoints=[(0.5,1.)], diracTags=['sss'])
174 omega=1.5
175
176 # test solution is u = a * z where a is complex
177 a=complex(3.45, 0.56)
178 sigma=complex(1e-3, 0.056)
179
180
181 data=Data([a.real, a.imag], FunctionOnBoundary(domain))
182 z=FunctionOnBoundary(domain).getX()[1]
183 w=whereZero(z-1.)
184 # F = - a*omega* sigma
185 F=Data( [-(a*omega**2*sigma).real, -(a*omega**2*sigma).imag ],Function(domain))
186
187 acw=AcousticWaveForm(domain, omega, w, data, F, coordinates=None, fixAtBottom=False, tol=1e-8, saveMemory=True, scaleF=False)
188 # this should be zero:
189 sigma_comps=[sigma.real, sigma.imag]
190 args=acw.getArguments(sigma_comps)
191 d=acw.getDefect(sigma_comps, *args)
192 self.assertTrue(isinstance(d, float))
193 self.assertTrue(Lsup(d) < 1e-10)
194 #self.assertTrue(d >= 0)
195 #self.assertTrue(d < 1e-10)
196
197 dg=acw.getGradient(sigma_comps, *args)
198
199 self.assertTrue(isinstance(dg, Data))
200 self.assertTrue(dg.getShape()==(2,))
201 self.assertTrue(dg.getFunctionSpace()==Solution(domain))
202 self.assertTrue(Lsup(dg) < 5e-10)
203 # this shouldn't be zero:
204 sigma0=Data([2*sigma.real, sigma.imag/2], Function(domain) )
205 args=acw.getArguments(sigma0)
206 d0=acw.getDefect(sigma0, *args)
207 self.assertTrue(isinstance(d0, float))
208 self.assertTrue(d0 >= 0)
209 self.assertTrue(d0 > 1e-10)
210
211 dg0=acw.getGradient(sigma0, *args)
212 self.assertTrue(isinstance(dg0, Data))
213 self.assertTrue(dg0.getShape()==(2,))
214 self.assertTrue(dg0.getFunctionSpace()==Solution(domain))
215 self.assertTrue(Lsup(dg0) > 1e-10)
216 # test the gradient numerrically:
217 h=0.001
218 X=Function(domain).getX()
219 p=h*sin(length(X)*np.pi)*Lsup(length(sigma0))
220
221 sigma1=sigma0+p*[1,0]
222 args=acw.getArguments(sigma1)
223 d1=acw.getDefect(sigma1, *args)
224
225 self.assertTrue( abs( d1-d0-integrate(dg0[0]*p) ) < 1e-2 * abs(d1-d0) )
226
227 sigma2=sigma0+p*[0,1]
228 args=acw.getArguments(sigma2)
229 d2=acw.getDefect(sigma2, *args)
230 self.assertTrue( abs(d2-d0-integrate(dg0[1]*p)) < 1e-2 * abs(d2-d0) )
231
232 class TestMT2DModelTEMode(unittest.TestCase):
233 def test_API(self):
234 from esys.ripley import Rectangle
235 domain=Rectangle(19, 19, d1=mpisize)
236 omega=2.
237 x=[ [0.2,0.5], [0.3,0.5] ]
238 Z_XY=[ complex(1.2,1.5), complex(1.3,2.5) ]
239 eta=1.
240 w0=1.
241 E_x0=1.
242 # now we do a real one
243 acw=MT2DModelTEMode(domain, omega, x, Z_XY, eta, w0=w0, E_x0=E_x0)
244 self.assertEqual(acw.getDomain(), domain)
245 pde=acw.setUpPDE()
246 self.assertIsInstance(pde, LinearPDE)
247 self.assertEqual(pde.getNumEquations(), 2)
248 self.assertEqual(pde.getNumSolutions(), 2)
249 self.assertEqual(pde.getDomain(), domain)
250
251 # other things that should work
252 acw=MT2DModelTEMode(domain, omega, x, Z_XY, eta=[1.,1.], w0=[2.,3.], E_x0=complex(4.5,6) )
253
254 # these shouldn't work
255 self.assertRaises(ValueError, MT2DModelTEMode, domain, omega, x, [3.], eta=[1.,1.], w0=[2.,3.], E_x0=complex(4.5,6) )
256 self.assertRaises(ValueError, MT2DModelTEMode, domain, omega, x, Z_XY, eta=[1.], w0=[2.,3.], E_x0=complex(4.5,6) )
257 self.assertRaises(ValueError, MT2DModelTEMode, domain, omega, [(6.7,5)], Z_XY, eta=[1.,1.], w0=[2.,3.], E_x0=complex(4.5,6) )
258
259 def test_PDE(self):
260 omega=2.
261 mu0=0.123
262 SIGMA=15.
263 k=cmath.sqrt(1j*omega*mu0*SIGMA) # Ex=exp(k*z)
264
265 from esys.ripley import Rectangle
266 domain=Rectangle(199,199, d1=mpisize)
267
268
269 IMP=cmath.sqrt(1j*omega*mu0/SIGMA)
270 Z_XY=[ IMP, IMP ]
271 x=[ [0.3,0.5], [0.6,0.5] ]
272 eta=0.005
273 z=domain.getX()[1]
274 Ex0_ex=exp(-k.real*z)*cos(-k.imag*z)
275 Ex0_ex_z=(-k.real*cos(-k.imag*z)+k.imag*sin(-k.imag*z)) * exp(-k.real*z)
276 Ex1_ex=exp(-k.real*z)*sin(-k.imag*z)
277 Ex1_ex_z=(-k.real*sin(-k.imag*z)-k.imag*cos(-k.imag*z)) * exp(-k.real*z)
278
279 acw=MT2DModelTEMode(domain, omega, x, Z_XY, eta, mu=mu0, fixAtBottom=True, E_x0=Ex0_ex*[1.,0]+ Ex1_ex*[0,1.], tol=1e-9)
280
281 args=acw.getArguments(SIGMA)
282 Ex=args[0]
283 Exz=args[1]
284 self.assertTrue(Lsup(Ex[0]-Ex0_ex) <= 1e-4 * Lsup(Ex0_ex))
285 self.assertTrue(Lsup(Ex[1]-Ex1_ex) <= 1e-4 * Lsup(Ex1_ex))
286 self.assertTrue(Lsup(Exz[0]-Ex0_ex_z) <= 1e-2 * Lsup(Ex0_ex_z))
287 self.assertTrue(Lsup(Exz[1]-Ex1_ex_z) <= 1e-2 * Lsup(Ex1_ex_z))
288
289 argsr=acw.getArguments(0.)
290 ref=acw.getDefect(0., *argsr)
291
292 # this should be almost zero:
293 args=acw.getArguments(SIGMA)
294 d=acw.getDefect(SIGMA, *args)
295
296 self.assertTrue( d > 0.)
297 self.assertTrue( ref > 0.)
298 self.assertTrue( d <= 1e-4 * ref ) # d should be zero (some sort of)
299
300 # and this should be zero
301 d0=acw.getDefect(SIGMA, Ex0_ex*[1.,0]+ Ex1_ex*[0,1.], Ex0_ex_z*[1.,0]+ Ex1_ex_z*[0,1.])
302 self.assertTrue( d0 <= 1e-8 * ref ) # d should be zero (some sort of)
303
304
305 # and this too
306 dg=acw.getGradient(SIGMA, Ex0_ex*[1.,0]+ Ex1_ex*[0,1.], Ex0_ex_z*[1.,0]+ Ex1_ex_z*[0,1.])
307 self.assertTrue(isinstance(dg, Data))
308 self.assertTrue(dg.getShape()==())
309 self.assertTrue(Lsup(dg) < 1e-10)
310
311 def test_Differential(self):
312
313 INC=0.01
314
315 omega=2.
316 mu0=0.123
317 SIGMA=15.
318 k=cmath.sqrt(1j*omega*mu0*SIGMA) # Ex=exp(k*z)
319
320 from esys.ripley import Rectangle
321 domain=Rectangle(99,99, d1=mpisize)
322
323
324 IMP=-cmath.sqrt(1j*omega*mu0/SIGMA)
325 Z_XY=[ IMP, IMP ]
326 x=[ [0.3,0.5], [0.6,0.5] ]
327 eta=0.005
328 z=domain.getX()[1]
329 Ex0_ex=exp(-k.real*z)*cos(-k.imag*z)
330 Ex0_ex_z=(-k.real*cos(-k.imag*z)+k.imag*sin(-k.imag*z)) * exp(-k.real*z)
331 Ex1_ex=exp(-k.real*z)*sin(-k.imag*z)
332 Ex1_ex_z=(-k.real*sin(-k.imag*z)-k.imag*cos(-k.imag*z)) * exp(-k.real*z)
333
334 acw=MT2DModelTEMode(domain, omega, x, Z_XY, eta, mu=mu0, fixAtBottom=True, E_x0=Ex0_ex*[1.,0]+ Ex1_ex*[0,1.], tol=1e-9 )
335
336 # this is the base line:
337 SIGMA0=10.
338 args0=acw.getArguments(SIGMA0)
339 d0=acw.getDefect(SIGMA0, *args0)
340
341 dg0=acw.getGradient(SIGMA0, *args0)
342 self.assertTrue(isinstance(dg0, Data))
343 self.assertTrue(dg0.getShape()==())
344
345
346 X=Function(domain).getX()
347
348 # test 1
349 p=INC
350 SIGMA1=SIGMA0+p
351 args1=acw.getArguments(SIGMA1)
352 d1=acw.getDefect(SIGMA1, *args1)
353 self.assertTrue( abs( d1-d0-integrate(dg0*p) ) < 1e-2 * abs(d1-d0) )
354
355 # test 2
356 p=exp(-length(X-(0.2,0.2))**2/10)*INC
357 SIGMA1=SIGMA0+p
358 args1=acw.getArguments(SIGMA1)
359 d1=acw.getDefect(SIGMA1, *args1)
360 self.assertTrue( abs( d1-d0-integrate(dg0*p) ) < 1e-2 * abs(d1-d0) )
361
362 # test 3
363 p=sin(length(X)*3*3.14)*INC
364 SIGMA1=SIGMA0+p
365 args1=acw.getArguments(SIGMA1)
366 d1=acw.getDefect(SIGMA1, *args1)
367 self.assertTrue( abs( d1-d0-integrate(dg0*p) ) < 1e-2 * abs(d1-d0) )
368
369 class TestSubsidence(unittest.TestCase):
370 def test_PDE(self):
371
372 lam=2.
373 mu=1.
374
375 from esys.ripley import Brick
376 domain=Brick(20,20,19, d2=mpisize)
377
378 xb=FunctionOnBoundary(domain).getX()
379 m=whereZero(xb[2]-1)
380 w=m*[0,0,1]
381 d=m*2.5
382 acw=Subsidence(domain, w,d, lam, mu )
383
384 P0=10.
385 args0=acw.getArguments(P0)
386 u=args0[0]
387 self.assertTrue(Lsup(u[0]) < 1.e-8)
388 self.assertTrue(Lsup(u[1]) < 1.e-8)
389 self.assertTrue(Lsup(u[2]-2.5*domain.getX()[2]) < 1.e-8)
390
391 dd=acw.getDefect(P0, *args0)
392
393 self.assertTrue( dd >= 0.)
394 self.assertTrue( dd <= 1e-7 * 2.5 )
395 def test_Differential(self):
396
397 lam=2.
398 mu=1.
399
400 INC=0.01
401 from esys.ripley import Brick
402 domain=Brick(20,20,20*mpisize-1 , d2=mpisize)
403
404 xb=FunctionOnBoundary(domain).getX()
405 m=whereZero(xb[2]-1)
406 w=m*[0,0,1]
407 d=m*2.5
408 acw=Subsidence(domain, w,d, lam, mu )
409
410
411 x=Function(domain).getX()
412 P0=x[0]*x[1]
413 args0=acw.getArguments(P0)
414 d0=acw.getDefect(P0, *args0)
415 grad_d=acw.getGradient(P0, *args0)
416
417
418 dP=exp(-(length(x-[0.5,0.5,0.5])/0.06)**2)
419 P1=P0+INC*dP
420 args1=acw.getArguments(P1)
421 d1=acw.getDefect(P1, *args1)
422 ref=abs((d1-d0)/INC)
423 self.assertTrue(abs((d1-d0)/INC-integrate(grad_d* dP)) < ref * 1.e-5)
424
425 dP=exp(-(length(x-[0.3,0.3,0.5])/0.06)**2)
426 P2=P0-INC*dP
427 args2=acw.getArguments(P2)
428 d2=acw.getDefect(P2, *args2)
429 ref=abs((d2-d0)/INC)
430 self.assertTrue(abs((d2-d0)/INC+integrate(grad_d* dP)) < ref * 1.e-5)
431
432 class TestDCResistivity(unittest.TestCase):
433
434 def test_PDE2D(self):
435
436 dx_tests=0.1
437
438 sigma0=1.
439 electrodes=[(0.5-2*dx_tests,1.), (0.5-dx_tests,1.), (0.5+dx_tests,1.), (0.5+2*dx_tests,1.)]
440 from esys.finley import Rectangle
441 domain=Rectangle(20,20, d1=mpisize, diracPoints=electrodes, diracTags=["sl0", "sl1", "sr0", "sr1"] )
442 loc=Locator(domain,electrodes[2:])
443
444 # this creates some reference Data:
445 x=domain.getX()
446 q=whereZero(x[0]-inf(x[0]))+whereZero(x[0]-sup(x[0]))+whereZero(x[1]-inf(x[1]))
447 ppde=LinearPDE(domain, numEquations=1)
448 s=Scalar(0.,DiracDeltaFunctions(domain))
449 s.setTaggedValue("sl0" ,1.)
450 s.setTaggedValue("sl1",-1.)
451 ppde.setValue(A=kronecker(2)*sigma0, q=q, y_dirac=s)
452 pp=ppde.getSolution()
453 uu=loc(pp)
454
455 # arguments for DcRes
456 current = 10.
457 sourceInfo = [ "sl0", "sl1" ]
458 sampleTags = [ ("sr0", "sr1") ]
459
460 sigmaPrimary=7.
461 phiPrimary=pp*current*sigma0/sigmaPrimary
462
463 uuscale=1-current*sigma0/sigmaPrimary
464 delphi_in = [ (uu[1]-uu[0]) * uuscale]
465
466 acw=DcRes(domain, loc, delphi_in, sampleTags, phiPrimary, sigmaPrimary)
467
468 self.assertTrue(Lsup(phiPrimary-acw.getPrimaryPotential()) < 1.e-10 * Lsup(acw.getPrimaryPotential()))
469
470 SIGMA=10. # matches current
471 args0=acw.getArguments(SIGMA)
472 p=args0[0]
473 u=args0[1]
474
475 # true secondary potential
476 pps=pp-phiPrimary
477 self.assertTrue(Lsup(p-pps) < 1.e-6 * Lsup(pps))
478
479
480 # test return values at electrodes:
481 self.assertTrue(abs(u[0]-uu[0]*uuscale) < 1.e-6 * abs(uu[0]*uuscale))
482 self.assertTrue(abs(u[1]-uu[1]*uuscale) < 1.e-6 * abs(uu[1]*uuscale))
483
484 # this sould be zero
485 dd=acw.getDefect(SIGMA, *args0)
486 self.assertTrue( dd >= 0.)
487 self.assertTrue( dd <= 1e-7 )
488
489 def test_Differential2D(self):
490
491 INC=0.001
492
493 sigma0=1.
494 dx_tests=0.1
495 electrodes=[(0.5-2*dx_tests,1.), (0.5-dx_tests,1.), (0.5+dx_tests,1.), (0.5+2*dx_tests,1.)]
496 from esys.finley import Rectangle
497 domain=Rectangle(20,20, d1=mpisize, diracPoints=electrodes, diracTags=["sl0", "sl1", "sr0", "sr1"] )
498 loc=Locator(domain,electrodes[2:])
499
500 # arguments for DcRes
501 #current = 10.
502 sampleTags = [ ("sr0", "sr1") ]
503
504 delphi_in = [ 0.05 ]
505
506 sigmaPrimary=1
507 x=domain.getX()
508 phiPrimary=(x[0]-inf(x[0]))*(x[1]-inf(x[1]))*(x[0]-sup(x[0]))
509
510 acw=DcRes(domain, loc, delphi_in, sampleTags, phiPrimary, sigmaPrimary)
511
512 #===========================================================================
513 x=Function(domain).getX()
514 SIGMA0=x[0]*x[1]+1
515 args0=acw.getArguments(SIGMA0)
516 d0=acw.getDefect(SIGMA0, *args0)
517 grad_d=acw.getGradient(SIGMA0, *args0)
518
519 dS=exp(-(length(x-[0.5,0.5])/0.2)**2)
520 SIGMA1=SIGMA0+INC*dS
521 args1=acw.getArguments(SIGMA1)
522 d1=acw.getDefect(SIGMA1, *args1)
523 ref=abs((d1-d0)/INC)
524 self.assertTrue(abs((d1-d0)/INC-integrate(grad_d* dS)) < ref * 1.e-3)
525
526 dS=-exp(-(length(x-[0.5,0.5])/0.2)**2)
527 SIGMA2=SIGMA0+INC*dS
528 args2=acw.getArguments(SIGMA2)
529 d2=acw.getDefect(SIGMA2, *args2)
530 ref=abs((d2-d0)/INC)
531 self.assertTrue(abs((d2-d0)/INC-integrate(grad_d* dS)) < ref * 1.e-3)
532
533 dS=-1
534 SIGMA3=SIGMA0+INC*dS
535 args3=acw.getArguments(SIGMA3)
536 d3=acw.getDefect(SIGMA3, *args3)
537 ref=abs((d3-d0)/INC)
538 self.assertTrue(abs((d3-d0)/INC-integrate(grad_d* dS)) < ref * 1.e-3)
539
540 dS=1
541 SIGMA4=SIGMA0+INC*dS
542 args4=acw.getArguments(SIGMA4)
543 d4=acw.getDefect(SIGMA4, *args4)
544 ref=abs((d4-d0)/INC)
545 self.assertTrue(abs((d4-d0)/INC-integrate(grad_d* dS)) < ref * 1.e-3)
546
547 class TestIsostaticPressure(unittest.TestCase):
548 def test_all(self):
549 from esys.ripley import Brick
550 domain=Brick(50,50,20*mpisize-1, d2=mpisize)
551
552 ps=IsostaticPressure(domain, level0=1., coordinates=None)
553
554 g=Vector(0., Function(domain))
555 rho=Scalar(100, Function(domain))
556 p0=ps.getPressure(g, rho)
557 p_ref=-(1.-domain.getX()[2])*981.
558 self.assertTrue(Lsup(p0-p_ref) < 1e-6 * Lsup(p_ref))
559
560 g=Vector([0,0,-10], Function(domain))
561 rho=Scalar(0, Function(domain))
562 p0=ps.getPressure(g, rho)
563 p_ref=-(1.-domain.getX()[2])*26700
564 self.assertTrue(Lsup(p0-p_ref) < 1e-6 * Lsup(p_ref))
565
566 g=Vector([0,0,-10], Function(domain))
567 rho=Scalar(100, Function(domain))
568 p0=ps.getPressure(g, rho)
569 p_ref=-(1.-domain.getX()[2])*(981.+26700+1000)
570 self.assertTrue(Lsup(p0-p_ref) < 1e-6 * Lsup(p_ref))
571
572 if __name__ == '__main__':
573 run_tests(__name__, exit_on_failure=True)
574

  ViewVC Help
Powered by ViewVC 1.1.26