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

Contents of /trunk/finley/test/python/run_escriptOnFinley.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: 11397 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
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2014 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 import os
25 import sys
26 import esys.escriptcore.utestselect as unittest
27
28 from esys.escript import *
29 from esys.finley import Rectangle, Brick
30 from test_objects import Test_Dump, Test_SetDataPointValue, Test_saveCSV, \
31 Test_TableInterpolation, Test_Domain, Test_GlobalMinMax, Test_Lazy
32 from test_shared import Test_Shared
33
34 try:
35 FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']
36 except KeyError:
37 FINLEY_WORKDIR='.'
38
39 mpisize=getMPISizeWorld()
40 NE=4 # number elements, must be even
41
42 class Test_SharedOnFinley(Test_Shared):
43 def setUp(self):
44 self.domain=Rectangle(NE,NE)
45 self.tol=0.001
46
47 def tearDown(self):
48 del self.domain
49 del self.tol
50
51 class Test_DomainOnFinley(Test_Domain):
52 def setUp(self):
53 self.boundary_tag_list = [1, 2, 10, 20]
54 self.domain =Rectangle(NE,NE+1,2)
55 self.rdomain=self.domain
56
57 def tearDown(self):
58 del self.domain
59 del self.rdomain
60 del self.boundary_tag_list
61
62 def test_setXError(self):
63 domain=Rectangle(NE,NE)
64 x=domain.getX()
65 z=interpolate(x, Function(domain))
66 self.assertRaises(RuntimeError, domain.setX, z)
67 del x
68 del z
69 del domain
70
71 def test_tagsContinuousFunction(self):
72 ref_tags=[0]
73 tags=ContinuousFunction(self.domain).getListOfTags()
74 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
75 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
76
77 def test_tagsFunction(self):
78 ref_tags=[0]
79 tags=Function(self.domain).getListOfTags()
80 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
81 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
82 def test_tagsReducedFunction(self):
83 ref_tags=[0]
84 tags=ReducedFunction(self.domain).getListOfTags()
85 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
86 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
87 def test_tagsFunctionOnBoundary(self):
88 ref_tags=[1, 2, 10, 20]
89 tags=FunctionOnBoundary(self.domain).getListOfTags()
90 # For an MPI-distributed domain some tags may be missing
91 if getMPISizeWorld() == 1: self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
92 for i in tags: self.assertTrue(i in ref_tags,"tag %s is missing."%i)
93 def test_tagsReducedFunctionOnBoundary(self):
94 ref_tags=[1, 2, 10, 20]
95 tags=ReducedFunctionOnBoundary(self.domain).getListOfTags()
96 # For an MPI-distributed domain some tags may be missing
97 if getMPISizeWorld() == 1: self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
98 for i in tags: self.assertTrue(i in ref_tags,"tag %s is missing."%i)
99 def test_tagsFunctionOnContactOne(self):
100 ref_tags=[]
101 tags=FunctionOnContactOne(self.domain).getListOfTags()
102 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
103 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
104 def test_tagsFunctionOnContactZero(self):
105 ref_tags=[]
106 tags=FunctionOnContactZero(self.domain).getListOfTags()
107 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
108 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
109 def test_tagsReducedFunctionOnContactOne(self):
110 ref_tags=[]
111 tags=ReducedFunctionOnContactOne(self.domain).getListOfTags()
112 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
113 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
114 def test_tagsReducedFunctionOnContactZero(self):
115 ref_tags=[]
116 tags=ReducedFunctionOnContactZero(self.domain).getListOfTags()
117 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
118 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
119
120 class Test_DataOpsOnFinley(Test_Dump, Test_SetDataPointValue, Test_GlobalMinMax, Test_Lazy):
121 def setUp(self):
122 self.domain =Rectangle(NE,NE+1,2)
123 self.domain_with_different_number_of_samples =Rectangle(2*NE,NE+1,2)
124 self.domain_with_different_number_of_data_points_per_sample =Rectangle(2*NE,NE+1,2,integrationOrder=2)
125 self.domain_with_different_sample_ordering =Rectangle(NE,NE+1,2, optimize=True)
126 self.filename_base=FINLEY_WORKDIR
127 self.mainfs=Function(self.domain)
128 self.otherfs=Solution(self.domain)
129
130 def tearDown(self):
131 del self.domain
132 del self.domain_with_different_number_of_samples
133 del self.domain_with_different_number_of_data_points_per_sample
134 del self.domain_with_different_sample_ordering
135 del self.mainfs
136 del self.otherfs
137
138
139 class Test_TableInterpolationOnFinley(Test_TableInterpolation):
140 def setUp(self):
141 self.domain=Brick(4,4,4)
142 self.functionspaces=[ContinuousFunction(self.domain), Function(self.domain), ReducedFunction(self.domain),
143 FunctionOnBoundary(self.domain), ReducedFunctionOnBoundary(self.domain),
144 FunctionOnContactZero(self.domain), FunctionOnContactOne(self.domain),
145 ReducedFunctionOnContactZero(self.domain), ReducedFunctionOnContactOne(self.domain)]
146 #We aren't testing DiracDeltaFunctions
147 self.xn=3 # number of grids on x axis
148 self.yn=3 # number of grids on y axis
149 self.zn=3 # number of grids on z axis
150
151 def tearDown(self):
152 del self.domain
153 del self.functionspaces
154
155
156 #This functionality is only testes on Finley.
157 #It is not finley specific but it does need a known set of input points so I've chosen to put it here
158 class Test_OtherInterpolationOnFinley(unittest.TestCase):
159 def setUp(self):
160 self.r=Rectangle(4,1).getX()[0]+2
161 self.z=Data(2)
162
163 def tearDown(self):
164 del self.z
165 del self.r
166
167 def test_nonuniformint(self):
168 self.assertRaises(RuntimeError, self.z.nonuniformInterpolate, [0,1], [5,6], True)
169 self.assertRaises(RuntimeError, self.z.nonuniformInterpolate, [3,4], [5,6], True)
170 self.assertTrue(Lsup(self.z.nonuniformInterpolate([0,1], [5,6], False)-6)<0.00001, "RHS edge not fitted")
171 self.assertTrue(Lsup(self.z.nonuniformInterpolate([3,4], [5,6], False)-5)<0.00001, "LHS edge not fitted")
172 tmp=self.r.nonuniformInterpolate([2.125, 2.4, 2.5, 2.8], [1, -1, 2, 4], False)
173 self.assertTrue(Lsup(sup(tmp)-4)<0.0001, "RHS edge not fitted for Rect")
174 self.assertTrue(Lsup(inf(tmp)-0.090909)<0.00001, "Internal interpolate failed")
175 tmp=self.r.nonuniformInterpolate([2.125, 2.4, 2.5, 3.2], [1, -1, 2, 4], False)
176 self.assertTrue(Lsup(sup(tmp)-3.42857)<0.00001, "Internal interpolate failed")
177
178 def test_nonuniformSlope(self):
179 self.assertRaises(RuntimeError, self.z.nonuniformSlope, [0,1], [5,6], True)
180 self.assertRaises(RuntimeError, self.z.nonuniformSlope, [3,4], [5,6], True)
181 self.assertTrue(Lsup(self.z.nonuniformSlope([0,1], [5,6], False))<0.00001, "RHS edge not fitted")
182 self.assertTrue(Lsup(self.z.nonuniformSlope([3,4], [5,6], False))<0.00001, "LHS edge not fitted")
183 tmp=self.r.nonuniformSlope([2.125, 2.4, 2.5, 3.2], [1, -1, 2, 4], False)
184 self.assertTrue(Lsup(sup(tmp)-30)<0.00001, "Internal interpolate failed")
185 self.assertTrue(Lsup(inf(tmp)+7.27273)<0.00001, "Internal interpolate failed")
186
187 class Test_CSVOnFinley(Test_saveCSV):
188 def setUp(self):
189 NE0=NE
190 NE1=NE+1
191 self.domain = Rectangle(NE0, NE1, order=2)
192 self.functionspaces = [ ContinuousFunction ]
193 # number of total data points for each function space
194 self.linecounts=[ (2*NE0+1)*(2*NE1+1)-NE0*NE1+1 ]
195 # number of masked points, i.e. where X[0] is non-zero
196 self.linecounts_masked=[ (2*NE0+1)*(2*NE1+1)-(2+NE0)*NE1 ]
197 # expected values in first line of masked data = [ X[:], X[0] ]
198 self.firstline=[ [1./(2*NE0), 0., 1./(2*NE0)] ]
199
200 if getMPISizeWorld() == 1:
201 self.functionspaces += [ ReducedContinuousFunction, Function,
202 ReducedFunction, FunctionOnBoundary, ReducedFunctionOnBoundary ]
203 self.linecounts += [ 31, 181, 81, 55, 37 ]
204 self.linecounts_masked += [ 25, 181, 81, 40, 27 ]
205 self.firstline += [ [.25, 0., .25],
206 [.02817541634481463,.02254033307585171,.02817541634481463],
207 [.05283121635129676,.04226497308103741,.05283121635129676],
208 [.02817541634481463,0.,.02817541634481463],
209 [.05283121635129676,0.,.05283121635129676]
210 ]
211 else:
212 print("Skipping some CSV tests on finley since MPI size > 1")
213
214 def tearDown(self):
215 del self.domain
216
217 @unittest.skipIf(mpisize>1, "more than 1 MPI rank")
218 def test_csv_multiFS(self):
219 fname=os.path.join(FINLEY_WORKDIR, "test_multifs.csv")
220 sol=Data(8,Solution(self.domain))
221 ctsfn=Data(9,ContinuousFunction(self.domain))
222 #test line 0
223 dirac=Data(-1,DiracDeltaFunctions(self.domain))
224 saveDataCSV(fname, A=sol, B=ctsfn, C=dirac)
225 #test line 1
226 fun=Data(5,Function(self.domain))
227 rfun=Data(3,ReducedFunction(self.domain))
228 saveDataCSV(fname, A=sol,B=ctsfn,C=fun, D=rfun)
229 #test line 2
230 bound=Data(1,FunctionOnBoundary(self.domain))
231 rbound=Data(3,ReducedFunctionOnBoundary(self.domain))
232 saveDataCSV(fname,A=sol,B=ctsfn,C=bound, D=rbound)
233 #test line 3
234 conzz=Data(7,FunctionOnContactZero(self.domain))
235 rconz=Data(8,ReducedFunctionOnContactZero(self.domain))
236 saveDataCSV(fname,A=sol,B=ctsfn, C=conzz, D=rconz)
237 #check for cross line exceptions
238 self.assertRaises(RuntimeError, saveDataCSV, fname, A=dirac, B=rfun)
239 self.assertRaises(RuntimeError, saveDataCSV, fname, A=bound, B=conzz)
240
241 if __name__ == '__main__':
242 suite = unittest.TestSuite()
243 suite.addTest(unittest.makeSuite(Test_SharedOnFinley))
244 suite.addTest(unittest.makeSuite(Test_DataOpsOnFinley))
245 suite.addTest(unittest.makeSuite(Test_DomainOnFinley))
246 suite.addTest(unittest.makeSuite(Test_TableInterpolationOnFinley))
247 suite.addTest(unittest.makeSuite(Test_CSVOnFinley))
248 suite.addTest(unittest.makeSuite(Test_OtherInterpolationOnFinley))
249 s=unittest.TextTestRunner(verbosity=2).run(suite)
250 if not s.wasSuccessful(): sys.exit(1)
251

  ViewVC Help
Powered by ViewVC 1.1.26