/[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 2646 by gross, Tue Jul 28 04:46:38 2009 UTC revision 2647 by gross, Fri Sep 4 05:25:25 2009 UTC
# Line 22  __url__="https://launchpad.net/escript-f Line 22  __url__="https://launchpad.net/escript-f
22  import unittest  import unittest
23  import tempfile  import tempfile
24                
 from esys.escript import *  
 from esys.finley import Rectangle  
 from esys.escript.models import DarcyFlow  
 import sys  
 import os  
 try:  
      FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']  
 except KeyError:  
      FINLEY_WORKDIR='.'  
25    
26    
27  VERBOSE=False # or True  VERBOSE=False # or True
28    
29  from esys.escript import *  from esys.escript import *
30  from esys.escript.models import StokesProblemCartesian, PowerLaw, IncompressibleIsotropicFlowCartesian  from esys.escript.models import StokesProblemCartesian, PowerLaw, IncompressibleIsotropicFlowCartesian, FaultSystem, DarcyFlow
31    from esys.escript.models import Mountains
32  from esys.finley import Rectangle, Brick  from esys.finley import Rectangle, Brick
33    
 from esys.escript.models import Mountains  
34  from math import pi  from math import pi
35    import numpy
36    import sys
37    import os
38    #====================================================================================================================
39    try:
40         FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']
41    except KeyError:
42         FINLEY_WORKDIR='.'
43    
44  #====================================================================================================================  #====================================================================================================================
45  class Test_StokesProblemCartesian2D(unittest.TestCase):  class Test_StokesProblemCartesian2D(unittest.TestCase):
# Line 1093  class Test_IncompressibleIsotropicFlowCa Line 1092  class Test_IncompressibleIsotropicFlowCa
1092         self.latestart=False         self.latestart=False
1093         self.runIt(free=0)         self.runIt(free=0)
1094    
1095    
1096    class Test_FaultSystem(unittest.TestCase):
1097       EPS=1.e-8
1098       NE=10
1099       def test_Fault2D_MaxValue(self):
1100          dom=Rectangle(2*self.NE,2*self.NE)
1101          x=dom.getX()
1102          f=FaultSystem(dim=2)
1103          f.addFault([[0.5,0.],[0.,0.5]], tag=1)
1104          f.addFault([[1.,0.5],[0.5,0.5],[0.5,1.]], tag=2)
1105    
1106          m, t, l=f.getMaxValue(x[0]*(1.-x[0])*(1-x[1]))
1107          self.failUnless(  m == 0.25, "wrong max value")
1108          self.failUnless(  t == 1, "wrong max tag")
1109          self.failUnless(  l == 0., "wrong max location")
1110          m, t, l=f.getMaxValue(x[1]*(1.-x[1])*(1-x[0])*x[0])
1111          self.failUnless(  m == 0.0625, "wrong max value")
1112          self.failUnless(  t == 2, "wrong max tag")
1113          self.failUnless(  l == 0.5, "wrong max location")
1114          m, t, l=f.getMaxValue(x[0]*(1.-x[0])*x[1])
1115          self.failUnless(  m == 0.25, "wrong max value")
1116          self.failUnless(  t == 2, "wrong max tag")
1117          self.failUnless(  l == 1.0, "wrong max location")
1118          m, t, l= f.getMaxValue(x[1]*(1.-x[1])*x[0])
1119          self.failUnless(  m == 0.25, "wrong max value")
1120          self.failUnless(  t == 2, "wrong max tag")
1121          self.failUnless(  l == 0., "wrong max location")
1122          m, t, l= f.getMaxValue(x[1]*(1.-x[1])*(1.-x[0]))
1123          self.failUnless(  m == 0.25, "wrong max value")
1124          self.failUnless(  t == 1, "wrong max tag")
1125          self.failUnless(  abs(l-0.70710678118654) <= self.EPS,  "wrong max location")
1126    
1127          
1128       def xtest_Fault2D_TwoFaults(self):
1129          f=FaultSystem(dim=2)
1130          top1=[ [1.,0.], [1.,1.], [0.,1.] ]
1131          self.failUnlessRaises(ValueError,f.addFault,top=top1,tag=1,bottom=top1)
1132          f.addFault(top=top1,tag=1)
1133          self.failUnless(f.getDim() == 2, "wrong dimension")
1134          self.failUnless( [ 1 ] == f.getTags(), "tags wrong")
1135          self.failUnless(  2. == f.getLength(1), "length wrong")
1136          self.failUnless(  0. == f.getDepth(1), "depth wrong")
1137          self.failUnless( (0., 2.) ==  f.getW0Range(1)," wrong W0 range")
1138          self.failUnless( (0., 0.) ==  f.getW1Range(1)," wrong W1 range")
1139          self.failUnless( [0., 1., 2.] ==  f.getW0Offsets(1)," wrong W0 offsets")
1140          segs=f.getFaultSegments(1)[0]
1141          self.failUnless( len(segs) == 3, "wrong number of segments")
1142          self.failUnless( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0")
1143          self.failUnless( segs[0].size == 2, "seg 0 has wrong size.")
1144          self.failUnless( numpy.linalg.norm(segs[0]-[1.,0.]) < self.EPS, "wrong vertex. 0 ")
1145          self.failUnless( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1")
1146          self.failUnless( segs[1].size == 2, "seg 1 has wrong size.")
1147          self.failUnless( numpy.linalg.norm(segs[1]-[1.,1.]) < self.EPS, "wrong vertex. 1 ")
1148          self.failUnless( isinstance(segs[2], numpy.ndarray), "wrong class of vertex 2")
1149          self.failUnless( segs[2].size == 2, "seg 2 has wrong size.")
1150          self.failUnless( numpy.linalg.norm(segs[2]-[0.,1.]) < self.EPS, "wrong vertex. 2 ")
1151          c=f.getCenterOnSurface()
1152          self.failUnless( isinstance(c, numpy.ndarray), "center has wrong class")
1153          self.failUnless( c.size == 2, "center size is wrong")
1154          self.failUnless( numpy.linalg.norm(c-[2./3.,2./3.]) < self.EPS, "center has wrong coordinates.")
1155          o=f.getOrientationOnSurface()/pi*180.
1156          self.failUnless( abs(o-45.) < self.EPS, "wrong orientation.")
1157    
1158          top2=[ [10.,0.], [0.,10.] ]
1159          f.addFault(top2, tag=2, w0_offsets=[0,20], w1_max=20)
1160          self.failUnless( [ 1, 2 ] == f.getTags(), "tags wrong")
1161          self.failUnless(  abs(f.getLength(2)-14.1421356237) < self.EPS * 14.1421356237, "wrong length")
1162          self.failUnless(  0. == f.getDepth(2), "depth wrong")
1163          self.failUnless( (0., 20.) ==  f.getW0Range(2)," wrong W0 range")
1164          self.failUnless( (0., 0.) ==  f.getW1Range(2)," wrong W1 range")
1165          self.failUnless( [0., 20.] ==  f.getW0Offsets(2)," wrong W0 offsets")
1166          segs=f.getFaultSegments(2)[0]
1167          self.failUnless( len(segs) == 2, "wrong number of segments")
1168          self.failUnless( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0")
1169          self.failUnless( numpy.linalg.norm(segs[0]-[10.,0.]) < self.EPS, "wrong vertex. 0 ")
1170          self.failUnless( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1")
1171          self.failUnless( numpy.linalg.norm(segs[1]-[0.,10.]) < self.EPS, "wrong vertex. 1 ")
1172          c=f.getCenterOnSurface()
1173          self.failUnless( isinstance(c, numpy.ndarray), "center has wrong class")
1174          self.failUnless( c.size == 2, "center size is wrong")
1175          self.failUnless( numpy.linalg.norm(c-[12./5.,12./5.]) < self.EPS, "center has wrong coordinates.")
1176          o=f.getOrientationOnSurface()/pi*180.
1177          self.failUnless( abs(o-45.) < self.EPS, "wrong orientation.")
1178    
1179          f.transform(rot=-pi/2., shift=[-1.,-1.])
1180          self.failUnless( [ 1, 2 ] == f.getTags(), "tags after transformation wrong")
1181          self.failUnless(  2. == f.getLength(1), "length after transformation wrong")
1182          self.failUnless(  0. == f.getDepth(1), "depth after transformation wrong")
1183          self.failUnless( (0., 2.) ==  f.getW0Range(1)," wrong W0 after transformation range")
1184          self.failUnless( (0., 0.) ==  f.getW1Range(1)," wrong W1 rangeafter transformation ")
1185          self.failUnless( [0., 1., 2.] ==  f.getW0Offsets(1)," wrong W0 offsetsafter transformation ")
1186          segs=f.getFaultSegments(1)[0]
1187          self.failUnless( len(segs) == 3, "wrong number of segmentsafter transformation ")
1188          self.failUnless( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0 after transformation")
1189          self.failUnless( segs[0].size == 2, "seg 0 has wrong size after transformation.")
1190          self.failUnless( numpy.linalg.norm(segs[0]-[-1.,0.]) < self.EPS, "wrong vertex. 0  after transformation")
1191          self.failUnless( isinstance(segs[1], numpy.ndarray), "wrong class of vertex  after transformation1")
1192          self.failUnless( segs[1].size == 2, "seg 1 has wrong size after transformation.")
1193          self.failUnless( numpy.linalg.norm(segs[1]-[0.,0.]) < self.EPS, "wrong vertex.  after transformation1 ")
1194          self.failUnless( isinstance(segs[2], numpy.ndarray), "wrong class of vertex  after transformation2")
1195          self.failUnless( segs[2].size == 2, "seg 2 has wrong size after transformation.")
1196          self.failUnless( numpy.linalg.norm(segs[2]-[0., 1.]) < self.EPS, "wrong vertex after transformation. 2 ")
1197          self.failUnless(  abs(f.getLength(2)-14.1421356237) < self.EPS * 14.1421356237, "wrong length after transformation")
1198          self.failUnless(  0. == f.getDepth(2), "depth wrong after transformation")
1199          self.failUnless( (0., 20.) ==  f.getW0Range(2)," wrong W0 range after transformation")
1200          self.failUnless( (0., 0.) ==  f.getW1Range(2)," wrong W1 range after transformation")
1201          self.failUnless( [0., 20.] ==  f.getW0Offsets(2)," wrong W0 offsets after transformation")
1202          segs=f.getFaultSegments(2)[0]
1203          self.failUnless( len(segs) == 2, "wrong number of segments after transformation")
1204          self.failUnless( isinstance(segs[0], numpy.ndarray), "wrong class of vertex 0 after transformation")
1205          self.failUnless( numpy.linalg.norm(segs[0]-[-1.,-9]) < self.EPS, "wrong vertex. 0  after transformation")
1206          self.failUnless( isinstance(segs[1], numpy.ndarray), "wrong class of vertex 1 after transformation")
1207          self.failUnless( numpy.linalg.norm(segs[1]-[9.,1.]) < self.EPS, "wrong vertex. 1  after transformation")
1208    
1209          c=f.getCenterOnSurface()
1210          self.failUnless( isinstance(c, numpy.ndarray), "center has wrong class")
1211          self.failUnless( c.size == 2, "center size is wrong")
1212          self.failUnless( numpy.linalg.norm(c-[7./5.,-7./5.]) < self.EPS, "center has wrong coordinates.")
1213          o=f.getOrientationOnSurface()/pi*180.
1214          self.failUnless( abs(o+45.) < self.EPS, "wrong orientation.")
1215    
1216          p=f.getParametrization([-1.,0.],1)
1217          self.failUnless(p[1]==1., "wrong value.")
1218          self.failUnless(abs(p[0])<self.EPS, "wrong value.")
1219          p=f.getParametrization([-0.5,0.],1)
1220          self.failUnless(p[1]==1., "wrong value.")
1221          self.failUnless(abs(p[0]-0.5)<self.EPS* 0.5, "wrong value.")
1222          p=f.getParametrization([0.,0.],1)
1223          self.failUnless(p[1]==1., "wrong value.")
1224          self.failUnless(abs(p[0]-1.)<self.EPS, "wrong value.")
1225          p=f.getParametrization([0.0000001,0.0000001],1, tol=1.e-8)
1226          self.failUnless(p[1]==0., "wrong value.")
1227          p=f.getParametrization([0.0000001,0.0000001],1, tol=1.e-6)
1228          self.failUnless(p[1]==1., "wrong value.")
1229          self.failUnless(abs(p[0]-1.0000001)<self.EPS, "wrong value.")
1230          p=f.getParametrization([0.,0.5],1)
1231          self.failUnless(p[1]==1., "wrong value.")
1232          self.failUnless(abs(p[0]-1.5)<self.EPS, "wrong value.")
1233          p=f.getParametrization([0,1.],1)
1234          self.failUnless(p[1]==1., "wrong value.")
1235          self.failUnless(abs(p[0]-2.)<self.EPS, "wrong value.")
1236          p=f.getParametrization([1.,1.],1)
1237          self.failUnless(p[1]==0., "wrong value.")
1238          p=f.getParametrization([0,1.11],1)
1239          self.failUnless(p[1]==0., "wrong value.")
1240          p=f.getParametrization([-1,-9.],2)
1241          self.failUnless(p[1]==1., "wrong value.")
1242          self.failUnless(abs(p[0])<self.EPS, "wrong value.")
1243          p=f.getParametrization([9,1],2)
1244          self.failUnless(p[1]==1., "wrong value.")
1245          self.failUnless(abs(p[0]-20.)<self.EPS, "wrong value.")
1246    
1247    
1248    
1249    
1250  if __name__ == '__main__':  if __name__ == '__main__':
1251     suite = unittest.TestSuite()     suite = unittest.TestSuite()
1252       suite.addTest(unittest.makeSuite(Test_FaultSystem))
1253     suite.addTest(unittest.makeSuite(Test_StokesProblemCartesian2D))     suite.addTest(unittest.makeSuite(Test_StokesProblemCartesian2D))
1254     suite.addTest(unittest.makeSuite(Test_Darcy3D))     suite.addTest(unittest.makeSuite(Test_Darcy3D))
1255     suite.addTest(unittest.makeSuite(Test_Darcy2D))     suite.addTest(unittest.makeSuite(Test_Darcy2D))

Legend:
Removed from v.2646  
changed lines
  Added in v.2647

  ViewVC Help
Powered by ViewVC 1.1.26