/[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 3792 - (show annotations)
Wed Feb 1 06:16:25 2012 UTC (7 years, 1 month ago) by caltinay
File MIME type: text/x-python
File size: 7296 byte(s)
Merged ripley rectangular domain into trunk.

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2012 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2012 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 import unittest
23 import tempfile
24
25 from esys.escript import *
26 from esys.ripley import Rectangle, Brick
27 import sys
28 import os
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.linecount1=(NE*NX)*(NE*NY)+1 #see test_save1 for the meaning of these params
134 self.linecount2=(NE*NX-1)*(NE*NY)+1
135 self.line_expected=[1./(NE*NX-1), 0., 1./(NE*NX-1)]
136
137 def tearDown(self):
138 del self.domain
139
140 #This test checks to see that all FunctionSpaces can be saved
141 def test_singleFS(self):
142 fname=os.path.join(RIPLEY_WORKDIR, "test_singlefs.csv")
143 fss=[ContinuousFunction(self.domain), Function(self.domain), ReducedFunction(self.domain),
144 FunctionOnBoundary(self.domain), ReducedFunctionOnBoundary(self.domain),
145 DiracDeltaFunctions(self.domain)]
146 for f in fss:
147 d=Data(7,f)
148 print("Testing "+str(f)+"\n")
149 saveDataCSV(fname, D=d)
150
151 def test_multiFS(self):
152 fname=os.path.join(RIPLEY_WORKDIR, "test_multifs.csv")
153 sol=Data(8,Solution(self.domain))
154 ctsfn=Data(9,ContinuousFunction(self.domain))
155 #test line 0
156 dirac=Data(-1,DiracDeltaFunctions(self.domain))
157 saveDataCSV(fname, A=sol, B=ctsfn, C=dirac)
158 #test line 1
159 fun=Data(5,Function(self.domain))
160 rfun=Data(3,ReducedFunction(self.domain))
161 saveDataCSV(fname, A=sol,B=ctsfn,C=fun, D=rfun)
162 #test line 2
163 bound=Data(1,FunctionOnBoundary(self.domain))
164 rbound=Data(3,ReducedFunctionOnBoundary(self.domain))
165 saveDataCSV(fname,A=sol,B=ctsfn,C=bound, D=rbound)
166
167 if __name__ == '__main__':
168 suite = unittest.TestSuite()
169 suite.addTest(unittest.makeSuite(Test_SharedOnRipley))
170 suite.addTest(unittest.makeSuite(Test_DataOpsOnRipley))
171 suite.addTest(unittest.makeSuite(Test_DomainOnRipley))
172 suite.addTest(unittest.makeSuite(Test_TableInterpolationOnRipley))
173 suite.addTest(unittest.makeSuite(Test_CSVOnRipley))
174 s=unittest.TextTestRunner(verbosity=2).run(suite)
175 if not s.wasSuccessful(): sys.exit(1)
176

  ViewVC Help
Powered by ViewVC 1.1.26