/[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 6743 - (hide annotations)
Mon Nov 12 01:03:04 2018 UTC (5 months, 1 week ago) by aellery
File MIME type: text/x-python
File size: 7672 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 caltinay 6119 from esys.dudley import Rectangle, Brick, LoadMesh, ReadMesh, ReadGmsh
42 aellery 6734 import os as os
43 ksteube 1754
44     try:
45 caltinay 3349 DUDLEY_WORKDIR=os.environ['DUDLEY_WORKDIR']
46     except KeyError:
47 aellery 6743 DUDLEY_WORKDIR=os.path.join(os.getcwd(),"dudley/test/")
48 caltinay 3349
49     try:
50 jfenwick 3085 DUDLEY_TEST_DATA=os.environ['DUDLEY_TEST_DATA']
51 ksteube 1754 except KeyError:
52 aellery 6733 DUDLEY_TEST_DATA=os.path.join(os.getcwd(), "dudley/test/python")
53 ksteube 1754
54 jfenwick 3085 DUDLEY_TEST_MESH_PATH=os.path.join(DUDLEY_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     NE0 = 7 * getMPISizeWorld()
60     NE1 = 11
61     NE2 = 5
62    
63 caltinay 6281 class Test_InputOutputOnDudley(unittest.TestCase):
64 ksteube 1754
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 3892 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
89     mydomain2 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=True)
90 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
91 ksteube 1754
92     # Does optimize=True change Brick for order=1?
93     def test_Brick_optimize_order1(self):
94 jfenwick 3892 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
95     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=True)
96 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
97 ksteube 1754
98 sshaw 5055 @unittest.skipIf(not loadIsConfigured(), "loading not configured")
99 ksteube 1805 def test_data_dump_to_NetCDF_rectangle(self):
100 sshaw 5055 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
101     d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
102     d1.expand()
103     dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.dump.nc")
104     d1.dump(dumpfile)
105     d2=load(dumpfile, mydomain1)
106     self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
107 ksteube 1805
108 sshaw 5055 @unittest.skipIf(not loadIsConfigured(), "loading not configured")
109 ksteube 1805 def test_data_dump_to_NetCDF_brick(self):
110 sshaw 5055 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
111     d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
112     d1.expand()
113     dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.dump.nc")
114     d1.dump(dumpfile)
115     d2=load(dumpfile, mydomain1)
116     self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
117 ksteube 1805
118 aellery 6738 @unittest.skipIf(not loadIsConfigured() or getMPISizeWorld()>1, "loading not configured or mpisize > 1")
119 ksteube 1755 def test_mesh_dump_to_NetCDF_rectangle(self):
120 sshaw 5055 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
121     dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.mesh.nc")
122     mydomain1.dump(dumpfile)
123     mydomain2=LoadMesh(dumpfile)
124     self.domainsEqual(mydomain1, mydomain2)
125 ksteube 1754
126 caltinay 6132 @unittest.skipIf(getMPISizeWorld()>1, "number of MPI ranks > 1")
127 jfenwick 3934 def test_gmshTags(self):
128 gross 4024 dom=ReadGmsh(os.path.join(DUDLEY_TEST_MESH_PATH, "tagtest.msh"),2)
129     tags=dom.showTagNames().split(', ')
130     self.assertEqual(tags,['tag1','tag2', 'tag3'],'error with tags')
131     self.assertEqual(dom.getTag('tag1'),1,'error with tag1')
132     self.assertEqual(dom.getTag('tag2'),2,'error with tag2')
133     self.assertEqual(dom.getTag('tag3'),3,'error with tag3')
134 caltinay 5984 self.assertRaises(ValueError, dom.getTag, 'tag4')
135 gross 4024
136     def test_flyTags(self):
137     dom=ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH, "tagtest2.fly"))
138 caltinay 6119 tags=sorted(dom.showTagNames().split(', '))
139     self.assertEqual(tags,sorted(['tag1', 'tag2', 'tag3', 'tag4', 'All']))
140 gross 4024 self.assertEqual(dom.getTag('tag1'),5,'error with tag1')
141     self.assertEqual(dom.getTag('tag2'),8,'error with tag2,')
142     self.assertEqual(dom.getTag('tag3'),6,'error with tag3')
143     self.assertEqual(dom.getTag('tag4'),7,'error with tag4')
144     self.assertEqual(dom.getTag('All'),10,'error with All')
145 caltinay 5984 self.assertRaises(ValueError, dom.getTag, 'tag6')
146 jfenwick 3934
147 aellery 6738 @unittest.skipIf(not loadIsConfigured() or getMPISizeWorld()>1, "loading not configured or mpisize > 1")
148 ksteube 1777 def test_mesh_dump_to_NetCDF_brick(self):
149 sshaw 5055 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
150     dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.mesh.nc")
151     mydomain1.dump(dumpfile)
152     mydomain2=LoadMesh(dumpfile)
153     self.domainsEqual(mydomain1, mydomain2)
154 ksteube 1755
155 sshaw 5055 @unittest.skipIf(getMPISizeWorld() >= 16, "Too many MPI processes")
156 jfenwick 3114 def fixme_test_mesh_read_rectangle_from_dudley_file(self):
157 sshaw 5055 mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
158     mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"rectangle_8x10.fly"))
159     self.domainsEqual(mydomain1, mydomain2)
160 ksteube 1772
161 sshaw 5055 @unittest.skipIf(getMPISizeWorld() >= 16, "Too many MPI processes")
162 jfenwick 3114 def fixme_test_mesh_read_brick_from_dudley_file(self):
163 sshaw 5055 mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
164     mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"brick_8x10x12.fly"))
165     self.domainsEqual(mydomain1, mydomain2)
166 ksteube 1772
167 ksteube 1754 if __name__ == '__main__':
168 sshaw 4984 run_tests(__name__, exit_on_failure=True)

  ViewVC Help
Powered by ViewVC 1.1.26