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

Diff of /trunk/dudley/test/python/run_inputOutput.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1777 by ksteube, Tue Sep 9 06:39:37 2008 UTC revision 1866 by ksteube, Thu Oct 9 04:01:06 2008 UTC
# Line 1  Line 1 
1    
2    ########################################################
3  #  #
4  # $Id$  # Copyright (c) 2003-2008 by University of Queensland
5  #  # Earth Systems Science Computational Center (ESSCC)
6  #######################################################  # http://www.uq.edu.au/esscc
7  #  #
8  #           Copyright 2003-2007 by ACceSS MNRF  # Primary Business: Queensland, Australia
9  #       Copyright 2007 by University of Queensland  # Licensed under the Open Software License version 3.0
10  #  # http://www.opensource.org/licenses/osl-3.0.php
11  #                http://esscc.uq.edu.au  #
12  #        Primary Business: Queensland, Australia  ########################################################
13  #  Licensed under the Open Software License version 3.0  
14  #     http://www.opensource.org/licenses/osl-3.0.php  __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  """  """
23  Test suite for input and output of meshes and data objects  Test suite for input and output of meshes and data objects
# Line 26  Test suite for input and output of meshe Line 31  Test suite for input and output of meshe
31  @var __date__: date of the version  @var __date__: date of the version
32  """  """
33    
 __copyright__="""  Copyright (c) 2006 by ACcESS MNRF  
                     http://www.access.edu.au  
                 Primary Business: Queensland, Australia"""  
 __license__="""Licensed under the Open Software License version 3.0  
              http://www.opensource.org/licenses/osl-3.0.php"""  
 __author__="Ken Steube, k.steube@uq.edu.au"  
 __url__="http://www.iservo.edu.au/esys/escript"  
 __version__="$Revision: 859 $"  
 __date__="$Date: 2006-09-26 12:19:18 +1000 (Tue, 26 Sep 2006) $"  
   
34  import unittest, sys  import unittest, sys
35    
36  from esys.escript import *  from esys.escript import *
37  from esys.finley import Rectangle, Brick, LoadMesh, ReadMesh, ReadMeshMPI  from esys.finley import Rectangle, Brick, LoadMesh, ReadMesh
38    
39  try:  try:
40       FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']       FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
# Line 48  except KeyError: Line 43  except KeyError:
43    
44  FINLEY_TEST_MESH_PATH=FINLEY_TEST_DATA+"/data_meshes/"  FINLEY_TEST_MESH_PATH=FINLEY_TEST_DATA+"/data_meshes/"
45    
 SOLVER_TOL=1.e-8  
