/[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 1805 - (hide annotations)
Wed Sep 24 23:39:00 2008 UTC (10 years, 7 months ago) by ksteube
Original Path: trunk/finley/test/python/run_inputOutput.py
File MIME type: text/x-python
File size: 6420 byte(s)
Added python-level methods getMPISizeWorld() and getMPIRankWorld() for MPI process info.
Test suite run_inputOutput.py runs on any number of cores now, hybrid may still be a problem.

1 ksteube 1754 #
2     # $Id$
3     #
4     #######################################################
5     #
6     # Copyright 2003-2007 by ACceSS MNRF
7     # Copyright 2007 by University of Queensland
8     #
9     # http://esscc.uq.edu.au
10     # Primary Business: Queensland, Australia
11     # Licensed under the Open Software License version 3.0
12     # http://www.opensource.org/licenses/osl-3.0.php
13     #
14     #######################################################
15     #
16    
17     """
18     Test suite for input and output of meshes and data objects
19    
20     @remark:
21    
22     @var __author__: name of author
23     @var __licence__: licence agreement
24     @var __url__: url entry point on documentation
25     @var __version__: version
26     @var __date__: date of the version
27     """
28    
29     __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
30     http://www.access.edu.au
31     Primary Business: Queensland, Australia"""
32     __license__="""Licensed under the Open Software License version 3.0
33     http://www.opensource.org/licenses/osl-3.0.php"""
34     __author__="Ken Steube, k.steube@uq.edu.au"
35     __url__="http://www.iservo.edu.au/esys/escript"
36     __version__="$Revision: 859 $"
37     __date__="$Date: 2006-09-26 12:19:18 +1000 (Tue, 26 Sep 2006) $"
38    
39     import unittest, sys
40    
41     from esys.escript import *
42     from esys.finley import Rectangle, Brick, LoadMesh, ReadMesh, ReadMeshMPI
43    
44     try:
45     FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
46     except KeyError:
47     FINLEY_TEST_DATA='.'
48    
49     FINLEY_TEST_MESH_PATH=FINLEY_TEST_DATA+"/data_meshes/"
50    
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 1772 def domainsEqual(self, m1, m2, nft=20):
63     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 ksteube 1805 # This is disabled due to a possible bug in order=2
89     def disabled_test_Rectangle_optimize_order2(self):
90     mydomain1 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=False)
91     mydomain2 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=True)
92 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
93 ksteube 1754
94     # 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 1805 # This is disabled due to a possible bug in order=2
102     def disabled_test_Brick_optimize_order2(self):
103     mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
104     mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=True)
105 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
106 ksteube 1754
107 ksteube 1805 def test_data_dump_to_NetCDF_rectangle(self):
108     if loadIsConfigured():
109     mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
110     d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
111     d1.expand()
112     d1.dump("tempfile.dump.nc")
113     d2=load("tempfile.dump.nc", mydomain1)
114     self.failUnless(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
115    
116     def test_data_dump_to_NetCDF_brick(self):
117     if loadIsConfigured():
118     mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
119     d1=Data(mydomain1.getMPIRank(), Function(mydomain1))
120     d1.expand()
121     d1.dump("tempfile.dump.nc")
122     d2=load("tempfile.dump.nc", mydomain1)
123     self.failUnless(Lsup(abs(d1-d2)) <= REL_TOL, "data objects differ")
124    
125 ksteube 1755 def test_mesh_dump_to_NetCDF_rectangle(self):
126 ksteube 1754 if loadIsConfigured():
127 ksteube 1805 mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
128     mydomain1.dump("tempfile.mesh.nc")
129     mydomain2=LoadMesh("tempfile.mesh.nc")
130 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
131 ksteube 1754
132 ksteube 1777 def test_mesh_dump_to_NetCDF_brick(self):
133 ksteube 1755 if loadIsConfigured():
134 ksteube 1805 mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
135     mydomain1.dump("tempfile.mesh.nc")
136     mydomain2=LoadMesh("tempfile.mesh.nc")
137 ksteube 1772 self.domainsEqual(mydomain1, mydomain2)
138 ksteube 1755
139 ksteube 1772 def test_mesh_read_rectangle_from_finley_file(self):
140 ksteube 1805 if getMPISizeWorld() < 16:
141     mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
142     mydomain2 = ReadMeshMPI(FINLEY_TEST_MESH_PATH+"rectangle_8x10.fly")
143     self.domainsEqual(mydomain1, mydomain2)
144 ksteube 1772
145     def test_mesh_read_brick_from_finley_file(self):
146 ksteube 1805 if getMPISizeWorld() < 16:
147     mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
148     mydomain2 = ReadMeshMPI(FINLEY_TEST_MESH_PATH+"brick_8x10x12.fly")
149     self.domainsEqual(mydomain1, mydomain2)
150 ksteube 1772
151 ksteube 1754 if __name__ == '__main__':
152     suite = unittest.TestSuite()
153     suite.addTest(unittest.makeSuite(InputOutput))
154     s=unittest.TextTestRunner(verbosity=2).run(suite)
155     if not s.wasSuccessful(): sys.exit(1)
156    

  ViewVC Help
Powered by ViewVC 1.1.26