/[escript]/trunk/finley/test/python/gentest
ViewVC logotype

Diff of /trunk/finley/test/python/gentest

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

revision 768 by gross, Fri Jun 30 09:26:16 2006 UTC revision 769 by gross, Sun Jul 2 23:58:22 2006 UTC
# Line 2  Line 2 
2  import numarray  import numarray
3  import random  import random
4  t_prog={}  t_prog={}
5  t_prog["2Do1_strong"]=""  t_prog["2Do1"]=""
6  t_prog["2Do2_strong"]=""  t_prog["2Do2"]=""
7  t_prog["3Do1_strong"]=""  t_prog["3Do1"]=""
8  t_prog["3Do2_strong"]=""  t_prog["3Do2"]=""
9  t_prog["2Do1_weak"]=""  t_prog["2Do1_reduced"]=""
10  t_prog["2Do2_weak"]=""  t_prog["2Do2_reduced"]=""
11  t_prog["3Do1_weak"]=""  t_prog["3Do1_reduced"]=""
12  t_prog["3Do2_weak"]=""  t_prog["3Do2_reduced"]=""
13  t_prog["2Do1_contact"]=""  t_prog["2Do1_contact"]=""
14  t_prog["2Do2_contact"]=""  t_prog["2Do2_contact"]=""
15  t_prog["3Do1_contact"]=""  t_prog["3Do1_contact"]=""
# Line 19  max_order=3 Line 19  max_order=3
19    
20  def makeTitle(d,coeffo,o,s,coef,case,typ,body="",mark="",pdeargs="",add_jump=False):  def makeTitle(d,coeffo,o,s,coef,case,typ,body="",mark="",pdeargs="",add_jump=False):
21     if mark=="":     if mark=="":
22       name="test_assemblage_%sD_solO%s_coeffO%s_neq%s_%s_%s_type%s"%(d,o,coeffo,s,coef,case,typ)       name="test_assemblage_%sD_solO%s_coeffO%s_NEqu%s_%s_%s_type%s"%(d,o,coeffo,s,coef,case,typ)
23     else:     else:
24       name="test_assemblage_%sD_solO%s_coeffO%s_neq%s_%s_%s_type%s_comp%s"%(d,o,coeffo,s,coef,case,typ,mark)       name="test_assemblage_%sD_solO%s_coeffO%s_NEqu%s_%s_%s_type%s_comp%s"%(d,o,coeffo,s,coef,case,typ,mark)
25     key="%sDo%s_%s"%(d,o,typ.lower())     if typ.lower()=="contact":
26          key="%sDo%s_contact"%(d,o)
27       elif coeffo.lower()=="reduced":
28          key="%sDo%s_reduced"%(d,o)
29       else:
30          key="%sDo%s"%(d,o)
31     t_prog[key]+=intend+"#"+50*"="+"\n"+intend+"def %s(self):\n"%name     t_prog[key]+=intend+"#"+50*"="+"\n"+intend+"def %s(self):\n"%name
32     t_prog[key]+=2*intend+"x=self.domain.getX()\n"     t_prog[key]+=2*intend+"x=self.domain.getX()\n"
33     if add_jump:     if add_jump:
# Line 402  def makeFunctionText(func,dim,func_name, Line 407  def makeFunctionText(func,dim,func_name,
407                   t=makeTermText(func[i,j])                   t=makeTermText(func[i,j])
408                   if not t=="0": out+=2*intend+"%s[%s,%s]=%s%s%s\n"%(func_name,i,j,extra_pre,t,extra)                   if not t=="0": out+=2*intend+"%s[%s,%s]=%s%s%s\n"%(func_name,i,j,extra_pre,t,extra)
409     return out     return out
410  for s in [1,2]:  for s in [1,2,3]:
411    for d in [2,3]:    for d in [2,3]:
412      for typ in ["Strong","Weak", "Contact"]:      for typ in ["Strong","Weak", "Contact"]:
413        for coffo in ["Full"]: # ["Full", "Reduced" ]:        for coffo in ["Full", "Reduced" ]:
414          if coffo=="Full":          if coffo=="Full":
415              func_i="Function"              func_i="Function"
416          else:          else:
# Line 465  for s in [1,2]: Line 470  for s in [1,2]:
470                              args="A=A_test, Y=Y_test, y=y_test"                              args="A=A_test, Y=Y_test, y=y_test"
471                           makeTitle(d,coffo,solo,s,"A",case,typ,body2,mark="%s%s%s%s"%(p,i,q,j),pdeargs=args)                           makeTitle(d,coffo,solo,s,"A",case,typ,body2,mark="%s%s%s%s"%(p,i,q,j),pdeargs=args)
472              # coefficient B:              # coefficient B:
473              if s==1:              if typ in ["Strong","Weak"] or coffo=="Full":
474                  for i in range(d):                if s==1:
                   test_func=makeTestSolution(order,s,d)  
                   body2=makeFunctionText(test_func,d,"u")  
                   body2+=2*intend+"B_test=Data(0.,(%d,),%s(self.domain))\n"%(d,func_i)  
                   if case == "Const" :  
                       f=int(8*random.random())+1  
                       body2+=2*intend+"B_test[%d]=%s\n"%(i,f)  
                       B=multiplyByFandX(f,-1,test_func,(0,),(1,d),(0,i))  
                   else:  
                       body2+=2*intend+"B_test[%d]=x[%i]\n"%(i,i)  
                       B=multiplyByFandX(1.,i,test_func,(0,),(1,d),(0,i))  
                   if typ=="Weak":  
                     body2+=makeFunctionText(B,d,"X_test")  
                     args="B=B_test, X=X_test"  
                   elif typ=="Strong":  
                     div_B=makeDiv(B,d)  
                     body2+=makeFunctionText(-div_B,d,"Y_test")  
                     body2+=makeNormalDerivativeText(B,d,"y_test")  
                     args="B=B_test, Y=Y_test, y=y_test"  
                   else:  
                     div_B=makeDiv(B,d)  
                     body2+=makeFunctionText(-div_B,d,"Y_test")  
                     body2+=makeNormalDerivativeText(B,d,"y_test")  
                     body2+=makeContactDerivativeText(-B,d,"y_contact_test")  
                     args="B=B_test, Y=Y_test, y=y_test, y_contact=y_contact_test"  
                   makeTitle(d,coffo,solo,s,"B",case,typ,body2,mark="%s"%(i),pdeargs=args)  
             else:  
                 for p in range(s):  
