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

Diff of /trunk/finley/test/python/run_models.py

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

revision 2850 by gross, Fri Jan 15 07:14:25 2010 UTC revision 3527 by gross, Tue May 24 06:59:20 2011 UTC
# Line 1  Line 1 
1    # -*- coding: utf-8 -*-
2    
3  ########################################################  ########################################################
4  #  #
5  # Copyright (c) 2003-2009 by University of Queensland  # Copyright (c) 2003-2010 by University of Queensland
6  # Earth Systems Science Computational Center (ESSCC)  # Earth Systems Science Computational Center (ESSCC)
7  # http://www.uq.edu.au/esscc  # http://www.uq.edu.au/esscc
8  #  #
# Line 11  Line 12 
12  #  #
13  ########################################################  ########################################################
14    
15  __copyright__="""Copyright (c) 2003-2009 by University of Queensland  __copyright__="""Copyright (c) 2003-2010 by University of Queensland
16  Earth Systems Science Computational Center (ESSCC)  Earth Systems Science Computational Center (ESSCC)
17  http://www.uq.edu.au/esscc  http://www.uq.edu.au/esscc
18  Primary Business: Queensland, Australia"""  Primary Business: Queensland, Australia"""
# Line 24  import tempfile Line 25  import tempfile
25                
26    
27    
28  VERBOSE=False # or True  VERBOSE=False  and True
29    
30  from esys.escript import *  from esys.escript import *
31  from esys.escript.models import StokesProblemCartesian, PowerLaw, IncompressibleIsotropicFlowCartesian, FaultSystem, DarcyFlow  from esys.escript.models import StokesProblemCartesian, PowerLaw, IncompressibleIsotropicFlowCartesian, FaultSystem, DarcyFlow
# Line 398  class Test_StokesProblemCartesian3D(unit Line 399  class Test_StokesProblemCartesian3D(unit
399         self.failUnless(error_v1<10*self.TOL, "1-velocity error too large.")         self.failUnless(error_v1<10*self.TOL, "1-velocity error too large.")
400         self.failUnless(error_v2<10*self.TOL, "2-velocity error too large.")         self.failUnless(error_v2<10*self.TOL, "2-velocity error too large.")
401  #====================================================================================================================  #====================================================================================================================
 class Test_Darcy(unittest.TestCase):  
     # this is a simple test for the darcy flux problem  
     #  
     #  
     #  p = 1/k * ( 1/2* (fb-f0)/xb* x **2 + f0 * x - ub*x ) +  p0  
     #  
     #  with f = (fb-f0)/xb* x + f0  
     #  
     #    u = f - k * p,x = ub  
     #  
     #  we prescribe pressure at x=x0=0 to p0  
     #  
     #  if we prescribe the pressure on the bottom x=xb we set  
     #  
     #  pb= 1/k * ( 1/2* (fb-f0)* xb + f0 * xb - ub*xb ) +  p0 = 1/k * ((fb+f0)/2 - ub ) * xb  + p0  
     #  
     #  which leads to ub = (fb+f0)/2-k*(pb-p0)/xb  
     #  
     def rescaleDomain(self):  
         x=self.dom.getX().copy()  
         for i in xrange(self.dom.getDim()):  
              x_inf=inf(x[i])  
              x_sup=sup(x[i])  
              if i == self.dom.getDim()-1:  
                 x[i]=-self.WIDTH*(x[i]-x_sup)/(x_inf-x_sup)  
              else:  
                 x[i]=self.WIDTH*(x[i]-x_inf)/(x_sup-x_inf)  
         self.dom.setX(x)  
     def getScalarMask(self,include_bottom=True):  
         x=self.dom.getX().copy()  
         x_inf=inf(x[self.dom.getDim()-1])  
         x_sup=sup(x[self.dom.getDim()-1])  
         out=whereZero(x[self.dom.getDim()-1]-x_sup)  
         if include_bottom: out+=whereZero(x[self.dom.getDim()-1]-x_inf)  
         return wherePositive(out)  
     def getVectorMask(self,include_bottom=True):  
         x=self.dom.getX().copy()  
         out=Vector(0.,Solution(self.dom))  
         for i in xrange(self.dom.getDim()):  
              x_inf=inf(x[i])  
              x_sup=sup(x[i])  
              if i != self.dom.getDim()-1: out[i]+=whereZero(x[i]-x_sup)  
              if i != self.dom.getDim()-1 or include_bottom: out[i]+=whereZero(x[i]-x_inf)  
         return wherePositive(out)  
   
     def setSolutionFixedBottom(self, p0, pb, f0, fb, k):  
          d=self.dom.getDim()  
          x=self.dom.getX()[d-1]  
          xb=inf(x)  
          u=Vector(0.,Solution(self.dom))+kronecker(d)[d-1]*((f0+fb)/2.-k*(pb-p0)/xb)  
          p=1./k*((fb-f0)/(xb*2.)* x**2 - (fb-f0)/2.*x)+(pb-p0)/xb*x +  p0  
          f= ((fb-f0)/xb* x + f0)*kronecker(Function(self.dom))[d-1]  
          return u,p,f  
           
     def testConstF_FixedBottom_smallK(self):  
         k=1.e-10  
         mp=self.getScalarMask(include_bottom=True)  
         mv=self.getVectorMask(include_bottom=False)  
         u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)  
         p=p_ref*mp  
         u=u_ref*mv  
         df=DarcyFlow(self.dom)  
         df.setValue(g=f,  
                       location_of_fixed_pressure=mp,  
                       location_of_fixed_flux=mv,  
                       permeability=Scalar(k,Function(self.dom)))  
         df.setTolerance(rtol=self.TOL)  
         v,p=df.solve(u_ref,p, max_iter=100, verbose=VERBOSE)  
         self.failUnless(Lsup(v-u_ref)<self.TOL*10.*Lsup(u_ref), "flux error too big.")  
         self.failUnless(Lsup(p-p_ref)<self.TOL*10.*Lsup(p_ref), "pressure error too big.")  
     def testConstF_FixedBottom_mediumK(self):  
         k=1.  
         mp=self.getScalarMask(include_bottom=True)  
         mv=self.getVectorMask(include_bottom=False)  
         u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)  
         p=p_ref*mp  
         u=u_ref*mv  
         df=DarcyFlow(self.dom)  
         df.setValue(g=f,  
                       location_of_fixed_pressure=mp,  
                       location_of_fixed_flux=mv,  
                       permeability=Scalar(k,Function(self.dom)))  
         df.setTolerance(rtol=self.TOL)  
         v,p=df.solve(u,p,max_iter=100, verbose=VERBOSE )  
         self.failUnless(Lsup(p-p_ref)<self.TOL*10.*Lsup(p_ref), "pressure error too big.")  
         self.failUnless(Lsup(v-u_ref)<self.TOL*10.*Lsup(u_ref), "flux error too big.")  
   
     def testConstF_FixedBottom_largeK(self):  
         k=1.e10  
         mp=self.getScalarMask(include_bottom=True)  
         mv=self.getVectorMask(include_bottom=False)  
         u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)  
         p=p_ref*mp  
         u=u_ref*mv  
         df=DarcyFlow(self.dom)  
         df.setValue(g=f,  
                       location_of_fixed_pressure=mp,  
                       location_of_fixed_flux=mv,  
                       permeability=Scalar(k,Function(self.dom)))  
         df.setTolerance(rtol=self.TOL)  
         v,p=df.solve(u,p, max_iter=100, verbose=VERBOSE)  
         self.failUnless(Lsup(v-u_ref)<self.TOL*10.*Lsup(u_ref), "flux error too big.")  
         self.failUnless(Lsup(p-p_ref)<self.TOL*10.*Lsup(p_ref), "pressure error too big.")  
   
     def testVarioF_FixedBottom_smallK(self):  
         k=1.e-10  
         mp=self.getScalarMask(include_bottom=True)  
         mv=self.getVectorMask(include_bottom=False)  
         u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)  
         p=p_ref*mp  
         u=u_ref*mv  
         df=DarcyFlow(self.dom)  
         df.setValue(g=f,  
                       location_of_fixed_pressure=mp,  
                       location_of_fixed_flux=mv,  
                       permeability=Scalar(k,Function(self.dom)))  
         df.setTolerance(rtol=self.TOL)  
         v,p=df.solve(u,p, max_iter=100, verbose=VERBOSE)  
         self.failUnless(Lsup(v-u_ref)<self.TOL*10.*Lsup(u_ref), "flux error too big.")  
         self.failUnless(Lsup(p-p_ref)<self.TOL*10.*Lsup(p_ref), "pressure error too big.")  
   
     def testVarioF_FixedBottom_mediumK(self):  
         k=1.  
         mp=self.getScalarMask(include_bottom=True)  
         mv=self.getVectorMask(include_bottom=False)  
         u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)  
         p=p_ref*mp  
         u=u_ref*mv  
         df=DarcyFlow(self.dom)  
         df.setValue(g=f,  
                       location_of_fixed_pressure=mp,  
                       location_of_fixed_flux=mv,  
                       permeability=Scalar(k,Function(self.dom)))  
         df.setTolerance(rtol=self.TOL)  
         v,p=df.solve(u,p, max_iter=100, verbose=VERBOSE)  
         self.failUnless(Lsup(v-u_ref)<self.TOL*10.*Lsup(u_ref), "flux error too big.")  
         self.failUnless(Lsup(p-p_ref)<self.TOL*10.*Lsup(p_ref), "pressure error too big.")  
   
     def testVarioF_FixedBottom_largeK(self):  
         k=1.e10  
         mp=self.getScalarMask(include_bottom=True)  
         mv=self.getVectorMask(include_bottom=False)  
         u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)  
         p=p_ref*mp  
         u=u_ref*mv  
         df=DarcyFlow(self.dom)  
         df.setValue(g=f,  
                       location_of_fixed_pressure=mp,  
                       location_of_fixed_flux=mv,  
                       permeability=Scalar(k,Function(self.dom)))  
         df.setTolerance(rtol=self.TOL)  
         v,p=df.solve(u,p, max_iter=100, verbose=VERBOSE)  
         self.failUnless(Lsup(v-u_ref)<self.TOL*10.*Lsup(u_ref), "flux error too big.")  
         self.failUnless(Lsup(p-p_ref)<self.TOL*10.*Lsup(p_ref), "pressure error too big.")  
   
     def testConstF_FreeBottom_smallK(self):  
         k=1.e-10  
         mp=self.getScalarMask(include_bottom=False)  
         mv=self.getVectorMask(include_bottom=True)  
         u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)  
         p=p_ref*mp  
         u=u_ref*mv  
         df=DarcyFlow(self.dom)  
         df.setValue(g=f,  
                     location_of_fixed_pressure=mp,  
                       location_of_fixed_flux=mv,  
                       permeability=Scalar(k,Function(self.dom)))  
         df.setTolerance(rtol=self.TOL)  
         v,p=df.solve(u,p, max_iter=100, verbose=VERBOSE)  
         self.failUnless(Lsup(v-u_ref)<self.TOL*10.*Lsup(u_ref), "flux error too big.")  
         self.failUnless(Lsup(p-p_ref)<self.TOL*10.*Lsup(p_ref), "pressure error too big.")  
   
     def testConstF_FreeBottom_mediumK(self):  
         k=1.  
         mp=self.getScalarMask(include_bottom=False)  
         mv=self.getVectorMask(include_bottom=True)  
         u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)  
         p=p_ref*mp  
         u=u_ref*mv  
         df=DarcyFlow(self.dom)  
         df.setValue(g=f,  
                       location_of_fixed_pressure=mp,  
                       location_of_fixed_flux=mv,  
                       permeability=Scalar(k,Function(self.dom)))  
         df.setTolerance(rtol=self.TOL)  
         v,p=df.solve(u,p, max_iter=100, verbose=VERBOSE)  
         self.failUnless(Lsup(v-u_ref)<self.TOL*10.*Lsup(u_ref), "flux error too big.")  
         self.failUnless(Lsup(p-p_ref)<self.TOL*10.*Lsup(p_ref), "pressure error too big.")  
   
     def testConstF_FreeBottom_largeK(self):  
         k=1.e10  
         mp=self.getScalarMask(include_bottom=False)  
         mv=self.getVectorMask(include_bottom=True)  
         u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=10.,k=k)  
         p=p_ref*mp  
         u=u_ref*mv  
         df=DarcyFlow(self.dom)  
         df.setValue(g=f,  
                       location_of_fixed_pressure=mp,  
                       location_of_fixed_flux=mv,  
                       permeability=Scalar(k,Function(self.dom)))  
         df.setTolerance(rtol=self.TOL)  
         v,p=df.solve(u,p, max_iter=100, verbose=VERBOSE)  
         self.failUnless(Lsup(v-u_ref)<self.TOL*10.*Lsup(u_ref), "flux error too big.")  
         self.failUnless(Lsup(p-p_ref)<self.TOL*10.*Lsup(p_ref), "pressure error too big.")  
   
     def testVarioF_FreeBottom_smallK(self):  
         k=1.e-10  
         mp=self.getScalarMask(include_bottom=False)  
         mv=self.getVectorMask(include_bottom=True)  
         u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)  
         p=p_ref*mp  
         u=u_ref*mv  
         df=DarcyFlow(self.dom)  
         df.setValue(g=f,  
                       location_of_fixed_pressure=mp,  
                       location_of_fixed_flux=mv,  
                       permeability=Scalar(k,Function(self.dom)))  
         df.setTolerance(rtol=self.TOL)  
         v,p=df.solve(u,p, max_iter=100, verbose=VERBOSE)  
         self.failUnless(Lsup(v-u_ref)<self.TOL*25.*Lsup(u_ref), "flux error too big.")  # 25 because of disc. error.  
         self.failUnless(Lsup(p-p_ref)<self.TOL*25.*Lsup(p_ref), "pressure error too big.")  
   
     def testVarioF_FreeBottom_mediumK(self):  
         k=1.  
         mp=self.getScalarMask(include_bottom=False)  
         mv=self.getVectorMask(include_bottom=True)  
         u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)  
         p=p_ref*mp  
         u=u_ref*mv  
         df=DarcyFlow(self.dom)  
         df.setValue(g=f,  
                       location_of_fixed_pressure=mp,  
                       location_of_fixed_flux=mv,  
                       permeability=Scalar(k,Function(self.dom)))  
         df.setTolerance(rtol=self.TOL)  
         v,p=df.solve(u,p, max_iter=100, verbose=VERBOSE)  
         self.failUnless(Lsup(v-u_ref)<self.TOL*10.*Lsup(u_ref), "flux error too big.")  
         self.failUnless(Lsup(p-p_ref)<self.TOL*10.*Lsup(p_ref), "pressure error too big.")  
   
     def testVarioF_FreeBottom_largeK(self):  
         k=1.e10  
         mp=self.getScalarMask(include_bottom=False)  
         mv=self.getVectorMask(include_bottom=True)  
         u_ref,p_ref,f=self.setSolutionFixedBottom(p0=2500,pb=4000.,f0=10.,fb=30.,k=k)  
         p=p_ref*mp  
         u=u_ref*mv  
         df=DarcyFlow(self.dom)  
         df.setValue(g=f,  
                       location_of_fixed_pressure=mp,  
                       location_of_fixed_flux=mv,  
                       permeability=Scalar(k,Function(self.dom)))  
         df.setTolerance(rtol=self.TOL)  
         v,p=df.solve(u,p, max_iter=100, verbose=VERBOSE)  
         self.failUnless(Lsup(v-u_ref)<self.TOL*10.*Lsup(u_ref), "flux error too big.")  
         self.failUnless(Lsup(p-p_ref)<self.TOL*10.*Lsup(p_ref), "pressure error too big.")  
   
 class Test_Darcy2D(Test_Darcy):  
     TOL=1e-4  
     WIDTH=1.  
     def setUp(self):  
         NE=40  # wrning smaller NE may case a failure for VarioF tests due to discretization errors.  
         self.dom = Rectangle(NE,NE)  
         self.rescaleDomain()  
     def tearDown(self):  
         del self.dom  
 class Test_Darcy3D(Test_Darcy):  
     TOL=1e-4  
     WIDTH=1.  
     def setUp(self):  
         NE=25  # wrning smaller NE may case a failure for VarioF tests due to discretization errors.  
         self.dom = Brick(NE,NE,NE)  
         self.rescaleDomain()  
     def tearDown(self):  
         del self.dom  
   
