/[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 1771 by ksteube, Mon Sep 8 22:47:55 2008 UTC revision 1772 by ksteube, Tue Sep 9 00:18:49 2008 UTC
# Line 51  FINLEY_TEST_MESH_PATH=FINLEY_TEST_DATA+" Line 51  FINLEY_TEST_MESH_PATH=FINLEY_TEST_DATA+"
51  SOLVER_TOL=1.e-8  SOLVER_TOL=1.e-8
52  REL_TOL=1.e-6  REL_TOL=1.e-6
53    
 def domainsEqual(m1, m2, nft=10):  
    if m1.getDim() != m2.getDim():  
      print "domainsEqual: different dimensions %d, %d" % (m1.getDim(), m2.getDim())  
      return False  
    if m1.getNumDataPointsGlobal() != m2.getNumDataPointsGlobal():  
      print "domainsEqual: different num data points: %d, %d" % (m1.getNumDataPointsGlobal(), m2.getNumDataPointsGlobal())  
      return False  
    for tagName in m1.showTagNames().split(", "):  
      if not m2.isValidTagName(tagName):  
        print "domainsEqual: m1 has a tag '%s' not present in m2" % tagName  
        return False  
    for tagName in m2.showTagNames().split(", "):  
      if not m1.isValidTagName(tagName):  
        print "domainsEqual: m2 has a tag '%s' not present in m1" % tagName  
        return False  
      if m1.getTag(tagName) != m2.getTag(tagName):  
        print "domainsEqual: values of tag '%s' differ" % tagName  
        return False  
    for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "FunctionOnBoundary", "ReducedFunctionOnBoundary", "ContinuousFunction", "ReducedContinuousFunction"]:  
      fs1 = eval("%s(m1)" % fs)  
      fs2 = eval("%s(m2)" % fs)  
      x1 = fs1.getX()  
      x2 = fs2.getX()  
      for n in range(1, nft+1):  
        integ1 = integrate(sin(n*x1))  
        integ2 = integrate(sin(n*x2))  
        if Lsup(abs(integ1-integ2)) > REL_TOL:  
      print "domainsEqual: integrals for n=%d differ" % n  
          return False  
    return True  
   
