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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1807 - (show annotations)
Thu Sep 25 01:04:51 2008 UTC (11 years, 6 months ago) by ksteube
File MIME type: text/x-python
File size: 6401 byte(s)
The new MPI parallel ReadMesh is now the default after having passed
all tests both with and without MPI.
If you have been using ReadMesh you should notice no difference.
If you were using ReadMeshMPI then change to ReadMesh.

1 #
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
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 # Number of elements scales up with number of MPI processes
54 NE0 = 7 * getMPISizeWorld()
55 NE1 = 11
56 NE2 = 5
57
58 class InputOutput(unittest.TestCase):
59
60 # Check that two domains are equal using Fourier integrals
61 # We cannot compare the X coordinates since they are on different domains
62 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 for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "ContinuousFunction", "ReducedContinuousFunction"]:
71 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 # Does optimize=True change Rectangle for order=1?
82 def test_Rectangle_optimize_order1(self):
83 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 self.domainsEqual(mydomain1, mydomain2)
86
87 # Does optimize=True change Rectangle for order=2?
88 # 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 self.domainsEqual(mydomain1, mydomain2)
93
94 # Does optimize=True change Brick for order=1?
95 def test_Brick_optimize_order1(self):
96 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 self.domainsEqual(mydomain1, mydomain2)
99
100 # Does optimize=True change Brick for order=2?
101 # 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 self.domainsEqual(mydomain1, mydomain2)
106
107 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 def test_mesh_dump_to_NetCDF_rectangle(self):
126 if loadIsConfigured():
127 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 self.domainsEqual(mydomain1, mydomain2)
131
132 def test_mesh_dump_to_NetCDF_brick(self):
133 if loadIsConfigured():
134 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 self.domainsEqual(mydomain1, mydomain2)
138
139 def test_mesh_read_rectangle_from_finley_file(self):
140 if getMPISizeWorld() < 16:
141 mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
142 mydomain2 = ReadMesh(FINLEY_TEST_MESH_PATH+"rectangle_8x10.fly")
143 self.domainsEqual(mydomain1, mydomain2)
144
145 def test_mesh_read_brick_from_finley_file(self):
146 if getMPISizeWorld() < 16:
147 mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
148 mydomain2 = ReadMesh(FINLEY_TEST_MESH_PATH+"brick_8x10x12.fly")
149 self.domainsEqual(mydomain1, mydomain2)
150
151 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