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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4984 - (show annotations)
Mon Jun 2 02:50:34 2014 UTC (4 years, 10 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
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2014 by 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
18
19 __copyright__="""Copyright (c) 2003-2014 by 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 """
27 Test suite for input and output of meshes and data objects
28
29 :remark:
30
31 :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 """
37
38 import esys.escriptcore.utestselect as unittest, sys
39 from esys.escriptcore.testing import *
40 from esys.escript import *
41 from esys.finley import Rectangle, Brick, LoadMesh, ReadMesh, GetMeshFromFile, ReadGmsh
42
43 try:
44 FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']
45 except KeyError:
46 FINLEY_WORKDIR='.'
47
48 try:
49 FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
50 except KeyError:
51 FINLEY_TEST_DATA='.'
52
53 FINLEY_TEST_MESH_PATH=os.path.join(FINLEY_TEST_DATA,"data_meshes")
54
55 REL_TOL=1.e-6
56
57 # Number of elements scales up with number of MPI processes
58 mpisize = getMPISizeWorld()
59 NE0 = 7 * mpisize
60 NE1 = 11
61 NE2 = 5
62
63 class InputOutput(unittest.TestCase):
64
65 # Check that two domains are equal using Fourier integrals
66 # We cannot compare the X coordinates since they are on different domains
67 def domainsEqual(self, m1, m2, nft=100):
68 self.assertTrue(m1.getDim() == m2.getDim(), "Dimensions differ")
69 self.assertTrue(m1.getNumDataPointsGlobal() == m2.getNumDataPointsGlobal(), "Num data points differ")
70 for tagName in m1.showTagNames().split(", "):
71 self.assertTrue(m2.isValidTagName(tagName), "m1 has a tag '%s' not present in m2" % tagName)
72 for tagName in m2.showTagNames().split(", "):
73 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 for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "ContinuousFunction", "ReducedContinuousFunction"]:
76 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 self.assertTrue(Lsup(abs(integ1-integ2)) <= REL_TOL, "integrals for n=%d differ" % n)
84 return True
85
86 # Does optimize=True change Rectangle for order=1?
87 def test_Rectangle_optimize_order1(self):
88 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 self.domainsEqual(mydomain1, mydomain2)
91
92 # Does optimize=True change Rectangle for order=2?
93 def test_Rectangle_optimize_order2(self):
94 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 self.domainsEqual(mydomain1, mydomain2)
97
98 # Does optimize=True change Rectangle for order=-1?
99 def test_Rectangle_optimize_macro(self):
100 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 self.domainsEqual(mydomain1, mydomain2)
103
104 # Does optimize=True change Brick for order=1?
105 def test_Brick_optimize_order1(self):
106 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 self.domainsEqual(mydomain1, mydomain2)
109
110 # Does optimize=True change Brick for order=2?
111 def test_Brick_optimize_order2(self):
112 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 self.domainsEqual(mydomain1, mydomain2)
115 # Does optimize=True change Brick for order=-1?
116 def test_Brick_optimize_macro(self):
117 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 self.domainsEqual(mydomain1, mydomain2)
120
121 def test_data_dump_to_NetCDF_rectangle(self):
122 if loadIsConfigured():
123 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False,useElementsOnFace=0)
124 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 self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
130
131 def test_data_dump_to_NetCDF_brick(self):
132 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 self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
140
141 def test_mesh_dump_to_NetCDF_rectangle(self):
142 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 self.domainsEqual(mydomain1, mydomain2)
148
149 @unittest.skipIf(mpisize>1, "more than 1 MPI rank")
150 def test_gmshTags(self):
151 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 tags=sorted(dom.showTagNames().split(', '))
162 self.assertEqual(tags,sorted(['top', 'bottom', 'left', 'right']))
163 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
169
170 def test_mesh_dump_to_NetCDF_brick(self):
171 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 self.domainsEqual(mydomain1, mydomain2)
177
178 @unittest.skipIf(mpisize>15, "more than 15 MPI ranks")
179 def test_mesh_read_rectangle_from_finley_file(self):
180 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
184 @unittest.skipIf(mpisize>15, "more than 15 MPI ranks")
185 def test_mesh_read_brick_from_finley_file(self):
186 mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
187 mydomain2 = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH,"brick_8x10x12.fly"))
188 self.domainsEqual(mydomain1, mydomain2)
189
190 @unittest.skipIf(mpisize>1, "more than 1 MPI rank")
191 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
198 if __name__ == '__main__':
199 run_tests(__name__, exit_on_failure=True)
200

  ViewVC Help
Powered by ViewVC 1.1.26