475                    for i in range(d):                    for i in range(d):
476                      for q in range(s):                      test_func=makeTestSolution(order,s,d)
477                        test_func=makeTestSolution(order,s,d)                            body2=makeFunctionText(test_func,d,"u")
478                        grad_test_func=makeGradient(test_func,d)                      body2+=2*intend+"B_test=Data(0.,(%d,),%s(self.domain))\n"%(d,func_i)
479                        body2=makeFunctionText(test_func,d,"u")                      if case == "Const" :
480                        body2+=2*intend+"B_test=Data(0.,(%d,%d,%d),%s(self.domain))\n"%(s,d,s,func_i)                          f=int(8*random.random())+1
481                        if case == "Const" :                          body2+=2*intend+"B_test[%d]=%s\n"%(i,f)
482                           f=int(8*random.random())+1                          B=multiplyByFandX(f,-1,test_func,(0,),(1,d),(0,i))
483                           body2+=2*intend+"B_test[%d,%d,%d]=%s\n"%(p,i,q,f)                      else:
484                           B=multiplyByFandX(f,-1,test_func,(q,),(s,d),(p,i))                          body2+=2*intend+"B_test[%d]=x[%i]\n"%(i,i)
485                        else:                          B=multiplyByFandX(1.,i,test_func,(0,),(1,d),(0,i))
486                           body2+=2*intend+"B_test[%d,%d,%d]=x[%i]\n"%(p,i,q,i)                      if typ=="Weak":
487                           B=multiplyByFandX(1.,i,test_func,(q,),(s,d),(p,i))                        body2+=makeFunctionText(B,d,"X_test")
488                        if typ=="Weak":                        args="B=B_test, X=X_test"
489                           body2+=makeFunctionText(B,d,"X_test")                      elif typ=="Strong":
490                           args="B=B_test, X=X_test"                        div_B=makeDiv(B,d)
491                        elif typ=="Strong":                        body2+=makeFunctionText(-div_B,d,"Y_test")
492                           div_B=makeDiv(B,d)                        body2+=makeNormalDerivativeText(B,d,"y_test")
493                           body2+=makeFunctionText(-div_B,d,"Y_test")                        args="B=B_test, Y=Y_test, y=y_test"
494                           body2+=makeNormalDerivativeText(B,d,"y_test")                      else:
495                           args="B=B_test, Y=Y_test, y=y_test"                        div_B=makeDiv(B,d)
496                        else:                        body2+=makeFunctionText(-div_B,d,"Y_test")
497                           div_B=makeDiv(B,d)                        body2+=makeNormalDerivativeText(B,d,"y_test")
498                           body2+=makeFunctionText(-div_B,d,"Y_test")                        body2+=makeContactDerivativeText(-B,d,"y_contact_test")
499                           body2+=makeNormalDerivativeText(B,d,"y_test")                        args="B=B_test, Y=Y_test, y=y_test, y_contact=y_contact_test"
500                           body2+=makeContactDerivativeText(-B,d,"y_contact_test")                      makeTitle(d,coffo,solo,s,"B",case,typ,body2,mark="%s"%(i),pdeargs=args)
501                           args="B=B_test, Y=Y_test, y=y_test, y_contact=y_contact_test"                else:
502                        makeTitle(d,coffo,solo,s,"B",case,typ,body2,mark="%s%s%s"%(p,i,q),pdeargs=args)                    for p in range(s):
503                        for i in range(d):
504                          for q in range(s):
505                            test_func=makeTestSolution(order,s,d)      
506                            grad_test_func=makeGradient(test_func,d)
507                            body2=makeFunctionText(test_func,d,"u")
508                            body2+=2*intend+"B_test=Data(0.,(%d,%d,%d),%s(self.domain))\n"%(s,d,s,func_i)
509                            if case == "Const" :
510                               f=int(8*random.random())+1
511                               body2+=2*intend+"B_test[%d,%d,%d]=%s\n"%(p,i,q,f)
512                               B=multiplyByFandX(f,-1,test_func,(q,),(s,d),(p,i))
513                            else:
514                               body2+=2*intend+"B_test[%d,%d,%d]=x[%i]\n"%(p,i,q,i)
515                               B=multiplyByFandX(1.,i,test_func,(q,),(s,d),(p,i))
516                            if typ=="Weak":
517                               body2+=makeFunctionText(B,d,"X_test")
518                               args="B=B_test, X=X_test"
519                            elif typ=="Strong":
520                               div_B=makeDiv(B,d)
521                               body2+=makeFunctionText(-div_B,d,"Y_test")
522                               body2+=makeNormalDerivativeText(B,d,"y_test")
523                               args="B=B_test, Y=Y_test, y=y_test"
524                            else:
525                               div_B=makeDiv(B,d)
526                               body2+=makeFunctionText(-div_B,d,"Y_test")
527                               body2+=makeNormalDerivativeText(B,d,"y_test")
528                               body2+=makeContactDerivativeText(-B,d,"y_contact_test")
529                               args="B=B_test, Y=Y_test, y=y_test, y_contact=y_contact_test"
530                            makeTitle(d,coffo,solo,s,"B",case,typ,body2,mark="%s%s%s"%(p,i,q),pdeargs=args)
531              if typ=="Strong":              if typ=="Strong":
532                 # coefficient C:                 # coefficient C:
533                 if s==1:                 if s==1:
# Line 678  print "import unittest" Line 684  print "import unittest"
684  print "import numarray"  print "import numarray"
685  print "from esys.escript import *"  print "from esys.escript import *"
686  print "from esys.finley import Rectangle,Brick"  print "from esys.finley import Rectangle,Brick"
687  #print "class Test_assemblage_2Do1_Strong(unittest.TestCase):"  print "class Test_assemblage_2Do1(unittest.TestCase):"
688  #print t_prog["2Do1_strong"]  print t_prog["2Do1"]
689  #print "class Test_assemblage_2Do2_Strong(unittest.TestCase):"  print "class Test_assemblage_2Do1_Reduced(unittest.TestCase):"
690  #print t_prog["2Do2_strong"]  print t_prog["2Do1_reduced"]
 #print "class Test_assemblage_3Do1_Strong(unittest.TestCase):"  
 #print t_prog["3Do1_strong"]  
 #print "class Test_assemblage_3Do2_Strong(unittest.TestCase):"  
 #print t_prog["3Do2_strong"]  
 #print "class Test_assemblage_2Do1_Weak(unittest.TestCase):"  
 #print t_prog["2Do1_weak"]  
 #print "class Test_assemblage_2Do2_Weak(unittest.TestCase):"  
 #print t_prog["2Do2_weak"]  
 #print "class Test_assemblage_3Do1_Weak(unittest.TestCase):"  
 #print t_prog["3Do1_weak"]  
 #print "class Test_assemblage_3Do2_Weak(unittest.TestCase):"  
 #print t_prog["3Do2_weak"]  
