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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6652 - (hide annotations)
Wed Mar 14 08:22:11 2018 UTC (3 years, 1 month ago) by jfenwick
File MIME type: text/x-python
File size: 20422 byte(s)
makeTagMap and skeleton test

The test is there and is hooked into Finley, Dudley and Ripley.
The test does not do enough.

1 ksteube 1809
2 jfenwick 3981 ##############################################################################
3 ksteube 1312 #
4 jfenwick 6651 # Copyright (c) 2003-2018 by The University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 ksteube 1312 #
7 ksteube 1809 # Primary Business: Queensland, Australia
8 jfenwick 6112 # Licensed under the Apache License, version 2.0
9     # http://www.apache.org/licenses/LICENSE-2.0
10 ksteube 1312 #
11 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 #
15     ##############################################################################
16 gross 983
17 sshaw 5706 from __future__ import print_function, division
18    
19 jfenwick 6651 __copyright__="""Copyright (c) 2003-2018 by The University of Queensland
20 jfenwick 3981 http://www.uq.edu.au
21 ksteube 1809 Primary Business: Queensland, Australia"""
22 jfenwick 6112 __license__="""Licensed under the Apache License, version 2.0
23     http://www.apache.org/licenses/LICENSE-2.0"""
24 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
25 ksteube 1809
26 caltinay 3993 import os
27     import sys
28 jfenwick 4938 import esys.escriptcore.utestselect as unittest
29 sshaw 4984 from esys.escriptcore.testing import *
30 gross 983 from esys.escript import *
31 jfenwick 4962 from esys.finley import Rectangle, Brick, ReadMesh, ReadGmsh
32 caltinay 3993 from test_objects import Test_Dump, Test_SetDataPointValue, Test_saveCSV, \
33 jfenwick 6652 Test_TableInterpolation, Test_Domain, Test_Lazy, Test_tagMap
34 jfenwick 2271 from test_shared import Test_Shared
35    
36 gross 983 try:
37     FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']
38     except KeyError:
39     FINLEY_WORKDIR='.'
40 caltinay 6282
41 jfenwick 4962 try:
42     FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
43     except KeyError:
44     FINLEY_TEST_DATA='.'
45 gross 983
46 jfenwick 4962 FINLEY_TEST_MESH_PATH=os.path.join(FINLEY_TEST_DATA,"data_meshes")
47    
48 caltinay 4437 mpisize=getMPISizeWorld()
49 caltinay 6282 NE=4 # number of elements, must be even
50 jfenwick 2271
51     class Test_SharedOnFinley(Test_Shared):
52     def setUp(self):
53 jfenwick 3892 self.domain=Rectangle(NE,NE)
54     self.tol=0.001
55 jfenwick 4687
56 jfenwick 2271 def tearDown(self):
57 jfenwick 3892 del self.domain
58     del self.tol
59 jfenwick 2271
60 gross 1044 class Test_DomainOnFinley(Test_Domain):
61     def setUp(self):
62 gross 2425 self.boundary_tag_list = [1, 2, 10, 20]
63 gross 1044 self.domain =Rectangle(NE,NE+1,2)
64 jfenwick 4687 self.rdomain=self.domain
65    
66 gross 1044 def tearDown(self):
67     del self.domain
68 jfenwick 4687 del self.rdomain
69 caltinay 3993 del self.boundary_tag_list
70    
71 jfenwick 3914 def test_setXError(self):
72     domain=Rectangle(NE,NE)
73 caltinay 3993 x=domain.getX()
74 jfenwick 3914 z=interpolate(x, Function(domain))
75 caltinay 5984 self.assertRaises(ValueError, domain.setX, z)
76 jfenwick 3914 del x
77     del z
78     del domain
79 gross 1716
80     def test_tagsContinuousFunction(self):
81     ref_tags=[0]
82     tags=ContinuousFunction(self.domain).getListOfTags()
83 jfenwick 3551 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
84     for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
85 gross 1716
86     def test_tagsFunction(self):
87     ref_tags=[0]
88     tags=Function(self.domain).getListOfTags()
89 jfenwick 3551 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
90     for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
91 gross 1716 def test_tagsReducedFunction(self):
92     ref_tags=[0]
93     tags=ReducedFunction(self.domain).getListOfTags()
94 jfenwick 3551 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
95     for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
96 gross 1716 def test_tagsFunctionOnBoundary(self):
97 ksteube 1829 ref_tags=[1, 2, 10, 20]
98     tags=FunctionOnBoundary(self.domain).getListOfTags()
99     # For an MPI-distributed domain some tags may be missing
100 jfenwick 3551 if getMPISizeWorld() == 1: self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
101     for i in tags: self.assertTrue(i in ref_tags,"tag %s is missing."%i)
102 gross 1716 def test_tagsReducedFunctionOnBoundary(self):
103 ksteube 1829 ref_tags=[1, 2, 10, 20]
104     tags=ReducedFunctionOnBoundary(self.domain).getListOfTags()
105     # For an MPI-distributed domain some tags may be missing
106 jfenwick 3551 if getMPISizeWorld() == 1: self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
107     for i in tags: self.assertTrue(i in ref_tags,"tag %s is missing."%i)
108 gross 1716 def test_tagsFunctionOnContactOne(self):
109     ref_tags=[]
110     tags=FunctionOnContactOne(self.domain).getListOfTags()
111 jfenwick 3551 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
112     for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
113 gross 1716 def test_tagsFunctionOnContactZero(self):
114     ref_tags=[]
115     tags=FunctionOnContactZero(self.domain).getListOfTags()
116 jfenwick 3551 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
117     for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
118 gross 1716 def test_tagsReducedFunctionOnContactOne(self):
119     ref_tags=[]
120     tags=ReducedFunctionOnContactOne(self.domain).getListOfTags()
121 jfenwick 3551 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
122     for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
123 gross 1716 def test_tagsReducedFunctionOnContactZero(self):
124     ref_tags=[]
125     tags=ReducedFunctionOnContactZero(self.domain).getListOfTags()
126 jfenwick 3551 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
127     for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
128 gross 1716
129 caltinay 6282 class Test_DumpOnFinley(Test_Dump):
130 gross 983 def setUp(self):
131 caltinay 6282 self.domain = Rectangle(NE, NE+1, 2)
132 gross 983 self.domain_with_different_number_of_samples =Rectangle(2*NE,NE+1,2)
133     self.domain_with_different_number_of_data_points_per_sample =Rectangle(2*NE,NE+1,2,integrationOrder=2)
134 gross 1856 self.domain_with_different_sample_ordering =Rectangle(NE,NE+1,2, optimize=True)
135 gross 1141 self.filename_base=FINLEY_WORKDIR
136 gross 983
137     def tearDown(self):
138     del self.domain
139     del self.domain_with_different_number_of_samples
140     del self.domain_with_different_number_of_data_points_per_sample
141     del self.domain_with_different_sample_ordering
142 caltinay 6282
143     class Test_SetDataPointValueOnFinley(Test_SetDataPointValue):
144     def setUp(self):
145     self.domain = Rectangle(NE, NE+1, 2)
146    
147     def tearDown(self):
148     del self.domain
149    
150     class Test_LazyOnFinley(Test_Lazy):
151     def setUp(self):
152     self.domain = Rectangle(NE,NE+1,2)
153     self.mainfs = Function(self.domain)
154     self.otherfs = Solution(self.domain)
155    
156     def tearDown(self):
157     del self.domain
158 jfenwick 2799 del self.mainfs
159     del self.otherfs
160 gross 983
161 jfenwick 6652
162     class Test_tagMapOnFinley(Test_tagMap):
163     def setUp(self):
164     self.domain=Brick(2,2,2)
165     self.functionspaces=[ContinuousFunction(self.domain), Function(self.domain), ReducedFunction(self.domain),
166     FunctionOnBoundary(self.domain), ReducedFunctionOnBoundary(self.domain),
167     FunctionOnContactZero(self.domain), FunctionOnContactOne(self.domain),
168     ReducedFunctionOnContactZero(self.domain), ReducedFunctionOnContactOne(self.domain)]
169    
170     def tearDown(self):
171     del self.domain
172     del self.functionspaces
173    
174 jfenwick 2646 class Test_TableInterpolationOnFinley(Test_TableInterpolation):
175     def setUp(self):
176 jfenwick 3892 self.domain=Brick(4,4,4)
177     self.functionspaces=[ContinuousFunction(self.domain), Function(self.domain), ReducedFunction(self.domain),
178 caltinay 3993 FunctionOnBoundary(self.domain), ReducedFunctionOnBoundary(self.domain),
179 jfenwick 3892 FunctionOnContactZero(self.domain), FunctionOnContactOne(self.domain),
180     ReducedFunctionOnContactZero(self.domain), ReducedFunctionOnContactOne(self.domain)]
181     #We aren't testing DiracDeltaFunctions
182     self.xn=3 # number of grids on x axis
183     self.yn=3 # number of grids on y axis
184     self.zn=3 # number of grids on z axis
185 jfenwick 2628
186 jfenwick 2646 def tearDown(self):
187 jfenwick 3892 del self.domain
188     del self.functionspaces
189 jfenwick 2646
190 caltinay 3993
191 caltinay 6282 # This functionality is only tested on Finley.
192     # It is not finley specific but it does need a known set of input points
193     # so I've chosen to put it here
194 jfenwick 4085 class Test_OtherInterpolationOnFinley(unittest.TestCase):
195     def setUp(self):
196     self.r=Rectangle(4,1).getX()[0]+2
197     self.z=Data(2)
198 caltinay 6282
199 jfenwick 4085 def tearDown(self):
200     del self.z
201     del self.r
202 caltinay 6282
203 jfenwick 4085 def test_nonuniformint(self):
204     self.assertRaises(RuntimeError, self.z.nonuniformInterpolate, [0,1], [5,6], True)
205     self.assertRaises(RuntimeError, self.z.nonuniformInterpolate, [3,4], [5,6], True)
206     self.assertTrue(Lsup(self.z.nonuniformInterpolate([0,1], [5,6], False)-6)<0.00001, "RHS edge not fitted")
207     self.assertTrue(Lsup(self.z.nonuniformInterpolate([3,4], [5,6], False)-5)<0.00001, "LHS edge not fitted")
208     tmp=self.r.nonuniformInterpolate([2.125, 2.4, 2.5, 2.8], [1, -1, 2, 4], False)
209     self.assertTrue(Lsup(sup(tmp)-4)<0.0001, "RHS edge not fitted for Rect")
210     self.assertTrue(Lsup(inf(tmp)-0.090909)<0.00001, "Internal interpolate failed")
211     tmp=self.r.nonuniformInterpolate([2.125, 2.4, 2.5, 3.2], [1, -1, 2, 4], False)
212     self.assertTrue(Lsup(sup(tmp)-3.42857)<0.00001, "Internal interpolate failed")
213 caltinay 6282
214 jfenwick 4085 def test_nonuniformSlope(self):
215     self.assertRaises(RuntimeError, self.z.nonuniformSlope, [0,1], [5,6], True)
216     self.assertRaises(RuntimeError, self.z.nonuniformSlope, [3,4], [5,6], True)
217     self.assertTrue(Lsup(self.z.nonuniformSlope([0,1], [5,6], False))<0.00001, "RHS edge not fitted")
218     self.assertTrue(Lsup(self.z.nonuniformSlope([3,4], [5,6], False))<0.00001, "LHS edge not fitted")
219     tmp=self.r.nonuniformSlope([2.125, 2.4, 2.5, 3.2], [1, -1, 2, 4], False)
220     self.assertTrue(Lsup(sup(tmp)-30)<0.00001, "Internal interpolate failed")
221     self.assertTrue(Lsup(inf(tmp)+7.27273)<0.00001, "Internal interpolate failed")
222 caltinay 6282
223 jfenwick 2644 class Test_CSVOnFinley(Test_saveCSV):
224 caltinay 3993 def setUp(self):
225 jfenwick 5419 try:
226     self.workdir=os.environ['FINLEY_WORKDIR']
227     except KeyError:
228     self.workdir='.'
229 caltinay 3993 NE0=NE
230     NE1=NE+1
231 caltinay 3996 self.domain = Rectangle(NE0, NE1, order=2)
232     self.functionspaces = [ ContinuousFunction ]
233 caltinay 3993 # number of total data points for each function space
234 caltinay 3996 self.linecounts=[ (2*NE0+1)*(2*NE1+1)-NE0*NE1+1 ]
235 caltinay 3993 # number of masked points, i.e. where X[0] is non-zero
236 caltinay 3996 self.linecounts_masked=[ (2*NE0+1)*(2*NE1+1)-(2+NE0)*NE1 ]
237 caltinay 3993 # expected values in first line of masked data = [ X[:], X[0] ]
238 caltinay 3996 self.firstline=[ [1./(2*NE0), 0., 1./(2*NE0)] ]
239 jfenwick 2644
240 caltinay 3996 if getMPISizeWorld() == 1:
241     self.functionspaces += [ ReducedContinuousFunction, Function,
242     ReducedFunction, FunctionOnBoundary, ReducedFunctionOnBoundary ]
243     self.linecounts += [ 31, 181, 81, 55, 37 ]
244     self.linecounts_masked += [ 25, 181, 81, 40, 27 ]
245     self.firstline += [ [.25, 0., .25],
246     [.02817541634481463,.02254033307585171,.02817541634481463],
247     [.05283121635129676,.04226497308103741,.05283121635129676],
248     [.02817541634481463,0.,.02817541634481463],
249     [.05283121635129676,0.,.05283121635129676]
250     ]
251     else:
252     print("Skipping some CSV tests on finley since MPI size > 1")
253    
254 caltinay 3993 def tearDown(self):
255     del self.domain
256 jfenwick 2644
257 caltinay 6282 @unittest.skipIf(mpisize > 1, "more than 1 MPI rank")
258 caltinay 3993 def test_csv_multiFS(self):
259 jfenwick 5419 fname=os.path.join(self.workdir, "test_multifs.csv")
260 caltinay 4437 sol=Data(8,Solution(self.domain))
261     ctsfn=Data(9,ContinuousFunction(self.domain))
262     #test line 0
263     dirac=Data(-1,DiracDeltaFunctions(self.domain))
264     saveDataCSV(fname, A=sol, B=ctsfn, C=dirac)
265     #test line 1
266     fun=Data(5,Function(self.domain))
267     rfun=Data(3,ReducedFunction(self.domain))
268     saveDataCSV(fname, A=sol,B=ctsfn,C=fun, D=rfun)
269     #test line 2
270     bound=Data(1,FunctionOnBoundary(self.domain))
271     rbound=Data(3,ReducedFunctionOnBoundary(self.domain))
272     saveDataCSV(fname,A=sol,B=ctsfn,C=bound, D=rbound)
273     #test line 3
274     conzz=Data(7,FunctionOnContactZero(self.domain))
275     rconz=Data(8,ReducedFunctionOnContactZero(self.domain))
276     saveDataCSV(fname,A=sol,B=ctsfn, C=conzz, D=rconz)
277     #check for cross line exceptions
278     self.assertRaises(RuntimeError, saveDataCSV, fname, A=dirac, B=rfun)
279     self.assertRaises(RuntimeError, saveDataCSV, fname, A=bound, B=conzz)
280 caltinay 3993
281 jfenwick 4962 class Test_DiracOnFinley(unittest.TestCase):
282     def test_rectconstr(self):
283 caltinay 5981 self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,0)])
284     self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,0), (1,1)], diracTags=[40])
285     self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,0), (1,1)], diracTags=[40])
286     self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,0), (1,1)], diracTags=["cows"])
287     self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,)], diracTags=["test"])
288 jfenwick 4962 z=Rectangle(4,4, diracPoints=[(0,0), (0.25,0.25)], diracTags=[40,51])
289 caltinay 6282 z=Rectangle(4,4, diracPoints=[(0.125,0.625), (0.5,1), (0.75, 0.25), (0.89, 0.875)], diracTags=["A", "B", "A", "C"])
290 jfenwick 4962 v=interpolate(z.getX(), DiracDeltaFunctions(z))
291     if mpisize==1:
292 caltinay 6257 self.assertEqual(v.toListOfTuples(),[(0.0, 0.5), (0.5, 1.0), (0.75, 0.25), (1.0, 0.75)])
293     self.assertEqual(v.getNumberOfDataPoints(), 4)
294     self.assertEqual(inf(v[0]), 0)
295     self.assertEqual(inf(v[1]), 0.25)
296     self.assertEqual(Lsup(v[0]), 1)
297     self.assertEqual(Lsup(v[1]), 1)
298 jfenwick 4962 v.setTaggedValue("A",(-10,0.5))
299 jfenwick 4965 if mpisize==1:
300 caltinay 6257 self.assertEqual(inf(v[0]), -10)
301     self.assertEqual(inf(v[1]), 0.5)
302 sshaw 5705 v.setTaggedValue(500,(-100,-100)) # non-existant tag
303 jfenwick 4965 if mpisize==1:
304 caltinay 6257 self.assertEqual(inf(v[0]), -10)
305     self.assertEqual(inf(v[1]), 0.5)
306     self.assertEqual(z.showTagNames(), 'A, B, C, bottom, left, right, top')
307     self.assertEqual(z.getTag("C"), 42)
308 caltinay 6282
309 jfenwick 4962 def test_brickconstr(self):
310 caltinay 5981 self.assertRaises(ValueError, Brick, 4,4, diracPoints=[(0,0,0)])
311     self.assertRaises(ValueError, Brick, 4,4, diracPoints=[(0,0,0), (1,1,1)], diracTags=[40])
312     self.assertRaises(ValueError, Brick, 4,4, diracPoints=[(0,0,0), (1,1,1)], diracTags=[40])
313     self.assertRaises(ValueError, Brick, 4,4, diracPoints=[(0,0,0), (1,1,1)], diracTags=["cows"])
314     self.assertRaises(ValueError, Brick, 4,4, diracPoints=[(0,0)], diracTags=["test"])
315 jfenwick 4962 z=Brick(4,4, diracPoints=[(0,0,0), (0.25,0.25, 0.25)], diracTags=[40,51])
316 caltinay 6282 z=Brick(4,4, diracPoints=[(0.125,0.625,0), (0.5,1,0), (0.75, 0.25, 0.51), (0.89, 0.875,1)], diracTags=["A", "B", "A", "C"])
317 jfenwick 4962 v=interpolate(z.getX(), DiracDeltaFunctions(z))
318     if mpisize==1:
319 caltinay 6257 self.assertEqual(v.toListOfTuples(),[(0.0, 0.5, 0.0), (0.5, 1.0, 0.0), (0.75, 0.25, 1), (1.0, 0.75, 1.0)])
320     self.assertEqual(v.getNumberOfDataPoints(), 4)
321     self.assertEqual(inf(v[0]), 0)
322     self.assertEqual(inf(v[1]), 0.25)
323     self.assertEqual(Lsup(v[0]), 1)
324     self.assertEqual(Lsup(v[1]), 1)
325 jfenwick 4962 v.setTaggedValue("A",(-10,0.5,-500))
326 jfenwick 4963 if mpisize==1:
327 caltinay 6257 self.assertEqual(inf(v[0]), -10)
328     self.assertEqual(inf(v[1]), 0.5)
329     self.assertEqual(inf(v[2]),-500)
330 sshaw 5705 v.setTaggedValue(500,(-100,-100, -100)) # non-existant tag
331 jfenwick 4963 if mpisize==1:
332 caltinay 6257 self.assertEqual(inf(v[0]), -10)
333     self.assertEqual(inf(v[1]), 0.5)
334     self.assertEqual(z.showTagNames(), 'A, B, C, back, bottom, front, left, right, top')
335     self.assertEqual(z.getTag("C"), 42)
336 jfenwick 4962
337    
338     def test_rectReadMesh(self):
339     fname=os.path.join(FINLEY_TEST_MESH_PATH,'rect_4x4.fly')
340 caltinay 5981 self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,)])
341     self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0)])
342     self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0), (1,1)], diracTags=[40])
343     self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0), (1,1)], diracTags=["cows"])
344 caltinay 6282 z=ReadMesh(fname, diracPoints=[(0,0), (0.25,0.25)], diracTags=[40,51])
345 jfenwick 4962 z=ReadMesh(fname, diracPoints=[(0.125,0.625), (0.5,1), (0.75, 0.25), (0.89, 0.875)], diracTags=["A", "B", "A", "C"])
346     v=interpolate(z.getX(), DiracDeltaFunctions(z))
347     if mpisize==1:
348 caltinay 6257 self.assertEqual(v.toListOfTuples(),[(0.0, 0.5), (0.5, 1.0), (0.75, 0.25), (1.0, 0.75)])
349     self.assertEqual(v.getNumberOfDataPoints(), 4)
350     self.assertEqual(inf(v[0]), 0)
351     self.assertEqual(inf(v[1]), 0.25)
352     self.assertEqual(Lsup(v[0]), 1)
353     self.assertEqual(Lsup(v[1]), 1)
354 jfenwick 4962 v.setTaggedValue("A",(-10,0.5))
355     if mpisize==1:
356 caltinay 6257 self.assertEqual(inf(v[0]), -10)
357     self.assertEqual(inf(v[1]), 0.5)
358 sshaw 5705 v.setTaggedValue(500,(-100,-100)) # non-existant tag
359 jfenwick 4962 if mpisize==1:
360 caltinay 6257 self.assertEqual(inf(v[0]), -10)
361     self.assertEqual(inf(v[1]), 0.5)
362     self.assertEqual(z.showTagNames(), 'A, B, C, bottom, left, right, top')
363 caltinay 6282 self.assertEqual(z.getTag("C"), 42)
364 jfenwick 4962
365    
366     def test_brickReadMesh(self):
367     fname=os.path.join(FINLEY_TEST_MESH_PATH,'brick_4x4x4.fly')
368 caltinay 5981 self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0)])
369     self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0,0)])
370     self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0,0), (1,1,1)], diracTags=[40])
371     self.assertRaises(ValueError, ReadMesh, fname, diracPoints=[(0,0,0), (1,1,1)], diracTags=["cows"])
372 caltinay 6282 z=ReadMesh(fname, diracPoints=[(0,0,1), (0.25,0.25, 0.25)], diracTags=[40,51])
373 jfenwick 4962 z=ReadMesh(fname, diracPoints=[(0.125,0.625,0), (0.5,1,1), (0.75, 0.25,0), (0.89, 0.875, 0.5)], diracTags=["A", "B", "A", "C"])
374     v=interpolate(z.getX(), DiracDeltaFunctions(z))
375     if mpisize==1:
376 caltinay 6257 self.assertEqual(v.toListOfTuples(),[(0.0, 0.5, 0.0), (0.5, 1.0, 1.0), (0.75, 0.25, 0.0), (1.0, 0.75, 0.5)])
377     self.assertEqual(v.getNumberOfDataPoints(), 4)
378     self.assertEqual(inf(v[0]), 0)
379     self.assertEqual(inf(v[1]), 0.25)
380     self.assertEqual(Lsup(v[0]), 1)
381     self.assertEqual(Lsup(v[1]), 1)
382 jfenwick 4962 v.setTaggedValue("A",(-10,0.5,-0.5))
383     if mpisize==1:
384 caltinay 6257 self.assertEqual(inf(v[0]), -10)
385     self.assertEqual(inf(v[1]), 0.5)
386     self.assertEqual(inf(v[2]), -0.5)
387 sshaw 5705 v.setTaggedValue(500,(-100,-100, -100)) # non-existant tag
388 jfenwick 4962 if mpisize==1:
389 caltinay 6257 self.assertEqual(inf(v[0]), -10)
390     self.assertEqual(inf(v[1]), 0.5)
391     self.assertEqual(inf(v[2]), -0.5)
392     self.assertEqual(z.showTagNames(), 'A, B, C, back, bottom, front, left, right, top')
393 caltinay 6282 self.assertEqual(z.getTag("C"), 203)
394 jfenwick 4962
395     def test_rectReadGmsh(self):
396     fname=os.path.join(FINLEY_TEST_MESH_PATH, 'rect_test.msh')
397 caltinay 5981 self.assertRaises(ValueError, ReadGmsh, fname, 2, diracPoints=[(0,0)])
398     self.assertRaises(ValueError, ReadGmsh, fname, 2, diracPoints=[(0,0), (1,1)], diracTags=[40])
399     self.assertRaises(ValueError, ReadGmsh, fname, 2, diracPoints=[(0,0), (1,1)], diracTags=["cows"])
400 jfenwick 4962 z=ReadGmsh(fname, 2, diracPoints=[(0,0), (1,1)], diracTags=[40,51])
401     z=ReadGmsh(fname, 2, diracPoints=[(0,0),(0,1),(1,0),(1,1)], diracTags=["A", "B", "A", "C"])
402     v=interpolate(z.getX(), DiracDeltaFunctions(z))
403     if mpisize==1:
404 caltinay 6257 self.assertEqual(v.toListOfTuples(),[(0,0), (0,1), (1,0), (1,1)])
405     self.assertEqual(v.getNumberOfDataPoints(), 4)
406 jfenwick 4962 v.setTaggedValue("A",(-10,99))
407 caltinay 6257 self.assertEqual(inf(v[0]), -10)
408     self.assertEqual(Lsup(v[1]), 99)
409 jfenwick 4962 v.setTaggedValue(500,(-100,-100)) # non-existant tag
410 caltinay 6257 self.assertEqual(inf(v[0]), -10)
411     self.assertEqual(Lsup(v[1]), 99)
412     self.assertEqual(z.showTagNames(), 'A, B, C')
413     self.assertEqual(z.getTag("C"), 42)
414 jfenwick 4962
415     def test_brickReadGmsh(self):
416     fname=os.path.join(FINLEY_TEST_MESH_PATH, 'brick_test.msh')
417 caltinay 5981 self.assertRaises(ValueError, ReadGmsh, fname, 3, diracPoints=[(0,0)])
418     self.assertRaises(ValueError, ReadGmsh, fname, 3, diracPoints=[(0,0,0)])
419     self.assertRaises(ValueError, ReadGmsh, fname, 3, diracPoints=[(0,0,0), (1,1,1)], diracTags=[40])
420     self.assertRaises(ValueError, ReadGmsh, fname, 3, diracPoints=[(0,0,0), (1,1,1)], diracTags=["cows"])
421 jfenwick 4962 z=ReadGmsh(fname, 3, diracPoints=[(0,0,0), (1,1,1)], diracTags=[40,51])
422     z=ReadGmsh(fname, 3, diracPoints=[(0,0,0),(0,1,0),(1,0,1),(1,1,1)], diracTags=["A", "B", "A", "C"])
423     v=interpolate(z.getX(), DiracDeltaFunctions(z))
424     if mpisize==1:
425 caltinay 6257 self.assertEqual(v.toListOfTuples(),[(0,0,0), (0,1,0), (1,0,1), (1,1,1)])
426     self.assertEqual(v.getNumberOfDataPoints(), 4)
427 jfenwick 4962 v.setTaggedValue("A",(-10,99,-98))
428 caltinay 6257 self.assertEqual(inf(v[0]), -10)
429     self.assertEqual(Lsup(v[1]), 99)
430     self.assertEqual(inf(v[2]), -98)
431 jfenwick 4962 v.setTaggedValue(500,(-100,-100,-100)) # non-existant tag
432 caltinay 6257 self.assertEqual(inf(v[0]), -10)
433     self.assertEqual(Lsup(v[1]), 99)
434     self.assertEqual(z.showTagNames(), 'A, B, C')
435     self.assertEqual(z.getTag("C"), 42)
436 jfenwick 4962
437    
438 gross 983 if __name__ == '__main__':
439 sshaw 4984 run_tests(__name__, exit_on_failure=True)
440 gross 1376

  ViewVC Help
Powered by ViewVC 1.1.26