/[escript]/trunk/dudley/test/python/run_inputOutput.py
ViewVC logotype

Annotation of /trunk/dudley/test/python/run_inputOutput.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4938 - (hide annotations)
Wed May 14 01:13:23 2014 UTC (5 years, 4 months ago) by jfenwick
File MIME type: text/x-python
File size: 8762 byte(s)
Modify unit tests to read their classes from
esys.escriptcore.utestselect

Change the line in that file to switch between unittest and unittest2


1 ksteube 1809
2 jfenwick 3981 ##############################################################################
3 ksteube 1754 #
4 jfenwick 4657 # Copyright (c) 2003-2014 by University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 ksteube 1754 #
7 ksteube 1809 # 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 ksteube 1754 #
11 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 #
15     ##############################################################################
16 ksteube 1754
17 jfenwick 4019 from __future__ import print_function
18    
19 jfenwick 4657 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
20 jfenwick 3981 http://www.uq.edu.au
21 ksteube 1809 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 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
25 ksteube 1809
26 ksteube 1754 """
27     Test suite for input and output of meshes and data objects
28    
29 jfenwick 2625 :remark:
30 ksteube 1754
31 jfenwick 2625 :var __author__: name of author
32     :var __licence__: licence agreement
33     :var __url__: url entry point on documentation
34     :var __version__: version
35     :var __date__: date of the version
36 ksteube 1754 """
37    
38 jfenwick 4938 import esys.escriptcore.utestselect as unittest, sys
39 ksteube 1754
40     from esys.escript import *
41 jfenwick 3934 from esys.dudley import Rectangle, Brick, LoadMesh, ReadMesh, ReadGmsh, ReadGmsh
42 ksteube 1754
43     try:
44 caltinay 3349 DUDLEY_WORKDIR=os.environ['DUDLEY_WORKDIR']
45     except KeyError:
46     DUDLEY_WORKDIR='.'
47    
48     try:
49 jfenwick 3085 DUDLEY_TEST_DATA=os.environ['DUDLEY_TEST_DATA']
50 ksteube 1754 except KeyError:
51 jfenwick 3085 DUDLEY_TEST_DATA='.'
52 ksteube 1754
53 jfenwick 3085 DUDLEY_TEST_MESH_PATH=os.path.join(DUDLEY_TEST_DATA,"data_meshes")
54 ksteube 1754
55     REL_TOL=1.e-6
56    
57 ksteube 1805 # Number of elements scales up with number of MPI processes
58     NE0 = 7 * getMPISizeWorld()
59     NE1 = 11
60     NE2 = 5
61    
62 ksteube 1754 class InputOutput(unittest.TestCase):
63    
64 ksteube 1805 # Check that two domains are equal using Fourier integrals
65     # We cannot compare the X coordinates since they are on different domains
66 ksteube 1866 def domainsEqual(self, m1, m2, nft=100):
67 jfenwick 3551 self.assertTrue(m1.getDim() == m2.getDim(), "Dimensions differ")
68     self.assertTrue(m1.getNumDataPointsGlobal() == m2.getNumDataPointsGlobal(), "Num data points differ")
69 ksteube 1772 for tagName in m1.showTagNames().split(", "):
70 jfenwick 3551 self.assertTrue(m2.isValidTagName(tagName), "m1 has a tag '%s' not present in m2" % tagName)
71 ksteube 1772 for tagName in m2.showTagNames().split(", "):
72 jfenwick 3551 self.assertTrue(m1.isValidTagName(tagName), "m2 has a tag '%s' not present in m1" % tagName)
73     self.assertTrue(m1.getTag(tagName) == m2.getTag(tagName), "values of tag '%s' differ" % tagName)
74 ksteube 1805 for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "ContinuousFunction", "ReducedContinuousFunction"]:
75 ksteube 1772 fs1 = eval("%s(m1)" % fs)
76     fs2 = eval("%s(m2)" % fs)
77     x1 = fs1.getX()
78     x2 = fs2.getX()
79     for n in range(1, nft+1):
80     integ1 = integrate(sin(n*x1))
81     integ2 = integrate(sin(n*x2))
82 jfenwick 3551 self.assertTrue(Lsup(abs(integ1-integ2)) <= REL_TOL, "integrals for n=%d differ" % n)
83 ksteube 1772 return True
84    
85 ksteube 1754 # Does optimize=True change Rectangle for order=1?
86     def test_Rectangle_optimize_order1(self):
87 jfenwick 3892 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
88     mydomain2 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=True)
89 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
90 ksteube 1754
91     # Does optimize=True change Rectangle for order=2?
92 jfenwick 3114 #def test_Rectangle_optimize_order2(self):
93 jfenwick 3892 #mydomain1 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=False)
94     #mydomain2 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=True)
95 jfenwick 3114 #self.domainsEqual(mydomain1, mydomain2)
96 ksteube 1754
97 gross 2722 # Does optimize=True change Rectangle for order=-1?
98     def test_Rectangle_optimize_macro(self):
99 jfenwick 3892 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=-1, l0=1., l1=1., optimize=False)
100     mydomain2 = Rectangle(n0=NE0, n1=NE1, order=-1, l0=1., l1=1., optimize=True)
101 gross 2722 self.domainsEqual(mydomain1, mydomain2)
102    
103 ksteube 1754 # Does optimize=True change Brick for order=1?
104     def test_Brick_optimize_order1(self):
105 jfenwick 3892 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
106     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=True)
107 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
108 ksteube 1754
109     # Does optimize=True change Brick for order=2?
110 jfenwick 3114 #def test_Brick_optimize_order2(self):
111 jfenwick 3892 #mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
112     #mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=True)
113 jfenwick 3114 #self.domainsEqual(mydomain1, mydomain2)
114 gross 2722 # Does optimize=True change Brick for order=-1?
115     def test_Brick_optimize_macro(self):
116 jfenwick 3892 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=-1, l0=1., l1=1., l2=1., optimize=False)
117     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=-1, l0=1., l1=1., l2=1., optimize=True)
118 gross 2722 self.domainsEqual(mydomain1, mydomain2)
119 ksteube 1754
120 ksteube 1805 def test_data_dump_to_NetCDF_rectangle(self):
121 jfenwick 3892 if loadIsConfigured():
122     mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
123     d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
124     d1.expand()
125     dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.dump.nc")
126     d1.dump(dumpfile)
127     d2=load(dumpfile, mydomain1)
128 jfenwick 3551 self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
129 ksteube 1805
130     def test_data_dump_to_NetCDF_brick(self):
131 jfenwick 3892 if loadIsConfigured():
132     mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
133     d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
134     d1.expand()
135     dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.dump.nc")
136     d1.dump(dumpfile)
137     d2=load(dumpfile, mydomain1)
138 jfenwick 3551 self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
139 ksteube 1805
140 ksteube 1755 def test_mesh_dump_to_NetCDF_rectangle(self):
141 jfenwick 3892 if loadIsConfigured():
142     mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
143     dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.mesh.nc")
144     mydomain1.dump(dumpfile)
145     mydomain2=LoadMesh(dumpfile)
146 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
147 ksteube 1754
148 jfenwick 3934
149     def test_gmshTags(self):
150 jfenwick 3941 if getEscriptParamInt('MPIBUILD',0)==0:
151 gross 4024 dom=ReadGmsh(os.path.join(DUDLEY_TEST_MESH_PATH, "tagtest.msh"),2)
152     tags=dom.showTagNames().split(', ')
153     self.assertEqual(tags,['tag1','tag2', 'tag3'],'error with tags')
154     self.assertEqual(dom.getTag('tag1'),1,'error with tag1')
155     self.assertEqual(dom.getTag('tag2'),2,'error with tag2')
156     self.assertEqual(dom.getTag('tag3'),3,'error with tag3')
157     self.assertRaises(RuntimeError, dom.getTag, 'tag4')
158    
159 jfenwick 3941 else:
160 jfenwick 4019 print("Test supressed due to MPI build")
161 gross 4024 def test_flyTags(self):
162     dom=ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH, "tagtest2.fly"))
163     tags=dom.showTagNames().split(', ')
164     self.assertEqual(tags,['tag1', 'tag2', 'tag3', 'tag4', 'All'])
165     self.assertEqual(dom.getTag('tag1'),5,'error with tag1')
166     self.assertEqual(dom.getTag('tag2'),8,'error with tag2,')
167     self.assertEqual(dom.getTag('tag3'),6,'error with tag3')
168     self.assertEqual(dom.getTag('tag4'),7,'error with tag4')
169     self.assertEqual(dom.getTag('All'),10,'error with All')
170     self.assertRaises(RuntimeError, dom.getTag, 'tag6')
171 jfenwick 3934
172 ksteube 1777 def test_mesh_dump_to_NetCDF_brick(self):
173 jfenwick 3892 if loadIsConfigured():
174     mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
175     dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.mesh.nc")
176     mydomain1.dump(dumpfile)
177     mydomain2=LoadMesh(dumpfile)
178 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
179 ksteube 1755
180 jfenwick 3114 def fixme_test_mesh_read_rectangle_from_dudley_file(self):
181 jfenwick 3892 if getMPISizeWorld() < 16:
182     mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
183 jfenwick 3085 mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"rectangle_8x10.fly"))
184 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
185 ksteube 1772
186 jfenwick 3114 def fixme_test_mesh_read_brick_from_dudley_file(self):
187 jfenwick 3892 if getMPISizeWorld() < 16:
188 ksteube 1805 mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
189 jfenwick 3085 mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"brick_8x10x12.fly"))
190 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
191 ksteube 1772
192 ksteube 1754 if __name__ == '__main__':
193     suite = unittest.TestSuite()
194     suite.addTest(unittest.makeSuite(InputOutput))
195     s=unittest.TextTestRunner(verbosity=2).run(suite)
196     if not s.wasSuccessful(): sys.exit(1)
197    

  ViewVC Help
Powered by ViewVC 1.1.26