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

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

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

revision 1311 by gross, Wed May 9 01:58:32 2007 UTC revision 1312 by ksteube, Mon Sep 24 06:18:44 2007 UTC
# Line 1  Line 1 
1    #
2  # $Id$  # $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  checks the mesh generators against the reference meshes in test_meshes  checks the mesh generators against the reference meshes in test_meshes
# Line 15  import sys Line 28  import sys
28  import os  import os
29  import unittest  import unittest
30  from esys.escript import *  from esys.escript import *
31  from esys.finley import Interval,Rectangle,Brick,JoinFaces, ReadGmsh, ReadMesh  from esys.finley import Rectangle,Brick,JoinFaces, ReadGmsh, ReadMesh
32    
33  try:  try:
34       FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']       FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
# Line 27  try: Line 40  try:
40  except KeyError:  except KeyError:
41       FINLEY_WORKDIR='.'       FINLEY_WORKDIR='.'
42    
43  FINLEY_TEST_MESH_PATH=os.path.join(FINLEY_TEST_DATA,"data_meshes")  FINLEY_TEST_MESH_PATH=FINLEY_TEST_DATA+"/data_meshes/"
44  FINLEY_WORKDIR_PATH=FINLEY_WORKDIR  if os.name == "nt":
45       FINLEY_TEST_MESH_PATH = FINLEY_TEST_MESH_PATH+"win32/"
46    FINLEY_WORKDIR_PATH=FINLEY_WORKDIR+"/"
47    
48  TEST_FILE_EXT=".test"  TEST_FILE_EXT=".test"
49  class Test_Generators(unittest.TestCase):  class Test_Generators(unittest.TestCase):
50    
51     def checker(self,dom,reference):     def checker(self,dom,reference):
52        dom_file=os.path.join(FINLEY_WORKDIR_PATH,TEST_FILE_EXT)        dom_file=FINLEY_WORKDIR_PATH+TEST_FILE_EXT
53        dom.write(dom_file)        dom.write(dom_file)
54  # Uncomment this section to dump the files for regression testing  # Uncomment this section to dump the files for regression testing
55  #      if True:  #      if True:
56  #         dom.write(os.path.join(FINLEY_TEST_MESH_PATH,reference))  #         dom.write(FINLEY_TEST_MESH_PATH+reference)
57        dom_string=open(dom_file).read().splitlines()        dom_string=open(dom_file).read().splitlines()
58        ref_string=open(os.path.join(FINLEY_TEST_MESH_PATH,reference)).read().splitlines()        ref_string=open(FINLEY_TEST_MESH_PATH+reference).read().splitlines()
59        self.failUnlessEqual(len(dom_string),len(ref_string),"number of lines in mesh files does not match reference")        self.failUnlessEqual(len(dom_string),len(ref_string),"number of lines in mesh files does not match reference")
60        for l in range(1,len(ref_string)):        for l in range(1,len(ref_string)):
61           line=dom_string[l].strip()           self.failUnlessEqual(dom_string[l].strip(),ref_string[l].strip(),"line %d (%s) in mesh files does not match reference (%s)"%(l,ref_string[l].strip(),dom_string[l].strip()))
          if os.name == "nt":  
               line=line.replace("e+00","e+0").replace("e-00","e-0")  
          self.failUnlessEqual(line,ref_string[l].strip(),"line %d=""%s"" in mesh file does not match line ""%s"" in reference %s" %(l,ref_string[l].strip(),line,os.path.join(FINLEY_TEST_MESH_PATH,reference)))  
   
    def test_hex_1D_order1(self):  
       file="hex_1D_order1.msh"  
       my_dom=Interval(1,1)  
       self.checker(my_dom,file)  
   
    def test_hex_1D_order1_onFace(self):  
       file="hex_1D_order1_onFace.msh"  
       my_dom=Interval(1,1,useElementsOnFace=1)  
       self.checker(my_dom,file)  
   
    def test_hex_1D_order2(self):  
       file="hex_1D_order2.msh"  
       my_dom=Interval(1,2)  
       self.checker(my_dom,file)  
   
    def test_hex_1D_order2_onFace(self):  
       file="hex_1D_order2_onFace.msh"  
       my_dom=Interval(1,2,useElementsOnFace=1)  
       self.checker(my_dom,file)  
