/[escript]/trunk/ripley/test/python/run_escriptOnRipley.py
ViewVC logotype

Contents of /trunk/ripley/test/python/run_escriptOnRipley.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3993 - (show annotations)
Wed Sep 26 07:00:55 2012 UTC (7 years ago) by caltinay
File MIME type: text/x-python
File size: 7607 byte(s)
Addressing mantis 651. Test for finley will fail under MPI since there is
sth wrong with the way ReducedContinuousFunction samples are interrogated.

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2012 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-2012 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.ripley import Rectangle, Brick
29 from test_objects import Test_Dump, Test_SetDataPointValue, Test_saveCSV, Test_TableInterpolation
30 from test_objects import Test_Domain, Test_GlobalMinMax, Test_Lazy
31
32 from test_shared import Test_Shared
33
34 try:
35 RIPLEY_WORKDIR=os.environ['RIPLEY_WORKDIR']
36 except KeyError:
37 RIPLEY_WORKDIR='.'
38
39 NE=4 # number elements, must be even
40 mpiSize=getMPISizeWorld()
41 for x in [int(sqrt(mpiSize)),2,3,5,7,1]:
42 NX=x
43 NY=mpiSize//x
44 if NX*NY == mpiSize:
45 break
46
47 for x in [(int(mpiSize**(1/3.)),int(mpiSize**(1/3.))),(2,3),(2,2),(1,2),(1,1)]:
48 NXb=x[0]
49 NYb=x[1]
50 NZb=mpiSize//(x[0]*x[1])
51 if NXb*NYb*NZb == mpiSize:
52 break
53
54 class Test_SharedOnRipley(Test_Shared):
55 def setUp(self):
56 self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
57 self.tol=0.001
58 def tearDown(self):
59 del self.domain
60 del self.tol
61
62 class Test_DomainOnRipley(Test_Domain):
63 def setUp(self):
64 self.boundary_tag_list = [1, 2, 10, 20]
65 self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
66 def tearDown(self):
67 del self.domain
68 del self.boundary_tag_list
69
70 def test_tagsContinuousFunction(self):
71 ref_tags=[0]
72 tags=ContinuousFunction(self.domain).getListOfTags()
73 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
74 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
75 def test_tagsFunction(self):
76 ref_tags=[0]
77 tags=Function(self.domain).getListOfTags()
78 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
79 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
80 def test_tagsReducedFunction(self):
81 ref_tags=[0]
82 tags=ReducedFunction(self.domain).getListOfTags()
83 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 def test_tagsFunctionOnBoundary(self):
86 ref_tags=[1, 2, 10, 20]
87 tags=FunctionOnBoundary(self.domain).getListOfTags()
88 # For an MPI-distributed domain some tags may be missing
89 if getMPISizeWorld() == 1: self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
90 for i in tags: self.assertTrue(i in ref_tags,"tag %s is missing."%i)
91 def test_tagsReducedFunctionOnBoundary(self):
92 ref_tags=[1, 2, 10, 20]
93 tags=ReducedFunctionOnBoundary(self.domain).getListOfTags()
94 # For an MPI-distributed domain some tags may be missing
95 if getMPISizeWorld() == 1: self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
96 for i in tags: self.assertTrue(i in ref_tags,"tag %s is missing."%i)
97
98 class Test_DataOpsOnRipley(Test_Dump, Test_SetDataPointValue, Test_GlobalMinMax, Test_Lazy):
99 def setUp(self):
100 self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
101 self.domain_with_different_number_of_samples=Rectangle(n0=7*NE*NX-1, n1=3*NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
102 self.domain_with_different_number_of_data_points_per_sample=Rectangle(n0=7*NE*NX-1, n1=3*NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
103 self.domain_with_different_sample_ordering=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
104 self.filename_base=RIPLEY_WORKDIR
105 self.mainfs=Function(self.domain)
106 self.otherfs=Solution(self.domain)
107
108 def tearDown(self):
109 del self.domain
110 del self.domain_with_different_number_of_samples
111 del self.domain_with_different_number_of_data_points_per_sample
112 del self.domain_with_different_sample_ordering
113 del self.mainfs
114 del self.otherfs
115
116 class Test_TableInterpolationOnRipley(Test_TableInterpolation):
117 def setUp(self):
118 self.domain = Brick(n0=NE*NXb-1, n1=NE*NYb-1, n2=NE*NZb-1, l0=1., l1=1., l2=1., d0=NXb, d1=NYb, d2=NZb)
119 self.functionspaces=[ContinuousFunction(self.domain), Function(self.domain), ReducedFunction(self.domain),
120 FunctionOnBoundary(self.domain), ReducedFunctionOnBoundary(self.domain)]
121 #We aren't testing DiracDeltaFunctions
122 self.xn=5 # number of grids on x axis
123 self.yn=5 # number of grids on y axis
124 self.zn=5
125
126 def tearDown(self):
127 del self.domain
128 del self.functionspaces
129
130 class Test_CSVOnRipley(Test_saveCSV):
131 def setUp(self):
132 self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
133 self.functionspaces=[ContinuousFunction, Function, ReducedFunction,
134 FunctionOnBoundary, ReducedFunctionOnBoundary]
135
136 NE0=NE*NX-1
137 NE1=NE*NY-1
138
139 # number of total data points for each function space
140 self.linecounts=[ (NE0+1)*(NE1+1)+1, 4*NE0*NE1+1, NE0*NE1+1,
141 4*NE0+4*NE1+1, 2*NE0+2*NE1+1 ]
142 # number of masked points, i.e. where X[0] is non-zero
143 self.linecounts_masked=[ NE0*(NE1+1)+1, 4*NE0*NE1+1, NE0*NE1+1,
144 2*NE0+4*NE1+1, NE0+2*NE1+1 ]
145 # expected values in first line of masked data = [ X[:], X[0] ]
146 self.firstline=[ [1./NE0, 0., 1./NE0],
147 [0.07044162180172903, 0.07044162180172903, 0.07044162180172903],
148 [0.1666666666666667, 0.1666666666666667, 0.1666666666666667],
149 [1., 0.07044162180172903, 1.],
150 [1., 0.1666666666666667, 1.] ]
151
152 def tearDown(self):
153 del self.domain
154
155 def test_csv_multiFS(self):
156 fname=os.path.join(RIPLEY_WORKDIR, "test_multifs.csv")
157 sol=Data(8,Solution(self.domain))
158 ctsfn=Data(9,ContinuousFunction(self.domain))
159 #test line 0
160 dirac=Data(-1,DiracDeltaFunctions(self.domain))
161 saveDataCSV(fname, A=sol, B=ctsfn, C=dirac)
162 #test line 1
163 fun=Data(5,Function(self.domain))
164 rfun=Data(3,ReducedFunction(self.domain))
165 saveDataCSV(fname, A=sol,B=ctsfn,C=fun, D=rfun)
166 #test line 2
167 bound=Data(1,FunctionOnBoundary(self.domain))
168 rbound=Data(3,ReducedFunctionOnBoundary(self.domain))
169 saveDataCSV(fname,A=sol,B=ctsfn,C=bound, D=rbound)
170
171 if __name__ == '__main__':
172 suite = unittest.TestSuite()
173 suite.addTest(unittest.makeSuite(Test_SharedOnRipley))
174 suite.addTest(unittest.makeSuite(Test_DataOpsOnRipley))
175 suite.addTest(unittest.makeSuite(Test_DomainOnRipley))
176 suite.addTest(unittest.makeSuite(Test_TableInterpolationOnRipley))
177 suite.addTest(unittest.makeSuite(Test_CSVOnRipley))
178 s=unittest.TextTestRunner(verbosity=2).run(suite)
179 if not s.wasSuccessful(): sys.exit(1)
180

  ViewVC Help
Powered by ViewVC 1.1.26