/[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 3087 - (hide 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 ksteube 1809
2     ########################################################
3 ksteube 1754 #
4 jfenwick 2881 # Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1809 # Earth Systems Science Computational Center (ESSCC)
6     # http://www.uq.edu.au/esscc
7 ksteube 1754 #
8 ksteube 1809 # 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 ksteube 1754 #
12 ksteube 1809 ########################################################
13 ksteube 1754
14 jfenwick 2881 __copyright__="""Copyright (c) 2003-2010 by University of Queensland
15 ksteube 1809 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 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
21 ksteube 1809
22 ksteube 1754 """
23     Test suite for input and output of meshes and data objects
24    
25 jfenwick 2625 :remark:
26 ksteube 1754
27 jfenwick 2625 :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 ksteube 1754 """
33    
34     import unittest, sys
35    
36     from esys.escript import *
37 jfenwick 3085 from esys.dudley import Rectangle, Brick, LoadMesh, ReadMesh
38 ksteube 1754
39     try:
40 jfenwick 3085 DUDLEY_TEST_DATA=os.environ['DUDLEY_TEST_DATA']
41 ksteube 1754 except KeyError:
42 jfenwick 3085 DUDLEY_TEST_DATA='.'
43 ksteube 1754
44 jfenwick 3085 DUDLEY_TEST_MESH_PATH=os.path.join(DUDLEY_TEST_DATA,"data_meshes")
45 ksteube 1754
46     REL_TOL=1.e-6
47    
48 ksteube 1805 # Number of elements scales up with number of MPI processes
49     NE0 = 7 * getMPISizeWorld()
50     NE1 = 11
51     NE2 = 5
52    
53 ksteube 1754 class InputOutput(unittest.TestCase):
54    
55 ksteube 1805 # Check that two domains are equal using Fourier integrals
56     # We cannot compare the X coordinates since they are on different domains
57 ksteube 1866 def domainsEqual(self, m1, m2, nft=100):
58 ksteube 1772 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 ksteube 1805 for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "ContinuousFunction", "ReducedContinuousFunction"]:
66 ksteube 1772 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 ksteube 1754 # Does optimize=True change Rectangle for order=1?
77     def test_Rectangle_optimize_order1(self):
78 ksteube 1805 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 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
81 ksteube 1754
82     # Does optimize=True change Rectangle for order=2?
83 ksteube 1829 def test_Rectangle_optimize_order2(self):
84 ksteube 1805 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 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
87 ksteube 1754
88 gross 2722 # 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 ksteube 1754 # Does optimize=True change Brick for order=1?
95     def test_Brick_optimize_order1(self):
96 ksteube 1805 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 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
99 ksteube 1754
100     # Does optimize=True change Brick for order=2?
101 ksteube 1829 def test_Brick_optimize_order2(self):
102 ksteube 1805 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 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
105 gross 2722 # 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 ksteube 1754
111 ksteube 1805 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 ksteube 1755 def test_mesh_dump_to_NetCDF_rectangle(self):
130 ksteube 1754 if loadIsConfigured():
131 ksteube 1805 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 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
135 ksteube 1754
136 ksteube 1777 def test_mesh_dump_to_NetCDF_brick(self):
137 ksteube 1755 if loadIsConfigured():
138 ksteube 1805 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 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
142 ksteube 1755
143 jfenwick 3087 def test_mesh_read_rectangle_from_dudley_file(self):
144 ksteube 1805 if getMPISizeWorld() < 16:
145     mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
146 jfenwick 3085 mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"rectangle_8x10.fly"))
147 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
148 ksteube 1772
149 jfenwick 3087 def test_mesh_read_brick_from_dudley_file(self):
150 ksteube 1805 if getMPISizeWorld() < 16:
151     mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
152 jfenwick 3085 mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"brick_8x10x12.fly"))
153 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
154 ksteube 1772
155 ksteube 1754 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