/[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 5986 - (show annotations)
Fri Feb 26 04:10:41 2016 UTC (3 years, 1 month ago) by caltinay
File MIME type: text/x-python
File size: 8515 byte(s)
more test fixes.

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2016 by The 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 from __future__ import print_function, division
18
19 __copyright__="""Copyright (c) 2003-2016 by The 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 os
27 import sys
28 import esys.escriptcore.utestselect as unittest
29 from esys.escriptcore.testing import *
30 from esys.escript import *
31 from esys.ripley import Rectangle, Brick, ripleycpp
32 from test_objects import Test_Dump, Test_SetDataPointValue, Test_saveCSV, Test_TableInterpolation
33 from test_objects import Test_Domain, Test_GlobalMinMax, Test_Lazy
34
35 from test_shared import Test_Shared
36
37 try:
38 RIPLEY_WORKDIR=os.environ['RIPLEY_WORKDIR']
39 except KeyError:
40 RIPLEY_WORKDIR='.'
41
42 NE=4 # number elements, must be even
43 mpiSize=getMPISizeWorld()
44 for x in [int(sqrt(mpiSize)),2,3,5,7,1]:
45 NX=x
46 NY=mpiSize//x
47 if NX*NY == mpiSize:
48 break
49
50 for x in [(int(mpiSize**(1/3.)),int(mpiSize**(1/3.))),(2,3),(2,2),(1,2),(1,1)]:
51 NXb=x[0]
52 NYb=x[1]
53 NZb=mpiSize//(x[0]*x[1])
54 if NXb*NYb*NZb == mpiSize:
55 break
56
57 class Test_SharedOnRipley(Test_Shared):
58 def setUp(self):
59 self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
60 self.tol=0.001
61 def tearDown(self):
62 del self.domain
63 del self.tol
64
65 class Test_DomainOnRipley(Test_Domain):
66 def setUp(self):
67 self.boundary_tag_list = [1, 2, 10, 20]
68 self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
69 self.rdomain=Rectangle(n0=(NE+6)*NX-1, n1=(NE+6)*NY-1, l0=1., l1=1., d0=NX, d1=NY)
70
71 def tearDown(self):
72 del self.domain
73 del self.boundary_tag_list
74
75 def test_tagsContinuousFunction(self):
76 ref_tags=[0]
77 tags=ContinuousFunction(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_tagsFunction(self):
81 ref_tags=[0]
82 tags=Function(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_tagsReducedFunction(self):
86 ref_tags=[0]
87 tags=ReducedFunction(self.domain).getListOfTags()
88 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
89 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
90 def test_tagsFunctionOnBoundary(self):
91 ref_tags=[1, 2, 10, 20]
92 tags=FunctionOnBoundary(self.domain).getListOfTags()
93 # For an MPI-distributed domain some tags may be missing
94 if getMPISizeWorld() == 1: self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
95 for i in tags: self.assertTrue(i in ref_tags,"tag %s is missing."%i)
96 def test_tagsReducedFunctionOnBoundary(self):
97 ref_tags=[1, 2, 10, 20]
98 tags=ReducedFunctionOnBoundary(self.domain).getListOfTags()
99 # For an MPI-distributed domain some tags may be missing
100 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
103 class Test_DataOpsOnRipley(Test_Dump, Test_SetDataPointValue, Test_GlobalMinMax, Test_Lazy):
104 def setUp(self):
105 self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
106 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)
107 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)
108 self.domain_with_different_sample_ordering=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
109 self.filename_base=RIPLEY_WORKDIR
110 self.mainfs=Function(self.domain)
111 self.otherfs=Solution(self.domain)
112
113 def tearDown(self):
114 del self.domain
115 del self.domain_with_different_number_of_samples
116 del self.domain_with_different_number_of_data_points_per_sample
117 del self.domain_with_different_sample_ordering
118 del self.mainfs
119 del self.otherfs
120
121 class Test_TableInterpolationOnRipley(Test_TableInterpolation):
122 def setUp(self):
123 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)
124 self.functionspaces=[ContinuousFunction(self.domain), Function(self.domain), ReducedFunction(self.domain),
125 FunctionOnBoundary(self.domain), ReducedFunctionOnBoundary(self.domain)]
126 #We aren't testing DiracDeltaFunctions
127 self.xn=5 # number of grids on x axis
128 self.yn=5 # number of grids on y axis
129 self.zn=5
130
131 def tearDown(self):
132 del self.domain
133 del self.functionspaces
134
135 class Test_CSVOnRipley(Test_saveCSV):
136 def setUp(self):
137 self.workdir=RIPLEY_WORKDIR
138 self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
139 self.functionspaces=[ContinuousFunction, Function, ReducedFunction,
140 FunctionOnBoundary, ReducedFunctionOnBoundary]
141
142 NE0=NE*NX-1
143 NE1=NE*NY-1
144
145 # number of total data points for each function space
146 self.linecounts=[ (NE0+1)*(NE1+1)+1, 4*NE0*NE1+1, NE0*NE1+1,
147 4*NE0+4*NE1+1, 2*NE0+2*NE1+1 ]
148 # number of masked points, i.e. where X[0] is non-zero
149 self.linecounts_masked=[ NE0*(NE1+1)+1, 4*NE0*NE1+1, NE0*NE1+1,
150 4*NE0+2*NE1+1, 2*NE0+NE1+1 ]
151 # expected values in first line of masked data = [ X[:], X[0] ]
152 self.firstline=[ [1./NE0, 0., 1./NE0],
153 [None, None, None],
154 [None, None, None],
155 [None, None, None],
156 [None, None, None] ]
157
158 def tearDown(self):
159 del self.domain
160
161 def test_csv_multiFS(self):
162 fname=os.path.join(RIPLEY_WORKDIR, "test_multifs.csv")
163 sol=Data(8,Solution(self.domain))
164 ctsfn=Data(9,ContinuousFunction(self.domain))
165 #test line 0
166 dirac=Data(-1,DiracDeltaFunctions(self.domain))
167 saveDataCSV(fname, A=sol, B=ctsfn, C=dirac)
168 #test line 1
169 fun=Data(5,Function(self.domain))
170 rfun=Data(3,ReducedFunction(self.domain))
171 saveDataCSV(fname, A=sol,B=ctsfn,C=fun, D=rfun)
172 #test line 2
173 bound=Data(1,FunctionOnBoundary(self.domain))
174 rbound=Data(3,ReducedFunctionOnBoundary(self.domain))
175 saveDataCSV(fname,A=sol,B=ctsfn,C=bound, D=rbound)
176
177 class Test_randomOnRipley(unittest.TestCase):
178 def test_FillRectangle(self):
179 fs=ContinuousFunction(Rectangle(10*(int(sqrt(mpiSize)+1)),10*(int(sqrt(mpiSize)+1))))
180 RandomData((), fs, 2,("gaussian",1,0.5))
181 RandomData((), fs, 0,("gaussian",2,0.76))
182 self.assertRaises(NotImplementedError, RandomData, (2,2), fs, 0, ("gaussian",2,0.76)) #data not scalar
183 self.assertRaises(ValueError, RandomData, (), fs, 0, ("gaussian",11,0.1)) #radius too large
184 RandomData((2,3),fs)
185
186 def test_FillBrick(self):
187 # If we are going to do really big tests of this, the size of this brick will need to be reduced
188 fs=ContinuousFunction(Brick(10*mpiSize,10*mpiSize, 10*mpiSize))
189 RandomData((), fs, 2,("gaussian",1,0.5))
190 RandomData((), fs, 0,("gaussian",2,0.76))
191 self.assertRaises(NotImplementedError, RandomData, (2,2), fs, 0, ("gaussian",2,0.76)) #data not scalar
192 self.assertRaises(ValueError, RandomData, (), fs, 0, ("gaussian",20,0.1)) #radius too large
193 RandomData((2,3),fs)
194
195
196 if __name__ == '__main__':
197 run_tests(__name__, exit_on_failure=True)
198

  ViewVC Help
Powered by ViewVC 1.1.26