/[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 3087 - (show annotations)
Fri Aug 6 05:25:59 2010 UTC (8 years, 8 months ago) by jfenwick
Original Path: branches/domexper/dudley/test/python/run_inputOutput.py
File MIME type: text/x-python
File size: 6796 byte(s)
Contiuneswq
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_TEST_DATA=os.environ['DUDLEY_TEST_DATA']
41 except KeyError:
42 DUDLEY_TEST_DATA='.'
43
44 DUDLEY_TEST_MESH_PATH=os.path.join(DUDLEY_TEST_DATA,"data_meshes")
45
46 REL_TOL=1.e-6
47
48 # Number of elements scales up with number of MPI processes
49 NE0 = 7 * getMPISizeWorld()
50 NE1 = 11
51 NE2 = 5
52
53 class InputOutput(unittest.TestCase):
54
55 # Check that two domains are equal using Fourier integrals
56 # We cannot compare the X coordinates since they are on different domains
57 def domainsEqual(self, m1, m2, nft=100):
58 self.failUnless(m1.getDim() == m2.getDim(), "Dimensions differ")
59 self.failUnless(m1.getNumDataPointsGlobal() == m2.getNumDataPointsGlobal(), "Num data points differ")
60 for tagName in m1.showTagNames().split(", "):
61 self.failUnless(m2.isValidTagName(tagName), "m1 has a tag '%s' not present in m2" % tagName)
62 for tagName in m2.showTagNames().split(", "):
63 self.failUnless(m1.isValidTagName(tagName), "m2 has a tag '%s' not present in m1" % tagName)
64 self.failUnless(m1.getTag(tagName) == m2.getTag(tagName), "values of tag '%s' differ" % tagName)
65 for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "ContinuousFunction", "ReducedContinuousFunction"]:
66 fs1 = eval("%s(m1)" % fs)
67 fs2 = eval("%s(m2)" % fs)
68 x1 = fs1.getX()
69 x2 = fs2.getX()
70 for n in range(1, nft+1):
71 integ1 = integrate(sin(n*x1))
72 integ2 = integrate(sin(n*x2))
73 self.failUnless(Lsup(abs(integ1-integ2)) <= REL_TOL, "integrals for n=%d differ" % n)
74 return True
75
76 # Does optimize=True change Rectangle for order=1?
77 def test_Rectangle_optimize_order1(self):
78 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
79 mydomain2 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=True)
80 self.domainsEqual(mydomain1, mydomain2)
81
82 # Does optimize=True change Rectangle for order=2?
83 def test_Rectangle_optimize_order2(self):
84 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=False)
85 mydomain2 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=True)
86 self.domainsEqual(mydomain1, mydomain2)
87
88 # Does optimize=True change Rectangle for order=-1?
89 def test_Rectangle_optimize_macro(self):
90 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=-1, l0=1., l1=1., optimize=False)
91 mydomain2 = Rectangle(n0=NE0, n1=NE1, order=-1, l0=1., l1=1., optimize=True)
92 self.domainsEqual(mydomain1, mydomain2)
93
94 # Does optimize=True change Brick for order=1?
95 def test_Brick_optimize_order1(self):
96 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
97 mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=True)
98 self.domainsEqual(mydomain1, mydomain2)
99
100 # Does optimize=True change Brick for order=2?
101 def test_Brick_optimize_order2(self):
102 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
103 mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=True)
104 self.domainsEqual(mydomain1, mydomain2)
105 # Does optimize=True change Brick for order=-1?
106 def test_Brick_optimize_macro(self):
107 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=-1, l0=1., l1=1., l2=1., optimize=False)
108 mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=-1, l0=1., l1=1., l2=1., optimize=True)
109 self.domainsEqual(mydomain1, mydomain2)
110
111 def test_data_dump_to_NetCDF_rectangle(self):
112 if loadIsConfigured():
113 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
114 d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
115 d1.expand()
116 d1.dump("tempfile.dump.nc")
117 d2=load("tempfile.dump.nc", mydomain1)
118 self.failUnless(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
119
120 def test_data_dump_to_NetCDF_brick(self):
121 if loadIsConfigured():
122 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
123 d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
124 d1.expand()
125 d1.dump("tempfile.dump.nc")
126 d2=load("tempfile.dump.nc", mydomain1)
127 self.failUnless(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
128
129 def test_mesh_dump_to_NetCDF_rectangle(self):
130 if loadIsConfigured():
131 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
132 mydomain1.dump("tempfile.mesh.nc")
133 mydomain2=LoadMesh("tempfile.mesh.nc")
134 self.domainsEqual(mydomain1, mydomain2)
135
136 def test_mesh_dump_to_NetCDF_brick(self):
137 if loadIsConfigured():
138 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
139 mydomain1.dump("tempfile.mesh.nc")
140 mydomain2=LoadMesh("tempfile.mesh.nc")
141 self.domainsEqual(mydomain1, mydomain2)
142
143 def test_mesh_read_rectangle_from_dudley_file(self):
144 if getMPISizeWorld() < 16:
145 mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
146 mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"rectangle_8x10.fly"))
147 self.domainsEqual(mydomain1, mydomain2)
148
149 def test_mesh_read_brick_from_dudley_file(self):
150 if getMPISizeWorld() < 16:
151 mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
152 mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"brick_8x10x12.fly"))
153 self.domainsEqual(mydomain1, mydomain2)
154
155 if __name__ == '__main__':
156 suite = unittest.TestSuite()
157 suite.addTest(unittest.makeSuite(InputOutput))
158 s=unittest.TextTestRunner(verbosity=2).run(suite)
159 if not s.wasSuccessful(): sys.exit(1)
160

  ViewVC Help
Powered by ViewVC 1.1.26