/[escript]/trunk/pycad/test/python/run_pycad_test.py
ViewVC logotype

Diff of /trunk/pycad/test/python/run_pycad_test.py

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

revision 932 by gross, Fri Jan 19 09:27:15 2007 UTC revision 933 by gross, Mon Jan 22 07:20:25 2007 UTC
# Line 12  import unittest Line 12  import unittest
12  import math  import math
13  import numarray  import numarray
14  from esys.pycad import *  from esys.pycad import *
15    from esys.pycad.design import Design as Design0
16    from esys.pycad.gmsh import Design as GMSHDesign
17    
18  try:  try:
19       PYCAD_TEST_DATA=os.environ['PYCAD_TEST_DATA']       PYCAD_TEST_DATA=os.environ['PYCAD_TEST_DATA']
# Line 23  try: Line 25  try:
25  except KeyError:  except KeyError:
26       PYCAD_WORKDIR='.'       PYCAD_WORKDIR='.'
27    
28  PYCAD_TEST_MESH_PATH=PYCAD_TEST_DATA+"/data_meshes/"  PYCAD_TEST_MESH_PATH=PYCAD_TEST_DATA+os.sep+"data_meshes"+os.sep
29  PYCAD_WORKDIR_PATH=PYCAD_WORKDIR+"/"  PYCAD_WORKDIR_PATH=PYCAD_WORKDIR+os.sep
30    
31  def _cross(x, y):  def _cross(x, y):
32      return numarray.array([x[1] * y[2] - x[2] * y[1], x[2] * y[0] - x[0] * y[2], x[0] * y[1] - x[1] * y[0]])      return numarray.array([x[1] * y[2] - x[2] * y[1], x[2] * y[0] - x[0] * y[2], x[0] * y[1] - x[1] * y[0]])
# Line 3306  class Test_PyCAD_Primitives(unittest.Tes Line 3308  class Test_PyCAD_Primitives(unittest.Tes
3308          self.failUnless(cc[cc.index(s6_i)].hasSameOrientation(s6_i),"s6_i in modified object has wrong orientation.")          self.failUnless(cc[cc.index(s6_i)].hasSameOrientation(s6_i),"s6_i in modified object has wrong orientation.")
3309          self.failUnless(s6_i.isColocated(s6_i_m),"s6_i in dilated object as wrong location.")          self.failUnless(s6_i.isColocated(s6_i_m),"s6_i in dilated object as wrong location.")
3310    
3311    class Test_PyCAD_Design(unittest.TestCase):
3312       def setUp(self):
3313             resetGlobalPrimitiveIdCounter()
3314       def test_Design(self):
3315        
3316           d=Design0(dim=2, element_size=0.01, order=1, keep_files=False)
3317           # check dimension:
3318           self.failUnlessRaises(ValueError,d.setDim,4)
3319           d.setDim(3)
3320           self.failUnless(d.getDim() == 3)
3321           # check element order
3322           self.failUnlessRaises(ValueError,d.setElementOrder,4)
3323           d.setElementOrder(2)
3324           self.failUnless(d.getElementOrder() == 2)
3325           # check element size
3326           self.failUnlessRaises(ValueError,d.setElementSize,0)
3327           d.setElementSize(0.02)
3328           self.failUnless(d.getElementSize() == 0.02)
3329           # files:
3330           d.setKeepFilesOff()
3331           self.failUnless(not d.keepFiles())
3332           d.setKeepFilesOn()
3333           self.failUnless(d.keepFiles())
3334           # mesh handler:
3335           self.failUnlessRaises(NotImplementedError,d.getMeshHandler)
3336    
3337           p0=Point(0.,0.,0.)
3338           p1=Point(1.,0.,0.)
3339           p2=Point(1.,1.,0.)
3340           p3=Point(0.,1.,0.)
3341           l01=Line(p0,p1)
3342           l12=Line(p1,p2)
3343           l23=Line(p2,p3)
3344           l30=Line(p3,p0)
3345           c=CurveLoop(l01,l12,l23,l30)
3346           s=PlaneSurface(c)
3347    
3348           self.failUnlessRaises(TypeError,d.addItems,1.)
3349           d.addItems(s)
3350           i=d.getItems()
3351           self.failUnless(isinstance(i,list))
3352           self.failUnless(len(i)==1)
3353           self.failUnless(s in i)
3354    
3355           p=d.getAllPrimitives()
3356           self.failUnless(isinstance(p,list))
3357           self.failUnless(len(p)==10)
3358           self.failUnless(p0 in p)
3359           self.failUnless(p1 in p)
3360           self.failUnless(p2 in p)
3361           self.failUnless(p3 in p)
3362           self.failUnless(l01 in p)
3363           self.failUnless(l12 in p)
3364           self.failUnless(l23 in p)
3365           self.failUnless(l30 in p)
3366           self.failUnless(c in p)
3367           self.failUnless(s in p)
3368           # clear things:
3369           d.clearItems()
3370           i=d.getItems()
3371           self.failUnless(isinstance(i,list))
3372           self.failUnless(len(i)==0)
3373    
3374       def test_GMSH(self):
3375        
3376           d=GMSHDesign(dim=2, element_size=0.01, order=1, keep_files=False)
3377    
3378           script_name=d.getScriptFileName()
3379           self.failUnless(isinstance(script_name,str))
3380           self.failUnless(script_name.split(".")[-1] == "geo")
3381           script_name=PYCAD_WORKDIR+os.sep+"script.geo"
3382           d.setScriptFileName(script_name)
3383           self.failUnless(script_name == d.getScriptFileName())
3384    
3385           mesh_name=d.getMeshFileName()
3386           self.failUnless(isinstance(mesh_name,str))
3387           self.failUnless(mesh_name.split(".")[-1] == "msh")
3388           mesh_name=PYCAD_WORKDIR+os.sep+"mesh.msh"
3389           d.setMeshFileName(mesh_name)
3390           self.failUnless(mesh_name == d.getMeshFileName())
3391          
3392           d.setOptions(algorithm=d.ANISO,optimize_quality=False,smoothing=4)
3393           cmd=d.getCommandString()
3394           self.failUnless("gmsh -2 -algo aniso -smooth 4  -v 0 -order 1 -o .%smesh.msh .%sscript.geo"%(os.sep,os.sep) == cmd)
3395    
3396           d.setOptions(optimize_quality=True)
3397           cmd=d.getCommandString()
3398           print cmd
3399           self.failUnless("gmsh -2 -algo iso -smooth 3 -optimize  -v 0 -order 1 -o .%smesh.msh .%sscript.geo"%(os.sep,os.sep) == cmd)
3400    
3401           p0=Point(0.,0.,0.)
3402           p1=Point(1.,0.,0.)
3403           p2=Point(1.,1.,0.)
3404           p3=Point(0.,1.,0.)
3405           l01=Line(p0,p1)
3406           l12=Line(p1,p2)
3407           l23=Line(p2,p3)
3408           l30=Line(p3,p0)
3409           c=CurveLoop(l01,l12,l23,l30)
3410           s=PlaneSurface(c)
3411           d.addItems(s)
3412           srpt=d.getScriptString()
3413           ref = \
3414    """// generated by esys.pycad
3415    Point(1) = {0.0 , 0.0, 0.0 , 0.01 };
3416    Point(2) = {1.0 , 0.0, 0.0 , 0.01 };
3417    Point(3) = {1.0 , 1.0, 0.0 , 0.01 };
3418    Point(4) = {0.0 , 1.0, 0.0 , 0.01 };
3419    Line(5) = {1, 2};
3420    Line(6) = {2, 3};
3421    Line(7) = {3, 4};
3422    Line(8) = {4, 1};
3423    Line Loop(9) = {5, 6, 7, 8};
3424    Plane Surface(10) = {9};
3425    """
3426           self.failUnless(srpt == ref )
3427          
3428    
3429  if __name__ == '__main__':  if __name__ == '__main__':
3430     suite = unittest.TestSuite()     suite = unittest.TestSuite()
3431     suite.addTest(unittest.makeSuite(Test_PyCAD_Transformations))     suite.addTest(unittest.makeSuite(Test_PyCAD_Transformations))
3432     suite.addTest(unittest.makeSuite(Test_PyCAD_Primitives))     suite.addTest(unittest.makeSuite(Test_PyCAD_Primitives))
3433       suite.addTest(unittest.makeSuite(Test_PyCAD_Design))
3434     s=unittest.TextTestRunner(verbosity=2).run(suite)     s=unittest.TextTestRunner(verbosity=2).run(suite)
3435     if s.wasSuccessful():     if s.wasSuccessful():
3436       sys.exit(0)       sys.exit(0)

Legend:
Removed from v.932  
changed lines
  Added in v.933

  ViewVC Help
Powered by ViewVC 1.1.26