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

  ViewVC Help
Powered by ViewVC 1.1.26