/[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 3349 - (hide annotations)
Mon Nov 15 05:09:56 2010 UTC (8 years, 5 months ago) by caltinay
File MIME type: text/x-python
File size: 7076 byte(s)
escript now supports out-of-tree builds.
All build and test files are now created under a user-definable build_dir
directory.
This also fixes issue 291.
Removed most svn:ignore props since they are no longer required.

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 caltinay 3349 DUDLEY_WORKDIR=os.environ['DUDLEY_WORKDIR']
41     except KeyError:
42     DUDLEY_WORKDIR='.'
43    
44     try:
45 jfenwick 3085 DUDLEY_TEST_DATA=os.environ['DUDLEY_TEST_DATA']
46 ksteube 1754 except KeyError:
47 jfenwick 3085 DUDLEY_TEST_DATA='.'
48 ksteube 1754
49 jfenwick 3085 DUDLEY_TEST_MESH_PATH=os.path.join(DUDLEY_TEST_DATA,"data_meshes")
50 ksteube 1754
51     REL_TOL=1.e-6
52    
53 ksteube 1805 # Number of elements scales up with number of MPI processes
54     NE0 = 7 * getMPISizeWorld()
55     NE1 = 11
56     NE2 = 5
57    
58 ksteube 1754 class InputOutput(unittest.TestCase):
59    
60 ksteube 1805 # Check that two domains are equal using Fourier integrals
61     # We cannot compare the X coordinates since they are on different domains
62 ksteube 1866 def domainsEqual(self, m1, m2, nft=100):
63 ksteube 1772 self.failUnless(m1.getDim() == m2.getDim(), "Dimensions differ")
64     self.failUnless(m1.getNumDataPointsGlobal() == m2.getNumDataPointsGlobal(), "Num data points differ")
65     for tagName in m1.showTagNames().split(", "):
66     self.failUnless(m2.isValidTagName(tagName), "m1 has a tag '%s' not present in m2" % tagName)
67     for tagName in m2.showTagNames().split(", "):
68     self.failUnless(m1.isValidTagName(tagName), "m2 has a tag '%s' not present in m1" % tagName)
69     self.failUnless(m1.getTag(tagName) == m2.getTag(tagName), "values of tag '%s' differ" % tagName)
70 ksteube 1805 for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "ContinuousFunction", "ReducedContinuousFunction"]:
71 ksteube 1772 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.failUnless(Lsup(abs(integ1-integ2)) <= REL_TOL, "integrals for n=%d differ" % n)
79     return True
80    
81 ksteube 1754 # Does optimize=True change Rectangle for order=1?
82     def test_Rectangle_optimize_order1(self):
83 ksteube 1805 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 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
86 ksteube 1754
87     # Does optimize=True change Rectangle for order=2?
88 jfenwick 3114 #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 ksteube 1754
93 gross 2722 # 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 ksteube 1754 # Does optimize=True change Brick for order=1?
100     def test_Brick_optimize_order1(self):
101 ksteube 1805 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 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
104 ksteube 1754
105     # Does optimize=True change Brick for order=2?
106 jfenwick 3114 #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 gross 2722 # 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 ksteube 1754
116 ksteube 1805 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 caltinay 3349 dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.dump.nc")
122     d1.dump(dumpfile)
123     d2=load(dumpfile, mydomain1)
124 ksteube 1805 self.failUnless(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
125    
126     def test_data_dump_to_NetCDF_brick(self):
127     if loadIsConfigured():
128 jfenwick 3231 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
129 ksteube 1805 d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
130     d1.expand()
131 caltinay 3349 dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.dump.nc")
132     d1.dump(dumpfile)
133     d2=load(dumpfile, mydomain1)
134 ksteube 1805 self.failUnless(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
135    
136 ksteube 1755 def test_mesh_dump_to_NetCDF_rectangle(self):
137 ksteube 1754 if loadIsConfigured():
138 ksteube 1805 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
139 caltinay 3349 dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.mesh.nc")
140     mydomain1.dump(dumpfile)
141     mydomain2=LoadMesh(dumpfile)
142 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
143 ksteube 1754
144 ksteube 1777 def test_mesh_dump_to_NetCDF_brick(self):
145 ksteube 1755 if loadIsConfigured():
146 jfenwick 3231 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
147 caltinay 3349 dumpfile=os.path.join(DUDLEY_WORKDIR, "tempfile.mesh.nc")
148     mydomain1.dump(dumpfile)
149     mydomain2=LoadMesh(dumpfile)
150 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
151 ksteube 1755
152 jfenwick 3114 def fixme_test_mesh_read_rectangle_from_dudley_file(self):
153 ksteube 1805 if getMPISizeWorld() < 16:
154     mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
155 jfenwick 3085 mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"rectangle_8x10.fly"))
156 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
157 ksteube 1772
158 jfenwick 3114 def fixme_test_mesh_read_brick_from_dudley_file(self):
159 ksteube 1805 if getMPISizeWorld() < 16:
160     mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
161 jfenwick 3085 mydomain2 = ReadMesh(os.path.join(DUDLEY_TEST_MESH_PATH,"brick_8x10x12.fly"))
162 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
163 ksteube 1772
164 ksteube 1754 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