46  REL_TOL=1.e-6  REL_TOL=1.e-6
47    
48    # Number of elements scales up with number of MPI processes
49    NE0 = 7 * getMPISizeWorld()
50    NE1 = 11
51    NE2 = 5
52    
53  class InputOutput(unittest.TestCase):  class InputOutput(unittest.TestCase):
54    
55       def domainsEqual(self, m1, m2, nft=20):       # Check that two domains are equal using Fourier integrals
56         # We cannot compare the X coordinates since they are on different domains
57         def domainsEqual(self, m1, m2, nft=100):
58          self.failUnless(m1.getDim() == m2.getDim(), "Dimensions differ")          self.failUnless(m1.getDim() == m2.getDim(), "Dimensions differ")
59          self.failUnless(m1.getNumDataPointsGlobal() == m2.getNumDataPointsGlobal(), "Num data points differ")          self.failUnless(m1.getNumDataPointsGlobal() == m2.getNumDataPointsGlobal(), "Num data points differ")
60          for tagName in m1.showTagNames().split(", "):          for tagName in m1.showTagNames().split(", "):
# Line 61  class InputOutput(unittest.TestCase): Line 62  class InputOutput(unittest.TestCase):
62          for tagName in m2.showTagNames().split(", "):          for tagName in m2.showTagNames().split(", "):
63            self.failUnless(m1.isValidTagName(tagName), "m2 has a tag '%s' not present in m1" % tagName)            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)            self.failUnless(m1.getTag(tagName) == m2.getTag(tagName), "values of tag '%s' differ" % tagName)
65          for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "FunctionOnBoundary", "ReducedFunctionOnBoundary", "ContinuousFunction", "ReducedContinuousFunction"]:          for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "ContinuousFunction", "ReducedContinuousFunction"]:
66            fs1 = eval("%s(m1)" % fs)            fs1 = eval("%s(m1)" % fs)
67            fs2 = eval("%s(m2)" % fs)            fs2 = eval("%s(m2)" % fs)
68            x1 = fs1.getX()            x1 = fs1.getX()
# Line 74  class InputOutput(unittest.TestCase): Line 75  class InputOutput(unittest.TestCase):
75    
76       # Does optimize=True change Rectangle for order=1?       # Does optimize=True change Rectangle for order=1?
77       def test_Rectangle_optimize_order1(self):       def test_Rectangle_optimize_order1(self):
78      mydomain1 = Rectangle(n0=7, n1=11, order=1, l0=1., l1=1., optimize=False)      mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
79      mydomain2 = Rectangle(n0=7, n1=11, order=1, l0=1., l1=1., optimize=True)      mydomain2 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=True)
80          self.domainsEqual(mydomain1, mydomain2)          self.domainsEqual(mydomain1, mydomain2)
81    
82       # Does optimize=True change Rectangle for order=2?       # Does optimize=True change Rectangle for order=2?
83       def test_Rectangle_optimize_order2(self):       def test_Rectangle_optimize_order2(self):
84      mydomain1 = Rectangle(n0=7, n1=11, order=2, l0=1., l1=1., optimize=False)      mydomain1 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=False)
85      mydomain2 = Rectangle(n0=7, n1=11, order=2, l0=1., l1=1., optimize=True)      mydomain2 = Rectangle(n0=NE0, n1=NE1, order=2, l0=1., l1=1., optimize=True)
86          self.domainsEqual(mydomain1, mydomain2)          self.domainsEqual(mydomain1, mydomain2)
87    
88       # Does optimize=True change Brick for order=1?       # Does optimize=True change Brick for order=1?
89       def test_Brick_optimize_order1(self):       def test_Brick_optimize_order1(self):
90      mydomain1 = Brick(n0=7, n1=11, n2=5, order=1, l0=1., l1=1., l2=1., optimize=False)      mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=False)
91      mydomain2 = Brick(n0=7, n1=11, n2=5, order=1, l0=1., l1=1., l2=1., optimize=True)      mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=1, l0=1., l1=1., l2=1., optimize=True)
92          self.domainsEqual(mydomain1, mydomain2)          self.domainsEqual(mydomain1, mydomain2)
93    
94       # Does optimize=True change Brick for order=2?       # Does optimize=True change Brick for order=2?
95       def test_Brick_optimize_order2(self):       def test_Brick_optimize_order2(self):
96      mydomain1 = Brick(n0=7, n1=11, n2=5, order=2, l0=1., l1=1., l2=1., optimize=False)      mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
97      mydomain2 = Brick(n0=7, n1=11, n2=5, order=2, l0=1., l1=1., l2=1., optimize=True)      mydomain2 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=True)
98          self.domainsEqual(mydomain1, mydomain2)          self.domainsEqual(mydomain1, mydomain2)
99    
100         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       def test_mesh_dump_to_NetCDF_rectangle(self):       def test_mesh_dump_to_NetCDF_rectangle(self):
119      if loadIsConfigured():      if loadIsConfigured():
120        mydomain1 = Rectangle(n0=7, n1=11, order=1, l0=1., l1=1., optimize=False)        mydomain1 = Rectangle(n0=NE0, n1=NE1, order=1, l0=1., l1=1., optimize=False)
121        mydomain1.dump("tt.mesh.nc")        mydomain1.dump("tempfile.mesh.nc")
122        mydomain2=LoadMesh("tt.mesh.nc")        mydomain2=LoadMesh("tempfile.mesh.nc")
123            self.domainsEqual(mydomain1, mydomain2)            self.domainsEqual(mydomain1, mydomain2)
124    
125       def test_mesh_dump_to_NetCDF_brick(self):       def test_mesh_dump_to_NetCDF_brick(self):
126      if loadIsConfigured():      if loadIsConfigured():
127        mydomain1 = Brick(n0=7, n1=11, n2=5, order=2, l0=1., l1=1., l2=1., optimize=False)        mydomain1 = Brick(n0=NE0, n1=NE1, n2=NE2, order=2, l0=1., l1=1., l2=1., optimize=False)
128        mydomain1.dump("tt.mesh.nc")        mydomain1.dump("tempfile.mesh.nc")
129        mydomain2=LoadMesh("tt.mesh.nc")        mydomain2=LoadMesh("tempfile.mesh.nc")
130            self.domainsEqual(mydomain1, mydomain2)            self.domainsEqual(mydomain1, mydomain2)
131    
132       def test_mesh_read_rectangle_from_finley_file(self):       def test_mesh_read_rectangle_from_finley_file(self):
133      mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)      if getMPISizeWorld() < 16:
134          mydomain2 = ReadMeshMPI(FINLEY_TEST_MESH_PATH+"rectangle_8x10.fly")        mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
135          self.domainsEqual(mydomain1, mydomain2)            mydomain2 = ReadMesh(FINLEY_TEST_MESH_PATH+"rectangle_8x10.fly")
136              self.domainsEqual(mydomain1, mydomain2)
137    
138       def test_mesh_read_brick_from_finley_file(self):       def test_mesh_read_brick_from_finley_file(self):
139          mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)      if getMPISizeWorld() < 16:
140          mydomain2 = ReadMeshMPI(FINLEY_TEST_MESH_PATH+"brick_8x10x12.fly")            mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
141          self.domainsEqual(mydomain1, mydomain2)            mydomain2 = ReadMesh(FINLEY_TEST_MESH_PATH+"brick_8x10x12.fly")
142              self.domainsEqual(mydomain1, mydomain2)
143    
144  if __name__ == '__main__':  if __name__ == '__main__':
145     suite = unittest.TestSuite()     suite = unittest.TestSuite()

Legend:
Removed from v.1777  
changed lines
  Added in v.1866

  ViewVC Help
Powered by ViewVC 1.1.26