402    
403  class Test_Mountains3D(unittest.TestCase):  class Test_Mountains3D(unittest.TestCase):
404     def setUp(self):     def setUp(self):
# Line 1732  class Test_FaultSystem(unittest.TestCase Line 1457  class Test_FaultSystem(unittest.TestCase
1457        s,d=f.getSideAndDistance([5.,12.,-4], tag=2)        s,d=f.getSideAndDistance([5.,12.,-4], tag=2)
1458        self.failUnless( s<0, "wrong side.")        self.failUnless( s<0, "wrong side.")
1459        self.failUnless( abs(d-2.*0.70710678118654757)<self.EPS, "wrong distance.")        self.failUnless( abs(d-2.*0.70710678118654757)<self.EPS, "wrong distance.")
1460    
1461  if __name__ == '__main__':  if __name__ == '__main__':
1462     suite = unittest.TestSuite()     suite = unittest.TestSuite()
1463     suite.addTest(unittest.makeSuite(Test_FaultSystem))     # suite.addTest(unittest.makeSuite(Test_FaultSystem))
1464     suite.addTest(unittest.makeSuite(Test_StokesProblemCartesian2D))     # suite.addTest(unittest.makeSuite(Test_StokesProblemCartesian2D))
    suite.addTest(unittest.makeSuite(Test_Darcy3D))  
    suite.addTest(unittest.makeSuite(Test_Darcy2D))  
