/[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 1312 by ksteube, Mon Sep 24 06:18:44 2007 UTC revision 1388 by trankine, Fri Jan 11 07:45:58 2008 UTC
# Line 15  Line 15 
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 and test the finley integration schemes.
19  """  """
20    
21  __copyright__="""  Copyright (c) 2006 by ACcESS MNRF  __copyright__="""  Copyright (c) 2006 by ACcESS MNRF
# Line 220  class Test_Reader(unittest.TestCase): Line 220  class Test_Reader(unittest.TestCase):
220         self.failUnless(dom2.getTag("B") == 2)         self.failUnless(dom2.getTag("B") == 2)
221         self.failUnless(dom2.isValidTagName("A"))         self.failUnless(dom2.isValidTagName("A"))
222         self.failUnless(dom2.isValidTagName("B"))         self.failUnless(dom2.isValidTagName("B"))
223          
224    class Test_Integration(unittest.TestCase):
225       TOL=EPSILON*100.
226       def __test_2DQ(self,dom,order):
227           x=Function(dom).getX()
228           x_bound=FunctionOnBoundary(dom).getX()
229           for i in xrange(order+1):
230             for j in xrange(order+1):
231                 res=integrate(x[0]**i*x[1]**j)
232                 ref=1./((i+1)*(j+1))
233                 error=abs(res-ref)/abs(ref)
234                 self.failUnless(error<=self.TOL,"integration for order (%s,%s) failed. True value = %s, calculated = %s"%(i,j,ref,res))
235    
236                 res=integrate(x_bound[0]**i*x_bound[1]**j)
237                 ref=0
238                 if i == 0:
239                    ref += 2./(j+1)
240                 else:
241                    ref += 1./(j+1)
242                 if j == 0:
243                    ref += 2./(i+1)
244                 else:
245                    ref += 1./(i+1)
246                 error=abs(res-ref)/abs(ref)
247                 self.failUnless(error<=self.TOL,"surface integration for order (%s,%s) failed. True value = %s, calculated = %s"%(i,j,ref,res))
248                
249       def __test_2DT(self,dom,order,raise_tol=1.):
250           x=Function(dom).getX()
251           x_bound=FunctionOnBoundary(dom).getX()
252           for i in xrange(order+1):
253             for j in xrange(order+1):
254               if i+j<=order:
255                 res=integrate(x[0]**i*x[1]**j)
256                 ref=1./((i+1)*(j+1))
257                 error=abs(res-ref)/abs(ref)
258                 # print order,error
259                 self.failUnless(error<=self.TOL*raise_tol,"integration for order (%s,%s) failed. True value = %s, calculated = %s"%(i,j,ref,res))
260    
261                 res=integrate(x_bound[0]**i*x_bound[1]**j)
262                 ref=0
263                 if i == 0:
264                    ref += 2./(j+1)
265                 else:
266                    ref += 1./(j+1)
267                 if j == 0:
268                    ref += 2./(i+1)
269                 else:
270                    ref += 1./(i+1)
271                 error=abs(res-ref)/abs(ref)
272                 self.failUnless(error<=self.TOL*raise_tol,"surface integration for order (%s,%s) failed. True value = %s, calculated = %s"%(i,j,ref,res))
273    
274    
275       def __test_3DQ(self,dom,order):
276           x=Function(dom).getX()
277           x_bound=FunctionOnBoundary(dom).getX()
278           for i in xrange(order+1):
279             for j in xrange(order+1):
280               for k in xrange(order+1):
281                 res=integrate(x[0]**i*x[1]**j*x[2]**k)
282                 ref=1./((i+1)*(j+1)*(k+1))
283                 error=abs(res-ref)/abs(ref)
284                 self.failUnless(error<=self.TOL,"integration for order (%s,%s,%s) failed. True value = %s, calculated = %s"%(i,j,k,ref,res))
285    
286                 res=integrate(x_bound[0]**i*x_bound[1]**j*x_bound[2]**k)
287                 ref=0
288                 if i == 0:
289                    ref += 2./((j+1)*(k+1))
290                 else:
291                    ref += 1./((j+1)*(k+1))
292                 if j == 0:
293                    ref += 2./((i+1)*(k+1))
294                 else:
295                    ref += 1./((i+1)*(k+1))
296                 if k == 0:
297                    ref += 2./((i+1)*(j+1))
298                 else:
299                    ref += 1./((i+1)*(j+1))
300                 error=abs(res-ref)/abs(ref)
301                 self.failUnless(error<=self.TOL,"surface integration for order (%s,%s,%s) failed. True value = %s, calculated = %s"%(i,j,k,ref,res))
302    
303       def __test_3DT(self,dom,order,raise_tol=1.):
304           x=Function(dom).getX()
305           x_bound=FunctionOnBoundary(dom).getX()
306           for i in xrange(order+1):
307             for j in xrange(order+1):
308               for k in xrange(order+1):
309                 if i+j+k<=order:
310                    res=integrate(x[0]**i*x[1]**j*x[2]**k)
311                    ref=1./((i+1)*(j+1)*(k+1))
312                    error=abs(res-ref)/abs(ref)
313                    self.failUnless(error<=self.TOL*raise_tol,"integration for order (%s,%s,%s) failed. True value = %s, calculated = %s"%(i,j,k,ref,res))
314    
315                    res=integrate(x_bound[0]**i*x_bound[1]**j*x_bound[2]**k)
316                    ref=0
317                    if i == 0:
318                       ref += 2./((j+1)*(k+1))
319                    else:
320                       ref += 1./((j+1)*(k+1))
321                    if j == 0:
322                       ref += 2./((i+1)*(k+1))
323                    else:
324                       ref += 1./((i+1)*(k+1))
325                    if k == 0:
326                       ref += 2./((i+1)*(j+1))
327                    else:
328                       ref += 1./((i+1)*(j+1))
329                    error=abs(res-ref)/abs(ref)
330                    self.failUnless(error<=self.TOL*raise_tol,"surface integration for order (%s,%s,%s) failed. True value = %s, calculated = %s"%(i,j,k,ref,res))
331    
332       def test_hex2D_order1(self):
333          my_dom=Rectangle(1,1,integrationOrder=1)
334          self.__test_2DQ(my_dom,1)
335       def test_hex2D_order2(self):
336          my_dom=Rectangle(1,1,integrationOrder=2)
337          self.__test_2DQ(my_dom,2)
338       def test_hex2D_order3(self):
339          my_dom=Rectangle(1,1,integrationOrder=3)
340          self.__test_2DQ(my_dom,3)
341       def test_hex2D_order4(self):
342          my_dom=Rectangle(1,1,integrationOrder=4)
343          self.__test_2DQ(my_dom,4)
344       def test_hex2D_order5(self):
345          my_dom=Rectangle(1,1,integrationOrder=5)
346          self.__test_2DQ(my_dom,5)
347       def test_hex2D_order6(self):
348          my_dom=Rectangle(1,1,integrationOrder=6)
349          self.__test_2DQ(my_dom,6)
350       def test_hex2D_order7(self):
351          my_dom=Rectangle(1,1,integrationOrder=7)
352          self.__test_2DQ(my_dom,7)
353       def test_hex2D_order8(self):
354          my_dom=Rectangle(1,1,integrationOrder=8)
355          self.__test_2DQ(my_dom,8)
356       def test_hex2D_order9(self):
357          my_dom=Rectangle(1,1,integrationOrder=9)
358          self.__test_2DQ(my_dom,9)
359       def test_hex2D_order10(self):
360          my_dom=Rectangle(1,1,integrationOrder=10)
361          self.__test_2DQ(my_dom,10)
362    
363       def test_Tet2D_order1(self):
364          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tri3.fly",optimize=False,integrationOrder=1)
365          self.__test_2DT(my_dom,1)
366       def test_Tet2D_order2(self):
367          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tri3.fly",optimize=False,integrationOrder=2)
368          self.__test_2DT(my_dom,2)
369       def test_Tet2D_order3(self):
370          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tri3.fly",optimize=False,integrationOrder=3)
371          self.__test_2DT(my_dom,3)
372       def test_Tet2D_order4(self):
373          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tri3.fly",optimize=False,integrationOrder=4)
374          self.__test_2DT(my_dom,4)
375       def test_Tet2D_order5(self):
376          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tri3.fly",optimize=False,integrationOrder=5)
377          self.__test_2DT(my_dom,5)
378       def test_Tet2D_order6(self):
379          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tri3.fly",optimize=False,integrationOrder=6)
380          self.__test_2DT(my_dom,6)
381       def test_Tet2D_order7(self):
382          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tri3.fly",optimize=False,integrationOrder=7)
383          self.__test_2DT(my_dom,7)
384       def test_Tet2D_order8(self):
385          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tri3.fly",optimize=False,integrationOrder=8)
386          self.__test_2DT(my_dom,8,1./sqrt(EPSILON))
387       def test_Tet2D_order9(self):
388          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tri3.fly",optimize=False,integrationOrder=9)
389          self.__test_2DT(my_dom,9,1./sqrt(EPSILON))
390       def test_Tet2D_order10(self):
391          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tri3.fly",optimize=False,integrationOrder=10)
392          self.__test_2DT(my_dom,10)
393    
394       def test_hex3D_order1(self):
395          my_dom=Brick(1,1,1,integrationOrder=1)
396          self.__test_3DQ(my_dom,1)
397       def test_hex3D_order2(self):
398          my_dom=Brick(1,1,1,integrationOrder=2)
399          self.__test_3DQ(my_dom,2)
400       def test_hex3D_order3(self):
401          my_dom=Brick(1,1,1,integrationOrder=3)
402          self.__test_3DQ(my_dom,3)
403       def test_hex3D_order4(self):
404          my_dom=Brick(1,1,1,integrationOrder=4)
405          self.__test_3DQ(my_dom,4)
406       def test_hex3D_order5(self):
407          my_dom=Brick(1,1,1,integrationOrder=5)
408          self.__test_3DQ(my_dom,5)
409       def test_hex3D_order6(self):
410          my_dom=Brick(1,1,1,integrationOrder=6)
411          self.__test_3DQ(my_dom,6)
412       def test_hex3D_order7(self):
413          my_dom=Brick(1,1,1,integrationOrder=7)
414          self.__test_3DQ(my_dom,7)
415       def test_hex3D_order8(self):
416          my_dom=Brick(1,1,1,integrationOrder=8)
417          self.__test_3DQ(my_dom,8)
418       def test_hex3D_order9(self):
419          my_dom=Brick(1,1,1,integrationOrder=9)
420          self.__test_3DQ(my_dom,9)
421       def test_hex3D_order10(self):
422          my_dom=Brick(1,1,1,integrationOrder=10)
423          self.__test_3DQ(my_dom,10)
424    
425       def test_Tet3D_order1(self):
426          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tet4.fly",optimize=False,integrationOrder=1)
427          self.__test_3DT(my_dom,1)
428       def test_Tet3D_order2(self):
429          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tet4.fly",optimize=False,integrationOrder=2)
430          self.__test_3DT(my_dom,2)
431       def test_Tet3D_order3(self):
432          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tet4.fly",optimize=False,integrationOrder=3)
433          self.__test_3DT(my_dom,3)
434       def test_Tet3D_order4(self):
435          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tet4.fly",optimize=False,integrationOrder=4)
436          self.__test_3DT(my_dom,4)
437       def test_Tet3D_order5(self):
438          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tet4.fly",optimize=False,integrationOrder=5)
439          self.__test_3DT(my_dom,5)
440       def test_Tet3D_order6(self):
441          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tet4.fly",optimize=False,integrationOrder=6)
442          self.__test_3DT(my_dom,6,1./sqrt(EPSILON))
443       def test_Tet3D_order7(self):
444          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tet4.fly",optimize=False,integrationOrder=7)
445          self.__test_3DT(my_dom,7,1./sqrt(EPSILON))
446       def test_Tet3D_order8(self):
447          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tet4.fly",optimize=False,integrationOrder=8)
448          self.__test_3DT(my_dom,8,1./sqrt(EPSILON))
449       def test_Tet3D_order9(self):
450          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tet4.fly",optimize=False,integrationOrder=9)
451          self.__test_3DT(my_dom,9,1./sqrt(EPSILON))
452       def test_Tet3D_order10(self):
453          my_dom = ReadMesh(FINLEY_TEST_MESH_PATH+os.sep+"tet4.fly",optimize=False,integrationOrder=10)
454          self.__test_3DT(my_dom,10)
455    
456  if __name__ == '__main__':  if __name__ == '__main__':
457     suite = unittest.TestSuite()     suite = unittest.TestSuite()
458     suite.addTest(unittest.makeSuite(Test_Generators))     suite.addTest(unittest.makeSuite(Test_Generators))
459     suite.addTest(unittest.makeSuite(Test_GMSHReader))     suite.addTest(unittest.makeSuite(Test_GMSHReader))
460     suite.addTest(unittest.makeSuite(Test_Reader))     suite.addTest(unittest.makeSuite(Test_Reader))
461       suite.addTest(unittest.makeSuite(Test_Integration))
462     s=unittest.TextTestRunner(verbosity=2).run(suite)     s=unittest.TextTestRunner(verbosity=2).run(suite)
463       if not s.wasSuccessful(): sys.exit(1)
464    

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

  ViewVC Help
Powered by ViewVC 1.1.26