/[escript]/trunk/dudley/test/python/run_models.py
ViewVC logotype

Contents of /trunk/dudley/test/python/run_models.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4938 - (show annotations)
Wed May 14 01:13:23 2014 UTC (5 years, 3 months ago) by jfenwick
File MIME type: text/x-python
File size: 77596 byte(s)
Modify unit tests to read their classes from
esys.escriptcore.utestselect

Change the line in that file to switch between unittest and unittest2


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 from __future__ import print_function
18
19 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
20 http://www.uq.edu.au
21 Primary Business: Queensland, Australia"""
22 __license__="""Licensed under the Open Software License version 3.0
23 http://www.opensource.org/licenses/osl-3.0.php"""
24 __url__="https://launchpad.net/escript-finley"
25
26 import esys.escriptcore.utestselect as unittest
27 import tempfile
28
29
30
31 VERBOSE=False and True
32
33 from esys.escript import *
34 from esys.escript.models import StokesProblemCartesian, PowerLaw, IncompressibleIsotropicFlowCartesian, FaultSystem, DarcyFlow
35 from esys.escript.models import Mountains
36 from esys.dudley import Rectangle, Brick
37
38 from math import pi
39 import numpy
40 import sys
41 import os
42 #====================================================================================================================
43 try:
44 DUDLEY_WORKDIR=os.environ['DUDLEY_WORKDIR']
45 except KeyError:
46 DUDLEY_WORKDIR='.'
47
48 #====================================================================================================================
49 class Test_StokesProblemCartesian2D(unittest.TestCase):
50 def setUp(self):
51 NE=6
52 self.TOL=1e-3
53 self.domain=Rectangle(NE,NE,order=-1)
54 def tearDown(self):
55 del self.domain
56 def test_PCG_P_0(self):
57 ETA=1.
58 P1=0.
59
60 x=self.domain.getX()
61 F=-P1*x[1]*[1.,0]+(2*ETA-P1*x[0])*[0.,1.]
62 mask=whereZero(x[0]) * [1.,1.] \
63 +whereZero(x[0]-1) * [1.,1.] \
64 +whereZero(x[1]) * [1.,0.] \
65 +whereZero(x[1]-1) * [1.,1.]
66
67 sp=StokesProblemCartesian(self.domain)
68
69 sp.initialize(f=F,fixed_u_mask=mask,eta=ETA)
70 u0=(1-x[0])*x[0]*[0.,1.]
71 p0=Scalar(-P1,ReducedSolution(self.domain))
72 sp.setTolerance(self.TOL)
73 u,p=sp.solve(u0*mask,p0,verbose=VERBOSE,max_iter=100,usePCG=True)
74
75 error_v0=Lsup(u[0]-u0[0])
76 error_v1=Lsup(u[1]-u0[1])/0.25
77 error_p=Lsup(p+P1*x[0]*x[1])
78 self.assertTrue(error_p<10*self.TOL, "pressure error too large.")
79 self.assertTrue(error_v0<10*self.TOL, "0-velocity error too large.")
80 self.assertTrue(error_v1<10*self.TOL, "1-velocity error too large.")
81
82 def test_PCG_P_small(self):
83 ETA=1.
84 P1=1.
85
86 x=self.domain.getX()
87 F=-P1*x[1]*[1.,0]+(2*ETA-P1*x[0])*[0.,1.]
88 mask=whereZero(x[0]) * [1.,1.] \
89 +whereZero(x[0]-1) * [1.,1.] \
90 +whereZero(x[1]) * [1.,0.] \
91 +whereZero(x[1]-1) * [1.,1.]
92
93 sp=StokesProblemCartesian(self.domain)
94
95 sp.initialize(f=F,fixed_u_mask=mask,eta=ETA)
96 u0=(1-x[0])*x[0]*[0.,1.]
97 p0=Scalar(-P1,ReducedSolution(self.domain))
98 sp.setTolerance(self.TOL)
99 u,p=sp.solve(u0,p0, verbose=VERBOSE,max_iter=100,usePCG=True)
100 error_v0=Lsup(u[0]-u0[0])
101 error_v1=Lsup(u[1]-u0[1])/0.25
102 error_p=Lsup(P1*x[0]*x[1]+p)
103 self.assertTrue(error_v0<10*self.TOL, "0-velocity error too large.")
104 self.assertTrue(error_v1<10*self.TOL, "1-velocity error too large.")
105 self.assertTrue(error_p<10*self.TOL, "pressure error too large.")
106
107 def test_PCG_P_large(self):
108 ETA=1.
109 P1=1000.
110
111 x=self.domain.getX()
112 F=-P1*x[1]*[1.,0]+(2*ETA-P1*x[0])*[0.,1.]
113 mask=whereZero(x[0]) * [1.,1.] \
114 +whereZero(x[0]-1) * [1.,1.] \
115 +whereZero(x[1]) * [1.,0.] \
116 +whereZero(x[1]-1) * [1.,1.]
117
118 sp=StokesProblemCartesian(self.domain)
119
120 sp.initialize(f=F,fixed_u_mask=mask,eta=ETA)
121 u0=(1-x[0])*x[0]*[0.,1.]
122 p0=Scalar(-P1,ReducedSolution(self.domain))
123 sp.setTolerance(self.TOL)
124 u,p=sp.solve(u0,p0, verbose=VERBOSE,max_iter=100,usePCG=True)
125 # u,p=sp.solve(u0,p0, verbose=VERBOSE,max_iter=100,usePCG=True)
126
127 error_v0=Lsup(u[0]-u0[0])
128 error_v1=Lsup(u[1]-u0[1])/0.25
129 error_p=Lsup(P1*x[0]*x[1]+p)/P1
130 self.assertTrue(error_p<10*self.TOL, "pressure error too large.")
131 self.assertTrue(error_v0<10*self.TOL, "0-velocity error too large.")
132 self.assertTrue(error_v1<10*self.TOL, "1-velocity error too large.")
133
134 def test_GMRES_P_0(self):
135 ETA=1.
136 P1=0.
137
138 x=self.domain.getX()
139 F=-P1*x[1]*[1.,0]+(2*ETA-P1*x[0])*[0.,1.]
140 mask=whereZero(x[0]) * [1.,1.] \
141 +whereZero(x[0]-1) * [1.,1.] \
142 +whereZero(x[1]) * [1.,0.] \
143 +whereZero(x[1]-1) * [1.,1.]
144
145 sp=StokesProblemCartesian(self.domain)
146
147 sp.initialize(f=F,fixed_u_mask=mask,eta=ETA)
148 u0=(1-x[0])*x[0]*[0.,1.]
149 p0=Scalar(-P1,ReducedSolution(self.domain))
150 sp.setTolerance(self.TOL)
151 u,p=sp.solve(u0,p0, verbose=VERBOSE,max_iter=50,usePCG=False,iter_restart=18)
152
153 error_v0=Lsup(u[0]-u0[0])
154 error_v1=Lsup(u[1]-u0[1])/0.25
155 error_p=Lsup(P1*x[0]*x[1]+p)
156 self.assertTrue(error_p<10*self.TOL, "pressure error too large.")
157 self.assertTrue(error_v0<10*self.TOL, "0-velocity error too large.")
158 self.assertTrue(error_v1<10*self.TOL, "1-velocity error too large.")
159
160 def test_GMRES_P_small(self):
161 ETA=1.
162 P1=1.
163
164 x=self.domain.getX()
165 F=-P1*x[1]*[1.,0]+(2*ETA-P1*x[0])*[0.,1.]
166 mask=whereZero(x[0]) * [1.,1.] \
167 +whereZero(x[0]-1) * [1.,1.] \
168 +whereZero(x[1]) * [1.,0.] \
169 +whereZero(x[1]-1) * [1.,1.]
170
171 sp=StokesProblemCartesian(self.domain)
172
173 sp.initialize(f=F,fixed_u_mask=mask,eta=ETA)
174 u0=(1-x[0])*x[0]*[0.,1.]
175 p0=Scalar(-P1,ReducedSolution(self.domain))
176 sp.setTolerance(self.TOL)
177 u,p=sp.solve(u0,p0, verbose=VERBOSE,max_iter=20,usePCG=False)
178
179 error_v0=Lsup(u[0]-u0[0])
180 error_v1=Lsup(u[1]-u0[1])/0.25
181 error_p=Lsup(P1*x[0]*x[1]+p)
182
183 self.assertTrue(error_p<10*self.TOL, "pressure error too large.")
184 self.assertTrue(error_v0<10*self.TOL, "0-velocity error too large.")
185 self.assertTrue(error_v1<10*self.TOL, "1-velocity error too large.")
186
187 def test_GMRES_P_large(self):
188 ETA=1.
189 P1=1000.
190
191 x=self.domain.getX()
192 F=-P1*x[1]*[1.,0]+(2*ETA-P1*x[0])*[0.,1.]
193 mask=whereZero(x[0]) * [1.,1.] \
194 +whereZero(x[0]-1) * [1.,1.] \
195 +whereZero(x[1]) * [1.,0.] \
196 +whereZero(x[1]-1) * [1.,1.]
197
198 sp=StokesProblemCartesian(self.domain)
199
200 sp.initialize(f=F,fixed_u_mask=mask,eta=ETA)
201 u0=(1-x[0])*x[0]*[0.,1.]
202 p0=Scalar(-P1,ReducedSolution(self.domain))
203 sp.setTolerance(self.TOL)
204 u,p=sp.solve(u0,p0, verbose=VERBOSE,max_iter=100,usePCG=False)
205
206 error_v0=Lsup(u[0]-u0[0])
207 error_v1=Lsup(u[1]-u0[1])/0.25
208 error_p=Lsup(P1*x[0]*x[1]+p)/P1
209 self.assertTrue(error_p<10*self.TOL, "pressure error too large.")
210 self.assertTrue(error_v0<10*self.TOL, "0-velocity error too large.")
211 self.assertTrue(error_v1<10*self.TOL, "1-velocity error too large.")
212 #====================================================================================================================
213 class Test_StokesProblemCartesian3D(unittest.TestCase):
214 def setUp(self):
215 NE=6
216 self.TOL=1e-4
217 self.domain=Brick(NE,NE,NE,order=-1)
218 def tearDown(self):
219 del self.domain
220 def test_PCG_P_0(self):
221 ETA=1.
222 P1=0.
223
224 x=self.domain.getX()
225 F=-P1*x[1]*x[2]*[1.,0.,0.]-P1*x[0]*x[2]*[0.,1.,0.]+(2*ETA*((1-x[0])*x[0]+(1-x[1])*x[1])-P1*x[0]*x[1])*[0.,0.,1.]
226 x=self.domain.getX()
227 mask=whereZero(x[0]) * [1.,1.,1.] \
228 +whereZero(x[0]-1) * [1.,1.,1.] \
229 +whereZero(x[1]) * [1.,0.,1.] \
230 +whereZero(x[1]-1) * [1.,1.,1.] \
231 +whereZero(x[2]) * [1.,1.,0.] \
232 +whereZero(x[2]-1) * [1.,1.,1.]
233
234
235 sp=StokesProblemCartesian(self.domain)
236
237 sp.initialize(f=F,fixed_u_mask=mask,eta=ETA)
238 u0=(1-x[0])*x[0]*(1-x[1])*x[1]*[0.,0.,1.]
239 p0=Scalar(-P1,ReducedSolution(self.domain))
240 sp.setTolerance(self.TOL)
241 u,p=sp.solve(u0,p0, verbose=VERBOSE ,max_iter=100,usePCG=True)
242
243 error_v0=Lsup(u[0]-u0[0])
244 error_v1=Lsup(u[1]-u0[1])
245 error_v2=Lsup(u[2]-u0[2])/0.25**2
246 error_p=Lsup(P1*x[0]*x[1]*x[2]+p)
247 self.assertTrue(error_p<10*self.TOL, "pressure error too large.")
248 self.assertTrue(error_v0<10*self.TOL, "0-velocity error too large.")
249 self.assertTrue(error_v1<10*self.TOL, "1-velocity error too large.")
250 self.assertTrue(error_v2<10*self.TOL, "2-velocity error too large.")
251
252 def test_PCG_P_small(self):
253 ETA=1.
254 P1=1.
255
256 x=self.domain.getX()
257 F=-P1*x[1]*x[2]*[1.,0.,0.]-P1*x[0]*x[2]*[0.,1.,0.]+(2*ETA*((1-x[0])*x[0]+(1-x[1])*x[1])-P1*x[0]*x[1])*[0.,0.,1.]
258 mask=whereZero(x[0]) * [1.,1.,1.] \
259 +whereZero(x[0]-1) * [1.,1.,1.] \
260 +whereZero(x[1]) * [1.,0.,1.] \
261 +whereZero(x[1]-1) * [1.,1.,1.] \
262 +whereZero(x[2]) * [1.,1.,0.] \
263 +whereZero(x[2]-1) * [1.,1.,1.]
264
265
266 sp=StokesProblemCartesian(self.domain)
267
268 sp.initialize(f=F,fixed_u_mask=mask,eta=ETA)
269 u0=(1-x[0])*x[0]*(1-x[1])*x[1]*[0.,0.,1.]
270 p0=Scalar(-P1,ReducedSolution(self.domain))
271 sp.setTolerance(self.TOL)
272 u,p=sp.solve(u0,p0, verbose=VERBOSE ,max_iter=100,usePCG=True)
273 error_v0=Lsup(u[0]-u0[0])
274 error_v1=Lsup(u[1]-u0[1])
275 error_v2=Lsup(u[2]-u0[2])/0.25**2
276 error_p=Lsup(P1*x[0]*x[1]*x[2]+p)
277 self.assertTrue(error_p<10*self.TOL, "pressure error too large.")
278 self.assertTrue(error_v0<10*self.TOL, "0-velocity error too large.")
279 self.assertTrue(error_v1<10*self.TOL, "1-velocity error too large.")
280 self.assertTrue(error_v2<10*self.TOL, "2-velocity error too large.")
281
282 def test_PCG_P_large(self):
283 ETA=1.
284 P1=1000.
285
286 x=self.domain.getX()
287 F=-P1*x[1]*x[2]*[1.,0.,0.]-P1*x[0]*x[2]*[0.,1.,0.]+(2*ETA*((1-x[0])*x[0]+(1-x[1])*x[1])-P1*x[0]*x[1])*[0.,0.,1.]
288 mask=whereZero(x[0]) * [1.,1.,1.] \
289 +whereZero(x[0]-1) * [1.,1.,1.] \
290 +whereZero(x[1]) * [1.,0.,1.] \
291 +whereZero(x[1]-1) * [1.,1.,1.] \
292 +whereZero(x[2]) * [1.,1.,0.] \
293 +whereZero(x[2]-1) * [1.,1.,1.]
294
295
296 sp=StokesProblemCartesian(self.domain)
297
298 sp.initialize(f=F,fixed_u_mask=mask,eta=ETA)
299 u0=(1-x[0])*x[0]*(1-x[1])*x[1]*[0.,0.,1.]
300 p0=Scalar(-P1,ReducedSolution(self.domain))
301 sp.setTolerance(self.TOL)
302 u,p=sp.solve(u0,p0, verbose=VERBOSE ,max_iter=100,usePCG=True)
303
304 error_v0=Lsup(u[0]-u0[0])
305 error_v1=Lsup(u[1]-u0[1])
306 error_v2=Lsup(u[2]-u0[2])/0.25**2
307 error_p=Lsup(P1*x[0]*x[1]*x[2]+p)/P1
308 self.assertTrue(error_p<10*self.TOL, "pressure error too large.")
309 self.assertTrue(error_v0<10*self.TOL, "0-velocity error too large.")
310 self.assertTrue(error_v1<10*self.TOL, "1-velocity error too large.")
311 self.assertTrue(error_v2<10*self.TOL, "2-velocity error too large.")
312
313 def test_GMRES_P_0(self):
314 ETA=1.
315 P1=0.
316
317 x=self.domain.getX()
318 F=-P1*x[1]*x[2]*[1.,0.,0.]-P1*x[0]*x[2]*[0.,1.,0.]+(2*ETA*((1-x[0])*x[0]+(1-x[1])*x[1])-P1*x[0]*x[1])*[0.,0.,1.]
319 x=self.domain.getX()
320 mask=whereZero(x[0]) * [1.,1.,1.] \
321 +whereZero(x[0]-1) * [1.,1.,1.] \
322 +whereZero(x[1]) * [1.,1.,1.] \
323 +whereZero(x[1]-1) * [1.,1.,1.] \
324 +whereZero(x[2]) * [1.,1.,0.] \
325 +whereZero(x[2]-1) * [1.,1.,1.]
326
327
328 sp=StokesProblemCartesian(self.domain)
329
330 sp.initialize(f=F,fixed_u_mask=mask,eta=ETA)
331 u0=(1-x[0])*x[0]*(1-x[1])*x[1]*[0.,0.,1.]
332 p0=Scalar(-P1,ReducedSolution(self.domain))
333 sp.setTolerance(self.TOL)
334 u,p=sp.solve(u0,p0, verbose=VERBOSE,max_iter=100,usePCG=False,iter_restart=20)
335
336 error_v0=Lsup(u[0]-u0[0])
337 error_v1=Lsup(u[1]-u0[1])
338 error_v2=Lsup(u[2]-u0[2])/0.25**2
339 error_p=Lsup(P1*x[0]*x[1]*x[2]+p)
340 self.assertTrue(error_p<10*self.TOL, "pressure error too large.")
341 self.assertTrue(error_v0<10*self.TOL, "0-velocity error too large.")
342 self.assertTrue(error_v1<10*self.TOL, "1-velocity error too large.")
343 self.assertTrue(error_v2<10*self.TOL, "2-velocity error too large.")
344 def test_GMRES_P_small(self):
345 ETA=1.
346 P1=1.
347
348 x=self.domain.getX()
349 F=-P1*x[1]*x[2]*[1.,0.,0.]-P1*x[0]*x[2]*[0.,1.,0.]+(2*ETA*((1-x[0])*x[0]+(1-x[1])*x[1])-P1*x[0]*x[1])*[0.,0.,1.]
350 mask=whereZero(x[0]) * [1.,1.,1.] \
351 +whereZero(x[0]-1) * [1.,1.,1.] \
352 +whereZero(x[1]) * [1.,1.,1.] \
353 +whereZero(x[1]-1) * [1.,1.,1.] \
354 +whereZero(x[2]) * [1.,1.,0.] \
355 +whereZero(x[2]-1) * [1.,1.,1.]
356
357
358 sp=StokesProblemCartesian(self.domain)
359
360 sp.initialize(f=F,fixed_u_mask=mask,eta=ETA)
361 u0=(1-x[0])*x[0]*(1-x[1])*x[1]*[0.,0.,1.]
362 p0=Scalar(-P1,ReducedSolution(self.domain))
363 sp.setTolerance(self.TOL/10)
364 u,p=sp.solve(u0,p0, verbose=VERBOSE,max_iter=100,usePCG=False)
365
366 error_v0=Lsup(u[0]-u0[0])
367 error_v1=Lsup(u[1]-u0[1])
368 error_v2=Lsup(u[2]-u0[2])/0.25**2
369 error_p=Lsup(P1*x[0]*x[1]*x[2]+p)/P1
370 self.assertTrue(error_v0<10*self.TOL, "0-velocity error too large.")
371 self.assertTrue(error_v1<10*self.TOL, "1-velocity error too large.")
372 self.assertTrue(error_v2<10*self.TOL, "2-velocity error too large.")
373 self.assertTrue(error_p<10*self.TOL, "pressure error too large.")
374 def test_GMRES_P_large(self):
375 ETA=1.
376 P1=1000.
377
378 x=self.domain.getX()
379 F=-P1*x[1]*x[2]*[1.,0.,0.]-P1*x[0]*x[2]*[0.,1.,0.]+(2*ETA*((1-x[0])*x[0]+(1-x[1])*x[1])-P1*x[0]*x[1])*[0.,0.,1.]
380 mask=whereZero(x[0]) * [1.,1.,1.] \
381 +whereZero(x[0]-1) * [1.,1.,1.] \
382 +whereZero(x[1]) * [1.,0.,1.] \
383 +whereZero(x[1]-1) * [1.,1.,1.] \
384 +whereZero(x[2]) * [1.,1.,0.] \
385 +whereZero(x[2]-1) * [1.,1.,1.]
386
387
388 sp=StokesProblemCartesian(self.domain)
389
390 sp.initialize(f=F,fixed_u_mask=mask,eta=ETA)
391 u0=(1-x[0])*x[0]*(1-x[1])*x[1]*[0.,0.,1.]
392 p0=Scalar(-P1,ReducedSolution(self.domain))
393 sp.setTolerance(self.TOL)
394 u,p=sp.solve(u0,p0, verbose=VERBOSE ,max_iter=100,usePCG=False)
395
396 error_v0=Lsup(u[0]-u0[0])
397 error_v1=Lsup(u[1]-u0[1])
398 error_v2=Lsup(u[2]-u0[2])/0.25**2
399 error_p=Lsup(P1*x[0]*x[1]*x[2]+p)/P1
400 self.assertTrue(error_p<10*self.TOL, "pressure error too large.")
401 self.assertTrue(error_v0<10*self.TOL, "0-velocity error too large.")
402 self.assertTrue(error_v1<10*self.TOL, "1-velocity error too large.")
403 self.assertTrue(error_v2<10*self.TOL, "2-velocity error too large.")
404 #====================================================================================================================
405 class Test_Darcy(unittest.TestCase):
406 # this is a simple test for the darcy flux problem
407 #
408 #
409 # p = 1/k * ( 1/2* (fb-f0)/xb* x **2 + f0 * x - ub*x ) + p0
410 #
411 # with f = (fb-f0)/xb* x + f0
412 #
413 # u = f - k * p,x = ub
414 #
415 # we prescribe pressure at x=x0=0 to p0
416 #
417 # if we prescribe the pressure on the bottom x=xb we set
418 #
419 # pb= 1/k * ( 1/2* (fb-f0)* xb + f0 * xb - ub*xb ) + p0 = 1/k * ((fb+f0)/2 - ub ) * xb + p0
420 #
421 # which leads to ub = (fb+f0)/2-k*(pb-p0)/xb
422 #
423 def rescaleDomain(self):
424 x=self.dom.getX().copy()
425 for i in range(self.dom.getDim()):
426 x_inf=inf(x[i])
427 x_sup=sup(x[i])
428 if i == self.dom.getDim()-1:
429 x[i]=-self.WIDTH*(x[i]-x_sup)/(x_inf-x_sup)
430 else:
431 x[i]=self.WIDTH*(x[i]-x_inf)/(x_sup-x_inf)
432 self.dom.setX(x)
433 def getScalarMask(self,include_bottom=True):
434 x=self.dom.getX().copy()
435 x_inf=inf(x[self.dom.getDim()-1])
436 x_sup=sup(x[self.dom.getDim()-1])
437 out=whereZero(x[self.dom.getDim()-1]-x_sup)
438 if include_bottom: out+=whereZero(x[self.dom.getDim()-1]-x_inf)
439 return wherePositive(out)
440 def getVectorMask(self,include_bottom=True):
441 x=self.dom.getX().copy()
442 out=Vector(0.,Solution(self.dom))
443 for i in range(self.dom.getDim()):
444 x_inf=inf(x[i])
445 x_sup=sup(x[i])
446 if i != self.dom.getDim()-1: out[i]+=whereZero(x[i]-x_sup)
447 if i != self.dom.getDim()-1 or include_bottom: out[i]+=whereZero(x[i]-x_inf)
448 return wherePositive(out)
449
450 def setSolutionFixedBottom(self, p0, pb, f0, fb, k):
451 d=self.dom.getDim()
452 x=self.dom.getX()[d-1]
453 xb=inf(x)
454 u=Vector(0.,Solution(self.dom))+kronecker(d)[d-1]*((f0+fb)/2.-k*(pb-p0)/xb)
455 p=1./k*((fb-f0)/(xb*2.)* x**2 - (fb-f0)/2.*x)+(pb-p0)/xb*x + p0
456 f= ((fb-f0)/xb* x + f0)*kronecker(Function(self.dom))[d-1]
457 return u,p,f
458
459 def testConstF_FixedBottom_smallK(self):
460 k=1.e-10
461 mp=self.getScalarMask(include_bottom=True)
462 mv=self.getVectorMask(include_bottom=False)
463 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)
464 p=p_ref*mp
465 u=u_ref*mv
466 df=DarcyFlow(self.dom)
467 df.setValue(g=f,
468 location_of_fixed_pressure=mp,
469 location_of_fixed_flux=mv,
470 permeability=Scalar(k,Function(self.dom)))
471 #df.setTolerance(rtol=self.TOL)
472 v,p=df.solve(u_ref,p)
473 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
474 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
475 def testConstF_FixedBottom_mediumK(self):
476 k=1.
477 mp=self.getScalarMask(include_bottom=True)
478 mv=self.getVectorMask(include_bottom=False)
479 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)
480 p=p_ref*mp
481 u=u_ref*mv
482 df=DarcyFlow(self.dom)
483 df.setValue(g=f,
484 location_of_fixed_pressure=mp,
485 location_of_fixed_flux=mv,
486 permeability=Scalar(k,Function(self.dom)))
487 #df.setTolerance(rtol=self.TOL)
488 v,p=df.solve(u,p )
489 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
490 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
491
492 def testConstF_FixedBottom_largeK(self):
493 k=1.e10
494 mp=self.getScalarMask(include_bottom=True)
495 mv=self.getVectorMask(include_bottom=False)
496 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)
497 p=p_ref*mp
498 u=u_ref*mv
499 df=DarcyFlow(self.dom)
500 df.setValue(g=f,
501 location_of_fixed_pressure=mp,
502 location_of_fixed_flux=mv,
503 permeability=Scalar(k,Function(self.dom)))
504 #df.setTolerance(rtol=self.TOL)
505 v,p=df.solve(u,p )
506 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
507 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
508
509 def testVarioF_FixedBottom_smallK(self):
510 k=1.e-10
511 mp=self.getScalarMask(include_bottom=True)
512 mv=self.getVectorMask(include_bottom=False)
513 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)
514 p=p_ref*mp
515 u=u_ref*mv
516 df=DarcyFlow(self.dom)
517 #df.getSolverOptionsPressure().setVerbosityOn()
518 df.setValue(g=f,
519 location_of_fixed_pressure=mp,
520 location_of_fixed_flux=mv,
521 permeability=Scalar(k,Function(self.dom)))
522 #df.setTolerance(rtol=self.TOL)
523 v,p=df.solve(u,p )
524
525 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
526 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
527
528 def testVarioF_FixedBottom_mediumK(self):
529 k=1.
530 mp=self.getScalarMask(include_bottom=True)
531 mv=self.getVectorMask(include_bottom=False)
532 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)
533 p=p_ref*mp
534 u=u_ref*mv
535 df=DarcyFlow(self.dom)
536 df.setValue(g=f,
537 location_of_fixed_pressure=mp,
538 location_of_fixed_flux=mv,
539 permeability=Scalar(k,Function(self.dom)))
540 #df.setTolerance(rtol=self.TOL)
541 v,p=df.solve(u,p )
542 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
543 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
544
545 def testVarioF_FixedBottom_largeK(self):
546 k=1.e10
547 mp=self.getScalarMask(include_bottom=True)
548 mv=self.getVectorMask(include_bottom=False)
549 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)
550 p=p_ref*mp
551 u=u_ref*mv
552 df=DarcyFlow(self.dom)
553 df.setValue(g=f,
554 location_of_fixed_pressure=mp,
555 location_of_fixed_flux=mv,
556 permeability=Scalar(k,Function(self.dom)))
557 #df.setTolerance(rtol=self.TOL)
558 v,p=df.solve(u,p )
559 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
560 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
561
562 def testConstF_FreeBottom_smallK(self):
563 k=1.e-10
564 mp=self.getScalarMask(include_bottom=False)
565 mv=self.getVectorMask(include_bottom=True)
566 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)
567 p=p_ref*mp
568 u=u_ref*mv
569 df=DarcyFlow(self.dom)
570 df.setValue(g=f,
571 location_of_fixed_pressure=mp,
572 location_of_fixed_flux=mv,
573 permeability=Scalar(k,Function(self.dom)))
574 #df.setTolerance(rtol=self.TOL)
575 v,p=df.solve(u,p)
576
577
578 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
579 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
580
581 def testConstF_FreeBottom_mediumK(self):
582 k=1.
583 mp=self.getScalarMask(include_bottom=False)
584 mv=self.getVectorMask(include_bottom=True)
585 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)
586 p=p_ref*mp
587 u=u_ref*mv
588 df=DarcyFlow(self.dom)
589 df.setValue(g=f,
590 location_of_fixed_pressure=mp,
591 location_of_fixed_flux=mv,
592 permeability=Scalar(k,Function(self.dom)))
593 #df.setTolerance(rtol=self.TOL)
594 v,p=df.solve(u,p)
595 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
596 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
597
598 def testConstF_FreeBottom_largeK(self):
599 k=1.e10
600 mp=self.getScalarMask(include_bottom=False)
601 mv=self.getVectorMask(include_bottom=True)
602 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)
603 p=p_ref*mp
604 u=u_ref*mv
605 df=DarcyFlow(self.dom)
606 df.setValue(g=f,
607 location_of_fixed_pressure=mp,
608 location_of_fixed_flux=mv,
609 permeability=Scalar(k,Function(self.dom)))
610 #df.setTolerance(rtol=self.TOL)
611 v,p=df.solve(u,p)
612 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
613 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
614
615 def testVarioF_FreeBottom_smallK(self):
616 k=1.e-10
617 mp=self.getScalarMask(include_bottom=False)
618 mv=self.getVectorMask(include_bottom=True)
619 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)
620 p=p_ref*mp
621 u=u_ref*mv
622 df=DarcyFlow(self.dom)
623 df.setValue(g=f,
624 location_of_fixed_pressure=mp,
625 location_of_fixed_flux=mv,
626 permeability=Scalar(k,Function(self.dom)))
627 #df.setTolerance(rtol=self.TOL)
628 v,p=df.solve(u,p)
629 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
630 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
631
632 def testVarioF_FreeBottom_mediumK(self):
633 k=1.
634 mp=self.getScalarMask(include_bottom=False)
635 mv=self.getVectorMask(include_bottom=True)
636 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)
637 p=p_ref*mp
638 u=u_ref*mv
639 df=DarcyFlow(self.dom)
640 df.setValue(g=f,
641 location_of_fixed_pressure=mp,
642 location_of_fixed_flux=mv,
643 permeability=Scalar(k,Function(self.dom)))
644 #df.setTolerance(rtol=self.TOL)
645 v,p=df.solve(u,p)
646 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
647 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
648
649 def testVarioF_FreeBottom_largeK(self):
650 k=1.e10
651 mp=self.getScalarMask(include_bottom=False)
652 mv=self.getVectorMask(include_bottom=True)
653 u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)
654 p=p_ref*mp
655 u=u_ref*mv
656 df=DarcyFlow(self.dom)
657 df.setValue(g=f,
658 location_of_fixed_pressure=mp,
659 location_of_fixed_flux=mv,
660 permeability=Scalar(k,Function(self.dom)))
661 #df.setTolerance(rtol=self.TOL)
662 v,p=df.solve(u,p)
663 self.assertTrue(Lsup(v-u_ref)<self.TEST_TOL*Lsup(u_ref), "flux error too big.")
664 self.assertTrue(Lsup(p-p_ref)<self.TEST_TOL*Lsup(p_ref), "pressure error too big.")
665
666 class Test_Darcy2D(Test_Darcy):
667 TOL=1e-6
668 TEST_TOL=2.e-3
669 WIDTH=1.
670 def setUp(self):
671 NE=40 # wrning smaller NE may case a failure for VarioF tests due to discretization errors.
672 self.dom = Rectangle(NE/2,NE)
673 self.rescaleDomain()
674 def tearDown(self):
675 del self.dom
676 class Test_Darcy3D(Test_Darcy):
677 TOL=1e-6
678 WIDTH=1.
679 TEST_TOL=4.e-3
680 def setUp(self):
681 NE=25 # wrning smaller NE may case a failure for VarioF tests due to discretization errors.
682 self.dom = Brick(NE,NE,NE)
683 self.rescaleDomain()
684 def tearDown(self):
685 del self.dom
686
687 class Test_Rheologies(unittest.TestCase):
688 """
689 this is the program used to generate the powerlaw tests:
690
691 TAU_Y=100.
692 N=10
693 M=5
694
695 def getE(tau):
696 if tau<=TAU_Y:
697 return 1./(0.5+20*sqrt(tau))
698 else:
699 raise ValueError,"out of range."
700 tau=[ i* (TAU_Y/N) for i in range(N+1)] + [TAU_Y for i in range(M)]
701 e=[ tau[i]/getE(tau[i]) for i in range(N+1)]
702 e+= [ (i+1+j)* (max(e)/N) for j in range(M) ]
703
704 print tau
705 print e
706 """
707 TOL=1.e-8
708 def test_PowerLaw_Init(self):
709 pl=PowerLaw(numMaterials=3,verbose=VERBOSE)
710
711 self.assertEqual(pl.getNumMaterials(),3,"num materials is wrong")
712 self.assertEqual(pl.validMaterialId(0),True,"material id 0 not found")
713 self.assertEqual(pl.validMaterialId(1),True,"material id 1 not found")
714 self.assertEqual(pl.validMaterialId(2),True,"material id 2 not found")
715 self.assertEqual(pl.validMaterialId(3),False,"material id 3 not found")
716
717 self.assertEqual(pl.getFriction(),None,"initial friction wrong.")
718 self.assertEqual(pl.getTauY(),None,"initial tau y wrong.")
719 pl.setDruckerPragerLaw(tau_Y=10,friction=3)
720 self.assertEqual(pl.getFriction(),3,"friction wrong.")
721 self.assertEqual(pl.getTauY(),10,"tau y wrong.")
722
723 self.assertEqual(pl.getElasticShearModulus(),None,"initial shear modulus is wrong")
724 pl.setElasticShearModulus(1000)
725 self.assertEqual(pl.getElasticShearModulus(),1000.,"shear modulus is wrong")
726
727 e=pl.getEtaN()
728 self.assertEqual(len(e),3,"initial length of etaN is wrong.")
729 self.assertEqual(e,[None, None, None],"initial etaN are wrong.")
730 self.assertEqual(pl.getEtaN(0),None,"initial material id 0 is wrong")
731 self.assertEqual(pl.getEtaN(1),None,"initial material id 1 is wrong")
732 self.assertEqual(pl.getEtaN(2),None,"initial material id 2 is wrong")
733 self.assertRaises(ValueError, pl.getEtaN, 3)
734
735 self.assertRaises(ValueError,pl.setPowerLaws,eta_N=[10,20,30,40],tau_t=[2], power=[5,6,7])
736 self.assertRaises(ValueError,pl.setPowerLaws,eta_N=[10,20,30],tau_t=[2,4,5,5], power=[5,6,7])
737 self.assertRaises(ValueError,pl.setPowerLaws,eta_N=[10,20,30],tau_t=[2,1,2], power=[5,6,7,7])
738
739 pl.setPowerLaws(eta_N=[10,20,30],tau_t=[100,200,300], power=[1,2,3])
740 self.assertEqual(pl.getPower(),[1,2,3],"powers are wrong.")
741 self.assertEqual(pl.getTauT(),[100,200,300],"tau t are wrong.")
742 self.assertEqual(pl.getEtaN(),[10,20,30],"etaN are wrong.")
743
744 pl.setPowerLaw(id=0,eta_N=40,tau_t=400, power=4)
745 self.assertEqual(pl.getPower(),[4,2,3],"powers are wrong.")
746 self.assertEqual(pl.getTauT(),[400,200,300],"tau t are wrong.")
747 self.assertEqual(pl.getEtaN(),[40,20,30],"etaN are wrong.")
748
749 self.assertRaises(ValueError,pl.getPower,-1)
750 self.assertEqual(pl.getPower(0),4,"power 0 is wrong.")
751 self.assertEqual(pl.getPower(1),2,"power 1 is wrong.")
752 self.assertEqual(pl.getPower(2),3,"power 2 is wrong.")
753 self.assertRaises(ValueError,pl.getPower,3)
754
755 self.assertRaises(ValueError,pl.getTauT,-1)
756 self.assertEqual(pl.getTauT(0),400,"tau t 0 is wrong.")
757 self.assertEqual(pl.getTauT(1),200,"tau t 1 is wrong.")
758 self.assertEqual(pl.getTauT(2),300,"tau t 2 is wrong.")
759 self.assertRaises(ValueError,pl.getTauT,3)
760
761 self.assertRaises(ValueError,pl.getEtaN,-1)
762 self.assertEqual(pl.getEtaN(0),40,"eta n 0 is wrong.")
763 self.assertEqual(pl.getEtaN(1),20,"eta n 1 is wrong.")
764 self.assertEqual(pl.getEtaN(2),30,"eta n 2 is wrong.")
765 self.assertRaises(ValueError,pl.getEtaN,3)
766
767 def checkResult(self,id,gamma_dot_, eta, tau_ref):
768 self.assertTrue(eta>=0,"eta needs to be positive (test %s)"%id)
769 error=abs(gamma_dot_*eta-tau_ref)
770 self.assertTrue(error<=self.TOL*tau_ref,"eta is wrong: error = gamma_dot_*eta-tau_ref = %s * %s - %s = %s (test %s)"%(gamma_dot_,eta,tau_ref,error,id))
771
772 def test_PowerLaw_Linear(self):
773 taus= [0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
774 gamma_dot_s=[0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0]
775 pl=PowerLaw(numMaterials=1,verbose=VERBOSE)
776 pl.setDruckerPragerLaw(tau_Y=100.)
777 pl.setPowerLaw(eta_N=2.)
778 pl.setEtaTolerance(self.TOL)
779 for i in range(len(taus)): self.checkResult(i,gamma_dot_s[i], pl.getEtaEff(gamma_dot_s[i]),taus[i])
780
781 def test_PowerLaw_QuadLarge(self):
782 taus=[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
783 gamma_dot_s=[0.0, 405.0, 1610.0, 3615.0, 6420.0, 10025.0, 14430.0, 19635.0, 25640.0, 32445.0, 40050.0, 44055.0, 48060.0, 52065.0, 56070.0, 60075.0]
784 pl=PowerLaw(numMaterials=2,verbose=VERBOSE)
785 pl.setDruckerPragerLaw(tau_Y=100.)
786 pl.setPowerLaws(eta_N=[2.,0.01],tau_t=[1, 25.], power=[1,2])
787 pl.setEtaTolerance(self.TOL)
788 for i in range(len(taus)): self.checkResult(i,gamma_dot_s[i], pl.getEtaEff(gamma_dot_s[i]),taus[i])
789
790 def test_PowerLaw_QuadSmall(self):
791 taus=[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
792 gamma_dot_s=[0.0, 5.4, 11.6, 18.6, 26.4, 35.0, 44.4, 54.6, 65.6, 77.4, 90.0, 99.0, 108.0, 117.0, 126.0, 135.0]
793 pl=PowerLaw(numMaterials=2,verbose=VERBOSE)
794 pl.setDruckerPragerLaw(tau_Y=100.)
795 pl.setPowerLaws(eta_N=[2.,10.],tau_t=[1, 25.], power=[1,2])
796 pl.setEtaTolerance(self.TOL)
797 for i in range(len(taus)): self.checkResult(i,gamma_dot_s[i], pl.getEtaEff(gamma_dot_s[i]),taus[i])
798
799 def test_PowerLaw_CubeLarge(self):
800 taus=[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
801 gamma_dot_s=[0.0, 8.90625, 41.25, 120.46875, 270.0, 513.28125, 873.75, 1374.84375, 2040.0, 2892.65625, 3956.25, 4351.875, 4747.5, 5143.125, 5538.75, 5934.375]
802 pl=PowerLaw(numMaterials=2,verbose=VERBOSE)
803 pl.setDruckerPragerLaw(tau_Y=100.)
804 pl.setPowerLaws(eta_N=[2.,1./16.],tau_t=[1, 64.], power=[1,3])
805 pl.setEtaTolerance(self.TOL)
806 for i in range(len(taus)): self.checkResult(i,gamma_dot_s[i], pl.getEtaEff(gamma_dot_s[i]),taus[i])
807
808 def test_PowerLaw_CubeSmall(self):
809 taus=[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
810 gamma_dot_s=[0.0, 5.0390625, 10.3125, 16.0546875, 22.5, 29.8828125, 38.4375, 48.3984375, 60.0, 73.4765625, 89.0625, 97.96875, 106.875, 115.78125, 124.6875, 133.59375]
811 pl=PowerLaw(numMaterials=2,verbose=VERBOSE)
812 pl.setDruckerPragerLaw(tau_Y=100.)
813 pl.setPowerLaws(eta_N=[2.,25./4.],tau_t=[1, 64.], power=[1,3])
814 pl.setEtaTolerance(self.TOL)
815 for i in range(len(taus)): self.checkResult(i,gamma_dot_s[i], pl.getEtaEff(gamma_dot_s[i]),taus[i])
816
817 def test_PowerLaw_QuadLarge_CubeLarge(self):
818 taus=[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
819 gamma_dot_s=[0.0, 408.90625, 1641.25, 3720.46875, 6670.0, 10513.28125, 15273.75, 20974.84375, 27640.000000000004, 35292.65625, 43956.25, 48351.875, 52747.5, 57143.125, 61538.75, 65934.375]
820
821 pl=PowerLaw(numMaterials=3,verbose=VERBOSE)
822 pl.setDruckerPragerLaw(tau_Y=100.)
823 pl.setPowerLaws(eta_N=[2.,0.01,1./16.],tau_t=[1, 25.,64.], power=[1,2,3])
824 pl.setEtaTolerance(self.TOL)
825 for i in range(len(taus)): self.checkResult(i,gamma_dot_s[i], pl.getEtaEff(gamma_dot_s[i]),taus[i])
826
827 def test_PowerLaw_QuadLarge_CubeSmall(self):
828 taus=[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
829 gamma_dot_s=[0.0, 405.0390625, 1610.3125, 3616.0546875, 6422.5, 10029.8828125, 14438.4375, 19648.3984375, 25660.0, 32473.4765625, 40089.0625, 44097.96875, 48106.875, 52115.78125, 56124.6875, 60133.59375]
830
831 pl=PowerLaw(numMaterials=3,verbose=VERBOSE)
832 pl.setDruckerPragerLaw(tau_Y=100.)
833 pl.setPowerLaws(eta_N=[2.,0.01,25./4.],tau_t=[1, 25.,64.], power=[1,2,3])
834 pl.setEtaTolerance(self.TOL)
835 for i in range(len(taus)): self.checkResult(i,gamma_dot_s[i], pl.getEtaEff(gamma_dot_s[i]),taus[i])
836
837 def test_PowerLaw_QuadSmall_CubeLarge(self):
838 taus=[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
839 gamma_dot_s=[0.0, 9.30625, 42.85, 124.06875, 276.4, 523.28125, 888.15, 1394.44375, 2065.6, 2925.05625, 3996.25, 4395.875, 4795.5, 5195.125, 5594.75, 5994.375]
840 pl=PowerLaw(numMaterials=3,verbose=VERBOSE)
841 pl.setDruckerPragerLaw(tau_Y=100.)
842 pl.setPowerLaws(eta_N=[2.,10.,1./16.],tau_t=[1, 25.,64.], power=[1,2,3])
843 pl.setEtaTolerance(self.TOL)
844 for i in range(len(taus)): self.checkResult(i,gamma_dot_s[i], pl.getEtaEff(gamma_dot_s[i]),taus[i])
845
846 def test_PowerLaw_QuadSmall_CubeSmall(self):
847 taus=[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
848 gamma_dot_s=[0.0, 5.4390625, 11.9125, 19.6546875, 28.9, 39.8828125, 52.8375, 67.9984375, 85.6, 105.8765625, 129.0625, 141.96875, 154.875, 167.78125, 180.6875, 193.59375]
849 pl=PowerLaw(numMaterials=3,verbose=VERBOSE)
850 pl.setDruckerPragerLaw(tau_Y=100.)
851 pl.setPowerLaws(eta_N=[2.,10.,25./4.],tau_t=[1, 25.,64.], power=[1,2,3])
852 pl.setEtaTolerance(self.TOL)
853 for i in range(len(taus)): self.checkResult(i,gamma_dot_s[i], pl.getEtaEff(gamma_dot_s[i]),taus[i])
854
855 def test_PowerLaw_withShear(self):
856 taus=[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
857 gamma_dot_s=[0.0, 15.0, 30.0, 45.0, 60.0, 75.0, 90.0, 105.0, 120.0, 135.0, 150.0, 165.0, 180.0, 195.0, 210.0, 225.0]
858 pl=PowerLaw(numMaterials=1,verbose=VERBOSE)
859 pl.setDruckerPragerLaw(tau_Y=100.)
860 pl.setPowerLaw(eta_N=2.)
861 pl.setElasticShearModulus(3.)
862 dt=1./3.
863 pl.setEtaTolerance(self.TOL)
864 self.assertRaises(ValueError, pl.getEtaEff,gamma_dot_s[0])
865 for i in range(len(taus)): self.checkResult(i,gamma_dot_s[i], pl.getEtaEff(gamma_dot_s[i],dt=dt),taus[i])
866
867
868 class Test_FaultSystem(unittest.TestCase):
869 EPS=1.e-8
870 NE=10
871 def test_Fault_MaxValue(self):
872 dom=Rectangle(2*self.NE,2*self.NE)
873 x=dom.getX()
874 f=FaultSystem(dim=2)
875 f.addFault(V0=[0.5,0.], strikes=[3.*pi/4], ls=[0.70710678118654757], tag=1)
876 f.addFault(V0=[1.,0.5], strikes=[pi, pi/2], ls=[0.5,0.5], tag=2)
877
878 u=x[0]*(1.-x[0])*(1-x[1])
879 t, loc=f.getMaxValue(u)
880 p=f.getParametrization(x,t)[0]
881 m, l=loc(u), loc(p)
882 self.assertTrue( m == 0.25, "wrong max value")
883 self.assertTrue( t == 1, "wrong max tag")
884 self.assertTrue( l == 0., "wrong max location")
885
886 u=x[1]*(1.-x[1])*(1-x[0])*x[0]
887 t, loc=f.getMaxValue(u)
888 p=f.getParametrization(x,t)[0]
889 m, l=loc(u), loc(p)
890 self.assertTrue( m == 0.0625, "wrong max value")
891 self.assertTrue( t == 2, "wrong max tag")
892 self.assertTrue( l == 0.5, "wrong max location")
893
894 u=x[0]*(1.-x[0])*x[1]
895 t, loc=f.getMaxValue(u)
896 p=f.getParametrization(x,t)[0]
897 m, l=loc(u), loc(p)
898 self.assertTrue( m == 0.25, "wrong max value")
899 self.assertTrue( t == 2, "wrong max tag")
900 self.assertTrue( l == 1.0, "wrong max location")
901
902 u=x[1]*(1.-x[1])*x[0]
903 t, loc=f.getMaxValue(u)
904 p=f.getParametrization(x,t)[0]
905 m, l=loc(u), loc(p)
906 self.assertTrue( m == 0.25, "wrong max value")
907 self.assertTrue( t == 2, "wrong max tag")
908 self.assertTrue( l == 0., "wrong max location")
909
910 u=x[1]*(1.-x[1])*(1.-x[0])
911 t, loc=f.getMaxValue(u)
912 p=f.getParametrization(x,t)[0]
913 m, l=loc(u), loc(p)
914 self.assertTrue( m == 0.25, "wrong max value")
915 self.assertTrue( t == 1, "wrong max tag")
916 self.assertTrue( abs(l-0.70710678118654) <= self.EPS, "wrong max location")
917 def test_Fault_MinValue(self):
918 dom=Rectangle(2*self.NE,2*self.NE)
919 x=dom.getX()
920 f=FaultSystem(dim=2)
921 f.addFault(V0=[0.5,0.], strikes=[3.*pi/4], ls=[0.70710678118654757], tag=1)
922 f.addFault(V0=[1.,0.5], strikes=[pi, pi/2], ls=[0.5,0.5], tag=2)
923
924 u=-x[0]*(1.-x[0])*(1-x[1])
925 t, loc=f.getMinValue(u)
926 p=f.getParametrization(x,t)[0]
927 m, l=loc(u), loc(p)
928 self.assertTrue( m == -0.25, "wrong min value")
929 self.assertTrue( t == 1, "wrong min tag")
930 self.assertTrue( l == 0., "wrong min location")
931 u=-x[1]*(1.-x[1])*(1-x[0])*x[0]
932 t, loc=f.getMinValue(u)
933 p=f.getParametrization(x,t)[0]
934 m, l=loc(u), loc(p)
935 self.assertTrue( m == -0.0625, "wrong min value")
936 self.assertTrue( t == 2, "wrong min tag")
937 self.assertTrue( l == 0.5, "wrong min location")
938 u=-x[0]*(1.-x[0])*x[1]
939 t, loc=f.getMinValue(u)
940 p=f.getParametrization(x,t)[0]
941 m, l=loc(u), loc(p)
942 self.assertTrue( m == -0.25, "wrong min value")
943 self.assertTrue( t == 2, "wrong min tag")
944 self.assertTrue( l == 1.0, "wrong min location")
945 u=-x[1]*(1.-x[1])*x[0]
946 t, loc=f.getMinValue(u)
947 p=f.getParametrization(x,t)[0]
948 m, l=loc(u), loc(p)
949 self.assertTrue( m == -0.25, "wrong min value")
950 self.assertTrue( t == 2, "wrong min tag")
951 self.assertTrue( l == 0., "wrong min location")
952 u=-x[1]*(1.-x[1])*(1.-x[0])
953 t, loc=f.getMinValue(u)
954 p=f.getParametrization(x,t)[0]
955 m, l=loc(u), loc(p)
956 self.assertTrue( m == -0.25, "wrong min value")
957 self.assertTrue( t == 1, "wrong min tag")
958 self.assertTrue( abs(l-0.70710678118654) <= self.EPS, "wrong min location")
959
960
961 def test_Fault2D(self):
962 f=FaultSystem(dim=2)
963 top1=[ [1.,0.], [1.,1.], [0.,1.] ]
964 self.assertRaises(ValueError,f.addFault,V0=[1.,0],strikes=[pi/2, pi/2],ls=[1.,1.],tag=1,dips=top1)
965 f.addFault(V0=[1.,0],strikes=[pi/2, pi],ls=[1.,1.],tag=1)
966 self.assertTrue(f.getDim() == 2, "wrong dimension")
967 self.assertTrue( [ 1 ] == f.getTags(), "tags wrong")
968 self.assertTrue( 2. == f.getTotalLength(1), "length wrong")
969 self.assertTrue( 0. == f.getMediumDepth(1), "depth wrong")
970 self.assertTrue( (0., 2.) == f.getW0Range(1)," wrong W0 range")
971 self.assertTrue( (0., 0.) == f.getW1Range(1)," wrong W1 range")
972 self.assertTrue( [0., 1., 2.] == f.getW0Offsets(1)," wrong W0 offsets")
973 segs=f.getTopPolyline(1)
974 self.assertTrue( len(segs) == 3, "wrong number of segments")
975 self.assertTrue( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0")
976 self.assertTrue( segs[0].size == 2, "seg 0 has wrong size.")
977 self.assertTrue( numpy.linalg.norm(segs[0]-[1.,0.]) < self.EPS, "wrong vertex. 0 ")
978 self.assertTrue( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1")
979 self.assertTrue( segs[1].size == 2, "seg 1 has wrong size.")
980 self.assertTrue( numpy.linalg.norm(segs[1]-[1.,1.]) < self.EPS, "wrong vertex. 1 ")
981 self.assertTrue( isinstance(segs[2], numpy.ndarray), "wrong class of vertex 2")
982 self.assertTrue( segs[2].size == 2, "seg 2 has wrong size.")
983 self.assertTrue( numpy.linalg.norm(segs[2]-[0.,1.]) < self.EPS, "wrong vertex. 2 ")
984 c=f.getCenterOnSurface()
985 self.assertTrue( isinstance(c, numpy.ndarray), "center has wrong class")
986 self.assertTrue( c.size == 2, "center size is wrong")
987 self.assertTrue( numpy.linalg.norm(c-[2./3.,2./3.]) < self.EPS, "center has wrong coordinates.")
988 o=f.getOrientationOnSurface()/pi*180.
989 self.assertTrue( abs(o+45.) < self.EPS, "wrong orientation.")
990
991 top2=[ [10.,0.], [0.,10.] ]
992 f.addFault(V0=[10.,0],strikes=[3.*pi/4],ls=[14.142135623730951], tag=2, w0_offsets=[0,20], w1_max=20)
993 self.assertTrue( [ 1, 2 ] == f.getTags(), "tags wrong")
994 self.assertTrue( abs(f.getTotalLength(2)-14.1421356237) < self.EPS * 14.1421356237, "wrong length")
995 self.assertTrue( 0. == f.getMediumDepth(2), "depth wrong")
996 self.assertTrue( (0., 20.) == f.getW0Range(2)," wrong W0 range")
997 self.assertTrue( (0., 0.) == f.getW1Range(2)," wrong W1 range")
998 self.assertTrue( [0., 20.] == f.getW0Offsets(2)," wrong W0 offsets")
999 segs=f.getTopPolyline(2)
1000 self.assertTrue( len(segs) == 2, "wrong number of segments")
1001 self.assertTrue( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0")
1002 self.assertTrue( numpy.linalg.norm(segs[0]-[10.,0.]) < self.EPS, "wrong vertex. 0 ")
1003 self.assertTrue( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1")
1004 self.assertTrue( numpy.linalg.norm(segs[1]-[0.,10.]) < self.EPS, "wrong vertex. 1 ")
1005 c=f.getCenterOnSurface()
1006 self.assertTrue( isinstance(c, numpy.ndarray), "center has wrong class")
1007 self.assertTrue( c.size == 2, "center size is wrong")
1008 self.assertTrue( numpy.linalg.norm(c-[12./5.,12./5.]) < self.EPS, "center has wrong coordinates.")
1009 o=f.getOrientationOnSurface()/pi*180.
1010 self.assertTrue( abs(o+45.) < self.EPS, "wrong orientation.")
1011
1012 s,d=f.getSideAndDistance([0.,0.], tag=1)
1013 self.assertTrue( s<0, "wrong side.")
1014 self.assertTrue( abs(d-1.)<self.EPS, "wrong distance.")
1015 s,d=f.getSideAndDistance([0.,2.], tag=1)
1016 self.assertTrue( s>0, "wrong side.")
1017 self.assertTrue( abs(d-1.)<self.EPS, "wrong distance.")
1018 s,d=f.getSideAndDistance([1.,2.], tag=1)
1019 self.assertTrue( s>0, "wrong side.")
1020 self.assertTrue( abs(d-1.)<self.EPS, "wrong distance.")
1021 s,d=f.getSideAndDistance([2.,1.], tag=1)
1022 self.assertTrue( s>0, "wrong side.")
1023 self.assertTrue( abs(d-1.)<self.EPS, "wrong distance.")
1024 s,d=f.getSideAndDistance([2.,0.], tag=1)
1025 self.assertTrue( s>0, "wrong side.")
1026 self.assertTrue( abs(d-1.)<self.EPS, "wrong distance.")
1027 s,d=f.getSideAndDistance([0.,-1.], tag=1)
1028 self.assertTrue( s<0, "wrong side.")
1029 self.assertTrue( abs(d-1.41421356237)<self.EPS, "wrong distance.")
1030 s,d=f.getSideAndDistance([-1.,0], tag=1)
1031 self.assertTrue( s<0, "wrong side.")
1032 self.assertTrue( abs(d-1.41421356237)<self.EPS, "wrong distance.")
1033
1034
1035 f.transform(rot=-pi/2., shift=[-1.,-1.])
1036 self.assertTrue( [ 1, 2 ] == f.getTags(), "tags after transformation wrong")
1037 self.assertTrue( 2. == f.getTotalLength(1), "length after transformation wrong")
1038 self.assertTrue( 0. == f.getMediumDepth(1), "depth after transformation wrong")
1039 self.assertTrue( (0., 2.) == f.getW0Range(1)," wrong W0 after transformation range")
1040 self.assertTrue( (0., 0.) == f.getW1Range(1)," wrong W1 rangeafter transformation ")
1041 self.assertTrue( [0., 1., 2.] == f.getW0Offsets(1)," wrong W0 offsetsafter transformation ")
1042 segs=f.getTopPolyline(1)
1043 self.assertTrue( len(segs) == 3, "wrong number of segmentsafter transformation ")
1044 self.assertTrue( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0 after transformation")
1045 self.assertTrue( segs[0].size == 2, "seg 0 has wrong size after transformation.")
1046 self.assertTrue( numpy.linalg.norm(segs[0]-[-1.,0.]) < self.EPS, "wrong vertex. 0 after transformation")
1047 self.assertTrue( isinstance(segs[1], numpy.ndarray), "wrong class of vertex after transformation1")
1048 self.assertTrue( segs[1].size == 2, "seg 1 has wrong size after transformation.")
1049 self.assertTrue( numpy.linalg.norm(segs[1]-[0.,0.]) < self.EPS, "wrong vertex. after transformation1 ")
1050 self.assertTrue( isinstance(segs[2], numpy.ndarray), "wrong class of vertex after transformation2")
1051 self.assertTrue( segs[2].size == 2, "seg 2 has wrong size after transformation.")
1052 self.assertTrue( numpy.linalg.norm(segs[2]-[0., 1.]) < self.EPS, "wrong vertex after transformation. 2 ")
1053 self.assertTrue( abs(f.getTotalLength(2)-14.1421356237) < self.EPS * 14.1421356237, "wrong length after transformation")
1054 self.assertTrue( 0. == f.getMediumDepth(2), "depth wrong after transformation")
1055 self.assertTrue( (0., 20.) == f.getW0Range(2)," wrong W0 range after transformation")
1056 self.assertTrue( (0., 0.) == f.getW1Range(2)," wrong W1 range after transformation")
1057 self.assertTrue( [0., 20.] == f.getW0Offsets(2)," wrong W0 offsets after transformation")
1058 segs=f.getTopPolyline(2)
1059 self.assertTrue( len(segs) == 2, "wrong number of segments after transformation")
1060 self.assertTrue( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0 after transformation")
1061 self.assertTrue( numpy.linalg.norm(segs[0]-[-1.,-9]) < self.EPS, "wrong vertex. 0 after transformation")
1062 self.assertTrue( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1 after transformation")
1063 self.assertTrue( numpy.linalg.norm(segs[1]-[9.,1.]) < self.EPS, "wrong vertex. 1 after transformation")
1064
1065 c=f.getCenterOnSurface()
1066 self.assertTrue( isinstance(c, numpy.ndarray), "center has wrong class")
1067 self.assertTrue( c.size == 2, "center size is wrong")
1068 self.assertTrue( numpy.linalg.norm(c-[7./5.,-7./5.]) < self.EPS, "center has wrong coordinates.")
1069 o=f.getOrientationOnSurface()/pi*180.
1070 self.assertTrue( abs(o-45.) < self.EPS, "wrong orientation.")
1071
1072 p=f.getParametrization([-1.,0.],1)
1073 self.assertTrue(p[1]==1., "wrong value.")
1074 self.assertTrue(abs(p[0])<self.EPS, "wrong value.")
1075 p=f.getParametrization([-0.5,0.],1)
1076 self.assertTrue(p[1]==1., "wrong value.")
1077 self.assertTrue(abs(p[0]-0.5)<self.EPS* 0.5, "wrong value.")
1078 p=f.getParametrization([0.,0.],1)
1079 self.assertTrue(p[1]==1., "wrong value.")
1080 self.assertTrue(abs(p[0]-1.)<self.EPS, "wrong value.")
1081 p=f.getParametrization([0.0000001,0.0000001],1, tol=1.e-8)
1082 self.assertTrue(p[1]==0., "wrong value.")
1083 p=f.getParametrization([0.0000001,0.0000001],1, tol=1.e-6)
1084 self.assertTrue(p[1]==1., "wrong value.")
1085 self.assertTrue(abs(p[0]-1.0000001)<self.EPS, "wrong value.")
1086 p=f.getParametrization([0.,0.5],1)
1087 self.assertTrue(p[1]==1., "wrong value.")
1088 self.assertTrue(abs(p[0]-1.5)<self.EPS, "wrong value.")
1089 p=f.getParametrization([0,1.],1)
1090 self.assertTrue(p[1]==1., "wrong value.")
1091 self.assertTrue(abs(p[0]-2.)<self.EPS, "wrong value.")
1092 p=f.getParametrization([1.,1.],1)
1093 self.assertTrue(p[1]==0., "wrong value.")
1094 p=f.getParametrization([0,1.11],1)
1095 self.assertTrue(p[1]==0., "wrong value.")
1096 p=f.getParametrization([-1,-9.],2)
1097 self.assertTrue(p[1]==1., "wrong value.")
1098 self.assertTrue(abs(p[0])<self.EPS, "wrong value.")
1099 p=f.getParametrization([9,1],2)
1100 self.assertTrue(p[1]==1., "wrong value.")
1101 self.assertTrue(abs(p[0]-20.)<self.EPS, "wrong value.")
1102
1103 def test_Fault3D(self):
1104 f=FaultSystem(dim=3)
1105 self.assertTrue(f.getDim() == 3, "wrong dimension")
1106
1107 top1=[ [0.,0.,0.], [1., 0., 0.] ]
1108 f.addFault(V0=[0.,0,0],strikes=[0.],ls=[1.,], dips=pi/2, depths=20.,tag=1)
1109 self.assertTrue( [ 1 ] == f.getTags(), "tags wrong")
1110 self.assertTrue( 1. == f.getTotalLength(1), "length wrong")
1111 self.assertTrue( 20. == f.getMediumDepth(1), "depth wrong")
1112 self.assertTrue( (0., 1.) == f.getW0Range(1)," wrong W0 range")
1113 self.assertTrue( (-20., 0.) == f.getW1Range(1)," wrong W1 range")
1114 self.assertTrue( [0., 1.] == f.getW0Offsets(1)," wrong W0 offsets")
1115 segs=f.getTopPolyline(1)
1116 self.assertTrue( len(segs) == 2, "wrong number of segments")
1117 self.assertTrue( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0")
1118 self.assertTrue( segs[0].size == 3, "seg 0 has wrong size.")
1119 self.assertTrue( numpy.linalg.norm(segs[0]-[0.,0.,0.]) < self.EPS, "wrong vertex. 0 ")
1120 self.assertTrue( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1")
1121 self.assertTrue( segs[1].size == 3, "seg 1 has wrong size.")
1122 self.assertTrue( numpy.linalg.norm(segs[1]-[1.,0.,0]) < self.EPS, "wrong vertex. 1 ")
1123 c=f.getCenterOnSurface()
1124 self.assertTrue( isinstance(c, numpy.ndarray), "center has wrong class")
1125 self.assertTrue( c.size == 3, "center size is wrong")
1126 self.assertTrue( numpy.linalg.norm(c-[0.5,0.,0.]) < self.EPS, "center has wrong coordinates.")
1127 o=f.getOrientationOnSurface()/pi*180.
1128 self.assertTrue( abs(o) < self.EPS, "wrong orientation.")
1129 d=f.getDips(1)
1130 self.assertTrue( len(d) == 1, "wrong number of dips")
1131 self.assertTrue( abs(d[0]-1.5707963267948966) < self.EPS, "wrong dip 0")
1132 sn=f.getSegmentNormals(1)
1133 self.assertTrue( len(sn) == 1, "wrong number of normals")
1134 self.assertTrue( isinstance(sn[0], numpy.ndarray), "wrong class of bottom vertex 0")
1135 self.assertTrue( numpy.linalg.norm(sn[0]-[0, -1., 0.]) < self.EPS, "wrong bottom vertex 1 ")
1136 dv=f.getDepthVectors(1)
1137 self.assertTrue( len(dv) == 2, "wrong number of depth vectors.")
1138 self.assertTrue( isinstance(dv[0], numpy.ndarray), "wrong class of depth vector 0")
1139 self.assertTrue( numpy.linalg.norm(dv[0]-[0., 0., -20.]) < self.EPS, "wrong depth vector 0 ")
1140 self.assertTrue( isinstance(dv[1], numpy.ndarray), "wrong class of depth vector 1")
1141 self.assertTrue( numpy.linalg.norm(dv[1]-[0., 0., -20.]) < self.EPS, "wrong depth vector 1 ")
1142 b=f.getBottomPolyline(1)
1143 self.assertTrue( len(b) == 2, "wrong number of bottom vertices")
1144 self.assertTrue( isinstance(b[0], numpy.ndarray), "wrong class of bottom vertex 0")
1145 self.assertTrue( numpy.linalg.norm(b[0]-[0., 0., -20.]) < self.EPS, "wrong bottom vertex 0 ")
1146 self.assertTrue( isinstance(b[1], numpy.ndarray), "wrong class of bottom vertex 1")
1147 self.assertTrue( numpy.linalg.norm(b[1]-[1., 0., -20.]) < self.EPS, "wrong bottom vertex 1 ")
1148 ds=f.getDepths(1)
1149 self.assertTrue( len(ds) == 2, "wrong number of depth")
1150 self.assertTrue( abs(ds[0]-20.) < self.EPS, "wrong depth at vertex 0 ")
1151 self.assertTrue( abs(ds[1]-20.) < self.EPS, "wrong depth at vertex 1 ")
1152
1153 top2=[ [0.,0.,0.], [0., 10., 0.] ]
1154 f.addFault(V0=[0.,0,0],strikes=[pi/2],ls=[10.,], dips=pi/2, depths=20.,tag=2)
1155 self.assertTrue( [ 1, 2 ] == f.getTags(), "tags wrong")
1156 self.assertTrue( 10. == f.getTotalLength(2), "length wrong")
1157 self.assertTrue( 20. == f.getMediumDepth(2), "depth wrong")
1158 self.assertTrue( (0., 10.) == f.getW0Range(2)," wrong W0 range")
1159 self.assertTrue( (-20., 0.) == f.getW1Range(2)," wrong W1 range")
1160 self.assertTrue( [0., 10.] == f.getW0Offsets(2)," wrong W0 offsets")
1161 segs=f.getTopPolyline(2)
1162 self.assertTrue( len(segs) == 2, "wrong number of segments")
1163 self.assertTrue( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0")
1164 self.assertTrue( segs[0].size == 3, "seg 0 has wrong size.")
1165 self.assertTrue( numpy.linalg.norm(segs[0]-[0.,0.,0.]) < self.EPS, "wrong vertex. 0 ")
1166 self.assertTrue( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1")
1167 self.assertTrue( segs[1].size == 3, "seg 1 has wrong size.")
1168 self.assertTrue( numpy.linalg.norm(segs[1]-[0., 10., 0]) < self.EPS, "wrong vertex. 1 ")
1169 d=f.getDips(2)
1170 self.assertTrue( len(d) == 1, "wrong number of dips")
1171 self.assertTrue( abs(d[0]-1.5707963267948966) < self.EPS, "wrong dip 0")
1172 sn=f.getSegmentNormals(2)
1173 self.assertTrue( len(sn) == 1, "wrong number of normals")
1174 self.assertTrue( isinstance(sn[0], numpy.ndarray), "wrong class of bottom vertex 0")
1175 self.assertTrue( numpy.linalg.norm(sn[0]-[1, 0., 0.]) < self.EPS, "wrong bottom vertex 1 ")
1176 dv=f.getDepthVectors(2)
1177 self.assertTrue( len(dv) == 2, "wrong number of depth vectors.")
1178 self.assertTrue( isinstance(dv[0], numpy.ndarray), "wrong class of depth vector 0")
1179 self.assertTrue( numpy.linalg.norm(dv[0]-[0., 0., -20.]) < self.EPS, "wrong depth vector 0 ")
1180 self.assertTrue( isinstance(dv[1], numpy.ndarray), "wrong class of depth vector 1")
1181 self.assertTrue( numpy.linalg.norm(dv[1]-[0., 0., -20.]) < self.EPS, "wrong depth vector 1 ")
1182 b=f.getBottomPolyline(2)
1183 self.assertTrue( len(b) == 2, "wrong number of bottom vertices")
1184 self.assertTrue( isinstance(b[0], numpy.ndarray), "wrong class of bottom vertex 0")
1185 self.assertTrue( numpy.linalg.norm(b[0]-[0., 0., -20.]) < self.EPS, "wrong bottom vertex 0 ")
1186 self.assertTrue( isinstance(b[1], numpy.ndarray), "wrong class of bottom vertex 1")
1187 self.assertTrue( numpy.linalg.norm(b[1]-[0., 10., -20.]) < self.EPS, "wrong bottom vertex 1 ")
1188 ds=f.getDepths(2)
1189 self.assertTrue( len(ds) == 2, "wrong number of depth")
1190 self.assertTrue( abs(ds[0]-20.) < self.EPS, "wrong depth at vertex 0 ")
1191 self.assertTrue( abs(ds[1]-20.) < self.EPS, "wrong depth at vertex 1 ")
1192
1193 top2=[ [10.,0.,0.], [0., 10., 0.] ]
1194 f.addFault(V0=[10.,0,0],strikes=3*pi/4,ls=14.142135623730951, dips=pi/2, depths=30.,tag=2)
1195 self.assertTrue( [ 1, 2 ] == f.getTags(), "tags wrong")
1196 self.assertTrue( abs(14.142135623730951 - f.getTotalLength(2)) <self.EPS, "length wrong")
1197 self.assertTrue( 30. == f.getMediumDepth(2), "depth wrong")
1198 self.assertTrue( (-30., 0.) == f.getW1Range(2)," wrong W1 range")
1199 segs=f.getTopPolyline(2)
1200 self.assertTrue( len(segs) == 2, "wrong number of segments")
1201 self.assertTrue( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0")
1202 self.assertTrue( segs[0].size == 3, "seg 0 has wrong size.")
1203 self.assertTrue( numpy.linalg.norm(segs[0]-[10.,0.,0.]) < self.EPS, "wrong vertex. 0 ")
1204 self.assertTrue( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1")
1205 self.assertTrue( segs[1].size == 3, "seg 1 has wrong size.")
1206 self.assertTrue( numpy.linalg.norm(segs[1]-[0., 10., 0]) < self.EPS, "wrong vertex. 1 ")
1207 d=f.getDips(2)
1208 self.assertTrue( len(d) == 1, "wrong number of dips")
1209 self.assertTrue( abs(d[0]-1.5707963267948966) < self.EPS, "wrong dip 0")
1210 sn=f.getSegmentNormals(2)
1211 self.assertTrue( len(sn) == 1, "wrong number of normals")
1212 self.assertTrue( isinstance(sn[0], numpy.ndarray), "wrong class of bottom vertex 0")
1213 self.assertTrue( numpy.linalg.norm(sn[0]-[0.70710678118654746, 0.70710678118654746, 0.]) < self.EPS, "wrong bottom vertex 1 ")
1214 dv=f.getDepthVectors(2)
1215 self.assertTrue( len(dv) == 2, "wrong number of depth vectors.")
1216 self.assertTrue( isinstance(dv[0], numpy.ndarray), "wrong class of depth vector 0")
1217 self.assertTrue( numpy.linalg.norm(dv[0]-[0., 0., -30.]) < self.EPS, "wrong depth vector 0 ")
1218 self.assertTrue( isinstance(dv[1], numpy.ndarray), "wrong class of depth vector 1")
1219 self.assertTrue( numpy.linalg.norm(dv[1]-[0., 0., -30.]) < self.EPS, "wrong depth vector 1 ")
1220 b=f.getBottomPolyline(2)
1221 self.assertTrue( len(b) == 2, "wrong number of bottom vertices")
1222 self.assertTrue( isinstance(b[0], numpy.ndarray), "wrong class of bottom vertex 0")
1223 self.assertTrue( numpy.linalg.norm(b[0]-[10., 0., -30.]) < self.EPS, "wrong bottom vertex 0 ")
1224 self.assertTrue( isinstance(b[1], numpy.ndarray), "wrong class of bottom vertex 1")
1225 self.assertTrue( numpy.linalg.norm(b[1]-[0., 10., -30.]) < self.EPS, "wrong bottom vertex 1 ")
1226 ds=f.getDepths(2)
1227 self.assertTrue( len(ds) == 2, "wrong number of depth")
1228 self.assertTrue( abs(ds[0]-30.) < self.EPS, "wrong depth at vertex 0 ")
1229 self.assertTrue( abs(ds[1]-30.) < self.EPS, "wrong depth at vertex 1 ")
1230
1231 top2=[ [10.,0.,0.], [0., 10., 0.] ]
1232 f.addFault(V0=[10.,0,0],strikes=3*pi/4,ls=14.142135623730951, dips=pi/4, depths=50.,tag=2)
1233 self.assertTrue( [ 1, 2 ] == f.getTags(), "tags wrong")
1234 self.assertTrue( abs(14.142135623730951 - f.getTotalLength(2)) <self.EPS, "length wrong")
1235 self.assertTrue( 50. == f.getMediumDepth(2), "depth wrong")
1236 self.assertTrue( (-50., 0.) == f.getW1Range(2)," wrong W1 range")
1237 segs=f.getTopPolyline(2)
1238 self.assertTrue( len(segs) == 2, "wrong number of segments")
1239 self.assertTrue( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0")
1240 self.assertTrue( segs[0].size == 3, "seg 0 has wrong size.")
1241 self.assertTrue( numpy.linalg.norm(segs[0]-[10.,0.,0.]) < self.EPS, "wrong vertex. 0 ")
1242 self.assertTrue( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1")
1243 self.assertTrue( segs[1].size == 3, "seg 1 has wrong size.")
1244 self.assertTrue( numpy.linalg.norm(segs[1]-[0., 10., 0]) < self.EPS, "wrong vertex. 1 ")
1245 d=f.getDips(2)
1246 self.assertTrue( len(d) == 1, "wrong number of dips")
1247 self.assertTrue( abs(d[0]-0.78539816339744828) < self.EPS, "wrong dip 0")
1248 sn=f.getSegmentNormals(2)
1249 self.assertTrue( len(sn) == 1, "wrong number of normals")
1250 self.assertTrue( isinstance(sn[0], numpy.ndarray), "wrong class of bottom vertex 0")
1251 self.assertTrue( numpy.linalg.norm(sn[0]-[0.5,0.5,0.70710678118654746]) < self.EPS, "wrong bottom vertex 1 ")
1252 dv=f.getDepthVectors(2)
1253 self.assertTrue( len(dv) == 2, "wrong number of depth vectors.")
1254 self.assertTrue( isinstance(dv[0], numpy.ndarray), "wrong class of depth vector 0")
1255 self.assertTrue( numpy.linalg.norm(dv[0]-[25., 25., -35.355339059327378]) < self.EPS, "wrong depth vector 0 ")
1256 self.assertTrue( isinstance(dv[1], numpy.ndarray), "wrong class of depth vector 1")
1257 self.assertTrue( numpy.linalg.norm(dv[1]-[25.,25., -35.355339059327378]) < self.EPS, "wrong depth vector 1 ")
1258 b=f.getBottomPolyline(2)
1259 self.assertTrue( len(b) == 2, "wrong number of bottom vertices")
1260 self.assertTrue( isinstance(b[0], numpy.ndarray), "wrong class of bottom vertex 0")
1261 self.assertTrue( numpy.linalg.norm(b[0]-[35., 25., -35.355339059327378]) < self.EPS, "wrong bottom vertex 0 ")
1262 self.assertTrue( isinstance(b[1], numpy.ndarray), "wrong class of bottom vertex 1")
1263 self.assertTrue( numpy.linalg.norm(b[1]-[25, 35., -35.355339059327378]) < self.EPS, "wrong bottom vertex 1 ")
1264 ds=f.getDepths(2)
1265 self.assertTrue( len(ds) == 2, "wrong number of depth")
1266 self.assertTrue( abs(ds[0]-50.) < self.EPS, "wrong depth at vertex 0 ")
1267 self.assertTrue( abs(ds[1]-50.) < self.EPS, "wrong depth at vertex 1 ")
1268
1269 top1=[ [10.,0.,0], [10.,10.,0], [0.,10.,0] ]
1270 f.addFault(V0=[10.,0.,0.],strikes=[pi/2, pi],ls=[10.,10.],tag=1, dips=pi/4, depths=20.)
1271 self.assertTrue( 20. == f.getTotalLength(1), "length wrong")
1272 self.assertTrue( 20. == f.getMediumDepth(1), "depth wrong")
1273 segs=f.getTopPolyline(1)
1274 self.assertTrue( len(segs) == 3, "wrong number of segments")
1275 self.assertTrue( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0")
1276 self.assertTrue( segs[0].size == 3, "seg 0 has wrong size.")
1277 self.assertTrue( numpy.linalg.norm(segs[0]-[10.,0.,0.]) < self.EPS, "wrong vertex. 0 ")
1278 self.assertTrue( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1")
1279 self.assertTrue( segs[1].size == 3, "seg 1 has wrong size.")
1280 self.assertTrue( numpy.linalg.norm(segs[1]-[10.,10.,0.]) < self.EPS, "wrong vertex. 1 ")
1281 self.assertTrue( isinstance(segs[2], numpy.ndarray), "wrong class of vertex 2")
1282 self.assertTrue( segs[2].size == 3, "seg 2 has wrong size.")
1283 self.assertTrue( numpy.linalg.norm(segs[2]-[0.,10.,0.]) < self.EPS, "wrong vertex. 2 ")
1284 d=f.getDips(1)
1285 self.assertTrue( len(d) == 2, "wrong number of dips")
1286 self.assertTrue( abs(d[0]-0.78539816339744828) < self.EPS, "wrong dip 0")
1287 self.assertTrue( abs(d[1]-0.78539816339744828) < self.EPS, "wrong dip 0")
1288 ds=f.getDepths(1)
1289 self.assertTrue( len(ds) == 3, "wrong number of depth")
1290 self.assertTrue( abs(ds[0]-20.) < self.EPS, "wrong depth at vertex 0 ")
1291 self.assertTrue( abs(ds[1]-20.) < self.EPS, "wrong depth at vertex 1 ")
1292 sn=f.getSegmentNormals(1)
1293 self.assertTrue( len(sn) == 2, "wrong number of normals")
1294 self.assertTrue( isinstance(sn[0], numpy.ndarray), "wrong class of bottom vertex 0")
1295 self.assertTrue( numpy.linalg.norm(sn[0]-[0.70710678118654746,0.,0.70710678118654746]) < self.EPS, "wrong bottom vertex 1 ")
1296 self.assertTrue( isinstance(sn[1], numpy.ndarray), "wrong class of bottom vertex 0")
1297 self.assertTrue( numpy.linalg.norm(sn[1]-[0.,0.70710678118654746,0.70710678118654746]) < self.EPS, "wrong bottom vertex 1 ")
1298 dv=f.getDepthVectors(1)
1299 self.assertTrue( len(dv) == 3, "wrong number of depth vectors.")
1300 self.assertTrue( isinstance(dv[0], numpy.ndarray), "wrong class of depth vector 0")
1301 self.assertTrue( numpy.linalg.norm(dv[0]-[14.142135623730951, 0., -14.142135623730951]) < self.EPS, "wrong depth vector 0 ")
1302 self.assertTrue( isinstance(dv[1], numpy.ndarray), "wrong class of depth vector 1")
1303 self.assertTrue( numpy.linalg.norm(dv[1]-[11.547005383792515,11.547005383792515, -11.547005383792515]) < self.EPS, "wrong depth vector 2 ")
1304 self.assertTrue( isinstance(dv[2], numpy.ndarray), "wrong class of depth vector 1")
1305 self.assertTrue( numpy.linalg.norm(dv[2]-[0.,14.142135623730951, -14.142135623730951]) < self.EPS, "wrong depth vector 2 ")
1306 segs=f.getBottomPolyline(1)
1307 self.assertTrue( len(segs) == 3, "wrong number of segments")
1308 self.assertTrue( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0")
1309 self.assertTrue( segs[0].size == 3, "seg 0 has wrong size.")
1310 self.assertTrue( numpy.linalg.norm(segs[0]-[24.142135623730951,0.,-14.142135623730951]) < self.EPS, "wrong vertex. 0 ")
1311 self.assertTrue( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1")
1312 self.assertTrue( segs[1].size == 3, "seg 1 has wrong size.")
1313 self.assertTrue( numpy.linalg.norm(segs[1]-[21.547005383792515,21.547005383792515, -11.547005383792515]) < self.EPS, "wrong vertex. 1 ")
1314 self.assertTrue( isinstance(segs[2], numpy.ndarray), "wrong class of vertex 2")
1315 self.assertTrue( segs[2].size == 3, "seg 2 has wrong size.")
1316 self.assertTrue( numpy.linalg.norm(segs[2]-[0., 24.142135623730951, -14.142135623730951]) < self.EPS, "wrong vertex. 2 ")
1317 self.assertTrue( abs(0.-f.getW0Range(1)[0]) <=self.EPS," wrong W0 range (0)")
1318 self.assertTrue( abs(31.857329272664341-f.getW0Range(1)[1]) <=self.EPS," wrong W0 range (1)")
1319 self.assertTrue( abs(-20. - f.getW1Range(1)[0]) <=self.EPS," wrong W1 range (0)")
1320 self.assertTrue( abs(0. - f.getW1Range(1)[1]) <=self.EPS," wrong W1 range (1)")
1321 self.assertTrue( abs(0.0-f.getW0Offsets(1)[0])<=self.EPS," wrong W0 offsets (0)")
1322 self.assertTrue( abs(15.92866463633217-f.getW0Offsets(1)[1])<=self.EPS," wrong W0 offsets (1)")
1323 self.assertTrue( abs(31.857329272664341-f.getW0Offsets(1)[2])<=self.EPS," wrong W0 offsets(2)")
1324 #
1325 # ============ fresh start ====================
1326 #
1327 f.addFault(V0=[1.,0,0.],strikes=[pi/2, pi],ls=[1.,1.], dips=pi/2,depths=20,tag=1)
1328 f.addFault(V0=[10.,0,0],strikes=[3.*pi/4],ls=[14.142135623730951], tag=2, w0_offsets=[0,20], w1_max=20, dips=pi/2,depths=20)
1329 c=f.getCenterOnSurface()
1330 self.assertTrue( isinstance(c, numpy.ndarray), "center has wrong class")
1331 self.assertTrue( c.size == 3, "center size is wrong")
1332 self.assertTrue( numpy.linalg.norm(c-[12./5.,12./5.,0.]) < self.EPS, "center has wrong coordinates.")
1333 o=f.getOrientationOnSurface()/pi*180.
1334 self.assertTrue( abs(o+45.) < self.EPS, "wrong orientation.")
1335
1336 f.transform(rot=-pi/2., shift=[-1.,-1.,0.])
1337 self.assertTrue( [ 1, 2 ] == f.getTags(), "tags after transformation wrong")
1338 self.assertTrue( 2. == f.getTotalLength(1), "length after transformation wrong")
1339 self.assertTrue( 20. == f.getMediumDepth(1), "depth after transformation wrong")
1340 rw0=f.getW0Range(1)
1341 self.assertTrue( len(rw0) ==2, "wo range has wrong length")
1342 self.assertTrue( abs(rw0[0]) < self.EPS,"W0 0 wrong.")
1343 self.assertTrue( abs(rw0[1]-2.) < self.EPS,"W0 1 wrong.")
1344 self.assertTrue( (-20., 0.) == f.getW1Range(1)," wrong W1 rangeafter transformation ")
1345 dips=f.getDips(1)
1346 self.assertTrue(len(dips) == 2, "wrong number of dips.")
1347 self.assertTrue( abs(dips[0]-1.5707963267948966) <= self.EPS, "wrong dip")
1348 self.assertTrue( abs(dips[1]-1.5707963267948966) <= self.EPS, "wrong dip")
1349 ds=f.getDepths(1)
1350 self.assertTrue( len(ds) == 3, "wrong number of depth")
1351 self.assertTrue( abs(ds[0]-20.) < self.EPS, "wrong depth at vertex 0 ")
1352 self.assertTrue( abs(ds[1]-20.) < self.EPS, "wrong depth at vertex 1 ")
1353 self.assertTrue( abs(ds[2]-20.) < self.EPS, "wrong depth at vertex 1 ")
1354 segs=f.getTopPolyline(1)
1355 self.assertTrue( len(segs) == 3, "wrong number of segmentsafter transformation ")
1356 self.assertTrue( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0 after transformation")
1357 self.assertTrue( segs[0].size == 3, "seg 0 has wrong size after transformation.")
1358 self.assertTrue( numpy.linalg.norm(segs[0]-[-1.,0.,0.]) < self.EPS, "wrong vertex. 0 after transformation")
1359 self.assertTrue( isinstance(segs[1], numpy.ndarray), "wrong class of vertex after transformation1")
1360 self.assertTrue( segs[1].size == 3, "seg 1 has wrong size after transformation.")
1361 self.assertTrue( numpy.linalg.norm(segs[1]-[0.,0.,0.]) < self.EPS, "wrong vertex. after transformation1 ")
1362 self.assertTrue( isinstance(segs[2], numpy.ndarray), "wrong class of vertex after transformation2")
1363 self.assertTrue( segs[2].size == 3, "seg 2 has wrong size after transformation.")
1364 self.assertTrue( numpy.linalg.norm(segs[2]-[0., 1.,0.]) < self.EPS, "wrong vertex after transformation. 2 ")
1365 self.assertTrue( abs(f.getTotalLength(2)-14.1421356237) < self.EPS * 14.1421356237, "wrong length after transformation")
1366 self.assertTrue( 20. == f.getMediumDepth(2), "depth wrong after transformation")
1367 rw0=f.getW0Range(2)
1368 self.assertTrue( len(rw0) ==2, "wo range has wrong length")
1369 self.assertTrue( abs(rw0[0]) < self.EPS,"W0 0 wrong.")
1370 self.assertTrue( abs(rw0[1]-20.) < self.EPS,"W0 1 wrong.")
1371 self.assertTrue( (-20., 0.) == f.getW1Range(2)," wrong W1 range after transformation")
1372 self.assertTrue( [0., 20.] == f.getW0Offsets(2)," wrong W0 offsets after transformation")
1373 dips=f.getDips(2)
1374 self.assertTrue(len(dips) == 1, "wrong number of dips.")
1375 self.assertTrue( abs(dips[0]-1.5707963267948966) <= self.EPS, "wrong dip")
1376 ds=f.getDepths(2)
1377 self.assertTrue( len(ds) == 2, "wrong number of depth")
1378 self.assertTrue( abs(ds[0]-20.) < self.EPS, "wrong depth at vertex 0 ")
1379 self.assertTrue( abs(ds[1]-20.) < self.EPS, "wrong depth at vertex 1 ")
1380 segs=f.getTopPolyline(2)
1381 self.assertTrue( len(segs) == 2, "wrong number of segments after transformation")
1382 self.assertTrue( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0 after transformation")
1383 self.assertTrue( numpy.linalg.norm(segs[0]-[-1.,-9,0.]) < self.EPS, "wrong vertex. 0 after transformation")
1384 self.assertTrue( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1 after transformation")
1385 self.assertTrue( numpy.linalg.norm(segs[1]-[9.,1.,0.]) < self.EPS, "wrong vertex. 1 after transformation")
1386 #
1387 # ============ fresh start ====================
1388 #
1389 f=FaultSystem(dim=3)
1390
1391 top1=[ [0.,0.,0.], [1., 0., 0.] ]
1392 f.addFault(V0=[0.,0,0],strikes=[0.],ls=[1.,], dips=pi/2, depths=1.,tag=1)
1393 top1=[ [10.,0.,0], [10.,10.,0], [0.,10.,0] ]
1394 f.addFault(V0=[10.,0.,0.],strikes=[pi/2, pi],ls=[10.,10.],tag=2, dips=pi/4, depths=20.)
1395
1396 p,m=f.getParametrization([0.3,0.,-0.5],1)
1397 self.assertTrue(length(p-[0.3,-0.5]) <= self.EPS, "wrong value.")
1398 self.assertTrue(m==1., "wrong value.")
1399
1400 p,m=f.getParametrization([0.5,0.,-0.5],1)
1401 self.assertTrue(length(p-[0.5,-0.5]) <= self.EPS, "wrong value.")
1402 self.assertTrue(m==1., "wrong value.")
1403
1404 p,m=f.getParametrization([0.25,0.,-0.5],1)
1405 self.assertTrue(length(p-[0.25,-0.5]) <= self.EPS, "wrong value.")
1406 self.assertTrue(m==1., "wrong value.")
1407
1408 p,m=f.getParametrization([0.5,0.,-0.25],1)
1409 self.assertTrue(length(p-[0.5,-0.25]) <= self.EPS, "wrong value.")
1410 self.assertTrue(m==1., "wrong value.")
1411
1412 p,m=f.getParametrization([0.001,0.,-0.001],1)
1413 self.assertTrue(length(p-[0.001, -0.001]) <= self.EPS, "wrong value.")
1414 self.assertTrue(m==1., "wrong value.")
1415
1416 p,m=f.getParametrization([0.001,0.,0.001],1)
1417 self.assertTrue(m==0., "wrong value.")
1418
1419 p,m=f.getParametrization([0.999,0.,0.001],1)
1420 self.assertTrue(m==0., "wrong value.")
1421
1422 p,m=f.getParametrization([1.001,0.,-0.001],1)
1423 self.assertTrue(m==0., "wrong value.")
1424 p,m=f.getParametrization([1.001,0.,-0.1],1)
1425 self.assertTrue(m==0., "wrong value.")
1426 p,m=f.getParametrization([1.001,0.,-0.000000001],1)
1427 self.assertTrue(m==0., "wrong value.")
1428
1429 p,m=f.getParametrization([0.999,0.,-0.001],1)
1430 self.assertTrue(length(p-[0.999, -0.001]) <= self.EPS, "wrong value.")
1431 self.assertTrue(m==1., "wrong value.")
1432
1433 p,m=f.getParametrization([ 16.29252873 , 6.46410161 ,-6.29252873], 2, tol=1.e-7)
1434 self.assertTrue(m==1., "wrong value.")
1435 self.assertTrue(length(p-[4.7785993908996511, -10]) <= self.EPS*10., "wrong value.")
1436 p,m=f.getParametrization([15.77350269, 12.77350269, -5.77350269], 2, tol=1.e-7)
1437 self.assertTrue(m==1., "wrong value.")
1438 self.assertTrue(length(p-[11.150065245432518, -10]) <= self.EPS*10., "wrong value.")
1439
1440 p,m=f.getParametrization([ 3., 17.0710678, -7.0710678], 2, tol=1.e-7)
1441 self.assertTrue(m==1., "wrong value.")
1442 self.assertTrue(length(p-[27.078729881764687, -10]) <= self.EPS*10., "wrong value.")
1443 p,m=f.getParametrization([9.30940108, 16.55204176, -6.55204176], 2, tol=1.e-7)
1444 self.assertTrue(m==1., "wrong value.")
1445 self.assertTrue(length(p-[20.707264027231822, -10]) <= self.EPS*10., "wrong value.")
1446
1447 p,m=f.getParametrization([ 21.54700538, 21.54700538, -11.54700538], 2, tol=1.e-7)
1448 self.assertTrue(m==1., "wrong value.")
1449 self.assertTrue(length(p-[15.92866463633217, -20]) <= self.EPS*10., "wrong value.")
1450
1451 p,m=f.getParametrization([ 0.,0.,0.], 2, tol=1.e-7)
1452 self.assertTrue(m==0., "wrong value.")
1453
1454 p,m=f.getParametrization([ 11.,11.,0.], 2, tol=1.e-7)
1455 self.assertTrue(m==0., "wrong value.")
1456
1457
1458 s,d=f.getSideAndDistance([0.,-1.,0.], tag=1)
1459 self.assertTrue( s>0, "wrong side.")
1460 self.assertTrue( abs(d-1.)<self.EPS, "wrong distance.")
1461 s,d=f.getSideAndDistance([1.,-1.,0.], tag=1)
1462 self.assertTrue( s>0, "wrong side.")
1463 self.assertTrue( abs(d-1.)<self.EPS, "wrong distance.")
1464 s,d=f.getSideAndDistance([0.,1.,0.], tag=1)
1465 self.assertTrue( s<0, "wrong side.")
1466 self.assertTrue( abs(d-1.)<self.EPS, "wrong distance.")
1467 s,d=f.getSideAndDistance([1.,1.,0.], tag=1)
1468 self.assertTrue( s<0, "wrong side.")
1469 self.assertTrue( abs(d-1.)<self.EPS, "wrong distance.")
1470
1471
1472 s,d=f.getSideAndDistance([0.,0.,0.], tag=2)
1473 self.assertTrue( s<0, "wrong side.")
1474 self.assertTrue( abs(d-10.)<self.EPS, "wrong distance.")
1475 s,d=f.getSideAndDistance([5.,5.,0.], tag=2)
1476 self.assertTrue( s<0, "wrong side.")
1477 self.assertTrue( abs(d-5.)<self.EPS, "wrong distance.")
1478
1479 s,d=f.getSideAndDistance([10.,10.,-1.], tag=2)
1480 self.assertTrue( s<0, "wrong side.")
1481 self.assertTrue( abs(d-0.70710678118654757)<self.EPS, "wrong distance.")
1482 s,d=f.getSideAndDistance([10.,10.,-2.], tag=2)
1483 self.assertTrue( s<0, "wrong side.")
1484 self.assertTrue( abs(d-2.*0.70710678118654757)<self.EPS, "wrong distance.")
1485 s,d=f.getSideAndDistance([10.,10.,-3.], tag=2)
1486 self.assertTrue( s<0, "wrong side.")
1487 self.assertTrue( abs(d-3.*0.70710678118654757)<self.EPS, "wrong distance.")
1488
1489 s,d=f.getSideAndDistance([5.,12.,0], tag=2)
1490 self.assertTrue( s>0, "wrong side.")
1491 self.assertTrue( abs(d-2*0.70710678118654757)<self.EPS, "wrong distance.")
1492 s,d=f.getSideAndDistance([5.,12.,-1], tag=2)
1493 self.assertTrue( s>0, "wrong side.")
1494 self.assertTrue( abs(d-0.70710678118654757)<self.EPS, "wrong distance.")
1495 s,d=f.getSideAndDistance([5.,12.,-2], tag=2)
1496 # s not checked as it is undefined.
1497 self.assertTrue( abs(d)<self.EPS, "wrong distance.")
1498 s,d=f.getSideAndDistance([5.,12.,-3], tag=2)
1499 self.assertTrue( s<0, "wrong side.")
1500 self.assertTrue( abs(d-0.70710678118654757)<self.EPS, "wrong distance.")
1501 s,d=f.getSideAndDistance([5.,12.,-4], tag=2)
1502 self.assertTrue( s<0, "wrong side.")
1503 self.assertTrue( abs(d-2.*0.70710678118654757)<self.EPS, "wrong distance.")
1504
1505 if __name__ == '__main__':
1506 suite = unittest.TestSuite()
1507 suite.addTest(unittest.makeSuite(Test_FaultSystem))
1508 # suite.addTest(unittest.makeSuite(Test_StokesProblemCartesian2D))
1509 suite.addTest(unittest.makeSuite(Test_Darcy3D))
1510 suite.addTest(unittest.makeSuite(Test_Darcy2D))
1511 # suite.addTest(Test_StokesProblemCartesian2D("test_PCG_P_small"))
1512 # suite.addTest(unittest.makeSuite(Test_StokesProblemCartesian3D))
1513 suite.addTest(unittest.makeSuite(Test_Rheologies))
1514 s=unittest.TextTestRunner(verbosity=2).run(suite)
1515 if not s.wasSuccessful(): sys.exit(1)
1516

  ViewVC Help
Powered by ViewVC 1.1.26