62    
63     def test_hex_2D_order1(self):     def test_hex_2D_order1(self):
64        file="hex_2D_order1.msh"        file="hex_2D_order1.msh"
# Line 113  class Test_Generators(unittest.TestCase) Line 105  class Test_Generators(unittest.TestCase)
105        ms1=Rectangle(1,1,1,l1=0.5,useElementsOnFace=False)        ms1=Rectangle(1,1,1,l1=0.5,useElementsOnFace=False)
106        ms2=Rectangle(1,1,1,l1=0.5,useElementsOnFace=False)        ms2=Rectangle(1,1,1,l1=0.5,useElementsOnFace=False)
107        ms2.setX(ms2.getX()+[0,0.5])        ms2.setX(ms2.getX()+[0,0.5])
108        my_dom=JoinFaces([ms1,ms2])        my_dom=JoinFaces([ms1,ms2],optimize=False)
109        self.checker(my_dom,file)        self.checker(my_dom,file)
110    
111     def test_hex_contact_2D_order1_onFace(self):     def test_hex_contact_2D_order1_onFace(self):
# Line 121  class Test_Generators(unittest.TestCase) Line 113  class Test_Generators(unittest.TestCase)
113        ms1=Rectangle(1,1,1,l1=0.5,useElementsOnFace=True)        ms1=Rectangle(1,1,1,l1=0.5,useElementsOnFace=True)
114        ms2=Rectangle(1,1,1,l1=0.5,useElementsOnFace=True)        ms2=Rectangle(1,1,1,l1=0.5,useElementsOnFace=True)
115        ms2.setX(ms2.getX()+[0,0.5])        ms2.setX(ms2.getX()+[0,0.5])
116        my_dom=JoinFaces([ms1,ms2])        my_dom=JoinFaces([ms1,ms2],optimize=False)
117        self.checker(my_dom,file)        self.checker(my_dom,file)
118    
119     def test_hex_contact_2D_order2(self):     def test_hex_contact_2D_order2(self):
# Line 129  class Test_Generators(unittest.TestCase) Line 121  class Test_Generators(unittest.TestCase)
121        ms1=Rectangle(1,1,2,l1=0.5,useElementsOnFace=False)        ms1=Rectangle(1,1,2,l1=0.5,useElementsOnFace=False)
122        ms2=Rectangle(1,1,2,l1=0.5,useElementsOnFace=False)        ms2=Rectangle(1,1,2,l1=0.5,useElementsOnFace=False)
123        ms2.setX(ms2.getX()+[0,0.5])        ms2.setX(ms2.getX()+[0,0.5])
124        my_dom=JoinFaces([ms1,ms2])        my_dom=JoinFaces([ms1,ms2],optimize=False)
125        self.checker(my_dom,file)        self.checker(my_dom,file)
126    
127     def test_hex_contact_2D_order2_onFace(self):     def test_hex_contact_2D_order2_onFace(self):
# Line 137  class Test_Generators(unittest.TestCase) Line 129  class Test_Generators(unittest.TestCase)
129        ms1=Rectangle(1,1,2,l1=0.5,useElementsOnFace=True)        ms1=Rectangle(1,1,2,l1=0.5,useElementsOnFace=True)
130        ms2=Rectangle(1,1,2,l1=0.5,useElementsOnFace=True)        ms2=Rectangle(1,1,2,l1=0.5,useElementsOnFace=True)
131        ms2.setX(ms2.getX()+[0,0.5])        ms2.setX(ms2.getX()+[0,0.5])
132        my_dom=JoinFaces([ms1,ms2])        my_dom=JoinFaces([ms1,ms2],optimize=False)
133        self.checker(my_dom,file)        self.checker(my_dom,file)
134    
135     def test_hex_contact_3D_order1(self):     def test_hex_contact_3D_order1(self):
# Line 145  class Test_Generators(unittest.TestCase) Line 137  class Test_Generators(unittest.TestCase)
137        ms1=Brick(1,1,1,1,l2=0.5,useElementsOnFace=False)        ms1=Brick(1,1,1,1,l2=0.5,useElementsOnFace=False)
138        ms2=Brick(1,1,1,1,l2=0.5,useElementsOnFace=False)        ms2=Brick(1,1,1,1,l2=0.5,useElementsOnFace=False)
139        ms2.setX(ms2.getX()+[0,0,0.5])        ms2.setX(ms2.getX()+[0,0,0.5])
140        my_dom=JoinFaces([ms1,ms2])        my_dom=JoinFaces([ms1,ms2],optimize=False)
141        self.checker(my_dom,file)        self.checker(my_dom,file)
142    
143     def test_hex_contact_3D_order1_onFace(self):     def test_hex_contact_3D_order1_onFace(self):
# Line 153  class Test_Generators(unittest.TestCase) Line 145  class Test_Generators(unittest.TestCase)
145        ms1=Brick(1,1,1,1,l2=0.5,useElementsOnFace=True)        ms1=Brick(1,1,1,1,l2=0.5,useElementsOnFace=True)
146        ms2=Brick(1,1,1,1,l2=0.5,useElementsOnFace=True)        ms2=Brick(1,1,1,1,l2=0.5,useElementsOnFace=True)
147        ms2.setX(ms2.getX()+[0,0,0.5])        ms2.setX(ms2.getX()+[0,0,0.5])
148        my_dom=JoinFaces([ms1,ms2])        my_dom=JoinFaces([ms1,ms2],optimize=False)
149        self.checker(my_dom,file)        self.checker(my_dom,file)
150    
151     def test_hex_contact_3D_order2(self):     def test_hex_contact_3D_order2(self):
# Line 161  class Test_Generators(unittest.TestCase) Line 153  class Test_Generators(unittest.TestCase)
153        ms1=Brick(1,1,1,2,l2=0.5,useElementsOnFace=False)        ms1=Brick(1,1,1,2,l2=0.5,useElementsOnFace=False)
154        ms2=Brick(1,1,1,2,l2=0.5,useElementsOnFace=False)        ms2=Brick(1,1,1,2,l2=0.5,useElementsOnFace=False)
155        ms2.setX(ms2.getX()+[0,0,0.5])        ms2.setX(ms2.getX()+[0,0,0.5])
156        my_dom=JoinFaces([ms1,ms2])        my_dom=JoinFaces([ms1,ms2],optimize=False)
157        self.checker(my_dom,file)        self.checker(my_dom,file)
158    
159     def test_hex_contact_3D_order2_onFace(self):     def test_hex_contact_3D_order2_onFace(self):
# Line 169  class Test_Generators(unittest.TestCase) Line 161  class Test_Generators(unittest.TestCase)
161        ms1=Brick(1,1,1,2,l2=0.5,useElementsOnFace=True)        ms1=Brick(1,1,1,2,l2=0.5,useElementsOnFace=True)
162        ms2=Brick(1,1,1,2,l2=0.5,useElementsOnFace=True)        ms2=Brick(1,1,1,2,l2=0.5,useElementsOnFace=True)
163        ms2.setX(ms2.getX()+[0,0,0.5])        ms2.setX(ms2.getX()+[0,0,0.5])
164        my_dom=JoinFaces([ms1,ms2])        my_dom=JoinFaces([ms1,ms2],optimize=False)
165        self.checker(my_dom,file)        self.checker(my_dom,file)
166    
167  class Test_GMSHReader(unittest.TestCase):  class Test_GMSHReader(unittest.TestCase):
# Line 178  class Test_GMSHReader(unittest.TestCase) Line 170  class Test_GMSHReader(unittest.TestCase)
170        ref_string=open(reference_file).read().splitlines()        ref_string=open(reference_file).read().splitlines()
171        self.failUnlessEqual(len(dom_string),len(ref_string),"number of lines in mesh files does not match reference")        self.failUnlessEqual(len(dom_string),len(ref_string),"number of lines in mesh files does not match reference")
172        for l in range(1,len(ref_string)):        for l in range(1,len(ref_string)):
173           line=dom_string[l].strip()           self.failUnlessEqual(dom_string[l].strip(),ref_string[l].strip(),"line %d (%s) in mesh files does not match reference (%s)"%(l,ref_string[l].strip(),dom_string[l].strip()))
          if os.name == "nt":  
               line=line.replace("e+00","e+0").replace("e-00","e-0")  
          self.failUnlessEqual(line,ref_string[l].strip(),"line %d=""%s"" in mesh file does not match line ""%s"" in reference %s" %(l,ref_string[l].strip(),line,reference_file))  