54  class InputOutput(unittest.TestCase):  class InputOutput(unittest.TestCase):
55    
56         def domainsEqual(self, m1, m2, nft=20):
57            self.failUnless(m1.getDim() == m2.getDim(), "Dimensions differ")
58            self.failUnless(m1.getNumDataPointsGlobal() == m2.getNumDataPointsGlobal(), "Num data points differ")
59            for tagName in m1.showTagNames().split(", "):
60              self.failUnless(m2.isValidTagName(tagName), "m1 has a tag '%s' not present in m2" % tagName)
61            for tagName in m2.showTagNames().split(", "):
62              self.failUnless(m1.isValidTagName(tagName), "m2 has a tag '%s' not present in m1" % tagName)
63              self.failUnless(m1.getTag(tagName) == m2.getTag(tagName), "values of tag '%s' differ" % tagName)
64            for fs in ["Solution", "ReducedSolution", "Function", "ReducedFunction", "FunctionOnBoundary", "ReducedFunctionOnBoundary", "ContinuousFunction", "ReducedContinuousFunction"]:
65              fs1 = eval("%s(m1)" % fs)
66              fs2 = eval("%s(m2)" % fs)
67              x1 = fs1.getX()
68              x2 = fs2.getX()
69              for n in range(1, nft+1):
70                integ1 = integrate(sin(n*x1))
71                integ2 = integrate(sin(n*x2))
72                self.failUnless(Lsup(abs(integ1-integ2)) <= REL_TOL, "integrals for n=%d differ" % n)
73            return True
74    
75       # Does optimize=True change Rectangle for order=1?       # Does optimize=True change Rectangle for order=1?
76       def test_Rectangle_optimize_order1(self):       def test_Rectangle_optimize_order1(self):
77      mydomain1 = Rectangle(n0=7, n1=11, order=1, l0=1., l1=1., optimize=False)      mydomain1 = Rectangle(n0=7, n1=11, order=1, l0=1., l1=1., optimize=False)
78      mydomain2 = Rectangle(n0=7, n1=11, order=1, l0=1., l1=1., optimize=True)      mydomain2 = Rectangle(n0=7, n1=11, order=1, l0=1., l1=1., optimize=True)
79          self.failUnless(domainsEqual(mydomain1, mydomain2), "Domains differ")          self.domainsEqual(mydomain1, mydomain2)
80    
81       # Does optimize=True change Rectangle for order=2?       # Does optimize=True change Rectangle for order=2?
82       def test_Rectangle_optimize_order2(self):       def test_Rectangle_optimize_order2(self):
83      mydomain1 = Rectangle(n0=7, n1=11, order=2, l0=1., l1=1., optimize=False)      mydomain1 = Rectangle(n0=7, n1=11, order=2, l0=1., l1=1., optimize=False)
84      mydomain2 = Rectangle(n0=7, n1=11, order=2, l0=1., l1=1., optimize=True)      mydomain2 = Rectangle(n0=7, n1=11, order=2, l0=1., l1=1., optimize=True)
85          self.failUnless(domainsEqual(mydomain1, mydomain2), "Domains differ")          self.domainsEqual(mydomain1, mydomain2)
86    
87       # Does optimize=True change Brick for order=1?       # Does optimize=True change Brick for order=1?
88       def test_Brick_optimize_order1(self):       def test_Brick_optimize_order1(self):
89      mydomain1 = Brick(n0=7, n1=11, n2=5, order=1, l0=1., l1=1., l2=1., optimize=False)      mydomain1 = Brick(n0=7, n1=11, n2=5, order=1, l0=1., l1=1., l2=1., optimize=False)
90      mydomain2 = Brick(n0=7, n1=11, n2=5, order=1, l0=1., l1=1., l2=1., optimize=True)      mydomain2 = Brick(n0=7, n1=11, n2=5, order=1, l0=1., l1=1., l2=1., optimize=True)
91          self.failUnless(domainsEqual(mydomain1, mydomain2), "Domains differ")          self.domainsEqual(mydomain1, mydomain2)
92    
93       # Does optimize=True change Brick for order=2?       # Does optimize=True change Brick for order=2?
94       def test_Brick_optimize_order2(self):       def test_Brick_optimize_order2(self):
95      mydomain1 = Brick(n0=7, n1=11, n2=5, order=2, l0=1., l1=1., l2=1., optimize=False)      mydomain1 = Brick(n0=7, n1=11, n2=5, order=2, l0=1., l1=1., l2=1., optimize=False)
96      mydomain2 = Brick(n0=7, n1=11, n2=5, order=2, l0=1., l1=1., l2=1., optimize=True)      mydomain2 = Brick(n0=7, n1=11, n2=5, order=2, l0=1., l1=1., l2=1., optimize=True)
97          self.failUnless(domainsEqual(mydomain1, mydomain2), "Domains differ")          self.domainsEqual(mydomain1, mydomain2)
98    
99       def test_mesh_dump_to_NetCDF_rectangle(self):       def test_mesh_dump_to_NetCDF_rectangle(self):
100      if loadIsConfigured():      if loadIsConfigured():
101        mydomain1 = Rectangle(n0=17, n1=111, order=1, l0=1., l1=1., optimize=False)        mydomain1 = Rectangle(n0=17, n1=111, order=1, l0=1., l1=1., optimize=False)
102        mydomain1.dump("tt.mesh.nc")        mydomain1.dump("tt.mesh.nc")
103        mydomain2=LoadMesh("tt.mesh.nc")        mydomain2=LoadMesh("tt.mesh.nc")
104            self.failUnless(domainsEqual(mydomain1, mydomain2), "Domains differ")            self.domainsEqual(mydomain1, mydomain2)
105    
106       def DISABLED_test_mesh_dump_to_NetCDF_brick(self):       def DISABLED_test_mesh_dump_to_NetCDF_brick(self):
107      if loadIsConfigured():      if loadIsConfigured():
108        mydomain1 = Brick(n0=7, n1=11, n2=5, order=2, l0=1., l1=1., l2=1., optimize=False)        mydomain1 = Brick(n0=7, n1=11, n2=5, order=2, l0=1., l1=1., l2=1., optimize=False)
109        mydomain1.dump("tt.mesh.nc")        mydomain1.dump("tt.mesh.nc")
110        mydomain2=LoadMesh("tt.mesh.nc")        mydomain2=LoadMesh("tt.mesh.nc")
111            self.failUnless(domainsEqual(mydomain1, mydomain2), "Domains differ")            self.domainsEqual(mydomain1, mydomain2)
112    
113         def test_mesh_read_rectangle_from_finley_file(self):
114        mydomain1 = Rectangle(n0=8, n1=10, order=1, l0=1., l1=1., optimize=False)
115            mydomain2 = ReadMeshMPI(FINLEY_TEST_MESH_PATH+"rectangle_8x10.fly")
116            self.domainsEqual(mydomain1, mydomain2)
117    
118         def test_mesh_read_brick_from_finley_file(self):
119            mydomain1 = Brick(n0=8, n1=10, n2=12, order=1, l0=1., l1=1., l2=1., optimize=False)
120            mydomain2 = ReadMeshMPI(FINLEY_TEST_MESH_PATH+"brick_8x10x12.fly")
121            self.domainsEqual(mydomain1, mydomain2)
122    
123  if __name__ == '__main__':  if __name__ == '__main__':
124     suite = unittest.TestSuite()     suite = unittest.TestSuite()

Legend:
Removed from v.1771  
changed lines
  Added in v.1772

  ViewVC Help
Powered by ViewVC 1.1.26