/[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 3892 - (show annotations)
Tue Apr 10 08:57:23 2012 UTC (6 years, 9 months ago) by jfenwick
File MIME type: text/x-python
File size: 7349 byte(s)
Merged changes across from the attempt2 branch.
This version builds and passes python2 tests.
It also passes most python3 tests.



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

  ViewVC Help
Powered by ViewVC 1.1.26