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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6743 - (show annotations)
Mon Nov 12 01:03:04 2018 UTC (5 months 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
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2018 by The University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Apache License, version 2.0
9 # http://www.apache.org/licenses/LICENSE-2.0
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, division
18
19 __copyright__="""Copyright (c) 2003-2018 by The University of Queensland
20 http://www.uq.edu.au
21 Primary Business: Queensland, Australia"""
22 __license__="""Licensed under the Apache License, version 2.0
23 http://www.apache.org/licenses/LICENSE-2.0"""
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.dudley import Rectangle, Brick, LoadMesh, ReadMesh, ReadGmsh
42 import os as os
43
44 try:
45 DUDLEY_WORKDIR=os.environ['DUDLEY_WORKDIR']
46 except KeyError:
47 DUDLEY_WORKDIR=os.path.join(os.getcwd(),"dudley/test/")
48
49 try:
50 DUDLEY_TEST_DATA=os.environ['DUDLEY_TEST_DATA']
51 except KeyError:
52 DUDLEY_TEST_DATA=os.path.join(os.getcwd(), "dudley/test/python")
53
54 DUDLEY_TEST_MESH_PATH=os.path.join(DUDLEY_TEST_DATA,"data_meshes")
55
56 REL_TOL=1.e-6
57
58 # Number of elements scales up with number of MPI processes
59 NE0 = 7 * getMPISizeWorld()
60 NE1 = 11
61 NE2 = 5
62
63 class Test_InputOutputOnDudley(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)
89 mydomain2 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=True)
90 self.domainsEqual(mydomain1, mydomain2)
91
92 # Does optimize=True change Brick for order=1?
93 def test_Brick_optimize_order1(self):
94 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 self.domainsEqual(mydomain1, mydomain2)
97
98 @unittest.skipIf(not loadIsConfigured(), "loading not configured")
99 def test_data_dump_to_NetCDF_rectangle(self):
100 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
108 @unittest.skipIf(not loadIsConfigured(), "loading not configured")
109 def test_data_dump_to_NetCDF_brick(self):
110 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
118 @unittest.skipIf(not loadIsConfigured() or getMPISizeWorld()>1, "loading not configured or mpisize > 1")
119 def test_mesh_dump_to_NetCDF_rectangle(self):
120 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
126 @unittest.skipIf(getMPISizeWorld()>1, "number of MPI ranks > 1")
127 def test_gmshTags(self):
128 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 self.assertRaises(ValueError, dom.getTag, 'tag4')
135
136 def test_flyTags(self):
137 dom=ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH, "tagtest2.fly"))
138 tags=sorted(dom.showTagNames().split(', '))
139 self.assertEqual(tags,sorted(['tag1', 'tag2', 'tag3', 'tag4', 'All']))
140 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 self.assertRaises(ValueError, dom.getTag, 'tag6')
146
147 @unittest.skipIf(not loadIsConfigured() or getMPISizeWorld()>1, "loading not configured or mpisize > 1")
148 def test_mesh_dump_to_NetCDF_brick(self):
149 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
155 @unittest.skipIf(getMPISizeWorld() >= 16, "Too many MPI processes")
156 def fixme_test_mesh_read_rectangle_from_dudley_file(self):
157 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
161 @unittest.skipIf(getMPISizeWorld() >= 16, "Too many MPI processes")
162 def fixme_test_mesh_read_brick_from_dudley_file(self):
163 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
167 if __name__ == '__main__':
168 run_tests(__name__, exit_on_failure=True)

  ViewVC Help
Powered by ViewVC 1.1.26