691  print "class Test_assemblage_2Do1_Contact(unittest.TestCase):"  print "class Test_assemblage_2Do1_Contact(unittest.TestCase):"
692  print t_prog["2Do1_contact"]  print t_prog["2Do1_contact"]
693    
694    #print "class Test_assemblage_2Do2(unittest.TestCase):"
695    #print t_prog["2Do2"]
696    #print "class Test_assemblage_2Do2_Reduced(unittest.TestCase):"
697    #print t_prog["2Do2_reduced"]
698  #print "class Test_assemblage_2Do2_Contact(unittest.TestCase):"  #print "class Test_assemblage_2Do2_Contact(unittest.TestCase):"
699  #print t_prog["2Do2_contact"]  #print t_prog["2Do2_contact"]
700    
701    #print "class Test_assemblage_3Do1(unittest.TestCase):"
702    #print t_prog["3Do1"]
703    #print "class Test_assemblage_3Do1_Reduced(unittest.TestCase):"
704    #print t_prog["3Do1_reduced"]
705  #print "class Test_assemblage_3Do1_Contact(unittest.TestCase):"  #print "class Test_assemblage_3Do1_Contact(unittest.TestCase):"
706  #print t_prog["3Do1_contact"]  #print t_prog["3Do1_contact"]
707    
708    #print "class Test_assemblage_3Do2(unittest.TestCase):"
709    #print t_prog["3Do2"]
710    #print "class Test_assemblage_3Do2_Reduced(unittest.TestCase):"
711    #print t_prog["3Do2_reduced"]
712  #print "class Test_assemblage_3Do2_contact(unittest.TestCase):"  #print "class Test_assemblage_3Do2_contact(unittest.TestCase):"
713  #print t_prog["3Do2_contact"]  #print t_prog["3Do2_contact"]
714    
715    
716  print "from esys.escript import *\n"  print "from esys.escript import *"
717  print "from esys.finley import *\n"  print "from esys.finley import *"
718  print "from esys.escript.linearPDEs import LinearPDE\n"  print "from esys.escript.linearPDEs import LinearPDE"
719  print "import numarray"  print "import numarray"
720  print "import unittest"  print "import unittest"
721    print "NE=2 # number of element sin each spatial direction (must be even)"
722    
723  # print "class Test_Finley_assemblage_2Do1(Test_assemblage_2Do1_Strong,Test_assemblage_2Do1_Weak):"  print "class Test_Finley_assemblage_2Do1(Test_assemblage_2Do1):"
724  # print "   RES_TOL=1.e-7"  print "   RES_TOL=1.e-7"
725  # print "   ABS_TOL=1.e-8"  print "   ABS_TOL=1.e-8"
726  # print "   def setUp(self):"  print "   def setUp(self):"
727  # print "       self.domain =Rectangle(2,2,1)"  print "       self.domain =Rectangle(NE,NE,1)"
728  print "class Test_Finley_assemblage_2Do1_Contact(Test_assemblage_2Do1_Contact):"  print "class Test_Finley_assemblage_2Do1_Contact(Test_assemblage_2Do1_Contact):"
729  print "   RES_TOL=1.e-7"  print "   RES_TOL=1.e-7"
730  print "   ABS_TOL=1.e-8"  print "   ABS_TOL=1.e-8"
731  print "   def setUp(self):"  print "   def setUp(self):"
732  print "       d1 = Rectangle(n0=2,n1=1,l0=0.5,order=1,useElementsOnFace=True)"  print "       d1 = Rectangle(n0=int(NE/2),n1=NE,l0=0.5,order=1,useElementsOnFace=True)"
733  print "       x1 = ContinuousFunction(d1).getX()"  print "       x1 = ContinuousFunction(d1).getX()"
734  print "       ContinuousFunction(d1).setTags(1,Scalar(1,ContinuousFunction(d1)))"  print "       ContinuousFunction(d1).setTags(1,Scalar(1,ContinuousFunction(d1)))"
735  print "       d2 = Rectangle(n0=2,n1=1,l0=0.5,order=1,useElementsOnFace=True)"  print "       d2 = Rectangle(n0=int(NE/2),n1=NE,l0=0.5,order=1,useElementsOnFace=True)"
736  print "       ContinuousFunction(d2).setTags(2,Scalar(1,ContinuousFunction(d2)))"  print "       ContinuousFunction(d2).setTags(2,Scalar(1,ContinuousFunction(d2)))"
737  print "       d2.setX(d2.getX()+[0.5,0.])"  print "       d2.setX(d2.getX()+[0.5,0.])"
738  print "       self.domain = JoinFaces([d1,d2])"  print "       self.domain = JoinFaces([d1,d2])"
739  print "suite = unittest.TestSuite()"  print "suite = unittest.TestSuite()"
740    print "suite.addTest(unittest.makeSuite(Test_Finley_assemblage_2Do1))"
741  print "suite.addTest(unittest.makeSuite(Test_Finley_assemblage_2Do1_Contact))"  print "suite.addTest(unittest.makeSuite(Test_Finley_assemblage_2Do1_Contact))"
742  print "unittest.TextTestRunner(verbosity=2).run(suite)"  print "unittest.TextTestRunner(verbosity=2).run(suite)"

Legend:
Removed from v.768  
changed lines
  Added in v.769

  ViewVC Help
Powered by ViewVC 1.1.26