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

Annotation of /trunk/finley/test/python/run_generators.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1135 - (hide annotations)
Wed May 9 01:58:32 2007 UTC (12 years, 7 months ago) by gross
File MIME type: text/x-python
File size: 8750 byte(s)
These are still modifications for windows.

The run_generators.py and run_visualization_interface.py pass now. There is no need for the win32 reference directory. 
1 jgs 150 # $Id$
2    
3    
4     """
5     checks the mesh generators against the reference meshes in test_meshes
6     """
7    
8 elspeth 617 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
9     http://www.access.edu.au
10     Primary Business: Queensland, Australia"""
11     __license__="""Licensed under the Open Software License version 3.0
12     http://www.opensource.org/licenses/osl-3.0.php"""
13 jgs 150
14 elspeth 626 import sys
15 gross 706 import os
16 elspeth 626 import unittest
17     from esys.escript import *
18 gross 1044 from esys.finley import Interval,Rectangle,Brick,JoinFaces, ReadGmsh, ReadMesh
19 elspeth 626
20 gross 798 try:
21     FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
22     except KeyError:
23     FINLEY_TEST_DATA='.'
24    
25     try:
26     FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']
27     except KeyError:
28     FINLEY_WORKDIR='.'
29    
30 gross 1135 FINLEY_TEST_MESH_PATH=os.path.join(FINLEY_TEST_DATA,"data_meshes")
31     FINLEY_WORKDIR_PATH=FINLEY_WORKDIR
32 gross 709
33 gross 706 TEST_FILE_EXT=".test"
34 jgs 150 class Test_Generators(unittest.TestCase):
35    
36     def checker(self,dom,reference):
37 gross 1135 dom_file=os.path.join(FINLEY_WORKDIR_PATH,TEST_FILE_EXT)
38 jgs 150 dom.write(dom_file)
39 woo409 757 # Uncomment this section to dump the files for regression testing
40     # if True:
41 gross 1135 # dom.write(os.path.join(FINLEY_TEST_MESH_PATH,reference))
42 jgs 150 dom_string=open(dom_file).read().splitlines()
43 gross 1135 ref_string=open(os.path.join(FINLEY_TEST_MESH_PATH,reference)).read().splitlines()
44 jgs 150 self.failUnlessEqual(len(dom_string),len(ref_string),"number of lines in mesh files does not match reference")
45     for l in range(1,len(ref_string)):
46 gross 1135 line=dom_string[l].strip()
47     if os.name == "nt":
48     line=line.replace("e+00","e+0").replace("e-00","e-0")
49     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)))
50 jgs 150
51     def test_hex_1D_order1(self):
52     file="hex_1D_order1.msh"
53     my_dom=Interval(1,1)
54     self.checker(my_dom,file)
55    
56     def test_hex_1D_order1_onFace(self):
57     file="hex_1D_order1_onFace.msh"
58     my_dom=Interval(1,1,useElementsOnFace=1)
59     self.checker(my_dom,file)
60    
61     def test_hex_1D_order2(self):
62     file="hex_1D_order2.msh"
63     my_dom=Interval(1,2)
64     self.checker(my_dom,file)
65    
66     def test_hex_1D_order2_onFace(self):
67     file="hex_1D_order2_onFace.msh"
68     my_dom=Interval(1,2,useElementsOnFace=1)
69     self.checker(my_dom,file)
70    
71     def test_hex_2D_order1(self):
72     file="hex_2D_order1.msh"
73     my_dom=Rectangle(1,1,1)
74     self.checker(my_dom,file)
75    
76     def test_hex_2D_order1_onFace(self):
77     file="hex_2D_order1_onFace.msh"
78     my_dom=Rectangle(1,1,1,useElementsOnFace=1)
79     self.checker(my_dom,file)
80    
81     def test_hex_2D_order2(self):
82     file="hex_2D_order2.msh"
83     my_dom=Rectangle(1,1,2)
84     self.checker(my_dom,file)
85    
86     def test_hex_2D_order2_onFace(self):
87     file="hex_2D_order2_onFace.msh"
88     my_dom=Rectangle(1,1,2,useElementsOnFace=1)
89     self.checker(my_dom,file)
90    
91     def test_hex_3D_order1(self):
92     file="hex_3D_order1.msh"
93     my_dom=Brick(1,1,1,1)
94     self.checker(my_dom,file)
95    
96     def test_hex_3D_order1_onFace(self):
97     file="hex_3D_order1_onFace.msh"
98     my_dom=Brick(1,1,1,1,useElementsOnFace=1)
99     self.checker(my_dom,file)
100    
101     def test_hex_3D_order2(self):
102     file="hex_3D_order2.msh"
103     my_dom=Brick(1,1,1,2)
104     self.checker(my_dom,file)
105    
106     def test_hex_3D_order2_onFace(self):
107     file="hex_3D_order2_onFace.msh"
108     my_dom=Brick(1,1,1,2,useElementsOnFace=1)
109     self.checker(my_dom,file)
110    
111     def test_hex_contact_2D_order1(self):
112     file="hex_contact_2D_order1.msh"
113     ms1=Rectangle(1,1,1,l1=0.5,useElementsOnFace=False)
114     ms2=Rectangle(1,1,1,l1=0.5,useElementsOnFace=False)
115     ms2.setX(ms2.getX()+[0,0.5])
116     my_dom=JoinFaces([ms1,ms2])
117     self.checker(my_dom,file)
118    
119     def test_hex_contact_2D_order1_onFace(self):
120     file="hex_contact_2D_order1_onFace.msh"
121     ms1=Rectangle(1,1,1,l1=0.5,useElementsOnFace=True)
122     ms2=Rectangle(1,1,1,l1=0.5,useElementsOnFace=True)
123     ms2.setX(ms2.getX()+[0,0.5])
124     my_dom=JoinFaces([ms1,ms2])
125     self.checker(my_dom,file)
126    
127     def test_hex_contact_2D_order2(self):
128     file="hex_contact_2D_order2.msh"
129     ms1=Rectangle(1,1,2,l1=0.5,useElementsOnFace=False)
130     ms2=Rectangle(1,1,2,l1=0.5,useElementsOnFace=False)
131     ms2.setX(ms2.getX()+[0,0.5])
132     my_dom=JoinFaces([ms1,ms2])
133     self.checker(my_dom,file)
134    
135     def test_hex_contact_2D_order2_onFace(self):
136     file="hex_contact_2D_order2_onFace.msh"
137     ms1=Rectangle(1,1,2,l1=0.5,useElementsOnFace=True)
138     ms2=Rectangle(1,1,2,l1=0.5,useElementsOnFace=True)
139     ms2.setX(ms2.getX()+[0,0.5])
140     my_dom=JoinFaces([ms1,ms2])
141     self.checker(my_dom,file)
142    
143     def test_hex_contact_3D_order1(self):
144     file="hex_contact_3D_order1.msh"
145     ms1=Brick(1,1,1,1,l2=0.5,useElementsOnFace=False)
146     ms2=Brick(1,1,1,1,l2=0.5,useElementsOnFace=False)
147     ms2.setX(ms2.getX()+[0,0,0.5])
148     my_dom=JoinFaces([ms1,ms2])
149     self.checker(my_dom,file)
150    
151     def test_hex_contact_3D_order1_onFace(self):
152     file="hex_contact_3D_order1_onFace.msh"
153     ms1=Brick(1,1,1,1,l2=0.5,useElementsOnFace=True)
154     ms2=Brick(1,1,1,1,l2=0.5,useElementsOnFace=True)
155     ms2.setX(ms2.getX()+[0,0,0.5])
156     my_dom=JoinFaces([ms1,ms2])
157     self.checker(my_dom,file)
158    
159     def test_hex_contact_3D_order2(self):
160     file="hex_contact_3D_order2.msh"
161     ms1=Brick(1,1,1,2,l2=0.5,useElementsOnFace=False)
162     ms2=Brick(1,1,1,2,l2=0.5,useElementsOnFace=False)
163     ms2.setX(ms2.getX()+[0,0,0.5])
164     my_dom=JoinFaces([ms1,ms2])
165     self.checker(my_dom,file)
166    
167     def test_hex_contact_3D_order2_onFace(self):
168     file="hex_contact_3D_order2_onFace.msh"
169     ms1=Brick(1,1,1,2,l2=0.5,useElementsOnFace=True)
170     ms2=Brick(1,1,1,2,l2=0.5,useElementsOnFace=True)
171     ms2.setX(ms2.getX()+[0,0,0.5])
172     my_dom=JoinFaces([ms1,ms2])
173     self.checker(my_dom,file)
174    
175 gross 934 class Test_GMSHReader(unittest.TestCase):
176     def compare(self, test_file, reference_file):
177     dom_string=open(test_file).read().splitlines()
178     ref_string=open(reference_file).read().splitlines()
179     self.failUnlessEqual(len(dom_string),len(ref_string),"number of lines in mesh files does not match reference")
180     for l in range(1,len(ref_string)):
181 gross 1135 line=dom_string[l].strip()
182     if os.name == "nt":
183     line=line.replace("e+00","e+0").replace("e-00","e-0")
184     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))
185 gross 934
186     def test_Tri3(self):
187     file="tri3_gmsh.msh"
188     ref ="tri3.fly"
189 gross 1135 test = os.path.join(FINLEY_WORKDIR,"tri3_test.fly")
190     dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,file),2)
191 gross 934 dom.write(test)
192 gross 1135 self.compare(test, os.path.join(FINLEY_TEST_MESH_PATH,ref))
193 gross 934
194     def test_Tri6(self):
195     file="tri6_gmsh.msh"
196     ref="tri6.fly"
197 gross 1135 test = os.path.join(FINLEY_WORKDIR,"tri8_test.fly")
198     dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,file),2)
199 gross 934 dom.write(test)
200 gross 1135 self.compare(test, os.path.join(FINLEY_TEST_MESH_PATH,ref))
201 gross 934
202     def test_Tet4(self):
203     file="tet4_gmsh.msh"
204     ref="tet4.fly"
205 gross 1135 test = os.path.join(FINLEY_WORKDIR,"tet4_test.fly")
206     dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,file),3)
207 gross 934 dom.write(test)
208 gross 1135 self.compare(test, os.path.join(FINLEY_TEST_MESH_PATH,ref))
209 gross 934
210     def test_Tet(self):
211     file="tet10_gmsh.msh"
212     ref="tet10.fly"
213 gross 1135 test = os.path.join(FINLEY_WORKDIR,"tet10_test.fly")
214     dom = ReadGmsh(os.path.join(FINLEY_TEST_MESH_PATH,file),3)
215 gross 934 dom.write(test)
216 gross 1135 self.compare(test, os.path.join(FINLEY_TEST_MESH_PATH,ref))
217 gross 934
218 gross 1044 class Test_Reader(unittest.TestCase):
219     def test_ReadWriteTagNames(self):
220     file="hex_2D_order2.msh"
221 gross 1135 test = os.path.join(FINLEY_WORKDIR,"test.fly")
222     dom = ReadMesh(os.path.join(FINLEY_TEST_MESH_PATH,file),3)
223 gross 1044 insertTagNames(dom,A=1,B=2)
224     dom.write(test)
225     dom2 = ReadMesh(test,3)
226     t=getTagNames(dom)
227     self.failUnless(len(t)==2)
228     self.failUnless("A" in t)
229     self.failUnless("B" in t)
230     self.failUnless(dom2.getTag("A") == 1)
231     self.failUnless(dom2.getTag("B") == 2)
232     self.failUnless(dom2.isValidTagName("A"))
233     self.failUnless(dom2.isValidTagName("B"))
234    
235    
236 jgs 150 if __name__ == '__main__':
237     suite = unittest.TestSuite()
238     suite.addTest(unittest.makeSuite(Test_Generators))
239 gross 934 suite.addTest(unittest.makeSuite(Test_GMSHReader))
240 gross 1044 suite.addTest(unittest.makeSuite(Test_Reader))
241 jgs 150 s=unittest.TextTestRunner(verbosity=2).run(suite)
242     if s.wasSuccessful():
243     sys.exit(0)
244     else:
245     sys.exit(1)

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26