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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4984 - (hide annotations)
Mon Jun 2 02:50:34 2014 UTC (4 years, 11 months ago) by sshaw
File MIME type: text/x-python
File size: 9333 byte(s)
revamping testrunners, now uses automated discovery and allows running specific tests without modifying files (see escriptcore/py_src/testing.py for more info/examples)

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 sshaw 4984 from esys.escriptcore.testing import *
40 ksteube 1754 from esys.escript import *
41 jfenwick 3934 from esys.finley import Rectangle, Brick, LoadMesh, ReadMesh, GetMeshFromFile, ReadGmsh
42 ksteube 1754
43     try:
44 caltinay 3349 FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']
45     except KeyError:
46     FINLEY_WORKDIR='.'
47    
48     try:
49 ksteube 1754 FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
50     except KeyError:
51     FINLEY_TEST_DATA='.'
52    
53 gross 2416 FINLEY_TEST_MESH_PATH=os.path.join(FINLEY_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 caltinay 4437 mpisize = getMPISizeWorld()
59     NE0 = 7 * mpisize
60 ksteube 1805 NE1 = 11
61     NE2 = 5
62    
63 ksteube 1754 class InputOutput(unittest.TestCase):
64    
65 ksteube 1805 # Check that two domains are equal using Fourier integrals
66     # We cannot compare the X coordinates since they are on different domains
67 ksteube 1866 def domainsEqual(self, m1, m2, nft=100):
68 jfenwick 3551 self.assertTrue(m1.getDim() == m2.getDim(), "Dimensions differ")
69     self.assertTrue(m1.getNumDataPointsGlobal() == m2.getNumDataPointsGlobal(), "Num data points differ")
70 ksteube 1772 for tagName in m1.showTagNames().split(", "):
71 jfenwick 3551 self.assertTrue(m2.isValidTagName(tagName), "m1 has a tag '%s' not present in m2" % tagName)
72 ksteube 1772 for tagName in m2.showTagNames().split(", "):
73 jfenwick 3551 self.assertTrue(m1.isValidTagName(tagName), "m2 has a tag '%s' not present in m1" % tagName)
74     self.assertTrue(m1.getTag(tagName) == m2.getTag(tagName), "values of tag '%s' differ" % tagName)
75 ksteube 1805 for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "ContinuousFunction", "ReducedContinuousFunction"]:
76 ksteube 1772 fs1 = eval("%s(m1)" % fs)
77     fs2 = eval("%s(m2)" % fs)
78     x1 = fs1.getX()
79     x2 = fs2.getX()
80     for n in range(1, nft+1):
81     integ1 = integrate(sin(n*x1))
82     integ2 = integrate(sin(n*x2))
83 jfenwick 3551 self.assertTrue(Lsup(abs(integ1-integ2)) <= REL_TOL, "integrals for n=%d differ" % n)
84 ksteube 1772 return True
85    
86 ksteube 1754 # Does optimize=True change Rectangle for order=1?
87     def test_Rectangle_optimize_order1(self):
88 jfenwick 3901 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False,useElementsOnFace=0)
89     mydomain2 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=True,useElementsOnFace=0)
90 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
91 ksteube 1754
92     # Does optimize=True change Rectangle for order=2?
93 ksteube 1829 def test_Rectangle_optimize_order2(self):
94 jfenwick 3901 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=False,useElementsOnFace=0)
95     mydomain2 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=True,useElementsOnFace=0)
96 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
97 ksteube 1754
98 gross 2722 # Does optimize=True change Rectangle for order=-1?
99     def test_Rectangle_optimize_macro(self):
100 jfenwick 3901 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=-1, l0=1., l1=1., optimize=False, useElementsOnFace=0)
101     mydomain2 = Rectangle(n0=NE0, n1=NE1, order=-1, l0=1., l1=1., optimize=True,useElementsOnFace=0)
102 gross 2722 self.domainsEqual(mydomain1, mydomain2)
103    
104 ksteube 1754 # Does optimize=True change Brick for order=1?
105     def test_Brick_optimize_order1(self):
106 jfenwick 3901 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False,useElementsOnFace=0)
107     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=True,useElementsOnFace=0)
108 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
109 ksteube 1754
110     # Does optimize=True change Brick for order=2?
111 ksteube 1829 def test_Brick_optimize_order2(self):
112 jfenwick 3901 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False,useElementsOnFace=0)
113     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=True,useElementsOnFace=0)
114 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
115 gross 2722 # Does optimize=True change Brick for order=-1?
116     def test_Brick_optimize_macro(self):
117 jfenwick 3901 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=-1, l0=1., l1=1., l2=1., optimize=False,useElementsOnFace=0)
118     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=-1, l0=1., l1=1., l2=1., optimize=True,useElementsOnFace=0)
119 gross 2722 self.domainsEqual(mydomain1, mydomain2)
120 ksteube 1754
121 ksteube 1805 def test_data_dump_to_NetCDF_rectangle(self):
122 jfenwick 3892 if loadIsConfigured():
123 jfenwick 3901 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False,useElementsOnFace=0)
124 jfenwick 3892 d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
125     d1.expand()
126     dumpfile=os.path.join(FINLEY_WORKDIR, "tempfile.dump.nc")
127     d1.dump(dumpfile)
128     d2=load(dumpfile, mydomain1)
129 jfenwick 3551 self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
130 ksteube 1805
131     def test_data_dump_to_NetCDF_brick(self):
132 jfenwick 3892 if loadIsConfigured():
133     mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
134     d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
135     d1.expand()
136     dumpfile=os.path.join(FINLEY_WORKDIR, "tempfile.dump.nc")
137     d1.dump(dumpfile)
138     d2=load(dumpfile, mydomain1)
139 jfenwick 3551 self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
140 ksteube 1805
141 ksteube 1755 def test_mesh_dump_to_NetCDF_rectangle(self):
142 jfenwick 3892 if loadIsConfigured():
143     mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
144     dumpfile=os.path.join(FINLEY_WORKDIR, "tempfile.mesh.nc")
145     mydomain1.dump(dumpfile)
146     mydomain2=LoadMesh(dumpfile)
147 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
148 ksteube 1754
149 caltinay 4437 @unittest.skipIf(mpisize>1, "more than 1 MPI rank")
150 jfenwick 3934 def test_gmshTags(self):
151 gross 4024 dom=ReadGmsh(os.path.join(FINLEY_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     def test_flyTags(self):
160     dom=ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "rectangle_8x10.fly"))
161 caltinay 4437 tags=sorted(dom.showTagNames().split(', '))
162     self.assertEqual(tags,sorted(['top', 'bottom', 'left', 'right']))
163 gross 4024 self.assertEqual(dom.getTag('top'),20,'error with top')
164     self.assertEqual(dom.getTag('bottom'),10,'error with bottom,')
165     self.assertEqual(dom.getTag('left'),1,'error with left')
166     self.assertEqual(dom.getTag('right'),2,'error with reight')
167     self.assertRaises(RuntimeError, dom.getTag, 'tag4')
168 jfenwick 3934
169 gross 4024
170 ksteube 1777 def test_mesh_dump_to_NetCDF_brick(self):
171 jfenwick 3892 if loadIsConfigured():
172     mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
173     dumpfile=os.path.join(FINLEY_WORKDIR, "tempfile.mesh.nc")
174     mydomain1.dump(dumpfile)
175     mydomain2=LoadMesh(dumpfile)
176 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
177 ksteube 1755
178 caltinay 4437 @unittest.skipIf(mpisize>15, "more than 15 MPI ranks")
179 ksteube 1772 def test_mesh_read_rectangle_from_finley_file(self):
180 caltinay 4437 mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
181     mydomain2 = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH,"rectangle_8x10.fly"))
182     self.domainsEqual(mydomain1, mydomain2)
183 ksteube 1772
184 caltinay 4437 @unittest.skipIf(mpisize>15, "more than 15 MPI ranks")
185 ksteube 1772 def test_mesh_read_brick_from_finley_file(self):
186 ksteube 1805 mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
187 gross 2416 mydomain2 = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH,"brick_8x10x12.fly"))
188 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
189 caltinay 4437
190     @unittest.skipIf(mpisize>1, "more than 1 MPI rank")
191 jfenwick 3912 def test_GetMeshFromFile(self):
192     m=GetMeshFromFile(os.path.join(FINLEY_TEST_MESH_PATH,'tet10_gmsh.msh'), numDim=3)
193     del m
194     m=GetMeshFromFile(os.path.join(FINLEY_TEST_MESH_PATH, 'tet10.fly'))
195     # now we try some params
196     m=GetMeshFromFile(os.path.join(FINLEY_TEST_MESH_PATH,'tet10_gmsh.msh'), numDim=3, integrationOrder=2)
197 ksteube 1772
198 ksteube 1754 if __name__ == '__main__':
199 sshaw 4984 run_tests(__name__, exit_on_failure=True)
200 ksteube 1754

  ViewVC Help
Powered by ViewVC 1.1.26