174    
175     def test_Tri3(self):     def test_Tri3(self):
176         file="tri3_gmsh.msh"         file="tri3_gmsh.msh"
177         ref ="tri3.fly"         ref ="tri3.fly"
178         test = os.path.join(FINLEY_WORKDIR,"tri3_test.fly")         test = FINLEY_WORKDIR+os.sep+"tri3_test.fly"
179         dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,file),2)         dom = ReadGmsh(FINLEY_TEST_MESH_PATH+os.sep+file,2,optimize=False)
180         dom.write(test)         dom.write(test)
181         self.compare(test, os.path.join(FINLEY_TEST_MESH_PATH,ref))         self.compare(test, FINLEY_TEST_MESH_PATH+os.sep+ref)
182    
183     def test_Tri6(self):     def test_Tri6(self):
184         file="tri6_gmsh.msh"         file="tri6_gmsh.msh"
185         ref="tri6.fly"         ref="tri6.fly"
186         test = os.path.join(FINLEY_WORKDIR,"tri8_test.fly")         test = FINLEY_WORKDIR+os.sep+"tri8_test.fly"
187         dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,file),2)         dom = ReadGmsh(FINLEY_TEST_MESH_PATH+os.sep+file,2,optimize=False)
188         dom.write(test)         dom.write(test)
189         self.compare(test, os.path.join(FINLEY_TEST_MESH_PATH,ref))         self.compare(test, FINLEY_TEST_MESH_PATH+os.sep+ref)
190    
191     def test_Tet4(self):     def test_Tet4(self):
192         file="tet4_gmsh.msh"         file="tet4_gmsh.msh"
193         ref="tet4.fly"         ref="tet4.fly"
194         test = os.path.join(FINLEY_WORKDIR,"tet4_test.fly")         test = FINLEY_WORKDIR+os.sep+"tet4_test.fly"
195         dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,file),3)         dom = ReadGmsh(FINLEY_TEST_MESH_PATH+os.sep+file,3,optimize=False)
196         dom.write(test)         dom.write(test)
197         self.compare(test, os.path.join(FINLEY_TEST_MESH_PATH,ref))         self.compare(test, FINLEY_TEST_MESH_PATH+os.sep+ref)
198    
199     def test_Tet(self):     def test_Tet10(self):
200         file="tet10_gmsh.msh"         file="tet10_gmsh.msh"
201         ref="tet10.fly"         ref="tet10.fly"
202         test = os.path.join(FINLEY_WORKDIR,"tet10_test.fly")         test = FINLEY_WORKDIR+os.sep+"tet10_test.fly"
203         dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,file),3)         dom = ReadGmsh(FINLEY_TEST_MESH_PATH+os.sep+file,3,optimize=False)
204         dom.write(test)         dom.write(test)
205         self.compare(test, os.path.join(FINLEY_TEST_MESH_PATH,ref))         self.compare(test, FINLEY_TEST_MESH_PATH+os.sep+ref)
206    
207  class Test_Reader(unittest.TestCase):  class Test_Reader(unittest.TestCase):
208     def test_ReadWriteTagNames(self):     def test_ReadWriteTagNames(self):
209         file="hex_2D_order2.msh"         file="hex_2D_order2.msh"
210         test = os.path.join(FINLEY_WORKDIR,"test.fly")         test = FINLEY_WORKDIR+os.sep+"test.fly"
211         dom = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH,file),3)         dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+file,3,optimize=False)
212         insertTagNames(dom,A=1,B=2)         insertTagNames(dom,A=1,B=2)
213         dom.write(test)         dom.write(test)
214         dom2 = ReadMesh(test,3)         dom2 = ReadMesh(test,3,optimize=False)
215         t=getTagNames(dom)         t=getTagNames(dom)
216         self.failUnless(len(t)==2)         self.failUnless(len(t)==6)
217         self.failUnless("A" in t)         self.failUnless("A" in t)
218         self.failUnless("B" in t)         self.failUnless("B" in t)
219         self.failUnless(dom2.getTag("A") == 1)         self.failUnless(dom2.getTag("A") == 1)
# Line 239  if __name__ == '__main__': Line 228  if __name__ == '__main__':
228     suite.addTest(unittest.makeSuite(Test_GMSHReader))     suite.addTest(unittest.makeSuite(Test_GMSHReader))
229     suite.addTest(unittest.makeSuite(Test_Reader))     suite.addTest(unittest.makeSuite(Test_Reader))
230     s=unittest.TextTestRunner(verbosity=2).run(suite)     s=unittest.TextTestRunner(verbosity=2).run(suite)
    if s.wasSuccessful():  
      sys.exit(0)  
    else:  
      sys.exit(1)  

Legend:
Removed from v.1311  
changed lines
  Added in v.1312

  ViewVC Help
Powered by ViewVC 1.1.26