/[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 1829 - (hide annotations)
Thu Oct 2 05:40:30 2008 UTC (10 years, 6 months ago) by ksteube
Original Path: trunk/finley/test/python/run_inputOutput.py
File MIME type: text/x-python
File size: 6129 byte(s)
Adjusted tests for MPI.
Enabled two tests in run_inputOutput.py for order=2 after recent bugfix.

1 ksteube 1809
2     ########################################################
3 ksteube 1754 #
4 ksteube 1809 # Copyright (c) 2003-2008 by University of Queensland
5     # 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 ksteube 1809 __copyright__="""Copyright (c) 2003-2008 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__="http://www.uq.edu.au/esscc/escript-finley"
21    
22 ksteube 1754 """
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 ksteube 1807 from esys.finley import Rectangle, Brick, LoadMesh, ReadMesh
38 ksteube 1754
39     try:
40     FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
41     except KeyError:
42     FINLEY_TEST_DATA='.'
43    
44     FINLEY_TEST_MESH_PATH=FINLEY_TEST_DATA+"/data_meshes/"
45    
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 1772 def domainsEqual(self, m1, m2, nft=20):
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 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     # Does optimize=True change Brick for order=1?
89     def test_Brick_optimize_order1(self):
90 ksteube 1805 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
91     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=True)
92 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
93 ksteube 1754
94     # Does optimize=True change Brick for order=2?
95 ksteube 1829 def test_Brick_optimize_order2(self):
96 ksteube 1805 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
97     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=True)
98 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
99 ksteube 1754
100 ksteube 1805 def test_data_dump_to_NetCDF_rectangle(self):
101     if loadIsConfigured():
102     mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
103     d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
104     d1.expand()
105     d1.dump("tempfile.dump.nc")
106     d2=load("tempfile.dump.nc", mydomain1)
107     self.failUnless(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
108    
109     def test_data_dump_to_NetCDF_brick(self):
110     if loadIsConfigured():
111     mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
112     d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
113     d1.expand()
114     d1.dump("tempfile.dump.nc")
115     d2=load("tempfile.dump.nc", mydomain1)
116     self.failUnless(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
117    
118 ksteube 1755 def test_mesh_dump_to_NetCDF_rectangle(self):
119 ksteube 1754 if loadIsConfigured():
120 ksteube 1805 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
121     mydomain1.dump("tempfile.mesh.nc")
122     mydomain2=LoadMesh("tempfile.mesh.nc")
123 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
124 ksteube 1754
125 ksteube 1777 def test_mesh_dump_to_NetCDF_brick(self):
126 ksteube 1755 if loadIsConfigured():
127 ksteube 1805 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
128     mydomain1.dump("tempfile.mesh.nc")
129     mydomain2=LoadMesh("tempfile.mesh.nc")
130 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
131 ksteube 1755
132 ksteube 1772 def test_mesh_read_rectangle_from_finley_file(self):
133 ksteube 1805 if getMPISizeWorld() < 16:
134     mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
135 ksteube 1807 mydomain2 = ReadMesh(FINLEY_TEST_MESH_PATH+"rectangle_8x10.fly")
136 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
137 ksteube 1772
138     def test_mesh_read_brick_from_finley_file(self):
139 ksteube 1805 if getMPISizeWorld() < 16:
140     mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
141 ksteube 1807 mydomain2 = ReadMesh(FINLEY_TEST_MESH_PATH+"brick_8x10x12.fly")
142 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
143 ksteube 1772
144 ksteube 1754 if __name__ == '__main__':
145     suite = unittest.TestSuite()
146     suite.addTest(unittest.makeSuite(InputOutput))
147     s=unittest.TextTestRunner(verbosity=2).run(suite)
148     if not s.wasSuccessful(): sys.exit(1)
149    

  ViewVC Help
Powered by ViewVC 1.1.26