/[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 3368 - (show annotations)
Fri Nov 19 05:59:46 2010 UTC (9 years ago) by jfenwick
File MIME type: text/x-python
File size: 8181 byte(s)
3d interpolateTable support.
New more generic interface for table interpolation.
tests and doco updated
1
2 ########################################################
3 #
4 # Copyright (c) 2003-2010 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-2010 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.finley 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 FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']
36 except KeyError:
37 FINLEY_WORKDIR='.'
38
39 NE=4 # number elements, must be even
40
41 class Test_SharedOnFinley(Test_Shared):
42 def setUp(self):
43 self.domain=Rectangle(NE,NE)
44 self.tol=0.001
45 def tearDown(self):
46 del self.domain
47 del self.tol
48
49 class Test_DomainOnFinley(Test_Domain):
50 def setUp(self):
51 self.boundary_tag_list = [1, 2, 10, 20]
52 self.domain =Rectangle(NE,NE+1,2)
53 def tearDown(self):
54 del self.domain
55 del self.boundary_tag_list
56
57 def test_tagsContinuousFunction(self):
58 ref_tags=[0]
59 tags=ContinuousFunction(self.domain).getListOfTags()
60 self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
61 for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
62
63 def test_tagsFunction(self):
64 ref_tags=[0]
65 tags=Function(self.domain).getListOfTags()
66 self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
67 for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
68 def test_tagsReducedFunction(self):
69 ref_tags=[0]
70 tags=ReducedFunction(self.domain).getListOfTags()
71 self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
72 for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
73 def test_tagsFunctionOnBoundary(self):
74 ref_tags=[1, 2, 10, 20]
75 tags=FunctionOnBoundary(self.domain).getListOfTags()
76 # For an MPI-distributed domain some tags may be missing
77 if getMPISizeWorld() == 1: self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
78 for i in tags: self.failUnless(i in ref_tags,"tag %s is missing."%i)
79 def test_tagsReducedFunctionOnBoundary(self):
80 ref_tags=[1, 2, 10, 20]
81 tags=ReducedFunctionOnBoundary(self.domain).getListOfTags()
82 # For an MPI-distributed domain some tags may be missing
83 if getMPISizeWorld() == 1: self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
84 for i in tags: self.failUnless(i in ref_tags,"tag %s is missing."%i)
85 def test_tagsFunctionOnContactOne(self):
86 ref_tags=[]
87 tags=FunctionOnContactOne(self.domain).getListOfTags()
88 self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
89 for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
90 def test_tagsFunctionOnContactZero(self):
91 ref_tags=[]
92 tags=FunctionOnContactZero(self.domain).getListOfTags()
93 self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
94 for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
95 def test_tagsReducedFunctionOnContactOne(self):
96 ref_tags=[]
97 tags=ReducedFunctionOnContactOne(self.domain).getListOfTags()
98 self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
99 for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
100 def test_tagsReducedFunctionOnContactZero(self):
101 ref_tags=[]
102 tags=ReducedFunctionOnContactZero(self.domain).getListOfTags()
103 self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
104 for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
105
106 class Test_DataOpsOnFinley(Test_Dump, Test_SetDataPointValue, Test_GlobalMinMax, Test_Lazy):
107 def setUp(self):
108 self.domain =Rectangle(NE,NE+1,2)
109 self.domain_with_different_number_of_samples =Rectangle(2*NE,NE+1,2)
110 self.domain_with_different_number_of_data_points_per_sample =Rectangle(2*NE,NE+1,2,integrationOrder=2)
111 self.domain_with_different_sample_ordering =Rectangle(NE,NE+1,2, optimize=True)
112 self.filename_base=FINLEY_WORKDIR
113 self.mainfs=Function(self.domain)
114 self.otherfs=Solution(self.domain)
115
116 def tearDown(self):
117 del self.domain
118 del self.domain_with_different_number_of_samples
119 del self.domain_with_different_number_of_data_points_per_sample
120 del self.domain_with_different_sample_ordering
121 del self.mainfs
122 del self.otherfs
123
124
125
126 class Test_TableInterpolationOnFinley(Test_TableInterpolation):
127 def setUp(self):
128 self.domain=Brick(4,4,4)
129 self.functionspaces=[ContinuousFunction(self.domain), Function(self.domain), ReducedFunction(self.domain),
130 FunctionOnBoundary(self.domain), ReducedFunctionOnBoundary(self.domain),
131 FunctionOnContactZero(self.domain), FunctionOnContactOne(self.domain),
132 ReducedFunctionOnContactZero(self.domain), ReducedFunctionOnContactOne(self.domain)]
133 #We aren't testing DiracDeltaFunction
134 self.xn=3 # number of grids on x axis
135 self.yn=3 # number of grids on y axis
136 self.zn=3 # number of grids on z axis
137
138 def tearDown(self):
139 del self.domain
140 del self.functionspaces
141
142
143
144
145 class Test_CSVOnFinley(Test_saveCSV):
146 def setUp(self):
147 self.domain =Rectangle(NE,NE+1,2)
148 self.linecount1=80 #see test_save1 for the meaning of these params
149 self.linecount2=69
150 self.line_expected=[0.125, 0., 0.125]
151
152 def tearDown(self):
153 del self.domain
154
155 #This test checks to see that all FunctionSpaces can be saved
156 def test_singleFS(self):
157 fname=os.path.join(FINLEY_WORKDIR, "test_singlefs.csv")
158 fss=[ContinuousFunction(self.domain), Function(self.domain), ReducedFunction(self.domain),
159 FunctionOnBoundary(self.domain), ReducedFunctionOnBoundary(self.domain),
160 FunctionOnContactZero(self.domain), FunctionOnContactOne(self.domain),
161 ReducedFunctionOnContactZero(self.domain), ReducedFunctionOnContactOne(self.domain),
162 DiracDeltaFunction(self.domain)]
163 for f in fss:
164 d=Data(7,f)
165 print "Testing "+str(f)+"\n"
166 saveDataCSV(fname, D=d)
167
168 def test_multiFS(self):
169 fname=os.path.join(FINLEY_WORKDIR, "test_multifs.csv")
170 sol=Data(8,Solution(self.domain))
171 ctsfn=Data(9,ContinuousFunction(self.domain))
172 #test line 0
173 dirac=Data(-1,DiracDeltaFunction(self.domain))
174 saveDataCSV(fname, A=sol, B=ctsfn, C=dirac)
175 #test line 1
176 fun=Data(5,Function(self.domain))
177 rfun=Data(3,ReducedFunction(self.domain))
178 saveDataCSV(fname, A=sol,B=ctsfn,C=fun, D=rfun)
179 #test line 2
180 bound=Data(1,FunctionOnBoundary(self.domain))
181 rbound=Data(3,ReducedFunctionOnBoundary(self.domain))
182 saveDataCSV(fname,A=sol,B=ctsfn,C=bound, D=rbound)
183 #test line 3
184 conzz=Data(7,FunctionOnContactZero(self.domain))
185 rconz=Data(8,ReducedFunctionOnContactZero(self.domain))
186 saveDataCSV(fname,A=sol,B=ctsfn, C=conzz, D=rconz)
187 #check for cross line exceptions
188 self.failUnlessRaises(RuntimeError, saveDataCSV, fname, A=dirac, B=rfun)
189 self.failUnlessRaises(RuntimeError, saveDataCSV, fname, A=bound, B=conzz)
190
191
192 if __name__ == '__main__':
193 suite = unittest.TestSuite()
194 suite.addTest(unittest.makeSuite(Test_SharedOnFinley))
195 suite.addTest(unittest.makeSuite(Test_DataOpsOnFinley))
196 suite.addTest(unittest.makeSuite(Test_DomainOnFinley))
197 suite.addTest(unittest.makeSuite(Test_TableInterpolationOnFinley))
198 suite.addTest(unittest.makeSuite(Test_CSVOnFinley))
199 s=unittest.TextTestRunner(verbosity=2).run(suite)
200 if not s.wasSuccessful(): sys.exit(1)
201

  ViewVC Help
Powered by ViewVC 1.1.26