1465     suite.addTest(unittest.makeSuite(Test_StokesProblemCartesian3D))     suite.addTest(unittest.makeSuite(Test_StokesProblemCartesian3D))
    # suite.addTest(Test_StokesProblemCartesian3D("test_PCG_P_large"))  
1466     suite.addTest(unittest.makeSuite(Test_Mountains3D))     suite.addTest(unittest.makeSuite(Test_Mountains3D))
1467     suite.addTest(unittest.makeSuite(Test_Mountains2D))     suite.addTest(unittest.makeSuite(Test_Mountains2D))
1468     suite.addTest(unittest.makeSuite(Test_Rheologies))     suite.addTest(unittest.makeSuite(Test_Rheologies))
    # suite.addTest(Test_IncompressibleIsotropicFlowCartesian("test_D2_Fixed_MuNone"))  
1469     suite.addTest(unittest.makeSuite(Test_IncompressibleIsotropicFlowCartesian))     suite.addTest(unittest.makeSuite(Test_IncompressibleIsotropicFlowCartesian))
1470     s=unittest.TextTestRunner(verbosity=2).run(suite)     s=unittest.TextTestRunner(verbosity=2).run(suite)
1471     if not s.wasSuccessful(): sys.exit(1)     if not s.wasSuccessful(): sys.exit(1)
   

Legend:
Removed from v.2850  
changed lines
  Added in v.3527

  ViewVC Help
Powered by ViewVC 1.1.26