/[escript]/trunk/finley/test/python/run_inputOutput.py
ViewVC logotype

Annotation of /trunk/finley/test/python/run_inputOutput.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1809 - (hide annotations)
Thu Sep 25 06:43:44 2008 UTC (11 years, 5 months ago) by ksteube
File MIME type: text/x-python
File size: 6261 byte(s)
Copyright updated in all python files

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 1805 # This is disabled due to a possible bug in order=2
84     def disabled_test_Rectangle_optimize_order2(self):
85     mydomain1 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=False)
86     mydomain2 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=True)
87 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
88 ksteube 1754
89     # Does optimize=True change Brick for order=1?
90     def test_Brick_optimize_order1(self):
91 ksteube 1805 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
92     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=True)
93 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
94 ksteube 1754
95     # Does optimize=True change Brick for order=2?
96 ksteube 1805 # This is disabled due to a possible bug in order=2
97     def disabled_test_Brick_optimize_order2(self):
98     mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
99     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=True)
100 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
101 ksteube 1754
102 ksteube 1805 def test_data_dump_to_NetCDF_rectangle(self):
103     if loadIsConfigured():
104     mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
105     d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
106     d1.expand()
107     d1.dump("tempfile.dump.nc")
108     d2=load("tempfile.dump.nc", mydomain1)
109     self.failUnless(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
110    
111     def test_data_dump_to_NetCDF_brick(self):
112     if loadIsConfigured():
113     mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=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 ksteube 1755 def test_mesh_dump_to_NetCDF_rectangle(self):
121 ksteube 1754 if loadIsConfigured():
122 ksteube 1805 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
123     mydomain1.dump("tempfile.mesh.nc")
124     mydomain2=LoadMesh("tempfile.mesh.nc")
125 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
126 ksteube 1754
127 ksteube 1777 def test_mesh_dump_to_NetCDF_brick(self):
128 ksteube 1755 if loadIsConfigured():
129 ksteube 1805 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
130     mydomain1.dump("tempfile.mesh.nc")
131     mydomain2=LoadMesh("tempfile.mesh.nc")
132 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
133 ksteube 1755
134 ksteube 1772 def test_mesh_read_rectangle_from_finley_file(self):
135 ksteube 1805 if getMPISizeWorld() < 16:
136     mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
137 ksteube 1807 mydomain2 = ReadMesh(FINLEY_TEST_MESH_PATH+"rectangle_8x10.fly")
138 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
139 ksteube 1772
140     def test_mesh_read_brick_from_finley_file(self):
141 ksteube 1805 if getMPISizeWorld() < 16:
142     mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
143 ksteube 1807 mydomain2 = ReadMesh(FINLEY_TEST_MESH_PATH+"brick_8x10x12.fly")
144 ksteube 1805 self.domainsEqual(mydomain1, mydomain2)
145 ksteube 1772
146 ksteube 1754 if __name__ == '__main__':
147     suite = unittest.TestSuite()
148     suite.addTest(unittest.makeSuite(InputOutput))
149     s=unittest.TextTestRunner(verbosity=2).run(suite)
150     if not s.wasSuccessful(): sys.exit(1)
151    

  ViewVC Help
Powered by ViewVC 1.1.26