/[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 6743 - (hide annotations)
Mon Nov 12 01:03:04 2018 UTC (6 months, 1 week ago) by aellery
File MIME type: text/x-python
File size: 9931 byte(s)
I believe that the openMP test fails on several of the buildbots because the environment variables FINLEY_WORKDIR and DUDLEY_WORKDIR are not defined. I have updated dudley/test/python/run_inputOutput.py and finley/test/python/run_inputOutput.py so that when FINLEY_WORKDIR and DUDLEY_WORKDIR are undefined they default to the test directory.


1 ksteube 1809
2 jfenwick 3981 ##############################################################################
3 ksteube 1754 #
4 jfenwick 6651 # Copyright (c) 2003-2018 by The University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 ksteube 1754 #
7 ksteube 1809 # Primary Business: Queensland, Australia
8 jfenwick 6112 # Licensed under the Apache License, version 2.0
9     # http://www.apache.org/licenses/LICENSE-2.0
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 sshaw 5706 from __future__ import print_function, division
18 jfenwick 4019
19 jfenwick 6651 __copyright__="""Copyright (c) 2003-2018 by The University of Queensland
20 jfenwick 3981 http://www.uq.edu.au
21 ksteube 1809 Primary Business: Queensland, Australia"""
22 jfenwick 6112 __license__="""Licensed under the Apache License, version 2.0
23     http://www.apache.org/licenses/LICENSE-2.0"""
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 aellery 6734 import os as os
43 ksteube 1754
44     try:
45 caltinay 3349 FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']
46     except KeyError:
47 aellery 6743 FINLEY_WORKDIR=os.path.join(os.getcwd(),"finley/test/")
48 caltinay 3349
49     try:
50 ksteube 1754 FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
51     except KeyError:
52 aellery 6743 FINLEY_TEST_DATA=os.path.join(os.getcwd(),"finley/test/python")
53 ksteube 1754
54 gross 2416 FINLEY_TEST_MESH_PATH=os.path.join(FINLEY_TEST_DATA,"data_meshes")
55 ksteube 1754
56     REL_TOL=1.e-6
57    
58 ksteube 1805 # Number of elements scales up with number of MPI processes
59 caltinay 4437 mpisize = getMPISizeWorld()
60     NE0 = 7 * mpisize
61 ksteube 1805 NE1 = 11
62     NE2 = 5
63    
64 caltinay 6282 class Test_InputOutputOnFinley(unittest.TestCase):
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 sshaw 5060 @unittest.skipIf(not loadIsConfigured(), "load not configured")
122 ksteube 1805 def test_data_dump_to_NetCDF_rectangle(self):
123 sshaw 5060 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 ksteube 1805
131 sshaw 5060 @unittest.skipIf(not loadIsConfigured(), "load not configured")
132 ksteube 1805 def test_data_dump_to_NetCDF_brick(self):
133 sshaw 5060 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 ksteube 1805
141 aellery 6738 @unittest.skipIf(not loadIsConfigured() or mpisize > 1, "load not configured or mpisize > 1")
142 ksteube 1755 def test_mesh_dump_to_NetCDF_rectangle(self):
143 sshaw 5060 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 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 caltinay 5984 self.assertRaises(ValueError, dom.getTag, 'tag4')
158 aellery 6743
159 jduplessis 5043 @unittest.skipIf(mpisize>1, "more than 1 MPI rank")
160 jduplessis 5032 def test_gmshNamedTags(self):
161     dom=ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH, "test_Add.msh"),3)
162     sigma = Scalar(0,Function(dom))
163     sigma.expand()
164     sigma.setTaggedValue("v5",10)
165     self.assertEqual(Lsup(sigma),10.0,"Named value not set properly")
166    
167 gross 4024 def test_flyTags(self):
168     dom=ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH, "rectangle_8x10.fly"))
169 caltinay 4437 tags=sorted(dom.showTagNames().split(', '))
170     self.assertEqual(tags,sorted(['top', 'bottom', 'left', 'right']))
171 gross 4024 self.assertEqual(dom.getTag('top'),20,'error with top')
172     self.assertEqual(dom.getTag('bottom'),10,'error with bottom,')
173     self.assertEqual(dom.getTag('left'),1,'error with left')
174     self.assertEqual(dom.getTag('right'),2,'error with reight')
175 caltinay 5984 self.assertRaises(ValueError, dom.getTag, 'tag4')
176 jfenwick 3934
177 aellery 6738 @unittest.skipIf(not loadIsConfigured() or mpisize>1, "load not configured or mpisize > 1")
178 ksteube 1777 def test_mesh_dump_to_NetCDF_brick(self):
179 sshaw 5060 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
180     dumpfile=os.path.join(FINLEY_WORKDIR, "tempfile.mesh.nc")
181     mydomain1.dump(dumpfile)
182     mydomain2=LoadMesh(dumpfile)
183     self.domainsEqual(mydomain1, mydomain2)
184 ksteube 1755
185 caltinay 4437 @unittest.skipIf(mpisize>15, "more than 15 MPI ranks")
186 ksteube 1772 def test_mesh_read_rectangle_from_finley_file(self):
187 caltinay 4437 mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
188     mydomain2 = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH,"rectangle_8x10.fly"))
189     self.domainsEqual(mydomain1, mydomain2)
190 ksteube 1772
191 caltinay 4437 @unittest.skipIf(mpisize>15, "more than 15 MPI ranks")
192 ksteube 1772 def test_mesh_read_brick_from_finley_file(self):
193 ksteube 1805 mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
194 gross 2416 mydomain2 = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH,"brick_8x10x12.fly"))
195 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
196 caltinay 4437
197     @unittest.skipIf(mpisize>1, "more than 1 MPI rank")
198 jfenwick 3912 def test_GetMeshFromFile(self):
199     m=GetMeshFromFile(os.path.join(FINLEY_TEST_MESH_PATH,'tet10_gmsh.msh'), numDim=3)
200     del m
201     m=GetMeshFromFile(os.path.join(FINLEY_TEST_MESH_PATH, 'tet10.fly'))
202     # now we try some params
203     m=GetMeshFromFile(os.path.join(FINLEY_TEST_MESH_PATH,'tet10_gmsh.msh'), numDim=3, integrationOrder=2)
204 ksteube 1772
205 ksteube 1754 if __name__ == '__main__':
206 sshaw 4984 run_tests(__name__, exit_on_failure=True)

  ViewVC Help
Powered by ViewVC 1.1.26