/[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 4019 - (show annotations)
Thu Oct 11 08:12:55 2012 UTC (6 years, 8 months ago) by jfenwick
File MIME type: text/x-python
File size: 7770 byte(s)
More tabbing errors,
range/xrange
...
1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2012 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 since 2012 by School of Earth Sciences
13 #
14 ##############################################################################
15
16 from __future__ import print_function
17
18 __copyright__="""Copyright (c) 2003-2012 by University of Queensland
19 http://www.uq.edu.au
20 Primary Business: Queensland, Australia"""
21 __license__="""Licensed under the Open Software License version 3.0
22 http://www.opensource.org/licenses/osl-3.0.php"""
23 __url__="https://launchpad.net/escript-finley"
24
25 """
26 Test suite for input and output of meshes and data objects
27
28 :remark:
29
30 :var __author__: name of author
31 :var __licence__: licence agreement
32 :var __url__: url entry point on documentation
33 :var __version__: version
34 :var __date__: date of the version
35 """
36
37 import unittest, sys
38
39 from esys.escript import *
40 from esys.dudley import Rectangle, Brick, LoadMesh, ReadMesh, ReadGmsh, ReadGmsh
41
42 try:
43 DUDLEY_WORKDIR=os.environ['DUDLEY_WORKDIR']
44 except KeyError:
45 DUDLEY_WORKDIR='.'
46
47 try:
48 DUDLEY_TEST_DATA=os.environ['DUDLEY_TEST_DATA']
49 except KeyError:
50 DUDLEY_TEST_DATA='.'
51
52 DUDLEY_TEST_MESH_PATH=os.path.join(DUDLEY_TEST_DATA,"data_meshes")
53
54 REL_TOL=1.e-6
55
56 # Number of elements scales up with number of MPI processes
57 NE0 = 7 * getMPISizeWorld()
58 NE1 = 11
59 NE2 = 5
60
61 class InputOutput(unittest.TestCase):
62
63 # Check that two domains are equal using Fourier integrals
64 # We cannot compare the X coordinates since they are on different domains
65 def domainsEqual(self, m1, m2, nft=100):
66 self.assertTrue(m1.getDim() == m2.getDim(), "Dimensions differ")
67 self.assertTrue(m1.getNumDataPointsGlobal() == m2.getNumDataPointsGlobal(), "Num data points differ")
68 for tagName in m1.showTagNames().split(", "):
69 self.assertTrue(m2.isValidTagName(tagName), "m1 has a tag '%s' not present in m2" % tagName)
70 for tagName in m2.showTagNames().split(", "):
71 self.assertTrue(m1.isValidTagName(tagName), "m2 has a tag '%s' not present in m1" % tagName)
72 self.assertTrue(m1.getTag(tagName) == m2.getTag(tagName), "values of tag '%s' differ" % tagName)
73 for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "ContinuousFunction", "ReducedContinuousFunction"]:
74 fs1 = eval("%s(m1)" % fs)
75 fs2 = eval("%s(m2)" % fs)
76 x1 = fs1.getX()
77 x2 = fs2.getX()
78 for n in range(1, nft+1):
79 integ1 = integrate(sin(n*x1))
80 integ2 = integrate(sin(n*x2))
81 self.assertTrue(Lsup(abs(integ1-integ2)) <= REL_TOL, "integrals for n=%d differ" % n)
82 return True
83
84 # Does optimize=True change Rectangle for order=1?
85 def test_Rectangle_optimize_order1(self):
86 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
87 mydomain2 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=True)
88 self.domainsEqual(mydomain1, mydomain2)
89
90 # Does optimize=True change Rectangle for order=2?
91 #def test_Rectangle_optimize_order2(self):
92 #mydomain1 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=False)
93 #mydomain2 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=True)
94 #self.domainsEqual(mydomain1, mydomain2)
95
96 # Does optimize=True change Rectangle for order=-1?
97 def test_Rectangle_optimize_macro(self):
98 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=-1, l0=1., l1=1., optimize=False)
99 mydomain2 = Rectangle(n0=NE0, n1=NE1, order=-1, l0=1., l1=1., optimize=True)
100 self.domainsEqual(mydomain1, mydomain2)
101
102 # Does optimize=True change Brick for order=1?
103 def test_Brick_optimize_order1(self):
104 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
105 mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=True)
106 self.domainsEqual(mydomain1, mydomain2)
107
108 # Does optimize=True change Brick for order=2?
109 #def test_Brick_optimize_order2(self):
110 #mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
111 #mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=True)
112 #self.domainsEqual(mydomain1, mydomain2)
113 # Does optimize=True change Brick for order=-1?
114 def test_Brick_optimize_macro(self):
115 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=-1, l0=1., l1=1., l2=1., optimize=False)
116 mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=-1, l0=1., l1=1., l2=1., optimize=True)
117 self.domainsEqual(mydomain1, mydomain2)
118
119 def test_data_dump_to_NetCDF_rectangle(self):
120 if loadIsConfigured():
121 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
122 d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
123 d1.expand()
124 dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.dump.nc")
125 d1.dump(dumpfile)
126 d2=load(dumpfile, mydomain1)
127 self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
128
129 def test_data_dump_to_NetCDF_brick(self):
130 if loadIsConfigured():
131 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
132 d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
133 d1.expand()
134 dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.dump.nc")
135 d1.dump(dumpfile)
136 d2=load(dumpfile, mydomain1)
137 self.assertTrue(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
138
139 def test_mesh_dump_to_NetCDF_rectangle(self):
140 if loadIsConfigured():
141 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
142 dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.mesh.nc")
143 mydomain1.dump(dumpfile)
144 mydomain2=LoadMesh(dumpfile)
145 self.domainsEqual(mydomain1, mydomain2)
146
147
148 def test_gmshTags(self):
149 if getEscriptParamInt('MPIBUILD',0)==0:
150 tags=ReadGmsh(os.path.join(DUDLEY_TEST_MESH_PATH, "tagtest.fly"),2).showTagNames()
151 self.assertEqual(tags,'tag1, tag2, tag3','error with tags')
152 else:
153 print("Test supressed due to MPI build")
154
155 def test_mesh_dump_to_NetCDF_brick(self):
156 if loadIsConfigured():
157 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
158 dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.mesh.nc")
159 mydomain1.dump(dumpfile)
160 mydomain2=LoadMesh(dumpfile)
161 self.domainsEqual(mydomain1, mydomain2)
162
163 def fixme_test_mesh_read_rectangle_from_dudley_file(self):
164 if getMPISizeWorld() < 16:
165 mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
166 mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"rectangle_8x10.fly"))
167 self.domainsEqual(mydomain1, mydomain2)
168
169 def fixme_test_mesh_read_brick_from_dudley_file(self):
170 if getMPISizeWorld() < 16:
171 mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
172 mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"brick_8x10x12.fly"))
173 self.domainsEqual(mydomain1, mydomain2)
174
175 if __name__ == '__main__':
176 suite = unittest.TestSuite()
177 suite.addTest(unittest.makeSuite(InputOutput))
178 s=unittest.TextTestRunner(verbosity=2).run(suite)
179 if not s.wasSuccessful(): sys.exit(1)
180

  ViewVC Help
Powered by ViewVC 1.1.26