+ def testSwig2SlowDADFindClosestTupleId(self):
+ nbPts=[10,]
+ for nbPt in nbPts:
+ d=DataArrayDouble(nbPt) ; d.iota() ; d*=1./(nbPt-1)
+ c=MEDCouplingCMesh() ; c.setCoords(d,d) ; m=c.buildUnstructured() ; pts=m.getCoords() ; del m
+ #
+ d0=DataArrayDouble((nbPt-1)*(nbPt-1)) ; d0.iota() ; d0*=(3./((nbPt-1)*(nbPt-1))) ; d0=d0.applyFunc("exp(x)-1")
+ d1=DataArrayDouble((nbPt-1)*(nbPt-1)) ; d1.iota()
+ d2=DataArrayDouble.Meld(d0,d1) ; d2=d2.fromPolarToCart() ; d2+=[0.32,0.73]
+ ids=pts.findClosestTupleId(d2)
+ #print "Start of costly computation"
+ idsExpected=DataArrayInt(len(d2))
+ tmp=1e300
+ for i,elt in enumerate(d2):
+ l,m=(pts-elt).magnitude().getMinValue()
+ idsExpected.setIJSilent(i,0,m)
+ if l<tmp:
+ tmp=l ; tmp1=m ; tmp2=i
+ pass
+ pass
+ #print "End of costly computation"
+ self.assertTrue(idsExpected.isEqual(ids))
+ a,b,c=pts.minimalDistanceTo(d2)
+ self.assertEqual(tmp,a)
+ self.assertEqual(tmp1,b)
+ self.assertEqual(tmp2,c)
+ #
+ l=[d2[:,i] for i in [0,1]]
+ for elt in l: elt.reverse()
+ d2i=DataArrayDouble.Meld(l)
+ ids1=pts.findClosestTupleId(d2i)
+ idsExpectedI=idsExpected.deepCpy() ; idsExpectedI.reverse()
+ self.assertTrue(idsExpectedI.isEqual(ids1))
+ #
+ l=[pts[:,i] for i in [0,1]]
+ for elt in l: elt.reverse()
+ ptsi=DataArrayDouble.Meld(l)
+ ids2=ptsi.findClosestTupleId(d2)
+ idsExpected2=nbPt*nbPt-1-ids
+ self.assertTrue(idsExpected2.isEqual(ids2))
+ #
+ ids3=ptsi.findClosestTupleId(d2i)
+ idsExpected3=idsExpected2.deepCpy() ; idsExpected3.reverse()
+ self.assertTrue(idsExpected3.isEqual(ids3))
+ pass
+
+ def testSwig2DataArrayAsciiChar1(self):
+ alpha=DataArrayInt(26) ; alpha.iota(ord("A"))
+ d=DataArrayAsciiChar(alpha.getValues(),2,13)
+ d.setInfoOnComponents(["c%i"%(v) for v in xrange(13)])
+ self.assertEqual('ABCDEFGHIJKLM',d.getTuple(0))
+ self.assertEqual('NOPQRSTUVWXYZ',d.getTuple(1))
+ self.assertEqual(2,d.getNumberOfTuples())
+ self.assertEqual(26,d.getNbOfElems())
+ self.assertEqual(13,d.getNumberOfComponents())
+ dd=d.deepCpy()
+ self.assertTrue(d.isEqual(dd))
+ dd.setIJ(0,3,'d')
+ self.assertTrue(not d.isEqual(dd))
+ d.setIJ(0,3,ord('d'))
+ self.assertTrue(d.isEqual(dd))
+ d.rearrange(1)
+ d.reserve(20)
+ self.assertEqual(20,d.getNumberOfTuples())
+ self.assertEqual(20,d.getNbOfElems())
+ self.assertEqual(1,d.getNumberOfComponents())
+ #
+ d0=DataArrayAsciiChar([ord('a')],1,1)
+ self.assertEqual('a',d0.asciiCharValue())
+ self.assertTrue(not d0.empty())
+ d0=DataArrayAsciiChar(0,3)
+ self.assertTrue(d0.empty())
+ d.pushBackSilent("U") ; d.pushBackSilent("V") ; d.pushBackSilent("W")
+ self.assertEqual("W",d.popBackSilent())
+ d.rearrange(2)
+ self.assertEqual(['AB','Cd','EF','GH','IJ','KL','MN','OP','QR','ST','UV'],d.toStrList())
+ d.fillWithZero()
+ self.assertEqual(11*[''],d.toStrList())
+ d.fillWithValue('T')
+ self.assertEqual(11*["TT"],d.toStrList())
+ d.rearrange(1)
+ self.assertTrue(d.isUniform("T"))
+ d.rearrange(2)
+ #
+ dd.rearrange(2)
+ dd2=dd.deepCpy()
+ dd.renumberInPlace([3,1,2,4,0,11,10,9,8,7,5,12,6])
+ self.assertEqual(dd.toStrList(),['IJ','Cd','EF','AB','GH','UV','YZ','ST','QR','OP','MN','KL','WX'])
+ dd.renumberInPlaceR([3,1,2,4,0,11,10,9,8,7,5,12,6])
+ self.assertEqual(['AB','Cd','EF','GH','IJ','KL','MN','OP','QR','ST','UV','WX','YZ'],dd.toStrList())
+ e=dd.renumber([3,1,2,4,0,11,10,9,8,7,5,12,6])
+ self.assertEqual(e.toStrList(),['IJ','Cd','EF','AB','GH','UV','YZ','ST','QR','OP','MN','KL','WX'])
+ e=dd.renumberR([3,1,2,4,0,11,10,9,8,7,5,12,6])
+ self.assertEqual(e.toStrList(),['GH','Cd','EF','IJ','AB','WX','UV','ST','QR','OP','KL','YZ','MN'])
+ e=dd.renumberAndReduce([1,1,1,1,1,1,1,2,0,0,0,0,0],3)
+ self.assertEqual(['YZ','MN','OP'],e.toStrList())
+ self.assertEqual(['GH','IJ'],dd.selectByTupleIdSafe([3,4]).toStrList())
+ self.assertEqual(['AB','GH','MN','ST','YZ'],dd.selectByTupleId2(0,13,3).toStrList())
+ dd3=dd.changeNbOfComponents(3,"G")
+ self.assertEqual(['ABG','CdG','EFG','GHG','IJG','KLG','MNG','OPG','QRG','STG','UVG','WXG','YZG'],dd3.toStrList())
+ dd3.rearrange(1) ; self.assertEqual("G",dd3.back()) ; dd3.rearrange(3)
+ self.assertTrue(dd3.changeNbOfComponents(2,"\0").isEqual(dd))
+ self.assertEqual(len(dd),13)
+ d=DataArrayAsciiChar(13,2) ; d.fillWithValue('Y')
+ dd3.meldWith(d)
+ self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','KLGYY','MNGYY','OPGYY','QRGYY','STGYY','UVGYY','WXGYY','YZGYY'],dd3.toStrList())
+ self.assertEqual("d",dd3.getIJ(0,6))
+ self.assertRaises(InterpKernelException,dd3.getIJSafe,0,6)
+ self.assertEqual("d",dd3.getIJSafe(1,1))
+ dd3.rearrange(1)
+ e=dd3.getIdsEqual("Y")
+ self.assertTrue(e.isEqual(DataArrayInt([3,4,8,9,13,14,18,19,23,24,28,29,33,34,38,39,43,44,48,49,53,54,58,59,60,63,64])))
+ e=dd3.getIdsNotEqual("Y")
+ self.assertTrue(e.isEqual(DataArrayInt([0,1,2,5,6,7,10,11,12,15,16,17,20,21,22,25,26,27,30,31,32,35,36,37,40,41,42,45,46,47,50,51,52,55,56,57,61,62])))
+ self.assertEqual(("d",6),dd3.getMaxValue())
+ self.assertEqual(("A",0),dd3.getMinValue())
+ self.assertEqual(26,dd3.search("LGYYM"))
+ self.assertEqual(-1,dd3.search("LGYYN"))
+ dd3.rearrange(5)
+ self.assertEqual(7,dd3.locateTuple("OPGYY"))
+ self.assertTrue("OPGYY" in dd3)
+ self.assertEqual(7,dd3.index("OPGYY"))
+ self.assertEqual(-1,dd3.locateTuple("OPGYP"))
+ dd3.rearrange(1)
+ self.assertEqual(2,dd3.locateValue("OPGYY"))
+ self.assertTrue(dd3.presenceOfValue("OPGYY"))
+ self.assertTrue("O" in dd3)
+ self.assertTrue(not dd3.presenceOfValue("z"))
+ self.assertTrue("z" not in dd3)
+ dd3.rearrange(5)
+ l=list(dd3)
+ self.assertEqual([e.buildDAAsciiChar().toStrList()[0] for e in list(dd3)],dd3.toStrList())
+ dd3.reAlloc(5)
+ dd4=DataArrayChar.Aggregate(dd3,dd3)
+ self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY'],dd4.toStrList())
+ dd5=DataArrayChar.Aggregate([dd4,dd3,dd4])
+ self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY'],dd5.toStrList())
+ # getitem,__iter__,__setitem__
+ a=list(dd3)
+ self.assertEqual("ABGYY",str(a[0]))
+ dd4=dd3[::2]
+ self.assertEqual(['ABGYY','EFGYY','IJGYY'],dd4.toStrList())
+ dd4=dd3[(3,2,1)]
+ self.assertEqual(['GHGYY','EFGYY','CdGYY'],dd4.toStrList())
+ dd4=dd3[:]
+ dd4[::2]=["12","345","67890"]
+ self.assertEqual(['12 ','CdGYY','345 ','GHGYY','67890'],dd4.toStrList())
+ dd4=dd3[:]
+ dd4[[1,2]]=" "
+ self.assertEqual(['ABGYY',' ',' ','GHGYY','IJGYY'],dd4.toStrList())
+ dd4=dd3[:]
+ dd4[4]='12345'
+ self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','12345'],dd4.toStrList())
+ dd4[0]=dd4[1]
+ self.assertEqual(['CdGYY','CdGYY','EFGYY','GHGYY','12345'],dd4.toStrList())
+ dd4=DataArrayAsciiChar(["abc","de","fghi"])
+ self.assertEqual(['abc ','de ','fghi'],dd4.toStrList())
+ dd4=DataArrayAsciiChar(["abc","de","fghi"],"t")
+ self.assertEqual(['abct','dett','fghi'],dd4.toStrList())
+ pass
+
+ def testSwig2GaussNELocalizationOfDiscValues(self):
+ m=MEDCouplingDataForTest.build2DTargetMesh_3()[[0,1,3,4,5,6,8,9]] # suppression of polygons
+ f=MEDCouplingFieldDouble(ON_GAUSS_NE)
+ f.setMesh(m)
+ loc=f.getLocalizationOfDiscr()
+ self.assertEqual(42,len(loc))
+ self.assertTrue(loc.isEqual(DataArrayDouble([0.,0.,1.,0.,0.5,1.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0.,1.,0.,0.5,1.,0.5,0.,0.75,0.5,0.25,0.5,0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5,0.,0.,0.5,1.,1.,0.,0.,0.,0.,1.,1.,1.,1.,0.,0.,0.,0.5,1.,1.,0.,0.25,0.5,0.75,0.5,0.5,0.,0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],42,2),1e-13))
+ m.changeSpaceDimension(3)
+ m.getCoords()[:,2]=7.
+ loc=f.getLocalizationOfDiscr()
+ self.assertEqual(42,len(loc))
+ self.assertTrue(loc.isEqual(DataArrayDouble([0.,0.,7.,1.,0.,7.,0.5,1.,7.,0.,0.,7.,1.,0.,7.,1.,1.,7.,0.,1.,7.,0.,0.,7.,1.,0.,7.,0.5,1.,7.,0.5,0.,7.,0.75,0.5,7.,0.25,0.5,7.,0.,0.,7.,1.,0.,7.,1.,1.,7.,0.,1.,7.,0.5,0.,7.,1.,0.5,7.,0.5,1.,7.,0.,0.5,7.,0.,0.,7.,0.5,1.,7.,1.,0.,7.,0.,0.,7.,0.,1.,7.,1.,1.,7.,1.,0.,7.,0.,0.,7.,0.5,1.,7.,1.,0.,7.,0.25,0.5,7.,0.75,0.5,7.,0.5,0.,7.,0.,0.,7.,0.,1.,7.,1.,1.,7.,1.,0.,7.,0.,0.5,7.,0.5,1.,7.,1.,0.5,7.,0.5,0.,7.],42,3),1e-13))
+ pass
+
+ def testSwig2GaussMeasureAndIntegral(self):
+ ft=MEDCouplingDataForTest.buildFieldOnGauss_1()
+ mea=ft.buildMeasureField(False)
+ mea.checkCoherency()
+ self.assertTrue(mea.getArray().isEqual(DataArrayDouble([-0.08504076274779823,-0.06378057206084897,-0.08504076274779869,-0.10630095343474463,-0.12756114412169625,-0.10630095343474734,-0.0637805720608491,-0.0850407627477968,-0.1063009534347449,-0.0850407627477994,-0.10630095343474809,-0.1275611441216954,-0.037205333702161475,-0.037205333702161475,-0.037205333702161475,-0.037205333702161475,-0.047835429045636084,-0.047835429045636084,-0.047835429045636084,-0.047835429045636084,-0.05846552438911087,-0.05846552438911087,-0.05846552438911087,-0.05846552438911087,-0.037205333702161725,-0.037205333702161725,-0.037205333702161725,-0.037205333702161725,-0.047835429045635834,-0.047835429045635834,-0.047835429045635834,-0.047835429045635834,-0.05846552438911058,-0.05846552438911058,-0.05846552438911058,-0.05846552438911058,-0.03879154890291829,-0.03879154890291829,-0.03879154890291829,-0.04120270848015563,-0.04120270848015563,-0.04120270848015563,-0.03393028948486933,-0.03393028948486933,-0.03393028948486933,-0.03151955746491709,-0.03151955746491709,-0.03151955746491709,-0.02424752187358276,-0.02424752187358276,-0.02424752187358276,-0.026657914642918758,-0.026657914642918758,-0.026657914642918758,-0.04120270848015456,-0.04120270848015456,-0.04120270848015456,-0.03879154890291757,-0.03879154890291757,-0.03879154890291757,-0.031519557464916595,-0.031519557464916595,-0.031519557464916595,-0.03393028948487046,-0.03393028948487046,-0.03393028948487046,-0.0266579146429191,-0.0266579146429191,-0.0266579146429191,-0.024247521873582645,-0.024247521873582645,-0.024247521873582645,-0.01851718920904466,-0.01851718920904466,-0.01851718920904466,-0.01851718920904466,-0.029627502734471456,-0.029627502734471456,-0.029627502734471456,-0.029627502734471456,-0.04740400437515433,-0.015150427534672922,-0.015150427534672922,-0.015150427534672922,-0.015150427534672922,-0.024240684055476674,-0.024240684055476674,-0.024240684055476674,-0.024240684055476674,-0.038785094488762675,-0.011783665860301345,-0.011783665860301345,-0.011783665860301345,-0.011783665860301345,-0.018853865376482152,-0.018853865376482152,-0.018853865376482152,-0.018853865376482152,-0.030166184602371443,-0.018517189209044892,-0.018517189209044892,-0.018517189209044892,-0.018517189209044892,-0.029627502734471827,-0.029627502734471827,-0.029627502734471827,-0.029627502734471827,-0.04740400437515492,-0.015150427534672776,-0.015150427534672776,-0.015150427534672776,-0.015150427534672776,-0.02424068405547644,-0.02424068405547644,-0.02424068405547644,-0.02424068405547644,-0.03878509448876231,-0.011783665860301277,-0.011783665860301277,-0.011783665860301277,-0.011783665860301277,-0.01885386537648204,-0.01885386537648204,-0.01885386537648204,-0.01885386537648204,-0.030166184602371266]),1e-14))
+ f=MEDCouplingFieldDouble(ft)
+ arr=DataArrayDouble(126,2)
+ arr[:,0]=range(126)
+ arr[:,1]=range(126)
+ arr[:,1]+=1000
+ f.setArray(arr)
+ f.checkCoherency()
+ self.assertTrue(DataArrayDouble(f.integral(False)).isEqual(DataArrayDouble([-211.66121638700983,-4863.9563007698835]),1e-11))
+ self.assertTrue(DataArrayDouble(f.getWeightedAverageValue()).isEqual(DataArrayDouble([45.496085813113595,1045.496085813114]),1e-11))
+ self.assertTrue(DataArrayDouble(f.normL1()).isEqual(DataArrayDouble([45.49608581311362,1045.496085813114]),1e-11))
+ self.assertTrue(DataArrayDouble(f.normL2()).isEqual(DataArrayDouble([58.16846378340898,1046.1241521947334]),1e-11))
+ pass
+
+ def testSwig2FieldDiscretizationComputeMeshRestrictionFromTupleIds1(self):
+ m=MEDCouplingDataForTest.build3DSurfTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_GAUSS_NE)
+ f.setMesh(m)
+ a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[3,4,5,6,8,9,10,14,15,16,17])
+ self.assertTrue(a.isEqual(DataArrayInt([1,4])))
+ self.assertTrue(b.isEqual(DataArrayInt([4,5,6,14,15,16,17])))
+ a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),DataArrayInt([0,1,2,3,5,7,8,9,10,11,12,18]))
+ self.assertTrue(a.isEqual(DataArrayInt([0,2])))
+ self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,7,8,9])))
+ #
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[3,4])
+ self.assertTrue(a.isEqual(DataArrayInt([3,4])))
+ self.assertTrue(b.isEqual(DataArrayInt([3,4])))
+ #
+ f=MEDCouplingFieldDouble(ON_NODES)
+ f.setMesh(m)
+ a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[1,2,3,4])
+ self.assertTrue(a.isEqual(DataArrayInt([1])))
+ self.assertTrue(b.isEqual(DataArrayInt([1,2,4])))
+ #
+ f=MEDCouplingDataForTest.buildFieldOnGauss_1()
+ a,b=f.getDiscretization().computeMeshRestrictionFromTupleIds(f.getMesh(),[0,11,12,13,14,15,17,18,19,36,37,38,115,117,118,119,120,121,122,123,124,125])
+ self.assertTrue(a.isEqual(DataArrayInt([0,11,12,18,35])))
+ self.assertTrue(b.isEqual(DataArrayInt([0,11,12,13,14,15,36,37,38,117,118,119,120,121,122,123,124,125])))
+ #
+ d=DataArrayInt([0,3,7,9,15,18])
+ e=DataArrayInt([0,1,2,3,7,8,15,16,17])
+ a,b=d.searchRangesInListOfIds(e)
+ self.assertTrue(a.isEqual(DataArrayInt([0,2,4])))
+ self.assertTrue(b.isEqual(DataArrayInt([0,1,2,7,8,15,16,17])))
+ pass
+
+ def testSwig2BigMem(self):
+ if MEDCouplingSizeOfVoidStar()==64:
+ d=DataArrayAsciiChar(223456789,16)
+ self.assertTrue(d.getNumberOfTuples(),223456789)
+ self.assertTrue(d.getNumberOfComponents(),16)
+ d.setIJ(223456788,5,"r")
+ self.assertTrue(d.getIJ(223456788,5),'r')
+ d[223456787]="1234567890123456"
+ self.assertTrue(d[223456787],'1234567890123456')
+ self.assertRaises(InterpKernelException,d.rearrange,1)# fails because it would lead to nb of tuples > 2147483647
+ pass
+ pass
+
+ def testSwig2DAReverseMultiCompo1(self):
+ d=DataArrayDouble(6,2)
+ d[:,0]=range(6)
+ d[:,1]=range(10,16)
+ d.reverse()
+ self.assertTrue(d.isEqual(DataArrayDouble([5.,15.,4.,14.,3.,13.,2.,12.,1.,11.,0.,10.],6,2),1e-14))
+ d=DataArrayDouble(7,2)
+ d[:,0]=range(7)
+ d[:,1]=range(10,17)
+ d.reverse()
+ self.assertTrue(d.isEqual(DataArrayDouble([6.,16.,5.,15.,4.,14.,3.,13.,2.,12.,1.,11.,0.,10.],7,2),1e-14))
+ #
+ d=DataArrayInt(6,2)
+ d[:,0]=range(6)
+ d[:,1]=range(10,16)
+ d.reverse()
+ self.assertTrue(d.isEqual(DataArrayInt([5,15,4,14,3,13,2,12,1,11,0,10],6,2)))
+ d=DataArrayInt(7,2)
+ d[:,0]=range(7)
+ d[:,1]=range(10,17)
+ d.reverse()
+ self.assertTrue(d.isEqual(DataArrayInt([6,16,5,15,4,14,3,13,2,12,1,11,0,10],7,2)))
+ pass
+
+ def testSwigDAPow1(self):
+ d=DataArrayInt(10)
+ d.iota(0)
+ d1=d.deepCpy()
+ d.setIJ(2,0,-2)
+ self.assertTrue((d**2).isEqual(DataArrayInt([0,1,4,9,16,25,36,49,64,81])))
+ self.assertTrue((d**3).isEqual(DataArrayInt([0,1,-8,27,64,125,216,343,512,729])))
+ for elt in [d]:
+ elt**=2
+ pass
+ self.assertTrue(d.isEqual(DataArrayInt([0,1,4,9,16,25,36,49,64,81])))
+ self.assertTrue((d1[:4]**d1[:4]).isEqual(DataArrayInt([1,1,4,27])))
+ self.assertTrue((3**d1[:4]).isEqual(DataArrayInt([1,3,9,27])))
+ d2=d1[:4]
+ d2**=d2
+ self.assertTrue(d2.isEqual(DataArrayInt([1,1,4,27])))
+ self.assertRaises(InterpKernelException,d2.__pow__,-1)#non supporting negative pow in DataArrayInt.__pow__
+ self.assertRaises(InterpKernelException,d2.__ipow__,-1)#non supporting negative pow in DataArrayInt.__pow__
+ #
+ d=DataArrayDouble(10)
+ d.iota(0)
+ d1=d.deepCpy()
+ d.setIJ(2,0,-2.)
+ self.assertTrue((d**2).isEqual(DataArrayDouble([0,1,4,9,16,25,36,49,64,81]),1e-12))
+ self.assertTrue((d**3).isEqual(DataArrayDouble([0,1,-8,27,64,125,216,343,512,729]),1e-12))
+ self.assertRaises(InterpKernelException,d.__pow__,3.1)#3.1 is double not integer -> not supporting negative values in d
+ for elt in [d]:
+ elt**=2
+ pass
+ self.assertTrue(d.isEqual(DataArrayDouble([0,1,4,9,16,25,36,49,64,81]),1e-12))
+ self.assertTrue((d1[:4]**d1[:4]).isEqual(DataArrayDouble([1,1,4,27]),1e-12))
+ self.assertTrue((3**d1[:4]).isEqual(DataArrayDouble([1,3,9,27]),1e-12))
+ d2=d1[:4]
+ d2**=d2
+ self.assertTrue(d2.isEqual(DataArrayDouble([1,1,4,27]),1e-12))
+ d2**=-0.5
+ self.assertTrue(d2.isEqual(DataArrayDouble([1,1,1./2,1./sqrt(27.)]),1e-14))
+ d3=-1./d1[1:5]
+ self.assertTrue((3**d3).isEqual(DataArrayDouble([0.3333333333333333,0.5773502691896257,0.6933612743506348,0.7598356856515925]),1e-14))
+ d4=d3.deepCpy() ; d4.abs()
+ self.assertTrue((d4**d3).isEqual(DataArrayDouble([1.,sqrt(2.),1.4422495703074083,sqrt(2.)]),1e-14))
+ d4**=d3
+ self.assertTrue(d4.isEqual(DataArrayDouble([1.,sqrt(2.),1.4422495703074083,sqrt(2.)]),1e-14))
+ pass
+
+ def testSwig2Baryenter3DForCellsWithVolumeZero1(self):
+ coo=DataArrayDouble([0.,0.,0.,1.,0.,0.,0.,1.,0.],3,3)
+ m2=MEDCouplingUMesh("mesh",2)
+ m2.allocateCells(0)
+ m2.insertNextCell(NORM_POLYGON,[0,1,2])
+ m2.setCoords(coo)
+ m2.checkCoherency1()
+ #
+ coo2=DataArrayDouble([0.,0.,0.,0.,0.,0.,0.,0.,2.],3,3)
+ m1=MEDCouplingUMesh("mesh",1)
+ m1.allocateCells(0)
+ m1.insertNextCell(NORM_SEG2,[0,1])
+ m1.insertNextCell(NORM_SEG2,[1,2])
+ m1.setCoords(coo2)
+ m1.checkCoherency1()
+ #
+ m3=m2.buildExtrudedMesh(m1,0)
+ m3.insertNextCell(NORM_POLYHED,[3,4,5,-1,8,7,6,-1,4,3,6,7,-1,5,4,7,8,-1,5,4,-1,3,5,8,6])# addition of face #4 with null surface
+ self.assertTrue(m3.getBarycenterAndOwner().isEqual(DataArrayDouble([0.3333333333333333,0.3333333333333333,0.,0.3333333333333333,0.3333333333333333,1.,0.3333333333333333,0.3333333333333333,1.],3,3),1e-13))
+ m4,a,b,c,d=m3.buildDescendingConnectivity()
+ self.assertTrue(m4.getBarycenterAndOwner().isEqual(DataArrayDouble([0.3333333333333333,0.3333333333333333,0.,0.3333333333333333,0.3333333333333333,0.,0.5,0.,0.,0.5,0.5,0.,0.,0.5,0.,0.3333333333333333,0.3333333333333333,2.,0.5,0.,1.,0.5,0.5,1.,0.,0.5,1.,0.5,0.5,0.],10,3),1e-13))
+ pass
+
+ def testSwigRepr1(self):
+ d=DataArrayDouble()
+ self.assertTrue(len(d.__repr__())<120)
+ d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
+ for i in xrange(100):
+ d.alloc(i,1) ; d.iota(1.1234567890123456) ; d*=1e123
+ self.assertTrue(len(d.__repr__())<500)
+ pass
+ for i in xrange(50):
+ d.alloc(i,2) ; d.rearrange(1) ; d.iota(1.1234567890123456) ; d.rearrange(2) ; d*=1e123
+ self.assertTrue(len(d.__repr__())<500)
+ pass
+ d.alloc(4000,1) ; d.iota() ; self.assertTrue(len(d.__repr__())<500)
+ for i in xrange(2,4):
+ d.alloc(362880,1) ; d.iota() ; d.rearrange(i) ; self.assertTrue(len(d.__repr__())<500)
+ pass
+ d.alloc(0,9)
+ self.assertTrue(len(d.__repr__())<120)
+ #
+ d=DataArrayInt()
+ self.assertTrue(len(d.__repr__())<100)
+ d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
+ for i in xrange(100):
+ d.alloc(i,1) ; d.iota(123456789)
+ self.assertTrue(len(d.__repr__())<500)
+ pass
+ for i in xrange(50):
+ d.alloc(i,2) ; d.rearrange(1) ; d.iota(123456789) ; d.rearrange(2)
+ self.assertTrue(len(d.__repr__())<500)
+ pass
+ d.alloc(4000,1) ; d.iota() ; self.assertTrue(len(d.__repr__())<500)
+ for i in xrange(2,10):
+ d.alloc(362880,1) ; d.iota() ; d.rearrange(i) ; self.assertTrue(len(d.__repr__())<500)
+ pass
+ d.alloc(0,9)
+ self.assertTrue(len(d.__repr__())<100)
+ #
+ d=DataArrayAsciiChar()
+ d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
+ d.alloc(2,16) ; d[:]='1234567890ABCDEF'
+ self.assertTrue(len(d.__repr__())<500)
+ d.alloc(2000,16) ; d[:]='1234567890ABCDEF'
+ self.assertTrue(len(d.__repr__())<500)
+ d.alloc(0,16) ; d[:]='1234567890ABCDEF'
+ self.assertTrue(len(d.__repr__())<120)
+ #
+ d=DataArrayByte()
+ self.assertTrue(len(d.__repr__())<100)
+ d.alloc(1000,0) ; self.assertTrue(len(d.__repr__())<100)
+ d.alloc(0,16) ; self.assertTrue(len(d.__repr__())<100)
+ d.alloc(5,1) ; d.fillWithValue(127)
+ self.assertTrue(len(d.__repr__())<200)
+ d.alloc(1000,1) ; d.fillWithValue(127)
+ self.assertTrue(len(d.__repr__())<500)
+ d.alloc(1000,3) ; d.fillWithValue(127)
+ self.assertTrue(len(d.__repr__())<500)
+ pass
+
+ def testSwig2MeshComputeIsoBarycenterOfNodesPerCell1(self):
+ coo=DataArrayDouble([26.17509821414239,5.0374,200.,26.175098214142388,-5.0374,200.,17.450065476094927,20.1496,200.,8.725032738047464,25.187,200.,43.62516369023732,5.0374,200.,34.90013095218986,10.0748,200.,34.900130952189855,-10.0748,200.,43.625163690237315,-5.0374,200.,26.175098214142402,25.187,200.,26.175098214142395,35.2618,200.,17.45006547609493,40.2992,200.,8.725032738047469,35.2618,200.,26.17509821414239,5.0374,200.,26.175098214142388,-5.0374,200.,17.450065476094927,20.1496,200.,8.725032738047464,25.187,200.,43.62516369023732,5.0374,200.,34.90013095218986,10.0748,200.,34.900130952189855,-10.0748,200.,43.625163690237315,-5.0374,200.,26.175098214142402,25.187,200.,26.175098214142395,35.2618,200.,17.45006547609493,40.2992,200.,8.725032738047469,35.2618,200.],24,3)
+ m=MEDCouplingUMesh.New("toto",3)
+ m.allocateCells(0)
+ m.insertNextCell(NORM_POLYHED,[4,5,0,1,6,7,-1,19,18,13,12,17,16,-1,5,4,16,17,-1,0,5,17,12,-1,1,0,12,13,-1,6,1,13,18,-1,7,6,18,19,-1,4,7,19,16])
+ m.insertNextCell(NORM_POLYHED,[9,10,11,3,2,8,-1,20,14,15,23,22,21,-1,10,9,21,22,-1,11,10,22,23,-1,3,11,23,15,-1,2,3,15,14,-1,8,2,14,20,-1,9,8,20,21])
+ m.setCoords(coo)
+ m.checkCoherency1()
+ #
+ dReference=DataArrayDouble([(34.900130952189848,0.,200),(17.450065476094931,30.2244,200.)])
+ self.assertTrue(m.computeIsoBarycenterOfNodesPerCell().isEqual(dReference,1e-12))
+ m.getNodalConnectivity().setIJ(87,0,24)
+ self.assertRaises(InterpKernelException,m.computeIsoBarycenterOfNodesPerCell)
+ m.getNodalConnectivity().setIJ(87,0,-2)
+ self.assertRaises(InterpKernelException,m.computeIsoBarycenterOfNodesPerCell)
+ m.getNodalConnectivity().setIJ(87,0,21)# put again 21 as at the beginning
+ #
+ self.assertTrue(m.unPolyze())
+ self.assertEqual([NORM_HEXGP12],m.getAllGeoTypes())
+ self.assertTrue(m.computeIsoBarycenterOfNodesPerCell().isEqual(dReference,1e-12))
+ m.getNodalConnectivity().setIJ(25,0,24)
+ self.assertRaises(InterpKernelException,m.computeIsoBarycenterOfNodesPerCell)
+ m.getNodalConnectivity().setIJ(25,0,-1)
+ self.assertRaises(InterpKernelException,m.computeIsoBarycenterOfNodesPerCell)
+ pass
+
+ def testSwig2NonRegressionBugDescHexa20(self):
+ coo=DataArrayDouble([0.,0.,0.,1.23,0.,0.,0.615,0.,0.,0.,2.1,0.,0.615,2.1,0.,1.23,2.1,0.,1.23,1.05,0.,0.,1.05,0.,0.,0.,2.16,1.23,0.,2.16,1.23,2.1,2.16,0.,2.1,2.16,0.,0.,4.32,0.615,0.,4.32,1.23,0.,4.32,1.23,1.05,4.32,1.23,2.1,4.32,0.615,2.1,4.32,0.,2.1,4.32,0.,1.05,4.32],20,3)
+ m=MEDCouplingUMesh('mesh',3)
+ m.allocateCells(0)
+ m.insertNextCell(NORM_HEXA20,[0,3,5,1,12,18,16,14,7,4,6,2,19,17,15,13,8,11,10,9])
+ m.setCoords(coo)
+ m.checkCoherency1()
+ #
+ a,b,c,d,e=m.buildDescendingConnectivity()
+ m2=MEDCouplingUMesh('mesh',2)
+ m2.allocateCells(0)
+ m2.setCoords(coo)
+ conn2=[[0,3,5,1,7,4,6,2],[12,14,16,18,13,15,17,19],[0,12,18,3,8,19,11,7],[3,18,16,5,11,17,10,4],[5,16,14,1,10,15,9,6],[1,14,12,0,9,13,8,2]]
+ for i in xrange(6):
+ m2.insertNextCell(NORM_QUAD8,conn2[i])
+ pass
+ self.assertTrue(m2.isEqual(a,1e-12))
+ self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,4,5])))
+ self.assertTrue(c.isEqual(DataArrayInt([0,6])))
+ self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0])))
+ self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6])))
+ #
+ m.convertQuadraticCellsToLinear() ; m.zipCoords()
+ m.convertLinearCellsToQuadratic(1)
+ #
+ coo2=DataArrayDouble([0.,0.,0.,1.23,0.,0.,0.,2.1,0.,1.23,2.1,0.,0.,0.,4.32,1.23,0.,4.32,1.23,2.1,4.32,0.,2.1,4.32,0.,1.05,0.,0.615,2.1,0.,1.23,1.05,0.,0.615,0.,0.,0.,1.05,4.32,0.615,2.1,4.32,1.23,1.05,4.32,0.615,0.,4.32,0.,0.,2.16,0.,2.1,2.16,1.23,2.1,2.16,1.23,0.,2.16,0.615,1.05,0.,0.,1.05,2.16,0.615,2.1,2.16,1.23,1.05,2.16,0.615,0.,2.16,0.615,1.05,4.32,0.615,1.05,2.16],27,3)
+ m3=MEDCouplingUMesh("mesh",3)
+ m3.allocateCells(1)
+ m3.insertNextCell(NORM_HEXA27,[0,2,3,1,4,7,6,5,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26])
+ m3.setCoords(coo2)
+ self.assertTrue(m3.isEqual(m,1e-12))
+ #
+ a,b,c,d,e=m.buildDescendingConnectivity()
+ conn4=[[0,2,3,1,8,9,10,11,20],[4,5,6,7,15,14,13,12,25],[0,4,7,2,16,12,17,8,21],[2,7,6,3,17,13,18,9,22],[3,6,5,1,18,14,19,10,23],[1,5,4,0,19,15,16,11,24]]
+ m4=MEDCouplingUMesh("mesh",2)
+ m4.allocateCells(0)
+ for i in xrange(6):
+ m4.insertNextCell(NORM_QUAD9,conn4[i])
+ pass
+ m4.setCoords(coo2)
+ self.assertTrue(m4.isEqual(a,1e-12))
+ self.assertTrue(b.isEqual(DataArrayInt([0,1,2,3,4,5])))
+ self.assertTrue(c.isEqual(DataArrayInt([0,6])))
+ self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0])))
+ self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6])))
+ pass
+
+ def testSwigAdvGauss(self):
+ f=MEDCouplingFieldTemplate(ON_GAUSS_PT)
+ f.setDiscretization(None)
+ f.__repr__() ; f.__str__()
+ #
+ f=MEDCouplingFieldTemplate(ON_GAUSS_PT)
+ d=f.getDiscretization()
+ i=DataArrayInt() ; i.alloc(10,1) ; i.iota(1)
+ d.setArrayOfDiscIds(i)
+ f.__repr__() ; f.__str__()
+ i2=d.getArrayOfDiscIds()
+ self.assertEqual(i.__repr__(),i2.__repr__())
+ #
+ f=MEDCouplingFieldDouble(ON_GAUSS_PT)
+ f.setDiscretization(None)
+ f.__repr__() ; f.__str__()
+ #
+ f=MEDCouplingFieldDouble(ON_GAUSS_PT)
+ d=f.getDiscretization()
+ i=DataArrayInt() ; i.alloc(10,1) ; i.iota(1)
+ d.setArrayOfDiscIds(i)
+ f.__repr__() ; f.__str__()
+ #
+ gl=MEDCouplingGaussLocalization(NORM_SEG2,[0,1],[0.5],[1.])
+ gl.setWeights([3.])
+ gl.__repr__() ; gl.__str__()
+ gl=MEDCouplingGaussLocalization(NORM_ERROR)
+ gl.setWeights([3.])
+ gl.__repr__() ; gl.__str__()
+ pass
+
+ def testSwig2NonRegressionBugSubstractInPlaceDM(self):
+ m0=MEDCouplingCMesh()
+ arr=DataArrayDouble(5,1) ; arr.iota(0.)
+ m0.setCoords(arr,arr)
+ m0=m0.buildUnstructured()
+ m00=m0[::2] ; m00.simplexize(0) ; m01=m0[1::2]
+ m0=MEDCouplingUMesh.MergeUMeshes([m00,m01])
+ m0.getCoords()[:]*=1/4.
+ m0.setName("mesh")
+ #
+ NodeField=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; NodeField.setTime(5.6,5,6) ; NodeField.setMesh(m0)
+ NodeField.setName("NodeField")
+ NodeField.fillFromAnalytic(1,"exp(-((x-1)*(x-1)+(y-1)*(y-1)))") ; NodeField.getArray().setInfoOnComponent(0,"powernode [W]")
+ proc0=m0.getCellsInBoundingBox([(0.,0.4),(0.,0.4)],1e-10)
+ proc1=proc0.buildComplement(m0.getNumberOfCells())
+ #
+ NodeField0=NodeField[proc0] ; NodeField0.getMesh().setName(m0.getName())
+ NodeField1=NodeField[proc1] ; NodeField1.getMesh().setName(m0.getName())
+ #
+ NodeField_read=MEDCouplingFieldDouble.MergeFields([NodeField0,NodeField1])
+ NodeField_read.mergeNodes(1e-10)
+ NodeFieldCpy=NodeField.deepCpy()
+ NodeFieldCpy.mergeNodes(1e-10)
+ NodeField.checkCoherency()
+ self.assertTrue(not NodeField.getArray().isUniform(0.,1e-12))
+ NodeField.substractInPlaceDM(NodeField_read,10,1e-12)
+ self.assertTrue(NodeField.getArray().isUniform(0.,1e-12))
+ pass
+
+ def testSwigFieldOperationOpen1(self):
+ ## MEDCouplingFieldDouble.__add__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__add__,2)
+ self.assertRaises(InterpKernelException,f.__add__,range(5))
+ self.assertRaises(InterpKernelException,f.__add__,arr)
+ self.assertRaises(InterpKernelException,f.__add__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__add__,2)
+ self.assertRaises(InterpKernelException,f.__add__,range(5))
+ self.assertRaises(InterpKernelException,f.__add__,arr)
+ self.assertRaises(InterpKernelException,f.__add__,f2)
+ self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ ff=f+2
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12))
+ ff=f+arr
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12))
+ self.assertRaises(InterpKernelException,f.__add__,f2)
+ f2.setArray(arr)
+ ff=f+f2
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12))
+ ff=f+[5,8]
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(5,15),(6,16),(7,17),(8,18),(9,19)]),1e-12))
+ ### MEDCouplingFieldDouble.__sub__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__sub__,2)
+ self.assertRaises(InterpKernelException,f.__sub__,range(5))
+ self.assertRaises(InterpKernelException,f.__sub__,arr)
+ self.assertRaises(InterpKernelException,f.__sub__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__sub__,2)
+ self.assertRaises(InterpKernelException,f.__sub__,range(5))
+ self.assertRaises(InterpKernelException,f.__sub__,arr)
+ self.assertRaises(InterpKernelException,f.__sub__,f2)
+ self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ ff=f-2
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-2,5),(-1,6),(0,7),(1,8),(2,9)]),1e-12))
+ ff=f-arr
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(0,6),(0,5),(0,4),(0,3)]),1e-12))
+ self.assertRaises(InterpKernelException,f.__sub__,f2)
+ f2.setArray(arr)
+ ff=f-f2
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(0,6),(0,5),(0,4),(0,3)]),1e-12))
+ ff=f-[5,8]
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-5,-1),(-4,0),(-3,1),(-2,2),(-1,3)]),1e-12))
+ ### MEDCouplingFieldDouble.__mul__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__mul__,2)
+ self.assertRaises(InterpKernelException,f.__mul__,range(5))
+ self.assertRaises(InterpKernelException,f.__mul__,arr)
+ self.assertRaises(InterpKernelException,f.__mul__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__mul__,2)
+ self.assertRaises(InterpKernelException,f.__mul__,range(5))
+ self.assertRaises(InterpKernelException,f.__mul__,arr)
+ self.assertRaises(InterpKernelException,f.__mul__,f2)
+ self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ ff=f*2
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12))
+ ff=f*arr
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12))
+ self.assertRaises(InterpKernelException,f.__mul__,f2)
+ f2.setArray(arr)
+ ff=f*f2
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12))
+ ff=f*[5,8]
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,56),(5,64),(10,72),(15,80),(20,88)]),1e-12))
+ ### MEDCouplingFieldDouble.__div__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__div__,2)
+ self.assertRaises(InterpKernelException,f.__div__,range(5))
+ self.assertRaises(InterpKernelException,f.__div__,arr)
+ self.assertRaises(InterpKernelException,f.__div__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__div__,2)
+ self.assertRaises(InterpKernelException,f.__div__,range(5))
+ self.assertRaises(InterpKernelException,f.__div__,arr)
+ self.assertRaises(InterpKernelException,f.__div__,f2)
+ self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ self.assertRaises(InterpKernelException,f.__div__,0)
+ ff=f/2
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,4),(1,4.5),(1.5,5),(2,5.5)]),1e-12))
+ ff=f/arr
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,2),(0.6666666666666666,1.5),(0.75,1.25),(0.8,1.1)]),1e-12))
+ self.assertRaises(InterpKernelException,f.__div__,f2)
+ f2.setArray(arr)
+ ff=f/f2
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,2),(0.6666666666666666,1.5),(0.75,1.25),(0.8,1.1)]),1e-12))
+ ff=f/[5,8]
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0.875),(0.2,1),(0.4,1.125),(0.6,1.25),(0.8,1.375)]),1e-12))
+ ### MEDCouplingFieldDouble.__pow__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5)
+ arr[:]=[1,1,3,2,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__div__,2)
+ self.assertRaises(InterpKernelException,f.__div__,range(5))
+ self.assertRaises(InterpKernelException,f.__div__,arr)
+ self.assertRaises(InterpKernelException,f.__div__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__div__,2)
+ self.assertRaises(InterpKernelException,f.__div__,range(5))
+ self.assertRaises(InterpKernelException,f.__div__,arr)
+ self.assertRaises(InterpKernelException,f.__div__,f2)
+ self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
+ f.getArray().alloc(5,1)
+ f.getArray()[:]=range(2,7)
+ ff=f**2
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([4,9,16,25,36]),1e-12))
+ ff=f**arr
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([2,3,64,25,1]),1e-12))
+ f2.setArray(arr)
+ ff=f**f2
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([2,3,64,25,1]),1e-12))
+ ## MEDCouplingFieldDouble.__iadd__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__iadd__,2)
+ self.assertRaises(InterpKernelException,f.__iadd__,range(5))
+ self.assertRaises(InterpKernelException,f.__iadd__,arr)
+ self.assertRaises(InterpKernelException,f.__iadd__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__iadd__,2)
+ self.assertRaises(InterpKernelException,f.__iadd__,range(5))
+ self.assertRaises(InterpKernelException,f.__iadd__,arr)
+ self.assertRaises(InterpKernelException,f.__iadd__,f2)
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.checkCoherency()
+ f+=2
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12))
+ f+=arr
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2,9),(4,12),(6,15),(8,18),(10,21)]),1e-12))
+ f2.setArray(arr)
+ f+=f2
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2,9),(5,14),(8,19),(11,24),(14,29)]),1e-12))
+ f+=[0.1,0.2]
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2.1,9.2),(5.1,14.2),(8.1,19.2),(11.1,24.2),(14.1,29.2)]),1e-12))
+ ## MEDCouplingFieldDouble.__isub__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__isub__,2)
+ self.assertRaises(InterpKernelException,f.__isub__,range(5))
+ self.assertRaises(InterpKernelException,f.__isub__,arr)
+ self.assertRaises(InterpKernelException,f.__isub__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__isub__,2)
+ self.assertRaises(InterpKernelException,f.__isub__,range(5))
+ self.assertRaises(InterpKernelException,f.__isub__,arr)
+ self.assertRaises(InterpKernelException,f.__isub__,f2)
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.checkCoherency()
+ f-=2
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-1,6),(0,7),(1,8),(2,9)]),1e-12))
+ f-=arr
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-2,4),(-2,3),(-2,2),(-2,1)]),1e-12))
+ f2.setArray(arr)
+ f-=f2
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-3,2),(-4,-1),(-5,-4),(-6,-7)]),1e-12))
+ f-=[0.1,0.2]
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2.1,4.8),(-3.1,1.8),(-4.1,-1.2),(-5.1,-4.2),(-6.1,-7.2)]),1e-12))
+ ## MEDCouplingFieldDouble.__imul__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__imul__,2)
+ self.assertRaises(InterpKernelException,f.__imul__,range(5))
+ self.assertRaises(InterpKernelException,f.__imul__,arr)
+ self.assertRaises(InterpKernelException,f.__imul__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__imul__,2)
+ self.assertRaises(InterpKernelException,f.__imul__,range(5))
+ self.assertRaises(InterpKernelException,f.__imul__,arr)
+ self.assertRaises(InterpKernelException,f.__imul__,f2)
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.checkCoherency()
+ f*=2
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12))
+ f*=arr
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(2,32),(8,72),(18,120),(32,176)]),1e-12))
+ f2.setArray(arr)
+ f*=f2
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(2,64),(16,288),(54,720),(128,1408)]),1e-12))
+ f*=[0.1,0.2]
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(0.2,12.8),(1.6,57.6),(5.4,144),(12.8,281.6)]),1e-12))
+ ## MEDCouplingFieldDouble.__idiv__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__idiv__,2)
+ self.assertRaises(InterpKernelException,f.__idiv__,range(5))
+ self.assertRaises(InterpKernelException,f.__idiv__,arr)
+ self.assertRaises(InterpKernelException,f.__idiv__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__idiv__,2)
+ self.assertRaises(InterpKernelException,f.__idiv__,range(5))
+ self.assertRaises(InterpKernelException,f.__idiv__,arr)
+ self.assertRaises(InterpKernelException,f.__idiv__,f2)
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.checkCoherency()
+ f/=2
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,4),(1,4.5),(1.5,5),(2,5.5)]),1e-12))
+ f/=arr
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,1.75),(0.25,1),(0.3333333333333333,0.75),(0.375,0.625),(0.4,0.55)]),1e-12))
+ f2.setArray(arr)
+ f/=f2
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0.875),(0.125,0.25),(0.1111111111111111,0.125),(0.09375,0.078125),(0.08,0.055)]),1e-12))
+ f/=[0.1,0.2]
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,4.375),(1.25,1.25),(1.1111111111111111,0.625),(0.9375,0.390625),(0.8,0.275)]),1e-12))
+ ## MEDCouplingFieldDouble.__ipow__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__ipow__,2)
+ self.assertRaises(InterpKernelException,f.__ipow__,range(5))
+ self.assertRaises(InterpKernelException,f.__ipow__,arr)
+ self.assertRaises(InterpKernelException,f.__ipow__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__ipow__,2)
+ self.assertRaises(InterpKernelException,f.__ipow__,range(5))
+ self.assertRaises(InterpKernelException,f.__ipow__,arr)
+ self.assertRaises(InterpKernelException,f.__ipow__,f2)
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ f.checkCoherency()
+ f**=2
+ f.checkCoherency()
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,49),(1,64),(4,81),(9,100),(16,121)]),1e-12))
+ ## MEDCouplingFieldDouble.__radd__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__radd__,2)
+ self.assertRaises(InterpKernelException,f.__radd__,range(5))
+ self.assertRaises(InterpKernelException,f.__radd__,arr)
+ self.assertRaises(InterpKernelException,f.__radd__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__radd__,2)
+ self.assertRaises(InterpKernelException,f.__radd__,range(5))
+ self.assertRaises(InterpKernelException,f.__radd__,arr)
+ self.assertRaises(InterpKernelException,f.__radd__,f2)
+ self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ ff=2+f
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12))
+ ff=arr+f
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12))
+ self.assertRaises(InterpKernelException,f.__radd__,f2)
+ ff=[5,8]+f
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(5,15),(6,16),(7,17),(8,18),(9,19)]),1e-12))
+ ### MEDCouplingFieldDouble.__rsub__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__rsub__,2)
+ self.assertRaises(InterpKernelException,f.__rsub__,range(5))
+ self.assertRaises(InterpKernelException,f.__rsub__,arr)
+ self.assertRaises(InterpKernelException,f.__rsub__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__rsub__,2)
+ self.assertRaises(InterpKernelException,f.__rsub__,range(5))
+ self.assertRaises(InterpKernelException,f.__rsub__,arr)
+ self.assertRaises(InterpKernelException,f.__rsub__,f2)
+ self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ ff=2-f
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,-5),(1,-6),(0,-7),(-1,-8),(-2,-9)]),1e-12))
+ ff=arr-f
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,-7),(0,-6),(0,-5),(0,-4),(0,-3)]),1e-12))
+ self.assertRaises(InterpKernelException,f.__rsub__,f2)
+ ### MEDCouplingFieldDouble.__rmul__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__rmul__,2)
+ self.assertRaises(InterpKernelException,f.__rmul__,range(5))
+ self.assertRaises(InterpKernelException,f.__rmul__,arr)
+ self.assertRaises(InterpKernelException,f.__rmul__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__rmul__,2)
+ self.assertRaises(InterpKernelException,f.__rmul__,range(5))
+ self.assertRaises(InterpKernelException,f.__rmul__,arr)
+ self.assertRaises(InterpKernelException,f.__rmul__,f2)
+ self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ ff=2*f
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12))
+ ff=arr*f
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12))
+ self.assertRaises(InterpKernelException,f.__rmul__,f2)
+ ff=f*[5,8]
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,56),(5,64),(10,72),(15,80),(20,88)]),1e-12))
+ ### MEDCouplingFieldDouble.__rdiv__
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2)
+ arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0]
+ f2=f.clone(True)
+ self.assertRaises(InterpKernelException,f.__rdiv__,2)
+ self.assertRaises(InterpKernelException,f.__rdiv__,range(5))
+ self.assertRaises(InterpKernelException,f.__rdiv__,arr)
+ self.assertRaises(InterpKernelException,f.__rdiv__,f2)
+ f.setArray(DataArrayDouble())
+ self.assertRaises(InterpKernelException,f.__rdiv__,2)
+ self.assertRaises(InterpKernelException,f.__rdiv__,range(5))
+ self.assertRaises(InterpKernelException,f.__rdiv__,arr)
+ self.assertRaises(InterpKernelException,f.__rdiv__,f2)
+ self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0))
+ f.getArray().alloc(5,2)
+ f.getArray()[:,0]=range(1,6) ; f.getArray()[:,1]=f.getArray()[:,0]+7
+ ff=2/f
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,0.25),(1,0.22222222222222221),(0.66666666666666663,0.20000000000000001),(0.5,0.18181818181818182),(0.40000000000000002,0.16666666666666666)]),1e-12))
+ ff=arr/f
+ ff.checkCoherency()
+ self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(1,0.25),(1,0.44444444444444442),(1,0.59999999999999998),(1,0.72727272727272729),(1,0.83333333333333337)]),1e-12))
+ self.assertRaises(InterpKernelException,f.__rdiv__,f2)
+ pass
+
+ def testSwig2FieldDoubleBuildSubPartRange1(self):
+ #ON_CELLS
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(5,2) ; arr[:,0]=range(7,12) ; arr[:,1]=100+arr[:,0]
+ f.setArray(arr)
+ f.checkCoherency()
+ ff=f[1:-1:2]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(2,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[1,3]],1e-12))
+ #
+ a,b=f.buildSubMeshDataRange(2,5,1)
+ self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12))
+ self.assertEqual(b,slice(2,5,1))
+ ff=f[2:]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[2,3,4]],1e-12))
+ #
+ ff=f[-2:0:-1]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[3,2,1]],1e-12))
+ self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[3,2,1],1],1e-12))
+ #ON_NODES
+ f=MEDCouplingFieldDouble(ON_NODES)
+ f.setMesh(m)
+ arr=DataArrayDouble(9,2) ; arr[:,0]=range(7,16) ; arr[:,1]=100+arr[:,0]
+ f.setArray(arr)
+ f.checkCoherency()
+ ff=f[1:-1:2]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([1,3],False)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(6,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(2,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[1,2,3,4,6,7]],1e-12))
+ #
+ m2=m.buildPartRange(2,5,1)
+ self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(m2,1e-12))
+ m2,b=m.buildPartRangeAndReduceNodes(2,5,1)
+ self.assertTrue(m.buildPartOfMySelf([2,3,4],False).isEqual(m2,1e-12))
+ self.assertTrue(b.isEqual(DataArrayInt([-1,-1,0,1,2,3,4,5,6])))
+ a,b=f.buildSubMeshDataRange(2,5,1)
+ self.assertTrue(m.buildPartOfMySelf([2,3,4],False).isEqual(a,1e-12))
+ self.assertTrue(b.isEqual(DataArrayInt([2,3,4,5,6,7,8])))
+ ff=f[2:]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([2,3,4],False)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(7,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[2,3,4,5,6,7,8]],1e-12))
+ #
+ ff=f[-2:0:-1]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([3,2,1],False)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(7,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[1,2,3,4,5,6,7]],1e-12))
+ self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[1,2,3,4,5,6,7],1],1e-12))
+ #ON_GAUSS_NE
+ f=MEDCouplingFieldDouble(ON_GAUSS_NE)
+ f.setMesh(m)
+ arr=DataArrayDouble(18,2) ; arr[:,0]=range(7,25) ; arr[:,1]=100+arr[:,0]
+ f.setArray(arr)
+ f.checkCoherency()
+ ff=f[1:-1:2]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(2,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[4,5,6,10,11,12,13]],1e-12))
+ #
+ a,b=f.buildSubMeshDataRange(2,5,1)
+ self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12))
+ self.assertEqual(b,slice(7,18,1))
+ ff=f[2:]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[7,8,9,10,11,12,13,14,15,16,17]],1e-12))
+ #
+ ff=f[-2:0:-1]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[10,11,12,13,7,8,9,4,5,6]],1e-12))
+ self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[10,11,12,13,7,8,9,4,5,6],1],1e-12))
+ #ON_GAUSS_PT
+ f=MEDCouplingFieldDouble(ON_GAUSS_PT)
+ f.setMesh(m)
+ f.setGaussLocalizationOnCells([0,4],[0,0,1,0,1,1,1,0],[1.1,1.1,2.2,2.2],[0.2,0.8]);
+ f.setGaussLocalizationOnCells([3],[0,0,1,0,1,1,1,0],[1.1,1.1,2.2,2.2,3.,3.],[0.2,0.4,0.4]);
+ f.setGaussLocalizationOnCells([1],[0,0,1,0,1,0],[1.1,1.1,2.2,2.2,3.,3.,4.,4.],[0.1,0.1,0.4,0.4]);
+ f.setGaussLocalizationOnCells([2],[0,0,1,0,1,0],[1.1,1.1,2.2,2.2,3.,3.,4.,4.,5.,5.],[0.1,0.1,0.4,0.3,0.1]);
+ arr=DataArrayDouble(16,2) ; arr[:,0]=range(7,23) ; arr[:,1]=100+arr[:,0]
+ f.setArray(arr)
+ f.checkCoherency()
+ ff=f[1:-1:2]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(2,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[2,3,4,5,11,12,13]],1e-12))
+ #
+ a,b=f.buildSubMeshDataRange(2,5,1)
+ self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12))
+ self.assertEqual(b,slice(6,16,1))
+ ff=f[2:]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[6,7,8,9,10,11,12,13,14,15]],1e-12))
+ #
+ ff=f[-2:0:-1]
+ ff.checkCoherency()
+ self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12))
+ self.assertTrue(9,ff.getMesh().getNumberOfNodes())
+ self.assertTrue(3,ff.getMesh().getNumberOfCells())
+ self.assertTrue(ff.getArray().isEqual(arr[[11,12,13,6,7,8,9,10,2,3,4,5]],1e-12))
+ self.assertTrue(f[-2:0:-1,0].getArray().isEqual(arr[[11,12,13,6,7,8,9,10,2,3,4,5],0],1e-12))
+ pass
+
+ def testSwig2FieldDoubleApplyFuncBug1(self):
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(MEDCouplingDataForTest.build2DTargetMesh_1())
+ f.applyFunc(3,700.)
+ f.checkCoherency()
+ self.assertEqual(3,f.getArray().getNumberOfComponents())
+ f.getArray().rearrange(1)
+ self.assertTrue(f.getArray().isUniform(700.,1e-10))
+ f.getArray().rearrange(3)
+ f.checkCoherency()
+ f.applyFunc(4,800.)
+ f.checkCoherency()
+ self.assertEqual(4,f.getArray().getNumberOfComponents())
+ f.getArray().rearrange(1)
+ self.assertTrue(f.getArray().isUniform(800.,1e-10))
+ f.getArray().rearrange(4)
+ f.checkCoherency()
+ pass
+
+ def testSwig2ComputeTupleIdsNearTupleBug1(self):
+ coords=[1.1,0.0, 1.1,0.0 ];
+ coordsArr=DataArrayDouble(coords,2,2);
+ mesh=MEDCouplingUMesh();
+ mesh.setCoords(coordsArr);
+ points=[1.1, 0.002]
+ c,cI=mesh.getNodeIdsNearPoints(points,0.00185);
+ self.assertTrue(c.isEqual(DataArrayInt([])))
+ self.assertTrue(cI.isEqual(DataArrayInt([0,0])))
+ c,cI=mesh.getNodeIdsNearPoints(points,0.00200000000000001);
+ self.assertTrue(c.isEqual(DataArrayInt([0,1])))
+ self.assertTrue(cI.isEqual(DataArrayInt([0,2])))
+ pass
+
+ def testSwig2NonRegressionBugChangeUnderlyingWithZeroCells(self):
+ coords1=[0.,1.,2.,3.]
+ coords2=[2.,1.,0.,3.] #0 <==> #2
+ # mesh 1
+ mesh1=MEDCouplingUMesh.New();
+ coordsArr=DataArrayDouble.New(coords1,4,1);
+ mesh1.setCoords(coordsArr);
+ mesh1.setMeshDimension(0);
+ mesh1.allocateCells(0);
+ mesh1.finishInsertingCells();
+ # mesh 2
+ mesh2=mesh1.deepCpy();
+ coordsArr=DataArrayDouble.New(coords2,4,1);
+ mesh2.setCoords(coordsArr);
+ field = mesh1.fillFromAnalytic(ON_NODES,1,"x")
+ field.checkCoherency()
+ levOfCheck = 10
+ field.changeUnderlyingMesh( mesh2, levOfCheck, 1e-13, 0 )
+ self.assertTrue( field.getArray().getValues() == coords2 )
+ pass
+
+ def testSwig2UMeshDistanceToMesh2(self):
+ sz=5
+ m=MEDCouplingCMesh()
+ arr=DataArrayDouble(sz+1) ; arr.iota() ; arr/=sz
+ m.setCoords(arr,arr,arr)
+ m=m.buildUnstructured()
+ m1=m.computeSkin()
+ m1.zipCoords()
+ c=m1.getCoords()[:]
+ d=2*(c-[0.5,0.5,0.5])+[0.5,0.5,0.5]
+ time_deb = datetime.now()
+ #print "go.."
+ a,b=m1.distanceToPoints(d)
+ #print 'time spent in distanceToPoints %s ' %str(datetime.now() - time_deb)
+ time_deb = datetime.now()
+ a1=DataArrayDouble(len(d))
+ b1=DataArrayInt(len(d))
+ m1s=[m1[i] for i in xrange(m1.getNumberOfCells())]
+ for j,pt in enumerate(d):
+ eter=1e308
+ fter=-1
+ for i,miter in enumerate(m1s):
+ e,f=miter.distanceToPoint(pt)
+ self.assertEqual(0,f)
+ if e<eter:
+ eter=e ; fter=i
+ pass
+ pass
+ a1[j]=eter
+ b1[j]=fter
+ pass
+ #print 'time spent in naive distanceToPoints %s ' %str(datetime.now() - time_deb)
+ self.assertTrue(a.isEqual(a1,1e-12))
+ self.assertTrue(b.isEqual(b1))
+ self.assertTrue(a.isEqual(DataArrayDouble([0.8660254037844386,0.714142842854285,0.7071067811865476,0.7071067811865476,0.714142842854285,0.8660254037844386,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706632,0.714142842854285,0.7071067811865475,0.5099019513592785,0.5,0.5,0.5099019513592785,0.7071067811865476,0.7071067811865475,0.5099019513592785,0.5,0.5,0.5099019513592785,0.7071067811865476,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706632,0.714142842854285,0.8660254037844386,0.714142842854285,0.7071067811865476,0.7071067811865476,0.714142842854285,0.8660254037844386,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706631,0.714142842854285,0.5196152422706631,0.5196152422706632,0.5099019513592784,0.5099019513592785,0.5099019513592784,0.5099019513592785,0.5196152422706631,0.5196152422706632,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706632,0.714142842854285,0.7071067811865475,0.5099019513592785,0.5,0.5,0.5099019513592784,0.7071067811865475,0.5099019513592784,0.5099019513592785,0.5,0.5,0.5,0.5,0.5099019513592785,0.5099019513592785,0.7071067811865476,0.5099019513592785,0.5,0.5,0.5099019513592785,0.7071067811865476,0.7071067811865475,0.5099019513592785,0.5,0.5,0.5099019513592784,0.7071067811865475,0.5099019513592784,0.5099019513592785,0.5,0.5,0.5,0.5,0.5099019513592785,0.5099019513592785,0.7071067811865476,0.5099019513592785,0.5,0.5,0.5099019513592785,0.7071067811865476,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706631,0.714142842854285,0.5196152422706631,0.5196152422706632,0.5099019513592784,0.5099019513592785,0.5099019513592784,0.5099019513592785,0.5196152422706631,0.5196152422706632,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706632,0.714142842854285,0.8660254037844386,0.714142842854285,0.7071067811865476,0.7071067811865476,0.714142842854285,0.8660254037844386,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706632,0.714142842854285,0.7071067811865475,0.5099019513592785,0.5,0.5,0.5099019513592785,0.7071067811865476,0.7071067811865475,0.5099019513592785,0.5,0.5,0.5099019513592785,0.7071067811865476,0.714142842854285,0.5196152422706632,0.5099019513592785,0.5099019513592785,0.5196152422706632,0.714142842854285,0.8660254037844386,0.714142842854285,0.7071067811865476,0.7071067811865476,0.714142842854285,0.8660254037844386]),1e-12))
+ self.assertTrue(b.isEqual(DataArrayInt([0,0,3,7,9,9,0,0,3,7,9,9,12,12,14,16,17,17,26,26,28,30,31,31,33,33,36,40,42,42,33,33,36,40,42,42,0,0,3,7,11,9,0,9,12,17,26,31,33,42,33,33,36,40,42,42,45,45,47,49,51,51,45,50,52,53,56,57,58,63,58,58,60,62,63,63,85,85,87,89,91,91,85,90,92,93,96,97,98,103,98,98,100,102,103,103,105,105,108,112,116,114,105,114,117,122,131,136,138,147,138,138,141,145,147,147,105,105,108,112,114,114,105,105,108,112,114,114,117,117,119,121,122,122,131,131,133,135,136,136,138,138,141,145,147,147,138,138,141,145,147,147])))
+ pass
+
+ def testSwig2NonRegressionBugDistance1(self):
+ pt=DataArrayDouble([(8.8452994616207476,3.1547005383792515,3.1547005383792515)])
+ coo=DataArrayDouble([(8,0,0),(8,0,8),(8,8,8),(8,8,0),(16,0,0),(16,0,8),(16,8,8),(16,8,0),(8,0,4),(8,4,8),(8,8,4),(8,4,0),(16,0,4),(16,4,8),(16,8,4),(16,4,0),(12,0,0),(12,0,8),(12,8,8),(12,8,0),(8,4,4),(16,4,4),(12,0,4),(12,4,8),(12,8,4),(12,4,0)])
+ conn=DataArrayInt([4,15,21,12,4,16,25,15,12,22,16,4,0,8,20,11,16,0,11,25,22,8,0,16,15,7,14,21,15,25,19,7,7,19,24,14,11,20,10,3,25,11,3,19,19,3,10,24,12,21,13,5,13,23,17,5,5,17,22,12,8,1,9,20,23,9,1,17,17,1,8,22,21,14,6,13,14,24,18,6 ,6,18,23,13,20,9,2,10,24,10,2,18,18,2,9,23])
+ m=MEDCouplingUMesh("mesh",2)
+ m.setCoords(coo)
+ m.allocateCells()
+ for i in xrange(24):
+ m.insertNextCell(NORM_QUAD4,conn[4*i:4*i+4])
+ pass
+ m.checkCoherency2()
+ m0=m[3] ; m0.zipCoords()
+ expectedDist=0.8452994616207476
+ a,b=m0.distanceToPoint(pt)
+ self.assertAlmostEqual(expectedDist,a,14)
+ self.assertEqual(0,b)
+ #
+ a,b=m.distanceToPoint(pt)
+ self.assertAlmostEqual(expectedDist,a,14)
+ self.assertEqual(3,b)
+ #
+ fd=MEDCouplingFieldDiscretization.New(ON_CELLS)
+ self.assertEqual(24,fd.getNumberOfTuples(m))
+ fd=MEDCouplingFieldDiscretization.New(ON_NODES)
+ self.assertEqual(26,fd.getNumberOfTuples(m))
+ pass
+
+ def testSwig2AreaBarySeg3Quad8Tri6QPolyg(self):
+ #QUAD8 representing a circle of center zeBary and radius zeRadius
+ zeBary=[5,6]
+ zeRadius=3
+ d=DataArrayDouble(8,2)
+ d[:,0]=zeRadius
+ d[:,1]=[87,-100,-170,110,5,-130,175,95] # angle in degree
+ d[:,1]*=pi/180. # angle in radian
+ d=d.fromPolarToCart()
+ d+=zeBary
+ m=MEDCouplingUMesh("quad8",2) ; m.allocateCells() ; m.insertNextCell(NORM_QUAD8,range(8)) ; m.setCoords(d)
+ self.assertTrue(m.getBarycenterAndOwner().isEqual(DataArrayDouble(zeBary,1,2),1e-13))
+ self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),pi*zeRadius*zeRadius,12)
+ tri32D=m.buildDescendingConnectivity()[0][0] ; tri32D.zipCoords()
+ # spaceDim=3 QUAD8 becomes QUAD4 ... for the moment
+ m.setCoords(m.getCoords().changeNbOfComponents(3,0.))
+ m2=m.deepCpy()
+ m2.convertQuadraticCellsToLinear()
+ self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),float(m2.getMeasureField(False).getArray()),12)
+ self.assertTrue(m.getBarycenterAndOwner().isEqual(m2.getBarycenterAndOwner(),1e-13))
+ #TRI6 representing a circle of center zeBary and radius zeRadius
+ zeBary=[5,6]
+ zeRadius=3
+ d=DataArrayDouble(6,2)
+ d[:,0]=zeRadius
+ d[:,1]=[87,-100,110,5,175,95] # angle in degree
+ d[:,1]*=pi/180. # angle in radian
+ d=d.fromPolarToCart()
+ d+=zeBary
+ m=MEDCouplingUMesh("tri6",2) ; m.allocateCells() ; m.insertNextCell(NORM_TRI6,range(6)) ; m.setCoords(d)
+ self.assertTrue(m.getBarycenterAndOwner().isEqual(DataArrayDouble(zeBary,1,2),1e-13))
+ self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),pi*zeRadius*zeRadius,12)
+ # spaceDim=3 TRI6 becomes TRI3 ... for the moment
+ m.setCoords(m.getCoords().changeNbOfComponents(3,0.))
+ m2=m.deepCpy()
+ m2.convertQuadraticCellsToLinear()
+ self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),float(m2.getMeasureField(False).getArray()),12)
+ self.assertTrue(m.getBarycenterAndOwner().isEqual(m2.getBarycenterAndOwner(),1e-13))
+ # QPOLYG representing a circle of center zeBary and radius zeRadius
+ zeBary=[5,6]
+ zeRadius=3
+ d=DataArrayDouble(10,2)
+ d[:,0]=zeRadius
+ d[:,1]=[87,-80,-100,-170,110,5,-90,-130,175,95] # angle in degree
+ d[:,1]*=pi/180. # angle in radian
+ d=d.fromPolarToCart()
+ d+=zeBary
+ m=MEDCouplingUMesh("qpolyg",2) ; m.allocateCells() ; m.insertNextCell(NORM_QPOLYG,range(10)) ; m.setCoords(d)
+ self.assertTrue(m.getBarycenterAndOwner().isEqual(DataArrayDouble(zeBary,1,2),1e-13))
+ self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),pi*zeRadius*zeRadius,12)
+ # spaceDim=3 QPOLYG becomes POLYG ... for the moment
+ m.setCoords(m.getCoords().changeNbOfComponents(3,0.))
+ m2=m.deepCpy()
+ m2.convertQuadraticCellsToLinear() ; m2.checkCoherency2()
+ self.assertTrue(m2.getAllGeoTypes()==[NORM_POLYGON] and m2.getNodalConnectivity().getValues()==[5,0,1,2,3,4])
+ self.assertAlmostEqual(float(m.getMeasureField(False).getArray()),float(m2.getMeasureField(False).getArray()),12)
+ self.assertTrue(m.getBarycenterAndOwner().isEqual(m2.getBarycenterAndOwner(),1e-13))
+ # TRI3
+ self.assertAlmostEqual(float(tri32D.getMeasureField(False).getArray()),(87+100)*pi/180*zeRadius,13)
+ exp=DataArrayDouble(1,2) ; exp[:,0]=3 ; exp[:,1]=(87-100)/2. ; exp[:,1]*=pi/180. ; exp=exp.fromPolarToCart() ; exp+=DataArrayDouble([5,6],1,2)
+ self.assertTrue(tri32D.getBarycenterAndOwner().isEqual(exp,1e-12))
+ # spaceDim=3 TRI3 becomes TRI2 ... for the moment
+ tri32D.changeSpaceDimension(3)
+ tri2=tri32D.deepCpy() ; tri2.convertQuadraticCellsToLinear()
+ self.assertAlmostEqual(float(tri32D.getMeasureField(False).getArray()),float(tri2.getMeasureField(False).getArray()),13)
+ self.assertTrue(tri32D.getBarycenterAndOwner().isEqual(tri2.getBarycenterAndOwner(),1e-12))
+ tri32D.changeSpaceDimension(1)
+ self.assertAlmostEqual(float(tri32D.getMeasureField(False).getArray()),-0.67795240172962323,12)
+ pass
+
+ # this bug 5/6/2013 is swig specific
+ def testSwigNonRegressionBugRotate3D1(self):
+ m=MEDCouplingUMesh.New()
+ dataArray=DataArrayDouble.New(100,3)
+ dataArray[:]=0.
+ dataArray[0]=[0.,1,3]
+ m.setCoords(dataArray[0])
+ m1=m.deepCpy()
+ m.rotate([0.,0.,3.],[1.,0.,0.],0.5*pi)
+ self.assertTrue(m.getCoords().isEqual(DataArrayDouble([0.,0.,4.],1,3),1e-15))
+ #
+ d1=DataArrayDouble([0.,0.,3.],1,3) ; d2=DataArrayDouble([1.,0.,0.],1,3)
+ pts=[[0.,0.,3.],[(0.,0.,3.)],DataArrayDouble([0.,0.,3.],1,3),list(d1)[0]]
+ vec=[[1.,0.,0.],[(1.,0.,0.)],DataArrayDouble([1.,0.,0.],1,3),list(d2)[0]]
+ for p in pts:
+ for v in vec:
+ m2=m1.deepCpy()
+ m2.rotate(p,v,0.5*pi)
+ self.assertTrue(m2.getCoords().isEqual(DataArrayDouble([0.,0.,4.],1,3),1e-15))
+ pass
+ pass
+
+ def testSwig2DataArrayCount1(self):
+ d=DataArrayInt([])
+ self.assertEqual(0,d.getNumberOfTuples())
+ self.assertEqual(1,d.getNumberOfComponents())
+ self.assertEqual(0,d.count(0))
+ self.assertEqual(0,d.count(1))
+ self.assertEqual(0,d.count(-1))
+ d=DataArrayInt([2,1,-2,-3,2,0,0,7,2,-2,3,0])
+ self.assertEqual(12,d.getNumberOfTuples())
+ self.assertEqual(1,d.getNumberOfComponents())
+ self.assertEqual(3,d.count(0))
+ self.assertEqual(1,d.count(1))
+ self.assertEqual(0,d.count(-1))
+ self.assertEqual(2,d.count(-2))
+ self.assertEqual(3,d.count(2))
+ e=d.getDifferentValues()
+ f=DataArrayInt()
+ for it in e:
+ f.pushBackSilent(d.count(int(it)))
+ pass
+ self.assertEqual(12,f.accumulate()[0])
+ #
+ eps=1e-12
+ d=DataArrayDouble([])
+ self.assertEqual(0,d.getNumberOfTuples())
+ self.assertEqual(1,d.getNumberOfComponents())
+ self.assertEqual(0,d.count(0,eps))
+ self.assertEqual(0,d.count(1,eps))
+ self.assertEqual(0,d.count(-1,eps))
+ d=DataArrayDouble([2,1,-2,-3,2,0,eps/10,7,2+eps/10,-2,3,0])
+ self.assertEqual(12,d.getNumberOfTuples())
+ self.assertEqual(1,d.getNumberOfComponents())
+ self.assertEqual(3,d.count(0,eps))
+ self.assertEqual(1,d.count(1,eps))
+ self.assertEqual(0,d.count(-1,eps))
+ self.assertEqual(2,d.count(-2,eps))
+ self.assertEqual(3,d.count(2,eps))
+ self.assertEqual(3,d.count(2,eps))
+ self.assertEqual(2,d.count(2,eps/100))
+ e=d.getDifferentValues(eps)
+ f=DataArrayInt()
+ for it in e:
+ f.pushBackSilent(d.count(float(it),eps))
+ pass
+ self.assertEqual(12,f.accumulate()[0])
+ pass
+
+ def testSwig2DataArrayGetSlice1(self):
+ s=slice(2,18,1)
+ self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),16)
+ self.assertEqual(DataArray.GetNumberOfItemGivenBES(s),16)
+ self.assertEqual(DataArray.GetSlice(s,0,4),slice(2,6,1))
+ self.assertEqual(DataArray.GetSlice(s,1,4),slice(6,10,1))
+ self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,14,1))
+ self.assertEqual(DataArray.GetSlice(s,3,4),slice(14,18,1))
+ #
+ s=slice(2,18,2)
+ self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),8)
+ self.assertEqual(DataArray.GetNumberOfItemGivenBES(s),8)
+ self.assertEqual(DataArray.GetSlice(s,0,4),slice(2,6,2))
+ self.assertEqual(DataArray.GetSlice(s,1,4),slice(6,10,2))
+ self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,14,2))
+ self.assertEqual(DataArray.GetSlice(s,3,4),slice(14,18,2))
+ #
+ s=slice(1,18,1)
+ self.assertEqual(DataArray.GetSlice(s,0,4),slice(1,5,1))
+ self.assertEqual(DataArray.GetSlice(s,1,4),slice(5,9,1))
+ self.assertEqual(DataArray.GetSlice(s,2,4),slice(9,13,1))
+ self.assertEqual(DataArray.GetSlice(s,3,4),slice(13,18,1))# 18 not 17
+ #
+ s=slice(1,18,2)
+ self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),9)
+ self.assertEqual(DataArray.GetNumberOfItemGivenBES(s),9)
+ self.assertEqual(DataArray.GetSlice(s,0,4),slice(1,5,2))
+ self.assertEqual(DataArray.GetSlice(s,1,4),slice(5,9,2))
+ self.assertEqual(DataArray.GetSlice(s,2,4),slice(9,13,2))
+ self.assertEqual(DataArray.GetSlice(s,3,4),slice(13,18,2))# 18 not 17
+ #
+ s=slice(18,2,-1)
+ self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-1))
+ self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-1))
+ self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-1))
+ self.assertEqual(DataArray.GetSlice(s,3,4),slice(6,2,-1))
+ #
+ s=slice(18,2,-2)
+ self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-2))
+ self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-2))
+ self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-2))
+ self.assertEqual(DataArray.GetSlice(s,3,4),slice(6,2,-2))
+ #
+ s=slice(18,1,-1)
+ self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-1))
+ self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-1))
+ self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-1))
+ self.assertEqual(DataArray.GetSlice(s,3,4),slice(6,1,-1))# 1 not 2
+ #
+ s=slice(18,1,-2)
+ self.assertEqual(DataArray.GetNumberOfItemGivenBESRelative(s),9)
+ self.assertRaises(InterpKernelException,DataArray.GetNumberOfItemGivenBES,s)
+ self.assertEqual(sum([DataArray.GetNumberOfItemGivenBESRelative(DataArray.GetSlice(s,i,4)) for i in xrange(4)]),DataArray.GetNumberOfItemGivenBESRelative(s))
+ self.assertEqual(DataArray.GetSlice(s,0,4),slice(18,14,-2))
+ self.assertEqual(DataArray.GetSlice(s,1,4),slice(14,10,-2))
+ self.assertEqual(DataArray.GetSlice(s,2,4),slice(10,6,-2))
+ self.assertEqual(DataArray.GetSlice(s,3,4),slice(6,1,-2))# 1 not 2
+ self.assertRaises(InterpKernelException,DataArray.GetSlice,slice(0,None,2),0,4)
+ #
+ d=DataArrayInt.Range(0,18,1)
+ s=slice(2,None,1)
+ self.assertEqual(d.getNumberOfItemGivenBES(s),16)
+ self.assertEqual(d.getNumberOfItemGivenBESRelative(s),16)
+ self.assertEqual(d.getSlice(s,0,4),slice(2,6,1))
+ self.assertEqual(d.getSlice(s,1,4),slice(6,10,1))
+ self.assertEqual(d.getSlice(s,2,4),slice(10,14,1))
+ self.assertEqual(d.getSlice(s,3,4),slice(14,18,1))
+ #
+ d=DataArrayInt.Range(0,18,1)
+ s=slice(2,-2,1)
+ self.assertEqual(d.getSlice(s,0,4),slice(2,5,1))
+ self.assertEqual(d.getSlice(s,1,4),slice(5,8,1))
+ self.assertEqual(d.getSlice(s,2,4),slice(8,11,1))
+ self.assertEqual(d.getSlice(s,3,4),slice(11,16,1))
+ #
+ d=DataArrayInt.Range(0,18,1)
+ s=slice(None,None,1)
+ self.assertEqual(d.getSlice(s,0,4),slice(0,4,1))
+ self.assertEqual(d.getSlice(s,1,4),slice(4,8,1))
+ self.assertEqual(d.getSlice(s,2,4),slice(8,12,1))
+ self.assertEqual(d.getSlice(s,3,4),slice(12,18,1))
+ #
+ d=DataArrayInt.Range(0,18,1)
+ s=slice(None,2,-2)
+ self.assertRaises(InterpKernelException,d.getNumberOfItemGivenBES,s)
+ self.assertEqual(d.getNumberOfItemGivenBESRelative(s),8)
+ self.assertEqual(d.getSlice(s,0,4),slice(17,13,-2))
+ self.assertEqual(d.getSlice(s,1,4),slice(13,9,-2))
+ self.assertEqual(d.getSlice(s,2,4),slice(9,5,-2))
+ self.assertEqual(d.getSlice(s,3,4),slice(5,2,-2))
+ pass
+
+ def testSwig2AccumulatePerChunk1(self):
+ arr=DataArrayDouble(11) ; arr.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
+ m=m.buildUnstructured()
+ m0=m[::2] ; ids0=m0.simplexize(0) ; m1=m[1::2]
+ m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m0,m1) ; m.setName("mesh")
+ m.checkConsecutiveCellTypesForMEDFileFrmt()
+ #
+ formula="7-sqrt((x-5.)*(x-5.)+(y-5.)*(y-5.))"
+ f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
+ f.fillFromAnalytic(1,formula)
+ f.setName("Field1") ; f.setTime(1.1,1,-1)
+ f.checkCoherency()
+ #
+ arr=f.getArray()
+ arr2=DataArrayDouble(len(arr),2) ; arr2[:,0]=arr
+ arr2=DataArrayDouble(len(arr),2) ; arr2[:,0]=arr ; arr2[:,1]=2*arr
+ f.setArray(arr2)
+ f.checkCoherency()
+ # here the compact code to obviously put field on cell to nodes
+ rn,rni=f.getMesh().getReverseNodalConnectivity()
+ arr2=f.getArray()[rn]
+ arr4=arr2.accumulatePerChunck(rni)
+ nbOfCellsSharingNodes=rni.deltaShiftIndex()
+ arr4/=nbOfCellsSharingNodes.convertToDblArr()
+ #
+ maxNbCSN=nbOfCellsSharingNodes.getMaxValue()[0]
+ arr3=DataArrayDouble(f.getMesh().getNumberOfNodes(),f.getArray().getNumberOfComponents()) ; arr3[:]=0.
+ for i in xrange(1,maxNbCSN+1):
+ ids=nbOfCellsSharingNodes.getIdsEqual(i)
+ if len(ids)==0:
+ continue
+ for j in range(i):
+ rni2=rni[ids] ; rni2+=j
+ arr3[ids]+=arr2[rni2]
+ pass
+ arr3[ids]/=i
+ pass
+ fNode=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; fNode.setMesh(m)
+ fNode.setName("Field1Node") ; fNode.setTime(1.1,1,-1)
+ fNode.setArray(arr3) ; fNode.checkCoherency()
+ self.assertTrue(arr3.isEqual(arr4,1e-12))
+ #
+ d=DataArrayInt.Range(0,20,1)
+ self.assertTrue(d.accumulatePerChunck([2,4,12]).isEqual(DataArrayInt([5,60])))
+ #
+ a=DataArrayDouble(12) ; a.iota() ; a.rearrange(3)
+ b=DataArrayDouble(12) ; b.iota(20) ; b.rearrange(3)
+ ids=DataArrayInt([])
+ self.assertEqual(len(a[ids]),0)
+ self.assertEqual(len(b[ids]),0)
+ a2=a.deepCpy() ; a2[ids]+=b[ids] ; self.assertTrue(a2.isEqual(a,1e-15))
+ a2=a.deepCpy() ; a2[ids]*=b[ids] ; self.assertTrue(a2.isEqual(a,1e-15))
+ a2=a.deepCpy() ; a2[ids]/=b[ids] ; self.assertTrue(a2.isEqual(a,1e-15))
+ a2=a.deepCpy() ; a2[ids]-=b[ids] ; self.assertTrue(a2.isEqual(a,1e-15))
+ pass
+
+ def testSwig2CheckAndPreparePermutation1(self):
+ a=DataArrayInt([10003,9999999,5,67])
+ self.assertTrue(a.checkAndPreparePermutation().isEqual(DataArrayInt([2,3,0,1])))
+ a=DataArrayInt([10003,-9999999,5,67])
+ self.assertTrue(a.checkAndPreparePermutation().isEqual(DataArrayInt([3,0,1,2])))
+ a=DataArrayInt([])
+ self.assertTrue(a.checkAndPreparePermutation().isEqual(DataArrayInt([])))
+ a=DataArrayInt([])
+ a.iota();
+ self.assertTrue(a.isEqual(DataArrayInt([])))
+ pass
+
+ def testSwig21SGTUMesh1(self):
+ m=MEDCoupling1GTUMesh.New("m",NORM_PENTA6)
+ m.__repr__() ; m.__str__()
+ self.assertTrue(isinstance(m,MEDCoupling1SGTUMesh))
+ m.setCoords(DataArrayDouble(20,3))
+ m.allocateCells()
+ m.__repr__() ; m.__str__()
+ m.insertNextCell([0,1,2,5,7,2])
+ self.assertEqual(1,m.getNumberOfCells())
+ self.assertTrue(DataArrayInt([6]).isEqual(m.computeNbOfNodesPerCell()))
+ self.assertTrue(DataArrayInt([5]).isEqual(m.computeNbOfFacesPerCell()))
+ m.__repr__() ; m.__str__()
+ m.checkCoherency()
+ m.checkCoherency2()
+ #
+ cm=MEDCouplingCMesh() ; cm.setName("m")
+ arr0=DataArrayDouble(6) ; arr0.iota()
+ arr1=DataArrayDouble([0,1])
+ cm.setCoords(arr0,arr1,arr1) ; um=cm.buildUnstructured()
+ #
+ m=MEDCoupling1SGTUMesh("m",NORM_QUAD4)
+ mem_m=m.getHeapMemorySize()
+ m.allocateCells(5)
+ self.assertIn(m.getHeapMemorySize()-mem_m,xrange(5*4*4,5*4*4+32))
+ self.assertEqual(m.getNodalConnectivity().getNbOfElemAllocated(),20)
+ m.setCoords(um.getCoords())
+ m.insertNextCell([1,0,6,7])
+ self.assertEqual(1,m.getNumberOfCells())
+ m.insertNextCell([2,1,7,8])
+ m.insertNextCell([3,2,8,9])
+ m.insertNextCell([4,3,9,10])
+ m.insertNextCell([5,4,10,11])
+ self.assertEqual(5,m.getNumberOfCells())
+ self.assertRaises(InterpKernelException,m.insertNextCell,[0,6,7])
+ self.assertRaises(InterpKernelException,m.insertNextCell,[0,6,7,1,2])
+ self.assertEqual(m.getNodalConnectivity().getNbOfElemAllocated(),20)
+ f=m.getMeasureField(ON_CELLS)
+ self.assertEqual(f.getMesh().getHiddenCppPointer(),m.getHiddenCppPointer())
+ self.assertTrue(f.getArray().isUniform(1,1e-14))
+ self.assertEqual(m.getType(),10)
+ self.assertEqual(m.getCellModelEnum(),NORM_QUAD4)
+ mo=MEDCoupling1SGTUMesh("m",NORM_QUAD4) ; mo.setCoords(m.getCoords())
+ mo.setNodalConnectivity(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11]))
+ self.assertTrue(m.isEqual(mo,1e-12))
+ #
+ mo2=MEDCoupling1SGTUMesh.Merge1SGTUMeshesOnSameCoords([m[[0,1]],m[[2]],m[[3,4]]])
+ mo2.setName(m.getName())
+ self.assertTrue(m.isEqual(mo2,1e-12))
+ #
+ mp0=m[[0]] ; mp0.zipCoords() ; mp1=m[2] ; mp1.zipCoords() ; mp2=m[4] ; mp2.zipCoords()
+ mo3=MEDCoupling1SGTUMesh.Merge1SGTUMeshes([mp0,mp1,mp2])
+ self.assertTrue(isinstance(mo3,MEDCoupling1SGTUMesh))
+ mo3.setName(m.getName())
+ m_ref=m[(0,2,4)] ; m_ref.zipCoords()
+ m_ref.tryToShareSameCoordsPermute(mo3,1e-12)
+ self.assertTrue(m_ref.isEqual(mo3,1e-12))
+ #
+ m1=um.buildDescendingConnectivity()[0]
+ ids=m1.getCellIdsFullyIncludedInNodeIds(DataArrayInt.Range(0,12,1))
+ m1=m1[ids]
+ m1c=m1.convertIntoSingleGeoTypeMesh()
+ self.assertTrue(isinstance(m1c,MEDCoupling1SGTUMesh))
+ self.assertEqual(m1c.getCoords().getHiddenCppPointer(),m.getCoords().getHiddenCppPointer())
+ m1c.checkCoherency2()
+ self.assertTrue(m1c.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11])))
+ self.assertEqual(20,m1c.getNodalConnectivityLength())
+ self.assertTrue(m.isEqual(m1c,1e-12))
+ m.getNodalConnectivity().setIJ(1,0,1)
+ self.assertTrue(not m.isEqual(m1c,1e-12))
+ m.getNodalConnectivity().setIJ(1,0,0)
+ self.assertTrue(m.isEqual(m1c,1e-12))
+ m1c.setCoords(m.getCoords().deepCpy())
+ self.assertTrue(m.isEqual(m1c,1e-12))
+ m1c.getCoords().setIJ(0,1,0.1)
+ self.assertTrue(not m.isEqual(m1c,1e-12))
+ m1c.getCoords().setIJ(0,1,0)
+ self.assertTrue(m.isEqual(m1c,1e-12))
+ m1c.getCoords().setInfoOnComponent(1,"X")
+ self.assertTrue(not m.isEqual(m1c,1e-12) and m.isEqualWithoutConsideringStr(m1c,1e-12))
+ m.getCoords().setInfoOnComponent(1,"X")
+ self.assertTrue(m.isEqual(m1c,1e-12) and m.isEqualWithoutConsideringStr(m1c,1e-12))
+ m.setName("m2")
+ self.assertTrue(not m.isEqual(m1c,1e-12) and m.isEqualWithoutConsideringStr(m1c,1e-12))
+ #
+ m.checkCoherency() ; m.checkCoherency1() ; m.checkCoherency2()
+ self.assertEqual(m.getMeshDimension(),2)
+ self.assertTrue(m.giveCellsWithType(NORM_QUAD4).isEqual(DataArrayInt([0,1,2,3,4])))
+ self.assertTrue(m.giveCellsWithType(NORM_TRI3).isEqual(DataArrayInt([])))
+ self.assertEqual(m.getNumberOfCellsWithType(NORM_QUAD4),5)
+ self.assertEqual(m.getNumberOfCellsWithType(NORM_TRI3),0)
+ self.assertEqual(m.getTypeOfCell(3),NORM_QUAD4)
+ self.assertRaises(InterpKernelException,m.getTypeOfCell,5)
+ self.assertEqual(m.getAllGeoTypes(),[NORM_QUAD4])
+ self.assertEqual(m.getDistributionOfTypes(),[[NORM_QUAD4,5,-1]])
+ ##
+ pfl1=DataArrayInt([1,3,4])
+ a,b,c=m.splitProfilePerType(pfl1)
+ d,e,f=m.buildUnstructured().splitProfilePerType(pfl1)
+ self.assertTrue(a==[[4,3,0]] and len(b)==1 and b[0].isEqual(DataArrayInt([0,1,2])) and len(c)==1 and c[0].getHiddenCppPointer()==pfl1.getHiddenCppPointer())
+ self.assertTrue(a==d and len(b)==1 and b[0].isEqual(e[0]) and len(c)==1 and c[0].isEqual(f[0]))
+ #
+ pfl2=DataArrayInt([0,1,2,3])
+ a,b,c=m.splitProfilePerType(pfl2)
+ d,e,f=m.buildUnstructured().splitProfilePerType(pfl2)
+ self.assertTrue(a==[[4,4,0]] and len(b)==1 and b[0].isEqual(DataArrayInt([0,1,2,3])) and len(c)==1 and c[0].getHiddenCppPointer()==pfl2.getHiddenCppPointer())
+ self.assertTrue(a==d and len(b)==1 and b[0].isEqual(e[0]) and len(c)==1 and c[0].isEqual(f[0]))
+ #
+ pfl3=DataArrayInt([0,1,2,3,4])
+ a,b,c=m.splitProfilePerType(pfl3)
+ d,e,f=m.buildUnstructured().splitProfilePerType(pfl3)
+ self.assertTrue(a==[[4,5,-1]] and len(b)==1 and b[0].isEqual(DataArrayInt([0,1,2,3,4])) and c==[])
+ self.assertTrue(a==d and len(b)==1 and b[0].isEqual(e[0]) and c==[])
+ #
+ invalidPfl=DataArrayInt([1,2,3,4,5])
+ self.assertRaises(InterpKernelException,m.splitProfilePerType,invalidPfl)
+ self.assertRaises(InterpKernelException,m.buildUnstructured().splitProfilePerType,invalidPfl)
+ ##
+ pfl1=DataArrayInt([1,2,3])
+ a=m.checkTypeConsistencyAndContig([NORM_QUAD4,3,0],[pfl1])
+ b=m.buildUnstructured().checkTypeConsistencyAndContig([NORM_QUAD4,3,0],[pfl1])
+ self.assertTrue(a.isEqual(b) and pfl1.getHiddenCppPointer(),a.getHiddenCppPointer())
+ #
+ pfl2=DataArrayInt([0,1,2,3])
+ a=m.checkTypeConsistencyAndContig([NORM_QUAD4,4,0],[pfl2])
+ b=m.buildUnstructured().checkTypeConsistencyAndContig([NORM_QUAD4,4,0],[pfl2])
+ self.assertTrue(a.isEqual(b) and pfl2.getHiddenCppPointer()==a.getHiddenCppPointer())
+ #
+ pfl3=DataArrayInt([0,1,2,3,4])
+ a=m.checkTypeConsistencyAndContig([NORM_QUAD4,4,0],[pfl3])
+ b=m.buildUnstructured().checkTypeConsistencyAndContig([NORM_QUAD4,5,0],[pfl3])
+ self.assertTrue(a.isEqual(b) and pfl3.getHiddenCppPointer()==a.getHiddenCppPointer())
+ #
+ invalidPfl=DataArrayInt([1,2,3,4,5])
+ self.assertRaises(InterpKernelException,m.checkTypeConsistencyAndContig,[NORM_QUAD4,5,0],[invalidPfl])
+ self.assertRaises(InterpKernelException,m.buildUnstructured().checkTypeConsistencyAndContig,[NORM_QUAD4,5,0],[invalidPfl])
+ ##
+ self.assertTrue(DataArrayInt([4,4,4,4,4]).isEqual(m.computeNbOfNodesPerCell()))
+ ##
+ self.assertEqual(m.getNodeIdsOfCell(1),[2,1,7,8])
+ ##
+ self.assertTrue(m.computeIsoBarycenterOfNodesPerCell().isEqual(DataArrayDouble([(0.5,0.5,0),(1.5,0.5,0),(2.5,0.5,0),(3.5,0.5,0),(4.5,0.5,0)]),1e-13))
+ ##
+ ref=m.getCoords().getHiddenCppPointer()
+ mcpy=m.deepCpy() ; mcpy.insertNextCell([1,0,6,7])
+ c=m.getNodalConnectivity().deepCpy()
+ o2n=DataArrayInt([2,0,1,4,3])
+ m.renumberCells(o2n,False)
+ c.rearrange(4) ; c.renumberInPlace(o2n) ; c.rearrange(1)
+ self.assertTrue(c.isEqual(m.getNodalConnectivity()))
+ self.assertEqual(ref,m.getCoords().getHiddenCppPointer())
+ m2=mcpy.mergeMyselfWith(m)
+ self.assertTrue(isinstance(m2,MEDCoupling1SGTUMesh))
+ self.assertEqual(11,m2.getNumberOfCells())
+ self.assertEqual(48,m2.getNumberOfNodes())
+ self.assertTrue(m2.getCoords().isEqual(DataArrayDouble.Aggregate([m.getCoords(),m.getCoords()]),1e-12))
+ self.assertTrue(m2.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11,1,0,6,7,26,25,31,32,27,26,32,33,25,24,30,31,29,28,34,35,28,27,33,34])))
+ ##
+ mu=m.buildUnstructured()
+ mu.checkCoherency2()
+ self.assertEqual(mu.getCoords().getHiddenCppPointer(),m.getCoords().getHiddenCppPointer())
+ self.assertEqual(2,mu.getMeshDimension())
+ self.assertEqual([NORM_QUAD4],mu.getAllGeoTypes())
+ self.assertTrue(mu.getNodalConnectivity().isEqual(DataArrayInt([4,2,1,7,8,4,3,2,8,9,4,1,0,6,7,4,5,4,10,11,4,4,3,9,10])))
+ self.assertTrue(mu.getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,10,15,20,25])))
+ ##
+ for typ in [0,1]:
+ mcpy2=m.deepCpy() ; umcpy2=mcpy2.buildUnstructured()
+ ids=mcpy2.simplexize(typ) ; ids2=umcpy2.simplexize(typ)
+ self.assertTrue(ids.isEqual(ids2))
+ mcpy3=umcpy2.convertIntoSingleGeoTypeMesh()
+ self.assertTrue(mcpy2.isEqual(mcpy3,1e-14))
+ pass
+ um1=um.convertIntoSingleGeoTypeMesh()
+ self.assertEqual(8,um1.getNumberOfNodesPerCell())
+ for typ in [PLANAR_FACE_5,PLANAR_FACE_6]:
+ mcpy2=um1.deepCpy() ; umcpy2=mcpy2.buildUnstructured()
+ ids=mcpy2.simplexize(typ) ; ids2=umcpy2.simplexize(typ)
+ self.assertTrue(ids.isEqual(ids2))
+ mcpy3=umcpy2.convertIntoSingleGeoTypeMesh()
+ self.assertTrue(mcpy2.isEqual(mcpy3,1e-14))
+ pass
+ ##
+ self.assertRaises(InterpKernelException,mcpy.mergeMyselfWithOnSameCoords,m)
+ mcpy.tryToShareSameCoords(m,1e-14)
+ m3=mcpy.mergeMyselfWithOnSameCoords(m)
+ self.assertTrue(isinstance(m3,MEDCoupling1SGTUMesh))
+ self.assertEqual(11,m3.getNumberOfCells())
+ self.assertEqual(24,m3.getNumberOfNodes())
+ self.assertEqual(m3.getCoords().getHiddenCppPointer(),mcpy.getCoords().getHiddenCppPointer())
+ self.assertTrue(m3.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11,1,0,6,7,2,1,7,8,3,2,8,9,1,0,6,7,5,4,10,11,4,3,9,10])))
+ ##
+ ref=mcpy.getCoords().deepCpy()
+ c3=mcpy.getNodalConnectivity()[:]
+ mcpy.getNodalConnectivity().setIJ(int(c3.getIdsEqual(11)),0,24)
+ c2=DataArrayDouble.Aggregate([mcpy.getCoords(),mcpy.getCoords()[11:]])
+ mcpy.setCoords(c2)
+ mcpy.checkCoherency2()
+ a,b=mcpy.getNodeIdsInUse()
+ self.assertEqual(12,b)
+ self.assertTrue(a.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1])))
+ ids=mcpy.zipCoordsTraducer()
+ self.assertTrue(ids.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1])))
+ self.assertTrue(mcpy.getCoords().isEqual(ref[:12],1e-12))
+ self.assertTrue(mcpy.getNodalConnectivity().isEqual(c3))
+ mcpy.checkCoherency2()
+ ##
+ m4=mcpy[DataArrayInt([0,3,4])]
+ m5=mcpy.buildPartOfMySelfKeepCoords(DataArrayInt([0,3,4]))
+ self.assertTrue(isinstance(m4,MEDCoupling1SGTUMesh))
+ self.assertTrue(m4.isEqual(m5,-1e-14))# < 0 not a bug it proves that coordinates pointer are equal
+ self.assertTrue(m4.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,4,3,9,10,5,4,10,11])))
+ m6=mcpy[::2]
+ self.assertTrue(isinstance(m6,MEDCoupling1SGTUMesh))
+ self.assertTrue(m6.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,3,2,8,9,5,4,10,11])))
+ ##
+ mcpy.setCoords(DataArrayDouble.Aggregate([mcpy.getCoords(),mcpy.getCoords()]))
+ mcpy.checkCoherency2()
+ ##
+ mcppy=mcpy.deepCpyConnectivityOnly()
+ self.assertTrue(mcppy.isEqual(mcpy,1e-12))
+ self.assertTrue(mcppy.getCoords().getHiddenCppPointer()==mcpy.getCoords().getHiddenCppPointer())
+ self.assertTrue(mcppy.getNodalConnectivity().isEqual(mcpy.getNodalConnectivity()))
+ self.assertTrue(mcppy.getNodalConnectivity().getHiddenCppPointer()!=mcpy.getNodalConnectivity().getHiddenCppPointer())
+ ##
+ a,b=mcpy.getReverseNodalConnectivity()
+ self.assertTrue(a.isEqual(DataArrayInt([0,5,0,1,5,1,2,2,3,3,4,4,0,5,0,1,5,1,2,2,3,3,4,4])))
+ self.assertTrue(b.isEqual(DataArrayInt([0,2,5,7,9,11,12,14,17,19,21,23,24,24,24,24,24,24,24,24,24,24,24,24,24])))
+ self.assertTrue(mcpy.fillCellIdsToKeepFromNodeIds([0,1,6,7],False).isEqual(DataArrayInt([0,1,5])))
+ self.assertTrue(mcpy.fillCellIdsToKeepFromNodeIds([0,1,6,7],True).isEqual(DataArrayInt([0,5])))
+ self.assertTrue(mcpy.getCellsInBoundingBox([(0,1),(0,1),(0,1)],1e-12).isEqual(DataArrayInt([0,1,5])))
+ f=mcpy.buildOrthogonalField()
+ self.assertEqual(f.getMesh().getHiddenCppPointer(),mcpy.getHiddenCppPointer())
+ self.assertTrue(f.getArray().isEqual(DataArrayDouble(6*[(0,0,-1)]),1e-12))
+ mcpy.changeSpaceDimension(2)
+ self.assertEqual(1,mcpy.getCellContainingPoint([1.5,0.5],1e-12))
+ ##
+ self.assertTrue(mcpy.fillCellIdsToKeepFromNodeIds(DataArrayInt([6,7]),False).isEqual(DataArrayInt([0,1,5])))
+ ##
+ mcpy2=mcpy.deepCpy()
+ self.assertEqual([None,None],mcpy.checkGeoEquivalWith(mcpy2,1,1e-12))#fast equal
+ mcpy.checkFastEquivalWith(mcpy2,1e-12)
+ mcpy2.renumberCells([0,2,4,3,1,5])
+ mcpy.checkFastEquivalWith(mcpy2,1e-12)
+ self.assertEqual([None,None],mcpy.checkGeoEquivalWith(mcpy2,1,1e-12))#fast equal
+ mcpy2.renumberCells([0,2,4,3,1,5])
+ mcpy2.renumberCells([1,3,5,0,2,4])
+ self.assertRaises(InterpKernelException,mcpy.checkFastEquivalWith,mcpy2,1e-12)
+ self.assertRaises(InterpKernelException,mcpy.checkGeoEquivalWith,mcpy2,1,1e-12)#fast equal
+ pass
+
+ def testSwig21DGTUMesh1(self):
+ a0=DataArrayInt([0,2,3,5,6,8])
+ a1=DataArrayInt([0,4,7,11,14,18,21,25])
+ a2=DataArrayInt([0,1,4,5])
+ self.assertTrue(DataArrayInt.AggregateIndexes([a0,a1,a2]).isEqual(DataArrayInt([0,2,3,5,6,8,12,15,19,22,26,29,33,34,37,38])))
+ self.assertEqual(a1[3:].front(),11)
+ self.assertEqual(a1[4:].convertToDblArr().front(),14.)
+ a1c=DataArrayInt([5,7,1,2, 8,11,0, 5,6,3,12, 1,5,2, 13,12,11,7, 6,1,0, 20,21,19,17])
+ d,e=MEDCouplingUMesh.ExtractFromIndexedArrays2(1,5,2,a1c,a1)
+ self.assertTrue(d.isEqual(DataArrayInt([8,11,0,1,5,2])))
+ self.assertTrue(e.isEqual(DataArrayInt([0,3,6])))
+ #
+ m=MEDCouplingDataForTest.build2DTargetMesh_1()[0,3,4]
+ ref=DataArrayInt([0,3,4,1,6,7,4,3,7,8,5,4])
+ self.assertTrue(m.convertNodalConnectivityToStaticGeoTypeMesh().isEqual(ref))
+ d,e=m.convertNodalConnectivityToDynamicGeoTypeMesh()
+ self.assertTrue(d.isEqual(ref))
+ self.assertTrue(e.isEqual(DataArrayInt.Range(0,13,4)))
+ self.assertTrue(m.fillCellIdsToKeepFromNodeIds(DataArrayInt([6,7]),False).isEqual(DataArrayInt([1,2])))
+ #
+ m=MEDCoupling1GTUMesh.New("m",NORM_POLYHED)
+ self.assertTrue(isinstance(m,MEDCoupling1DGTUMesh))
+ m.__repr__() ; m.__str__()
+ m.setCoords(DataArrayDouble(20,3))
+ m.allocateCells()
+ m.__repr__() ; m.__str__()
+ m.insertNextCell([0,1,2,5,7,2,-1,1,3])
+ self.assertEqual(1,m.getNumberOfCells())
+ self.assertTrue(DataArrayInt([8]).isEqual(m.computeNbOfNodesPerCell()))
+ self.assertTrue(DataArrayInt([2]).isEqual(m.computeNbOfFacesPerCell()))
+ m.__repr__() ; m.__str__()
+ m.checkCoherency()
+ m.checkCoherency2()
+ #
+ cm=MEDCouplingCMesh() ; cm.setName("m")
+ arr0=DataArrayDouble(6) ; arr0.iota()
+ arr1=DataArrayDouble([0,1])
+ cm.setCoords(arr0,arr1,arr1) ; um=cm.buildUnstructured() ; um.convertAllToPoly()
+ um2=um.deepCpyConnectivityOnly()
+ self.assertTrue(um2.isEqual(um,1e-12))
+ self.assertEqual(um2.getCoords().getHiddenCppPointer(),um.getCoords().getHiddenCppPointer())
+ self.assertTrue(um2.getNodalConnectivity().isEqual(um.getNodalConnectivity()))
+ self.assertTrue(um2.getNodalConnectivity().getHiddenCppPointer()!=um.getNodalConnectivity().getHiddenCppPointer())
+ self.assertTrue(um2.getNodalConnectivityIndex().isEqual(um.getNodalConnectivityIndex()))
+ self.assertTrue(um2.getNodalConnectivityIndex().getHiddenCppPointer()!=um.getNodalConnectivityIndex().getHiddenCppPointer())
+ #
+ self.assertRaises(InterpKernelException,MEDCoupling1SGTUMesh.New,"m",NORM_POLYHED)
+ m=MEDCoupling1DGTUMesh("m",NORM_POLYHED)
+ m.allocateCells(5)
+ self.assertEqual(15,m.getNodalConnectivity().getNbOfElemAllocated())
+ self.assertEqual(6,m.getNodalConnectivityIndex().getNbOfElemAllocated())
+ m.setCoords(um.getCoords())
+ m.insertNextCell([1,0,6,7,-1,7,6,1])
+ self.assertEqual(1,m.getNumberOfCells())
+ m.insertNextCell([2,1,7,8,-1,2,1,-1,8,-1,7])
+ m.insertNextCell([3,2,8,9])
+ m.insertNextCell([4,3,9,10,-1,5,3,9])
+ m.insertNextCell([5,4,10,11,-1,11,10,-1,5])
+ m.checkCoherency()
+ m.checkCoherency2()
+ self.assertEqual(5,m.getNumberOfCells())
+ self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,8,19,23,31,40])))
+ self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,-1,7,6,1,2,1,7,8,-1,2,1,-1,8,-1,7,3,2,8,9,4,3,9,10,-1,5,3,9,5,4,10,11,-1,11,10,-1,5])))
+ #
+ m4=m.deepCpy()
+ self.assertTrue(m.isEqual(m4,1e-12))
+ m4.getNodalConnectivity().setIJ(2,0,5)
+ self.assertTrue(not m.isEqual(m4,1e-12))
+ m4.getNodalConnectivity().setIJ(2,0,6)
+ self.assertTrue(m.isEqual(m4,1e-12))
+ m4.getNodalConnectivityIndex().setIJ(2,0,21)
+ self.assertTrue(not m.isEqual(m4,1e-12))
+ m4.getNodalConnectivityIndex().setIJ(2,0,19)
+ self.assertTrue(m.isEqual(m4,1e-12))
+ m4.getCoords().setIJ(10,1,1.1)
+ self.assertTrue(not m.isEqual(m4,1e-12))
+ m4.getCoords().setIJ(10,1,1.)
+ self.assertTrue(m.isEqual(m4,1e-12))
+ m4.getNodalConnectivity().pushBackSilent(7)
+ self.assertTrue(not m.isEqual(m4,1e-12))
+ self.assertEqual(7,m4.getNodalConnectivity().popBackSilent())
+ self.assertTrue(m.isEqual(m4,1e-12))
+ m4.setName("m4")
+ self.assertTrue(not m.isEqual(m4,1e-12))
+ m4.setName("m")
+ self.assertTrue(m.isEqual(m4,1e-12))
+ #
+ self.assertEqual(6,m.getNodalConnectivityIndex().getNbOfElemAllocated())
+ self.assertEqual(60,m.getNodalConnectivity().getNbOfElemAllocated())
+ self.assertTrue(m.computeNbOfNodesPerCell().isEqual(DataArrayInt([7,8,4,7,7])))
+ self.assertTrue(m.computeNbOfFacesPerCell().isEqual(DataArrayInt([2,4,1,2,3])))
+ self.assertEqual(m.getNodeIdsOfCell(1),[2,1,7,8,-1,2,1,-1,8,-1,7])
+ f=m.computeIsoBarycenterOfNodesPerCell()
+ self.assertTrue(DataArrayDouble([(0.5714285714285714,0.5714285714285714,0),(1.5,0.5,0),(2.5,0.5,0),(3.5714285714285712,0.42857142857142855,0),(4.5714285714285712,0.5714285714285714,0)]).isEqual(f,1e-14))
+ mu0=m.buildUnstructured()
+ o2n=[1,2,0,4,3]
+ m2=m.deepCpy()
+ m3=m.deepCpyConnectivityOnly()
+ self.assertTrue(m3.isEqual(m,1e-12))
+ self.assertEqual(m3.getCoords().getHiddenCppPointer(),m.getCoords().getHiddenCppPointer())
+ self.assertTrue(m3.getNodalConnectivity().getHiddenCppPointer()!=m.getNodalConnectivity().getHiddenCppPointer())
+ self.assertTrue(m3.getNodalConnectivity().isEqual(m.getNodalConnectivity()))
+ self.assertTrue(m3.getNodalConnectivityIndex().getHiddenCppPointer()!=m.getNodalConnectivityIndex().getHiddenCppPointer())
+ self.assertTrue(m3.getNodalConnectivityIndex().isEqual(m.getNodalConnectivityIndex()))
+ m.renumberCells(o2n)
+ mu0.renumberCells(o2n)
+ self.assertTrue(mu0.isEqual(m.buildUnstructured(),1e-12))
+ self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,12,23,32,40])))
+ self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([3,2,8,9,1,0,6,7,-1,7,6,1,2,1,7,8,-1,2,1,-1,8,-1,7,5,4,10,11,-1,11,10,-1,5,4,3,9,10,-1,5,3,9])))
+ #
+ mcpy0=m.buildUnstructured()
+ self.assertTrue(isinstance(mcpy0,MEDCouplingUMesh))
+ self.assertTrue(mcpy0.getNodalConnectivity().isEqual(DataArrayInt([31,3,2,8,9,31,1,0,6,7,-1,7,6,1,31,2,1,7,8,-1,2,1,-1,8,-1,7,31,5,4,10,11,-1,11,10,-1,5,31,4,3,9,10,-1,5,3,9])))
+ self.assertTrue(mcpy0.getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,14,26,36,45])))
+ self.assertEqual(mcpy0.getAllGeoTypes(),[NORM_POLYHED])
+ mcpy0.checkCoherency()
+ mcpy0.checkCoherency2()
+ mcpy1=mcpy0.convertIntoSingleGeoTypeMesh()
+ self.assertTrue(mcpy1.isEqual(m,1e-12))
+ #
+ m_mrg=MEDCoupling1DGTUMesh.Merge1DGTUMeshes([m2,m,m2])
+ self.assertTrue(m_mrg.getNodalConnectivityIndex().isEqual(DataArrayInt([0,8,19,23,31,40,44,52,63,72,80,88,99,103,111,120])))
+ self.assertTrue(m_mrg.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,-1,7,6,1,2,1,7,8,-1,2,1,-1,8,-1,7,3,2,8,9,4,3,9,10,-1,5,3,9,5,4,10,11,-1,11,10,-1,5,27,26,32,33,25,24,30,31,-1,31,30,25,26,25,31,32,-1,26,25,-1,32,-1,31,29,28,34,35,-1,35,34,-1,29,28,27,33,34,-1,29,27,33,49,48,54,55,-1,55,54,49,50,49,55,56,-1,50,49,-1,56,-1,55,51,50,56,57,52,51,57,58,-1,53,51,57,53,52,58,59,-1,59,58,-1,53])))
+ m_mrg2=MEDCoupling1DGTUMesh.Merge1DGTUMeshesOnSameCoords([m3,m,m3])
+ self.assertTrue(m_mrg2.getNodalConnectivityIndex().isEqual(DataArrayInt([0,8,19,23,31,40,44,52,63,72,80,88,99,103,111,120])))
+ self.assertTrue(m_mrg2.getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,-1,7,6,1,2,1,7,8,-1,2,1,-1,8,-1,7,3,2,8,9,4,3,9,10,-1,5,3,9,5,4,10,11,-1,11,10,-1,5,3,2,8,9,1,0,6,7,-1,7,6,1,2,1,7,8,-1,2,1,-1,8,-1,7,5,4,10,11,-1,11,10,-1,5,4,3,9,10,-1,5,3,9,1,0,6,7,-1,7,6,1,2,1,7,8,-1,2,1,-1,8,-1,7,3,2,8,9,4,3,9,10,-1,5,3,9,5,4,10,11,-1,11,10,-1,5])))
+ a,b=m_mrg2.getReverseNodalConnectivity()
+ self.assertTrue(b.isEqual(DataArrayInt([0,3,15,24,33,39,48,54,66,75,84,93,99,99,99,99,99,99,99,99,99,99,99,99,99])))
+ self.assertTrue(a.isEqual(DataArrayInt([0,6,10,0,0,1,1,6,6,7,7,10,10,11,11,1,1,2,5,7,7,11,11,12,2,3,3,5,9,9,12,13,13,3,4,8,9,13,14,3,4,4,8,8,9,13,14,14,0,0,6,6,10,10,0,0,1,1,6,6,7,7,10,10,11,11,1,1,2,5,7,7,11,11,12,2,3,3,5,9,9,12,13,13,3,4,4,8,8,9,13,14,14,4,4,8,8,14,14])))
+ self.assertTrue(m_mrg2.fillCellIdsToKeepFromNodeIds([7],False).isEqual(DataArrayInt([0,1,6,7,10,11])))
+ self.assertTrue(m_mrg2.fillCellIdsToKeepFromNodeIds([0,1,6,7],True).isEqual(DataArrayInt([0,6,10])))
+ #
+ self.assertTrue(m_mrg2.isPacked())
+ self.assertEqual(120,m_mrg2.getNodalConnectivityIndex().popBackSilent())
+ self.assertEqual(m_mrg2.getNumberOfCells(),14)
+ m_mrg2.checkCoherency2()
+ self.assertTrue(not m_mrg2.isPacked())
+ m_mrg4,b=m_mrg2.copyWithNodalConnectivityPacked()
+ self.assertTrue(not b)
+ m_mrg4.checkCoherency2()
+ self.assertEqual(m_mrg4.getNumberOfCells(),14)
+ self.assertTrue(m_mrg4.getNodalConnectivityIndex().isEqual(m_mrg2.getNodalConnectivityIndex()))
+ self.assertEqual(len(m_mrg4.getNodalConnectivity()),111)
+ self.assertEqual(len(m_mrg2.getNodalConnectivity()),120)
+ self.assertTrue(m_mrg4.getNodalConnectivity().isEqual(m_mrg2.getNodalConnectivity()[:111]))
+ #
+ m0=m_mrg2[:5]
+ m1=m_mrg2[[5,6,7,8,9]]
+ m2=m_mrg2[10:]
+ self.assertTrue(m1.isEqualWithoutConsideringStr(m,1e-12))
+ a,b=m.checkGeoEquivalWith(m0,12,1e-12)
+ self.assertTrue(a.isEqual(DataArrayInt(o2n)))
+ self.assertTrue(b is None)
+ pass
+
+ def testSwig2DADAreIncludedInMe1(self):
+ a=DataArrayDouble(30) ; a.iota() ; a.rearrange(3)
+ p=DataArrayInt([5,2,1,9])
+ b,c=a.areIncludedInMe(a[p],1e-12)
+ self.assertTrue(b)
+ self.assertTrue(c.isEqual(p))
+ d=a[p]
+ d.setIJ(3,1,28.1)
+ b,c=a.areIncludedInMe(d,1e-12)
+ self.assertTrue(not b)
+ self.assertTrue(c.isEqual(DataArrayInt([5,2,1,10])))
+ pass
+
+ def testSwig2DADesallocate1(self):
+ d=DataArrayDouble([(1,2),(6,7),(6,8)]) ; d.setInfoOnComponents(["aa","bbb"])
+ self.assertTrue(d.isAllocated())
+ d.checkAllocated()
+ self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
+ ref=d.getHeapMemorySize()
+ d.desallocate()
+ self.assertEqual(ref-d.getHeapMemorySize(),6*8)
+ self.assertTrue(not d.isAllocated())
+ self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
+ self.assertRaises(InterpKernelException,d.checkAllocated)
+ #
+ d=DataArrayInt([(1,2),(6,7),(6,8)]) ; d.setInfoOnComponents(["aa","bbb"])
+ self.assertTrue(d.isAllocated())
+ d.checkAllocated()
+ self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
+ ref=d.getHeapMemorySize()
+ d.desallocate()
+ self.assertEqual(ref-d.getHeapMemorySize(),6*4)
+ self.assertTrue(not d.isAllocated())
+ self.assertEqual(d.getInfoOnComponents(),["aa","bbb"])
+ self.assertRaises(InterpKernelException,d.checkAllocated)
+ pass
+
+ def testSwig2IsPartStructured1(self):
+ #dim 1
+ d10=DataArrayInt([2,3,4,5,6,7,8,9,10,11])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d10,[13])
+ self.assertTrue(a) ; self.assertEqual(b,[(2,12)])
+ d11=DataArrayInt([2,3,4,5,6,7,8,10,9,11])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d11,[13])
+ self.assertTrue(not a)
+ self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d10,[11])
+ #dim 2
+ st=[10,4]
+ d20=DataArrayInt([1,2,3,4,11,12,13,14,21,22,23,24])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
+ self.assertTrue(a) ; self.assertEqual(b,[(1,5),(0,3)])
+ d20=DataArrayInt([1,2,3,4,12,11,13,14,21,22,23,24])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
+ self.assertTrue(not a)
+ d20=DataArrayInt([1,2,3,4,11,12,13,15,21,22,23,24])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
+ self.assertTrue(not a)
+ d21=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d21,st)
+ self.assertTrue(a) ; self.assertEqual(b,[(0,10),(0,4)])
+ d22=DataArrayInt([1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44])
+ self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d22,st)
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d22,[10,5])
+ self.assertTrue(a) ; self.assertEqual(b,[(1,5),(0,5)])
+ #dim 3
+ d30=DataArrayInt([11,12,13,14,21,22,23,24,51,52,53,54,61,62,63,64])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d30,[10,4,2])
+ self.assertTrue(a) ; self.assertEqual(b,[(1,5),(1,3),(0,2)])
+ d31=DataArrayInt([11,12,13,14,21,22,24,23,51,52,53,54,61,62,63,64])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d31,[10,4,2])
+ self.assertTrue(not a)
+ self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d30,[10,4,1])
+ pass
+
+ def testSwig2PartStructured1(self):
+ c=MEDCouplingCMesh() ; c.setName("toto")
+ arr0=DataArrayDouble(10); arr0.iota()
+ arr1=DataArrayDouble(4) ; arr1.iota(3)
+ c.setCoords(arr0,arr1)
+ self.assertEqual(c.getNodeGridStructure(),(10,4))
+ self.assertEqual(c.getCellGridStructure(),(9,3))
+ d20=DataArrayInt([1,2,3,4,10,11,12,13,19,20,21,22])
+ self.assertEqual(27,c.getNumberOfCells())
+ self.assertEqual(40,c.getNumberOfNodes())
+ self.assertEqual(2,c.getMeshDimension())
+ c.checkCoherency()
+ #
+ arr2=MEDCouplingStructuredMesh.BuildExplicitIdsFrom([9,3],[(1,5),(0,3)])
+ self.assertTrue(arr2.isEqual(DataArrayInt([1,2,3,4,10,11,12,13,19,20,21,22])))
+ # CMesh
+ c2=c.buildStructuredSubPart([(1,5),(0,3)])
+ c2.checkCoherency()
+ self.assertTrue(isinstance(c2,MEDCouplingCMesh))
+ self.assertEqual(12,c2.getNumberOfCells())
+ self.assertEqual(20,c2.getNumberOfNodes())
+ self.assertEqual(2,c2.getMeshDimension())
+ self.assertEqual("toto",c2.getName())
+ self.assertTrue(c2.getCoordsAt(0).isEqual(DataArrayDouble([1.,2.,3.,4.,5.]),1e-12))
+ self.assertTrue(c2.getCoordsAt(1).isEqual(DataArrayDouble([3.,4.,5.,6.]),1e-12))
+ #
+ a,b=c.buildPartAndReduceNodes(d20)
+ a.checkCoherency()
+ exp2=DataArrayInt([-1,0,1,2,3,4,-1,-1,-1,-1,-1,5,6,7,8,9,-1,-1,-1,-1,-1,10,11,12,13,14,-1,-1,-1,-1,-1,15,16,17,18,19,-1,-1,-1,-1])
+ self.assertTrue(exp2.isEqual(b))
+ self.assertTrue(isinstance(a,MEDCouplingCMesh))
+ self.assertTrue(a.buildUnstructured().isEqual(c.buildUnstructured().buildPartAndReduceNodes(d20)[0],1e-12))
+ # CurveLinearMesh
+ c2=MEDCouplingCurveLinearMesh() ; c2.setName("toto")
+ c2.setCoords(c.buildUnstructured().getCoords())
+ c2.setNodeGridStructure([10,4])
+ c2.checkCoherency()
+ a,b=c2.buildPartAndReduceNodes(d20)
+ a.checkCoherency()
+ self.assertTrue(exp2.isEqual(b))
+ self.assertTrue(isinstance(a,MEDCouplingCurveLinearMesh))
+ self.assertTrue(a.buildUnstructured().isEqual(c2.buildUnstructured().buildPartAndReduceNodes(d20)[0],1e-12))
+ pass
+
+ def testSwig2FindPermutationFromFirstToSecond1(self):
+ ids1=DataArrayInt([3,1,103,4,6,10,-7,205])
+ ids2=DataArrayInt([-7,1,205,10,6,3,103,4])
+ ids3=DataArrayInt.FindPermutationFromFirstToSecond(ids1,ids2)
+ self.assertTrue(ids3.isEqual(DataArrayInt([5,1,6,7,4,3,0,2])))
+ ids2ToTest=ids1.renumber(ids3)
+ self.assertTrue(ids2ToTest.isEqual(ids2))
+ self.assertRaises(InterpKernelException,DataArrayInt.FindPermutationFromFirstToSecond,DataArrayInt([3,1,103]),DataArrayInt([1,103]))
+ self.assertRaises(InterpKernelException,DataArrayInt.FindPermutationFromFirstToSecond,DataArrayInt([3,1,103]),DataArrayInt([1,103,2]))
+ self.assertRaises(InterpKernelException,DataArrayInt.FindPermutationFromFirstToSecond,DataArrayInt([3,1,103]),DataArrayInt([1,103,1]))
+ self.assertTrue(DataArrayInt.FindPermutationFromFirstToSecond(DataArrayInt([]),DataArrayInt([])).empty())
+ pass
+
+ def testSwig2BugStructuredMeshGetNodeIdsOfCell1(self):
+ m=MEDCouplingCMesh("mesh")
+ coordsX=DataArrayDouble([0,1.1,2.2,3.3,4.4]) ; coordsX.setInfoOnComponents(["XX [m]"])
+ coordsY=DataArrayDouble([0,1.7,3.4]) ; coordsY.setInfoOnComponents(["YYY [km]"])
+ m.setCoords(coordsX,coordsY)
+ self.assertEqual([2,3,8,7],m.getNodeIdsOfCell(2))
+ self.assertEqual([3,4,9,8],m.getNodeIdsOfCell(3))
+ self.assertEqual([7,8,13,12],m.getNodeIdsOfCell(6))
+ self.assertEqual([8,9,14,13],m.getNodeIdsOfCell(7))
+ pass
+
+ def testSwig2ThrowOnDAIInvertN2O2ON2(self):
+ p1=DataArrayInt([3,5,8])
+ p2=DataArrayInt([0,3,4,5,6,7,8,9,10])
+ p1.transformWithIndArr(p2.invertArrayN2O2O2N(11))
+ self.assertTrue(p1.isEqual(DataArrayInt([1,3,6])))
+ self.assertTrue(p2.invertArrayN2O2O2N(11).isEqual(DataArrayInt([0,-1,-1,1,2,3,4,5,6,7,8])))
+ self.assertRaises(InterpKernelException,p2.invertArrayN2O2O2N,10)
+ pass
+
+ def testSwig2ComputeEffectiveNbOfNodesPerCell1(self):
+ coords=DataArrayDouble([ 0.241310763507 , 0.0504777305619 , 0.0682283524903 , 0.252501053866 , -0.0625176732937 , 0.137272639894 ,
+ 0.152262663601 , 0.241816569527 , 0.133812556197 , 0.18047750211 , -0.0789949051358 , 0.339098173401 ,
+ 0.151741971857 , 0.238885278571 , 0.137715037333 , 0.242532155481 , -0.0928169086456 , 0.0678043417367 ,
+ 0.240941965335 , -0.015461491464 , 0.0617186345825 , 0.24127650112 , 0.0499427876717 , 0.0679634099148 ,
+ -0.145828917428 , 0.206291632565 , 0.0310071927543 , 0.0125651775307 , 0.266262085828 , 0.105228430543 ,
+ -0.0994066533286 , 0.233224271238 , 0.0572213839567 , -0.0951345338317 , 0.234819509426 , 0.0592126284538 ,
+ 0.136580574205 , -0.205486212579 , 0.0572866072014 , 0.0637270784978 , -0.168886355238 , 0.446614057077 ,
+ 0.041337157151 , -0.213402568198 , 0.372407095999 , 0.0411601970268 , -0.202387875756 , 0.411334979491 ,
+ -0.108355701857 , 0.193636239335 , 0.204886756738 , 0.00639779029829 , 0.155296981517 , 0.252585892979 ,
+ 0.0262473111702 , -0.112919732543 , 0.424286639249 ,-0.224103052733 , -0.139430015438 , -0.0122352295701 ,
+ -0.0312760589481 , -0.274272003594 , 0.0323959636568 , -0.166663422532 , -0.217754445175 , 0.00392109070364 ,
+ -0.30586619777 , -0.0475168041091 , -0.0144585228182 , -0.280881480586 , 0.135571293538 , 0.00623923647986 ,
+ -0.25548538234 , 0.156819217766 , 0.0645277879769 , -0.131567009284 , 0.184133752309 , 0.206021802753 ,
+ -0.196204010965 , 0.151602971681 , 0.212974777736 , -0.183713879463 , 0.0802946639531 , 0.260115662599 ,
+ -0.244241178767 , -0.0738873389604 , 0.144590565817 , -0.155804057829 , -0.164892720025 , 0.210613950558 ,
+ -0.170950800428 , -0.215099334026 , 0.00610122860092 , -0.30552634869 , -0.0490020791904 , -0.0132786533145 ,
+ 0.271831011884 , 0.15105657296 , 0.0230534827908 , 0.281919192283 , 0.0898544306288 , -0.0625201489143 ,
+ 0.260240727276 , -0.0120688706637 , -0.0532316588626 , 0.244947737722 , 0.0197984684293 , 0.0309341209233 ,
+ 0.23439631578 , 0.229825279875 , 0.0508520585381 , 0.160921316875 , 0.265078502128 , 0.121716560626 ,
+ -0.315088694175 , 0.0747700471918 , -0.245836615071 , -0.327728781776 , 0.0857114674649 , -0.239431905957 ,
+ -0.308385460634 , 0.145142997084 , -0.149886828433 , 0.0488236045164 , 0.309462801914 , 0.0849169148265 ,
+ -0.0244964803395 , 0.33145611751 , -0.0476415818061 , 0.0060567994229 , 0.32418412014 , 0.0367779543812 ,
+ -0.0950221448063 , 0.236675326003 , 0.0572594453983 , 0.248723023186 , 0.0886648784791 , -0.176629430538 ,
+ 0.116796984 , 0.256596599567 , -0.292863523603 , 0.118024552914 , 0.229154257843 , -0.34233232501 ,
+ 0.217507892549 , -0.0417822335742 , -0.176771782888 , -0.224429321304 , 0.0125595300114 , -0.362064725588 ,
+ 0.0937301100955 , -0.0500824832657 , -0.299713548444 , -0.244162220397 , 0.0383853931293 , -0.389856984411 ,
+ -0.0281989366102 , 0.097392811563 , -0.458244577284 , -0.385010847162 , 0.10122766194 , -0.140052859922 ,
+ -0.377936358012 , 0.110875172128 , -0.176207095463 , 0.244483045556 , -0.0991073977045 , 0.0575134372934 ,
+ 0.262605120167 , -0.100243191645 , -0.0495620806935 , 0.240306880972 , -0.136153701579 , -0.114745281696 ,
+ 0.215763176129 , -0.0836766059189 , -0.183249640616 , 0.237870396603 , -0.132449578286 , -0.121598854639 ,
+ -0.0637683083097 , -0.27921020214 , -0.149112321992 , -0.0856211014977 , -0.2973233473 , -0.0446878139589 ,
+ 0.104675342288 , -0.0625908305324 , -0.290346256534 , 0.0248264249186 , -0.247797708548 , -0.165830884019 ,
+ 0.0719302438309 , -0.178468260473 , -0.211432157345 , 0.142871843159 , -0.208769948542 , 0.0454101128246 ,
+ 0.167803379307 , -0.207851396623 , -0.088802726124 , 0.12868717152 , -0.230920439715 , 0.00760508389036 ,
+ -0.0372812069535 , -0.286740286332 , 0.00963701291166 ], 69, 3)
+ connN = [ #polyhedron 0
+ 0 , 1 , 3 , 4 , 2 , -1 , 1 , 5 , 6 , 7 , 0 , -1 , 0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 1 , 5 , 12 , 14 , 15 , 13 , 3 , -1 , 16 , 9 , 2 , 4 , 17 , -1
+ , 4 , 3 , 13 , 18 , 17 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1 , 6 , 7 , 8 , 23 , 22 , 19 , -1 , 23 , 24 , 10 , 8 , -1 , 25 , 11 , 9 , 16 , -1
+ , 24 , 26 , 25 , 11 , 10 , -1 , 12 , 14 , 20 , -1 , 27 , 28 , 29 , 15 , 13 , 18 , -1 , 14 , 15 , 29 , 30 , 21 , 20 , -1 , 26 , 27 , 18 , 17 , 16 , 25 , -1
+ , 22 , 19 , 21 , 30 , 31 , -1 , 22 , 31 , 28 , 27 , 26 , 24 , 23 , -1 , 31 , 30 , 29 , 28,
+ # polyhedron 1
+ 0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 32 , 0 , 7 , 35 , 34 , 33 , -1 , 32 , 0 , 2 , 37 , 36 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1
+ , 2 , 37 , 41 , 9 , -1 , 40 , 8 , 10 , 44 , 43 , 42 , -1 , 41 , 9 , 11 , 44 , 43 , -1 , 44 , 11 , 10 , -1 , 32 , 33 , 45 , 47 , 46 , 36 , -1
+ , 33 , 34 , 48 , 45 , -1 , 35 , 34 , 48 , 50 , 49 , 38 , -1 , 41 , 43 , 42 , 46 , 36 , 37 , -1 , 38 , 39 , 51 , 49 , -1
+ , 39 , 40 , 42 , 46 , 47 , 52 , 51 , -1 , 45 , 47 , 52 , 50 , 48 , -1 , 52 , 51 , 49 , 50,
+ # polyhedron 2
+ 6 , 7 , 8 , 23 , 22 , 19 , -1 , 6 , 35 , 7 , -1 , 6 , 35 , 38 , 19 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1 , 53 , 22 , 19 , 38 , 39 , 54 , -1
+ , 23 , 53 , 54 , 40 , 8 , -1 , 53 , 22 , 23 , -1 , 39 , 54 , 40,
+ # polyhedron 3
+ 35 , 34 , 48 , 50 , 49 , 38 , -1 , 6 , 35 , 34 , 56 , 55 , 5 , -1 , 6 , 35 , 38 , 19 , -1 , 34 , 56 , 57 , 59 , 58 , 48 , -1
+ , 60 , 61 , 21 , 19 , 38 , 49 , -1 , 62 , 50 , 48 , 58 , -1 , 60 , 63 , 64 , 62 , 50 , 49 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1
+ , 55 , 5 , 12 , 65 , -1 , 66 , 67 , 65 , 55 , 56 , 57 , -1 , 63 , 66 , 57 , 59 , 64 , -1 , 64 , 62 , 58 , 59 , -1
+ , 60 , 63 , 66 , 67 , 68 , 61 , -1 , 61 , 68 , 20 , 21 , -1 , 67 , 68 , 20 , 12 , 65]
+ meshN=MEDCouplingUMesh.New()
+ meshN.setName("ForBary")
+ meshN.setMeshDimension(3) ; meshN.setCoords(coords)
+ meshN.allocateCells(4)
+ meshN.insertNextCell(NORM_POLYHED,113,connN);
+ meshN.insertNextCell(NORM_POLYHED,99,connN[113:])
+ meshN.insertNextCell(NORM_POLYHED,43,connN[212:])
+ meshN.insertNextCell(NORM_POLYHED,92,connN[255:])
+ d=meshN.computeEffectiveNbOfNodesPerCell()
+ e=meshN.computeNbOfNodesPerCell()
+ self.assertTrue(d.isEqual(DataArrayInt([32,28,12,26])))
+ self.assertTrue(e.isEqual(DataArrayInt([96,84,36,78])))
+ m0=MEDCoupling1DGTUMesh(meshN)
+ c=MEDCouplingCMesh()
+ arr=DataArrayDouble(3) ; arr.iota(10)
+ c.setCoords(arr,arr,arr)
+ m10=c.buildUnstructured()
+ m11=c.build1SGTUnstructured()
+ m12=MEDCoupling1SGTUMesh.New(m10)
+ self.assertTrue(m12.isEqual(m11,1e-12))
+ m12.setCoords(m0.getCoords()) # m12 is not OK geometrically but the aim of the test is only connectivity values
+ m3=MEDCoupling1GTUMesh.AggregateOnSameCoordsToUMesh([m12,m0])
+ m3.checkCoherency()
+ self.assertEqual(m3.getCoords().getHiddenCppPointer(),m12.getCoords().getHiddenCppPointer())
+ self.assertTrue(m3.getNodalConnectivity().isEqual(DataArrayInt([18,1,0,3,4,10,9,12,13,18,2,1,4,5,11,10,13,14,18,4,3,6,7,13,12,15,16,18,5,4,7,8,14,13,16,17,18,10,9,12,13,19,18,21,22,18,11,10,13,14,20,19,22,23,18,13,12,15,16,22,21,24,25,18,14,13,16,17,23,22,25,26,31,0,1,3,4,2,-1,1,5,6,7,0,-1,0,7,8,10,11,9,2,-1,1,5,12,14,15,13,3,-1,16,9,2,4,17,-1,4,3,13,18,17,-1,5,6,19,21,20,12,-1,6,7,8,23,22,19,-1,23,24,10,8,-1,25,11,9,16,-1,24,26,25,11,10,-1,12,14,20,-1,27,28,29,15,13,18,-1,14,15,29,30,21,20,-1,26,27,18,17,16,25,-1,22,19,21,30,31,-1,22,31,28,27,26,24,23,-1,31,30,29,28,31,0,7,8,10,11,9,2,-1,32,0,7,35,34,33,-1,32,0,2,37,36,-1,35,7,8,40,39,38,-1,2,37,41,9,-1,40,8,10,44,43,42,-1,41,9,11,44,43,-1,44,11,10,-1,32,33,45,47,46,36,-1,33,34,48,45,-1,35,34,48,50,49,38,-1,41,43,42,46,36,37,-1,38,39,51,49,-1,39,40,42,46,47,52,51,-1,45,47,52,50,48,-1,52,51,49,50,31,6,7,8,23,22,19,-1,6,35,7,-1,6,35,38,19,-1,35,7,8,40,39,38,-1,53,22,19,38,39,54,-1,23,53,54,40,8,-1,53,22,23,-1,39,54,40,31,35,34,48,50,49,38,-1,6,35,34,56,55,5,-1,6,35,38,19,-1,34,56,57,59,58,48,-1,60,61,21,19,38,49,-1,62,50,48,58,-1,60,63,64,62,50,49,-1,5,6,19,21,20,12,-1,55,5,12,65,-1,66,67,65,55,56,57,-1,63,66,57,59,64,-1,64,62,58,59,-1,60,63,66,67,68,61,-1,61,68,20,21,-1,67,68,20,12,65])))
+ self.assertTrue(m3.getNodalConnectivityIndex().isEqual(DataArrayInt([0,9,18,27,36,45,54,63,72,186,286,330,423])))
+ pass
+
+ def testSwig2Tetrahedrize1(self):
+ d=DataArrayInt([0,3,6,10,14,20])
+ d2=d.buildExplicitArrOfSliceOnScaledArr(slice(0,5,2))
+ self.assertTrue(d2.isEqual(DataArrayInt([0,0,0, 2,2,2,2, 4,4,4,4,4,4])))
+ m=MEDCouplingUMesh("Penta6",3)
+ m.setCoords(DataArrayDouble([0,0,0,0,1,0,1,0,0,0,0,2,0,1,2,1,0,2],6,3)) ; m.getCoords().setInfoOnComponents(["X","YY","ZZZ"])
+ m.allocateCells()
+ m.insertNextCell(NORM_PENTA6,[1,2,0,4,5,3])
+ st=m.getCoords().getHiddenCppPointer()
+ c,a,b=m.tetrahedrize(PLANAR_FACE_5)
+ c.checkCoherency2()
+ self.assertTrue(a.isEqual(DataArrayInt([0,0,0])))
+ self.assertEqual(0,b)
+ self.assertEqual(m.getCoords().getHiddenCppPointer(),c.getCoords().getHiddenCppPointer())
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([1,2,0,4,4,3,5,0,5,0,2,4])))
+ del m,c
+ #
+ m2=MEDCouplingUMesh("octa12",3)
+ coords=DataArrayDouble([1.,0.,0.,0.5,0.8660254037844386,0.,-0.5,0.8660254037844387,0.,-1.,1.2246467991473532e-16,0.,-0.5,-0.8660254037844384,0.,0.5,-0.866025403784439,0.,1.,0.,2.,0.5,0.8660254037844386,2.,-0.5,0.8660254037844387,2.,-1.,1.2246467991473532e-16,2.,-0.5,-0.8660254037844384,2.,0.5,-0.866025403784439,2.0],12,3)
+ m2.setCoords(coords)
+ m2.allocateCells()
+ m2.insertNextCell(NORM_HEXGP12,[3,2,1,0,5,4,9,8,7,6,11,10])
+ c,a,b=m2.tetrahedrize(PLANAR_FACE_5)
+ c.checkCoherency2()
+ self.assertTrue(a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0])))
+ self.assertEqual(0,b)
+ self.assertEqual(c.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,2,4,9,9,10,8,4,8,4,2,9,2,5,4,8,8,10,11,4,11,4,5,8,2,1,5,8,8,11,7,5,7,5,1,8,1,0,5,7,7,11,6,5,6,5,0,7])))
+ del m2,coords,c
+ #
+ coords=DataArrayDouble([0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,2.,1.,0.,2.,1.,1.,2.,0.,1.,2.],8,3) ; coords.setInfoOnComponents(["X","YY","ZZZ"])
+ m3=MEDCouplingUMesh("hexa8",3)
+ m3.setCoords(coords)
+ m3.allocateCells(0)
+ m3.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
+ st=m3.getCoords().getHiddenCppPointer()
+ c,a,b=m3.tetrahedrize(PLANAR_FACE_5)
+ c.checkCoherency2()
+ a.isEqual(DataArrayInt([0,0,0,0,0]))
+ self.assertEqual(0,b)
+ self.assertEqual(m3.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,6,2,1,3,7,6,4,3,0,4,1,6,4,5,1,3,6,1,4])))
+ #
+ m4=MEDCouplingUMesh("hexa8",3)
+ m4.setCoords(coords)
+ m4.allocateCells(0)
+ m4.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
+ c,a,b=m4.tetrahedrize(PLANAR_FACE_6)
+ c.checkCoherency2()
+ a.isEqual(DataArrayInt([0,0,0,0,0,0]))
+ self.assertEqual(0,b)
+ self.assertEqual(c.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,6,2,5,3,2,1,5,3,7,6,5,3,4,7,5,3,1,0,5,3,0,4,5])))
+ #
+ m4=MEDCouplingUMesh("hexa8",3)
+ m4.setCoords(coords)
+ m4.allocateCells(0)
+ m4.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
+ st=m4.getCoords().getHiddenCppPointer()
+ c,a,b=m4.tetrahedrize(GENERAL_24)
+ c.checkCoherency2()
+ a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]))
+ self.assertEqual(7,b)
+ self.assertTrue(c.getCoords().getHiddenCppPointer()!=coords.getHiddenCppPointer())
+ self.assertTrue(c.getCoords()[:8].isEqual(coords,0))
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,7,8,14,7,6,8,14,6,2,8,14,2,3,8,14,3,2,9,14,2,1,9,14,1,0,9,14,0,3,9,14,3,0,10,14,0,4,10,14,4,7,10,14,7,3,10,14,2,6,11,14,6,5,11,14,5,1,11,14,1,2,11,14,7,4,12,14,4,5,12,14,5,6,12,14,6,7,12,14,1,5,13,14,5,4,13,14,4,0,13,14,0,1,13,14])))
+ m4CoordsExp=DataArrayDouble([0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,2.,1.,0.,2.,1.,1.,2.,0.,1.,2.,0.5,1.,1.,0.5,0.5,0.,0.,0.5,1.,1.,0.5,1.,0.5,0.5,2.,0.5,0.,1.,0.5,0.5,1.],15,3)
+ m4CoordsExp.setInfoOnComponents(["X","YY","ZZZ"])
+ self.assertTrue(c.getCoords().isEqual(m4CoordsExp,1e-12))
+ self.assertAlmostEqual(2.,c.getMeasureField(False).accumulate()[0],12)
+ #
+ m6=MEDCouplingUMesh("hexa8",3)
+ m6.setCoords(coords)
+ m6.allocateCells(0)
+ m6.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
+ st=m6.getCoords().getHiddenCppPointer()
+ c,a,b=m6.tetrahedrize(GENERAL_48)
+ c.checkCoherency2()
+ a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]))
+ self.assertEqual(19,b)
+ self.assertTrue(c.getCoords().getHiddenCppPointer()!=coords.getHiddenCppPointer())
+ self.assertTrue(c.getCoords()[:8].isEqual(coords,0))
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,20,8,26,3,8,21,26,3,9,20,26,3,22,9,26,3,21,12,26,3,12,22,26,8,10,2,23,8,2,13,23,8,20,10,23,8,26,20,23,8,13,21,23,8,21,26,23,12,26,21,25,12,21,16,25,12,22,26,25,12,17,22,25,12,16,0,25,12,0,17,25,21,23,13,18,21,13,1,18,21,26,23,18,21,25,26,18,21,1,16,18,21,16,25,18,9,11,20,24,9,20,26,24,9,7,11,24,9,14,7,24,9,26,22,24,9,22,14,24,20,6,10,15,20,10,23,15,20,11,6,15,20,24,11,15,20,23,26,15,20,26,24,15,22,24,26,19,22,26,25,19,22,14,24,19,22,4,14,19,22,25,17,19,22,17,4,19,26,15,23,5,26,23,18,5,26,24,15,5,26,19,24,5,26,18,25,5,26,25,19,5])))
+ m6CoordsExp=DataArrayDouble([0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,2.,1.,0.,2.,1.,1.,2.,0.,1.,2.,0.5,1.,0.,0.,1.,1.,1.,1.,1.,0.5,1.,2.,0.,0.5,0.,1.,0.5,0.,0.,0.5,2.,1.,0.5,2.,0.5,0.,0.,0.,0.,1.,1.,0.,1.,0.5,0.,2.,0.5,1.,1.,0.5,0.5,0.,0.,0.5,1.,1.,0.5,1.,0.5,0.5,2.,0.5,0.,1.,0.5,0.5,1.],27,3)
+ m6CoordsExp.setInfoOnComponents(["X","YY","ZZZ"])
+ self.assertTrue(c.getCoords().isEqual(m6CoordsExp,1e-12))
+ self.assertAlmostEqual(2.,c.getMeasureField(False).accumulate()[0],12)
+ #
+ m7=MEDCouplingUMesh("polyhed",3)
+ coords=DataArrayDouble([1.,0.,0.,0.5,0.8660254037844386,0.,-0.5,0.8660254037844387,0.,-1.,0.,0.,-0.5,-0.8660254037844384,0.,0.5,-0.866025403784439,0.,1.,0.,2.,0.5,0.8660254037844386,2.,-0.5,0.8660254037844387,2.,-1.,0.,2.,-0.5,-0.8660254037844384,2.,0.5,-0.866025403784439,2.0],12,3) ; coords.setInfoOnComponents(["X","YY","ZZZ"])
+ m7.setCoords(coords)
+ m7.allocateCells()
+ m7.insertNextCell(NORM_POLYHED,[3,2,1,0,5,4,-1,9,10,11,6,7,8,-1,3,9,8,2,-1,2,8,7,1,-1,1,7,6,0,-1,0,6,11,5,-1,5,11,10,4,-1,4,10,9,3])
+ c,a,b=m7.tetrahedrize(PLANAR_FACE_5)
+ c.checkCoherency2()
+ self.assertTrue(a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])))
+ self.assertEqual(9,b)
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,2,12,20,2,1,12,20,1,0,12,20,0,5,12,20,5,4,12,20,4,3,12,20,9,10,13,20,10,11,13,20,11,6,13,20,6,7,13,20,7,8,13,20,8,9,13,20,3,9,14,20,9,8,14,20,8,2,14,20,2,3,14,20,2,8,15,20,8,7,15,20,7,1,15,20,1,2,15,20,1,7,16,20,7,6,16,20,6,0,16,20,0,1,16,20,0,6,17,20,6,11,17,20,11,5,17,20,5,0,17,20,5,11,18,20,11,10,18,20,10,4,18,20,4,5,18,20,4,10,19,20,10,9,19,20,9,3,19,20,3,4,19,20])))
+ self.assertAlmostEqual(5.196152422706635,c.getMeasureField(False).accumulate()[0],12)
+ m7CoordsExp=DataArrayDouble([1.0,0.0,0.0,0.5,0.8660254037844386,0.0,-0.5,0.8660254037844387,0.0,-1.0,0.,0.0,-0.5,-0.8660254037844384,0.0,0.5,-0.866025403784439,0.0,1.0,0.0,2.0,0.5,0.8660254037844386,2.0,-0.5,0.8660254037844387,2.0,-1.0,0.,2.0,-0.5,-0.8660254037844384,2.0,0.5,-0.866025403784439,2.0,0.0,0.0,0.0,0.0,0.,2.0,-0.75,0.4330127018922194,1.0,0.0,0.8660254037844386,1.0,0.75,0.4330127018922193,1.0,0.75,-0.4330127018922195,1.0,0.0,-0.8660254037844387,1.0,-0.75,-0.4330127018922191,1.0,0.0,0.,1.0],21,3)
+ m7CoordsExp.setInfoOnComponents(["X","YY","ZZZ"])
+ self.assertTrue(c.getCoords().isEqual(m7CoordsExp,1e-12))
+ del m7,coords,c
+ #
+ coords=DataArrayDouble([0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,2.,1.,0.,2.,1.,1.,2.,0.,1.,2.],8,3) ; coords.setInfoOnComponents(["X","YY","ZZZ"])
+ m8=MEDCouplingUMesh("pyra5",3)
+ m8.setCoords(coords)
+ m8.allocateCells(0)
+ m8.insertNextCell(NORM_PYRA5,[3,2,1,0,7])
+ st=m8.getCoords().getHiddenCppPointer()
+ c,a,b=m8.tetrahedrize(PLANAR_FACE_5)
+ self.assertEqual(m8.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
+ c.checkCoherency2()
+ self.assertTrue(a.isEqual(DataArrayInt([0,0])))
+ self.assertEqual(0,b)
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,2,1,7,3,1,0,7])))
+ self.assertAlmostEqual(0.6666666666666667,c.getMeasureField(False).accumulate()[0],12)
+ pass
+
+ def testDualMesh3D1(self):
+ arr=DataArrayDouble(2) ; arr.iota()
+ c=MEDCouplingCMesh() ; c.setCoords(arr,arr,arr)
+ m=c.buildUnstructured()
+ t=m.tetrahedrize(PLANAR_FACE_5)[0]
+ d=t.computeDualMesh()
+ self.assertTrue(d.getNodalConnectivityIndex().isEqual(DataArrayInt([0,29,118,207,236,325,354,383,472])))
+ self.assertTrue(d.getNodalConnectivity().isEqual(DataArrayInt([26,11,42,8,-1,25,8,42,10,-1,29,10,42,11,-1,0,26,8,25,-1,0,25,10,29,-1,0,29,11,26,24,9,42,8,-1,26,8,42,11,-1,27,11,42,9,-1,1,24,8,26,-1,1,26,11,27,-1,30,13,43,12,-1,24,12,43,15,-1,32,15,43,13,-1,1,30,12,24,-1,1,32,13,30,-1,35,17,44,16,-1,32,16,44,19,-1,27,19,44,17,-1,1,35,16,32,-1,1,27,17,35,-1,24,15,46,9,-1,27,9,46,19,-1,32,19,46,15,27,9,42,11,-1,29,11,42,10,-1,28,10,42,9,-1,2,29,10,28,-1,2,27,11,29,-1,27,17,44,19,-1,38,19,44,18,-1,37,18,44,17,-1,2,37,17,27,-1,2,38,18,37,-1,28,21,45,23,-1,41,23,45,22,-1,38,22,45,21,-1,2,41,22,38,-1,2,28,23,41,-1,27,19,46,9,-1,28,9,46,21,-1,38,21,46,19,35,16,44,17,-1,36,18,44,16,-1,37,17,44,18,-1,3,36,16,35,-1,3,35,17,37,-1,3,37,18,36,24,8,42,9,-1,25,10,42,8,-1,28,9,42,10,-1,4,25,8,24,-1,4,28,10,25,-1,24,15,43,12,-1,31,12,43,14,-1,34,14,43,15,-1,4,24,12,31,-1,4,31,14,34,-1,34,21,45,20,-1,40,20,45,23,-1,28,23,45,21,-1,4,34,20,40,-1,4,40,23,28,-1,24,9,46,15,-1,28,21,46,9,-1,34,15,46,21,30,12,43,13,-1,31,14,43,12,-1,33,13,43,14,-1,5,31,12,30,-1,5,30,13,33,-1,5,33,14,31,40,23,45,20,-1,39,20,45,22,-1,41,22,45,23,-1,6,40,20,39,-1,6,39,22,41,-1,6,41,23,40,32,13,43,15,-1,34,15,43,14,-1,33,14,43,13,-1,7,33,13,32,-1,7,34,14,33,-1,32,19,44,16,-1,36,16,44,18,-1,38,18,44,19,-1,7,32,16,36,-1,7,36,18,38,-1,34,20,45,21,-1,39,22,45,20,-1,38,21,45,22,-1,7,39,20,34,-1,7,38,22,39,-1,32,15,46,19,-1,38,19,46,21,-1,34,21,46,15])))
+ self.assertTrue(d.getCoords().isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,0.,1.,0.,1.,1.,0.,0.,0.,1.,1.,0.,1.,0.,1.,1.,1.,1.,1.,0.3333333333333333,0.,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.,0.6666666666666666,0.,0.6666666666666666,1.,0.3333333333333333,0.6666666666666666,0.6666666666666666,0.3333333333333333,1.,0.6666666666666666,0.3333333333333333,0.6666666666666666,1.,0.6666666666666666,0.3333333333333333,0.6666666666666666,0.6666666666666666,0.,0.6666666666666666,1.,0.3333333333333333,0.6666666666666666,0.6666666666666666,0.3333333333333333,0.3333333333333333,0.6666666666666666,1.,0.3333333333333333,0.6666666666666666,0.6666666666666666,0.3333333333333333,1.,0.6666666666666666,0.,0.6666666666666666,0.6666666666666666,0.5,0.,0.5,0.,0.,0.5,0.5,0.,0.,0.5,0.5,0.,0.,0.5,0.5,0.,0.5,0.,1.,0.,0.5,0.5,0.,1.,1.,0.5,0.5,1.,0.5,1.,0.5,0.5,1.,1.,0.5,0.,1.,1.,0.5,0.5,1.,0.,0.5,1.,0.5,0.5,1.,1.,0.,0.5,1.,0.,1.,0.5,0.25,0.25,0.25,0.75,0.25,0.75,0.75,0.75,0.25,0.25,0.75,0.75,0.5,0.5,0.5],47,3),1e-12))
+ self.assertAlmostEqual(1.,d.getMeasureField(False).accumulate()[0],1e-13)
+ pass
+
+ def testDualMesh2D1(self):
+ arr=DataArrayDouble(5) ; arr.iota()
+ c=MEDCouplingCMesh() ; c.setCoords(arr,arr)
+ m=c.buildUnstructured()
+ m.simplexize(0)
+ t=MEDCoupling1SGTUMesh(m)
+ d=t.computeDualMesh()
+ self.assertTrue(d.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,12,20,28,34,42,54,66,78,86,94,106,118,130,138,146,158,170,182,190,196,204,212,220,224])))
+ self.assertTrue(d.getNodalConnectivity().isEqual(DataArrayInt([26,81,25,0,25,81,27,82,29,83,30,1,30,83,31,84,33,85,34,2,34,85,35,86,37,87,38,3,38,87,39,88,41,4,27,81,26,5,42,89,28,82,29,82,28,89,43,90,45,91,32,84,31,83,33,84,32,91,46,92,48,93,36,86,35,85,37,86,36,93,49,94,51,95,40,88,39,87,41,88,40,95,52,96,54,9,43,89,42,10,55,97,44,90,45,90,44,97,56,98,58,99,47,92,46,91,48,92,47,99,59,100,61,101,50,94,49,93,51,94,50,101,62,102,64,103,53,96,52,95,54,96,53,103,65,104,67,14,56,97,55,15,68,105,57,98,58,98,57,105,69,106,71,107,60,100,59,99,61,100,60,107,72,108,74,109,63,102,62,101,64,102,63,109,75,110,77,111,66,104,65,103,67,104,66,111,78,112,80,19,69,105,68,20,70,106,71,106,70,21,73,108,72,107,74,108,73,22,76,110,75,109,77,110,76,23,79,112,78,111,80,112,79,24])))
+ self.assertTrue(d.getCoords().isEqual(DataArrayDouble([0.,0.,1.,0.,2.,0.,3.,0.,4.,0.,0.,1.,1.,1.,2.,1.,3.,1.,4.,1.,0.,2.,1.,2.,2.,2.,3.,2.,4.,2.,0.,3.,1.,3.,2.,3.,3.,3.,4.,3.,0.,4.,1.,4.,2.,4.,3.,4.,4.,4.,0.5,0.,0.,0.5,0.5,0.5,0.5,1.,1.,0.5,1.5,0.,1.5,0.5,1.5,1.,2.,0.5,2.5,0.,2.5,0.5,2.5,1.,3.,0.5,3.5,0.,3.5,0.5,3.5,1.,4.,0.5,0.,1.5,0.5,1.5,0.5,2.,1.,1.5,1.5,1.5,1.5,2.,2.,1.5,2.5,1.5,2.5,2.,3.,1.5,3.5,1.5,3.5,2.,4.,1.5,0.,2.5,0.5,2.5,0.5,3.,1.,2.5,1.5,2.5,1.5,3.,2.,2.5,2.5,2.5,2.5,3.,3.,2.5,3.5,2.5,3.5,3.,4.,2.5,0.,3.5,0.5,3.5,0.5,4.,1.,3.5,1.5,3.5,1.5,4.,2.,3.5,2.5,3.5,2.5,4.,3.,3.5,3.5,3.5,3.5,4.,4.,3.5,0.3333333333333333,0.3333333333333333,0.6666666666666666,0.6666666666666666,1.3333333333333333,0.3333333333333333,1.6666666666666665,0.6666666666666666,2.333333333333333,0.3333333333333333,2.6666666666666665,0.6666666666666666,3.333333333333333,0.3333333333333333,3.6666666666666665,0.6666666666666666,0.3333333333333333,1.3333333333333333,0.6666666666666666,1.6666666666666665,1.3333333333333333,1.3333333333333333,1.6666666666666665,1.6666666666666665,2.333333333333333,1.3333333333333333,2.6666666666666665,1.6666666666666665,3.333333333333333,1.3333333333333333,3.6666666666666665,1.6666666666666665,0.3333333333333333,2.333333333333333,0.6666666666666666,2.6666666666666665,1.3333333333333333,2.333333333333333,1.6666666666666665,2.6666666666666665,2.333333333333333,2.333333333333333,2.6666666666666665,2.6666666666666665,3.333333333333333,2.333333333333333,3.6666666666666665,2.6666666666666665,0.3333333333333333,3.333333333333333,0.6666666666666666,3.6666666666666665,1.3333333333333333,3.333333333333333,1.6666666666666665,3.6666666666666665,2.333333333333333,3.333333333333333,2.6666666666666665,3.6666666666666665,3.333333333333333,3.333333333333333,3.6666666666666665,3.6666666666666665],113,2),1e-12))
+ self.assertAlmostEqual(16.,d.getMeasureField(False).accumulate()[0],1e-13)
+ pass
+
+ def testSwig2LoadBalanceBBox1(self):
+ arr=DataArrayDouble(5) ; arr.iota()
+ t=MEDCouplingCMesh() ; t.setCoords(arr,arr)
+ arr=DataArrayDouble(16) ; arr.iota() ; arr*=2./15
+ s=MEDCouplingCMesh() ; s.setCoords(arr,arr[:]) ; s.translate([2.,1.])
+ #
+ s1=s.build1SGTUnstructured()
+ t1=t.build1SGTUnstructured()
+ w=MEDCouplingPointSet.ComputeNbOfInteractionsWithSrcCells(s1,t1,1e-12)
+ wExp=DataArrayInt([0,0,0,0,0,0,64,64,0,0,64,64,0,0,0,0])
+ self.assertTrue(w.isEqual(wExp))
+ slcs=w.splitInBalancedSlices(4)
+ self.assertEqual(len(slcs),4)
+ self.assertEqual(slcs,[slice(0,7,1),slice(7,8,1),slice(8,11,1),slice(11,16,1)])
+ bbs=s1.getBoundingBoxForBBTree()
+ bbt=t1.getBoundingBoxForBBTree()
+ self.assertTrue(bbt.computeNbOfInteractionsWith(bbs,1e-12).isEqual(wExp))
+ pass
+
+ def testKrSpatialDiscretization2(self):
+ srcPointCoordsXY=DataArrayDouble([0.8401877171547095,0.39438292681909304,0.7830992237586059,0.7984400334760733,0.9116473579367843,0.19755136929338396,0.335222755714889,0.768229594811904,0.2777747108031878,0.5539699557954305,0.47739705186216025,0.6288709247619244,0.36478447279184334,0.5134009101956155,0.9522297251747128,0.9161950680037007,0.6357117279599009,0.7172969294326831,0.14160255535580338,0.6069688762570586,0.01630057162432958,0.24288677062973696,0.13723157678601872,0.8041767542269904,0.15667908925408455,0.4009443942461835,0.12979044678145574,0.10880880202576929,0.998924518003559,0.21825690531090688,0.5129323944043984,0.8391122346926072,0.6126398325956612,0.29603161769734304,0.6375522677030192,0.5242871900667843,0.493582986990727,0.9727750238835695,0.29251678441302703,0.7713576977939148,0.5267449792133388,0.7699138362751873,0.4002286220901779,0.8915294520051822,0.2833147460051415,0.3524583472648907,0.8077245200088827,0.9190264739650424,0.06975527623191256,0.9493270753646861,0.5259953502221011,0.08605584785624214,0.19221384599442307,0.6632269270081198,0.8902326025488938,0.3488929352485076,0.06417132078864207,0.02002304886468828,0.4577017372742769,0.06309583832653977,0.23827995417559517,0.9706341316786754,0.9022080734848082,0.8509197867712563,0.2666657493760184,0.5397603407221662,0.3752069763723793,0.7602487363667454,0.5125353641400744,0.6677237607854063,0.5316064341606602,0.039280343353413204,0.4376375965949323,0.9318350562508382,0.9308097953585953,0.7209523430657351,0.28429340305006756,0.7385343149018168,0.6399788165651163,0.3540486797476414,0.687861390266503,0.16597416632155615,0.4401045276038835,0.880075236260926,0.829201093329676,0.3303371296871161,0.22896817104377232,0.8933724145839793,0.35036017855180435,0.6866699083180492,0.9564682529105192,0.5886401331930609,0.6573040395310633,0.8586763259296661,0.4395599194986559,0.9239697889070817,0.39843666665183225,0.8147668963366965,0.6842185252738271,0.9109720307919067,0.4824906566564416,0.21582495896882609,0.9502523741453198,0.9201282537170352,0.14766001475400292,0.8810621695039152,0.641080596317109,0.43195341826973177,0.6195964839400707,0.281059412416564,0.7860020980173732,0.3074578737409124,0.44703357920378145,0.22610662515559543,0.18753310953617705,0.27623467206779617,0.5564437553083728,0.4165012805799494,0.16960708618611428,0.9068039338601771,0.10317118843233734,0.1260753390966334,0.49544406658757667,0.7604752284290619,0.9847516650262995,0.9350039865518939,0.6844450168704823,0.3831883312124705,0.7497708824229291,0.36866354167864823,0.2941603620043771,0.2322615386137094,0.5844885006474743,0.24441273568403568,0.15238979186508328,0.7321485158671385,0.12547490472228962,0.7934703881821923,0.164101933671209,0.7450713891280216,0.07452980059875632,0.9501040316885822,0.05252926240327268,0.5215633798025378,0.1762106563785163,0.24006237240511102,0.797798051870334,0.732654411686889,0.6565636529850605,0.9674051385221095,0.6394583455470663,0.7597348418830591,0.09348047715308166,0.13490241166898162,0.5202100698464597,0.07823214171371988,0.06990639775521419,0.2046550862512808,0.4614204733918516,0.8196772801781433,0.5733186283955903,0.7555808353962288,0.05193881879185271,0.1578071285774033,0.9999935710802644,0.204328610656936,0.8899556444445419,0.12546847580255405,0.9977989993047895,0.054057577650089554,0.8705398649305757,0.07232879943788462,0.004161608873010431,0.9230691273338484,0.5938921792404224,0.180372265717188,0.16313149927329806,0.3916902306450951,0.9130266774040771,0.8196951527240198,0.35909536870154335,0.552485022485482,0.5794299941414176,0.452575845854625,0.687387434620125,0.09964006352221597,0.5308079880340062,0.7572938323753392,0.30429514977349675,0.9922284614258579,0.5769711125534824,0.877613778169087,0.7478092963564253,0.6289099313453351,0.03542090674649035,0.7478028669710285,0.8332385420022712,0.9253765511910322,0.8732713427735824,0.8310375408413995],100,2)
+ srcFieldValsOnPoints=DataArrayDouble([0.7643742528498438,-0.023507696856211995,1.1082895131907775,0.6299357452572031,0.8892623544912389,0.72212114810697,0.9196401044320336,-0.759961711221917,0.40801932617748826,0.8441134300809151,0.982483804252809,0.6752368914020778,0.9924403977479798,1.1063334970204484,0.9403055261137516,0.3624481886322733,1.1344772505996308,0.7522965618948239,0.17077741651388564,0.6504551671311436,0.45843479588425423,0.41098905950326753,1.0681420394050904,-0.3483587903820091,0.5620151050607809,1.384969776596035,0.7948875141132845,0.7931192000237167,1.062498042490183,1.3709072529577366,0.44929346605311893,-0.4469683401788374,0.9035857424514101,0.6137249300593463,0.6355610879026966,1.4318174829507697,0.3097567072129551,-0.20515052260807165,0.6922559820922779,1.0341638749443423,1.3072652153341024,0.38511367353000436,0.9160514929274943,0.54513408530581,0.722252267913328,0.06684522818576251,0.10571899758067793,0.3193844999960903,0.5213532270828706,-0.04834998649603944,1.2408805068350615,-0.7632951295676795,0.5980054665011202,0.9064738717547436,1.1541070755096696,1.008234260272265,1.2225806960553827,1.0788560195121106,0.9818990282104452,0.5621951325841853,1.0796757508374188,0.5082872315589883,-0.9153702001062469,0.9560418838920791,0.9251098559152824,1.1603063610984021,1.2122303611181837,0.7379539363312343,0.6877611899207183,0.723966552446608,0.5596025827162566,0.8849725005989729,1.0908363665075547,0.08956512916455672,-0.10247645571248344,0.3236718069555875,1.069478546398975,1.3900071080692746,1.0322398863403262,0.45315515354558034,0.4249870238786733,1.030226761858634,0.974024629584669,1.2838885424020365,1.3451943506525155,1.4029933267831995,0.6025539675442462,1.2947650597767038,1.0006061239483002,-0.4017336259949164,0.8771165113201297,0.9158909024218246,1.403798605551443,0.4742904006425974,0.3671787905896653,0.20646491720419674,0.40739337434288925,0.7341932402033597,-0.4295893651836911,-0.3187777570661546],100,1)
+ targetPointCoordsXY=DataArrayDouble([-0.5,-0.5,-0.5,-0.35,-0.5,-0.2,-0.5,-0.05,-0.5,0.1,-0.5,0.25,-0.5,0.4,-0.5,0.55,-0.5,0.7,-0.5,0.85,-0.5,1.0,-0.5,1.15,-0.5,1.3,-0.5,1.45,-0.35,-0.5,-0.35,-0.35,-0.35,-0.2,-0.35,-0.05,-0.35,0.1,-0.35,0.25,-0.35,0.4,-0.35,0.55,-0.35,0.7,-0.35,0.85,-0.35,1.0,-0.35,1.15,-0.35,1.3,-0.35,1.45,-0.2,-0.5,-0.2,-0.35,-0.2,-0.2,-0.2,-0.05,-0.2,0.1,-0.2,0.25,-0.2,0.4,-0.2,0.55,-0.2,0.7,-0.2,0.85,-0.2,1.0,-0.2,1.15,-0.2,1.3,-0.2,1.45,-0.05,-0.5,-0.05,-0.35,-0.05,-0.2,-0.05,-0.05,-0.05,0.1,-0.05,0.25,-0.05,0.4,-0.05,0.55,-0.05,0.7,-0.05,0.85,-0.05,1.0,-0.05,1.15,-0.05,1.3,-0.05,1.45,0.1,-0.5,0.1,-0.35,0.1,-0.2,0.1,-0.05,0.1,0.1,0.1,0.25,0.1,0.4,0.1,0.55,0.1,0.7,0.1,0.85,0.1,1.0,0.1,1.15,0.1,1.3,0.1,1.45,0.25,-0.5,0.25,-0.35,0.25,-0.2,0.25,-0.05,0.25,0.1,0.25,0.25,0.25,0.4,0.25,0.55,0.25,0.7,0.25,0.85,0.25,1.0,0.25,1.15,0.25,1.3,0.25,1.45,0.4,-0.5,0.4,-0.35,0.4,-0.2,0.4,-0.05,0.4,0.1,0.4,0.25,0.4,0.4,0.4,0.55,0.4,0.7,0.4,0.85,0.4,1.0,0.4,1.15,0.4,1.3,0.4,1.45,0.55,-0.5,0.55,-0.35,0.55,-0.2,0.55,-0.05,0.55,0.1,0.55,0.25,0.55,0.4,0.55,0.55,0.55,0.7,0.55,0.85,0.55,1.0,0.55,1.15,0.55,1.3,0.55,1.45,0.7,-0.5,0.7,-0.35,0.7,-0.2,0.7,-0.05,0.7,0.1,0.7,0.25,0.7,0.4,0.7,0.55,0.7,0.7,0.7,0.85,0.7,1.0,0.7,1.15,0.7,1.3,0.7,1.45,0.85,-0.5,0.85,-0.35,0.85,-0.2,0.85,-0.05,0.85,0.1,0.85,0.25,0.85,0.4,0.85,0.55,0.85,0.7,0.85,0.85,0.85,1.0,0.85,1.15,0.85,1.3,0.85,1.45,1.0,-0.5,1.0,-0.35,1.0,-0.2,1.0,-0.05,1.0,0.1,1.0,0.25,1.0,0.4,1.0,0.55,1.0,0.7,1.0,0.85,1.0,1.0,1.0,1.15,1.0,1.3,1.0,1.45,1.15,-0.5,1.15,-0.35,1.15,-0.2,1.15,-0.05,1.15,0.1,1.15,0.25,1.15,0.4,1.15,0.55,1.15,0.7,1.15,0.85,1.15,1.0,1.15,1.15,1.15,1.3,1.15,1.45,1.3,-0.5,1.3,-0.35,1.3,-0.2,1.3,-0.05,1.3,0.1,1.3,0.25,1.3,0.4,1.3,0.55,1.3,0.7,1.3,0.85,1.3,1.0,1.3,1.15,1.3,1.3,1.3,1.45,1.45,-0.5,1.45,-0.35,1.45,-0.2,1.45,-0.05,1.45,0.1,1.45,0.25,1.45,0.4,1.45,0.55,1.45,0.7,1.45,0.85,1.45,1.0,1.45,1.15,1.45,1.3,1.45,1.45],196,2)
+ targetFieldValsExpected=DataArrayDouble([1.645976003316459, 1.454458180060204, 1.286087532859835, 1.147305389930914, 1.040143042030752, 0.9592075185603157, 0.8932542207607532, 0.8296417057622609, 0.7572539678257579, 0.6669048311361028, 0.551329882743212, 0.4064445075734602, 0.2323703965460786, 0.03253142054561309, 1.615321686989539, 1.414941300553572, 1.238383118538708, 1.096701655702075, 0.9955792747382535, 0.9271194507282707, 0.8741000712825546, 0.8201879508155141, 0.7537335933761495, 0.6656210809234322, 0.5470285414729397, 0.3927301586610237, 0.2044036897887453, -0.01181672742825013, 1.609602552867195, 1.400625195269133, 1.213287847440801, 1.065318574929208, 0.9717609562002842, 0.9182626517777217, 0.8760698972315855, 0.8258196104516153, 0.7586487405165288, 0.6686168424854784, 0.5434121624038266, 0.3741815029337978, 0.1661376046619205, -0.0704038088420833, 1.635421686625182, 1.422642113482769, 1.225977424080963, 1.066864693789366, 0.9864801043792362, 0.9486639217909161, 0.9075176697327381, 0.8471248730261529, 0.7660983406349626, 0.6675300501188994, 0.5320013361909732, 0.3404583135353376, 0.1074346390951333, -0.1520751802856468, 1.695346918429566, 1.489526279573347, 1.297678617961701, 1.139921240332637, 1.080508463804929, 1.036847769764088, 0.9687840669352359, 0.8790397822170175, 0.76938768351059, 0.6441978169925557, 0.4915328571013788, 0.2742929463574293, 0.0148214290833748, -0.2671755287427691, 1.782761788232491, 1.59423004798623, 1.422317125787222, 1.286999529473285, 1.20500638941831, 1.127058114031519, 1.022332539190471, 0.8945753999401338, 0.7469190939381181, 0.582396906110898, 0.4015920181411496, 0.1584700483835366, -0.1251860255418387, -0.4254052799545267, 1.881794862747652, 1.712890309994015, 1.557517508390291, 1.422727414977963, 1.308048056353061, 1.187569766723152, 1.03942150436647, 0.8677583087532357, 0.6766652050643343, 0.4703897480238999, 0.2497994532908829, -0.02005989176786582, -0.3224387891441491, -0.6331519303649853, 1.973114284621266, 1.820187301531605, 1.673403730111759, 1.528504440482262, 1.379693463484634, 1.207642134784147, 1.008217764780293, 0.7863328498822348, 0.5465383049529959, 0.2944879513187435, 0.03250657765404452, -0.2670900851421072, -0.5806516907976924, -0.8911331026431459, 2.038729888975378, 1.895652364645637, 1.751759791756183, 1.594035761810714, 1.403016809171641, 1.171403152610878, 0.913267035125007, 0.6343281031932027, 0.3434843176189371, 0.04195410032095204, -0.2645533663891493, -0.58577400250975, -0.8958218846257981, -1.192230697656513, 2.064018033720731, 1.922048791644444, 1.773847180028208, 1.600340336378483, 1.361620036333164, 1.060873411411508, 0.7373484802125152, 0.3868966266761109, 0.04316272760227413, -0.3009370030949727, -0.6505233805563486, -0.9669887470696283, -1.250005719852354, -1.519122595631787, 2.039938287785342, 1.887400820799651, 1.722008733683987, 1.523879290022419, 1.23834392230135, 0.8606985727866472, 0.4844892131548788, 0.08077959236877175, -0.3195742594962179, -0.726291368696764, -1.094357645641832, -1.359078900303776, -1.604725656501341, -1.845297168323687, 1.965762248218393, 1.791665198563286, 1.595056719739704, 1.353692777435502, 1.033006623003495, 0.6416349531117889, 0.2290046916364761, -0.1993180965088852, -0.6311618804827295, -1.051489875129883, -1.409404344854132, -1.681249363331096, -1.917859637689007, -2.145034400762945, 1.849053542205925, 1.648479366622312, 1.418493963148431, 1.141939527533839, 0.8042385795619003, 0.4127534639189761, -0.008572116677791453, -0.4428317297963555, -0.8745477268718713, -1.281769237471681, -1.635421857742795, -1.926210204560556, -2.175577364628722, -2.405762639746138, 1.701519686999922, 1.475879908746998, 1.219065416294153, 0.9203732349759972, 0.5740137315474942, 0.1856460506119944, -0.2298288912529738, -0.6558565521653752, -1.075391078040103, -1.469402631469075, -1.820558929095151, -2.123592211415966, -2.388177455227765, -2.628832075944413])
+ coeffsExpected=DataArrayDouble([0.3953237723894342,-0.17220705170185724,0.620727139132215,-0.01938292763088709,-0.007524685306185282,0.0016277944443884584,-0.0005209587893117361,-1.8992696595839718,-0.13154330748345855,0.11248800965389728,-0.47310750305033406,0.03685741122098605,0.21362468750754374,0.8082608687799991,-0.6775548200221704,-0.027683208482275873,-0.007806877014495724,-0.013539239795959668,0.3478535665778018,0.005145793726360813,0.03708618549628136,-0.18235332489209385,-0.04517273339177797,-0.081755114492025,0.12791746560435255,0.09659355695676189,-0.024809653129318366,0.08327587452569823,-1.790380673650165,-0.10622983512164165,0.14989029282340274,0.05949513762355707,0.004548072841131278,0.011252095917834793,-0.004848057194721367,-0.2658537133108412,0.016651579133606154,-0.021640915366981317,0.008975511042160175,-0.021052213988815974,-0.09347841701844657,0.03533229488135717,-0.014556185287109863,-0.27228591670520086,0.002989987191209683,-0.5489428537951813,-0.02134456783001304,-0.22462281620064825,0.005230853443767429,-0.1894678262257301,0.0033140729457334884,5.295483062326795,-0.2724500716060311,0.026433905662192683,0.01368706308878908,-0.03014264855048227,0.053679001877659956,0.08109477254132096,-0.005004603067203444,0.016907143132293558,0.2105509502082437,0.003657404455024417,-4.904755847017426,0.01634808163992959,-0.008325515865305198,0.062188432751569676,-0.013114633511406406,0.11020519384963083,-0.008599402366091309,-0.012125149710784723,0.31723729052927313,-0.10298398036815914,-0.07250078775612204,0.39976713701763433,0.45897498107347223,0.01018626210400031,0.20163425809089347,0.19729093298588943,0.42863333455911523,0.015595097081693168,0.06060353651437489,-0.16379444813161725,-0.43290344196574165,-0.5931022701412187,1.1906610004748832,0.44418106894148945,0.06536220001548931,0.010261694323554562,-0.05943099382075491,-0.04939614579484797,0.002234505477641322,-0.011262130967449935,0.09644905007708474,-0.029518792883267808,0.41564004027396634,-0.18459770295961597,0.3100981306103734,-0.2509873737065425,0.5434321443668653,0.3009912967350914,1.9560655796099518,-0.7143435150084513,-1.5123449469879784])
+ #
+ nbOfInputPoints=100;
+ f=MEDCouplingFieldDouble.New(ON_NODES_KR,ONE_TIME);
+ mesh=MEDCoupling1SGTUMesh.New("aMesh",NORM_POINT1);
+ mesh.setCoords(srcPointCoordsXY);
+ f.setMesh(mesh);
+ f.setArray(srcFieldValsOnPoints);
+ f.checkCoherency();
+ #
+ res0=f.getValueOn([-0.5,-0.5]);
+ self.assertAlmostEqual(targetFieldValsExpected.getIJ(0,0),res0[0],10)
+ #
+ valuesToTest=f.getValueOnMulti(targetPointCoordsXY);
+ self.assertEqual(196,valuesToTest.getNumberOfTuples());
+ self.assertEqual(1,valuesToTest.getNumberOfComponents());
+ for i in xrange(40):
+ self.assertAlmostEqual(targetFieldValsExpected[i],valuesToTest.getIJ(i,0),10)
+ pass
+ fd=f.getDiscretization()
+ del f
+ self.assertTrue(isinstance(fd,MEDCouplingFieldDiscretizationKriging))
+ coeffs,isDrift=fd.computeVectorOfCoefficients(mesh,srcFieldValsOnPoints)
+ self.assertEqual(3,isDrift)
+ self.assertTrue(coeffsExpected.isEqual(coeffs,1e-8))
+ # testing matrix
+ pts3=[-0.5,-0.5,-0.5,-0.35,-0.35,-0.2]
+ mesh.setCoords(srcPointCoordsXY[:4])
+ m,nbCols=fd.computeEvaluationMatrixOnGivenPts(mesh,pts3)
+ self.assertTrue(m.isEqual(DataArrayDouble([0.05768877688524917,-4.438982030395039,1.9495386255911573,3.431754627918642,0.11803848510231275,-4.138339658420563,1.6630742187104417,3.357226954607818,0.14630203028580618,-3.5156045565871734,1.414680070737206,2.954622455564169]),1e-12))
+ if MEDCouplingHasNumPyBindings():
+ import numpy as np
+ m0=m.toNumPyArray() ; m0=m0.reshape(3,nbCols) ; m0=np.matrix(m0)
+ srcFieldValsOnPoints2=DataArrayDouble(4,2) ; srcFieldValsOnPoints2[:,0]=srcFieldValsOnPoints[:4] ; srcFieldValsOnPoints2[:,1]=2*srcFieldValsOnPoints[:4]
+ n0=srcFieldValsOnPoints2.toNumPyArray() ; n0=n0.reshape(4,2) ; n0=np.matrix(n0)
+ #
+ f=MEDCouplingFieldDouble.New(ON_NODES_KR,ONE_TIME) ; f.setMesh(mesh) ; f.setArray(srcFieldValsOnPoints2) ; f.checkCoherency()
+ self.assertTrue(DataArrayDouble(np.array((m0*n0))).isEqual(f.getValueOnMulti(pts3),1e-14))
+ pass
+ #
+ pass
+
+ # test the when input slice is all the same object is return by MEDCouplingMesh.buildPartRange
+ def testSwig2MeshPartSlice1(self):
+ a=DataArrayDouble(4) ; a.iota()
+ c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m=c.buildUnstructured()
+ fc0=c.getMeasureField(False) ; fc1=fc0[:] ; fc2=fc0*fc1 ; fc2.setName(fc0.getName())
+ self.assertEqual(fc0.getMesh().getHiddenCppPointer(),fc1.getMesh().getHiddenCppPointer())
+ self.assertEqual(fc2.getMesh().getHiddenCppPointer(),fc1.getMesh().getHiddenCppPointer())
+ self.assertTrue(fc2.isEqual(fc1,1e-12,1e-12))
+ #
+ fm0=m.getMeasureField(False) ; fm1=fm0[:] ; fm2=fm0*fm1 ; fm2.setName(fm0.getName())
+ self.assertEqual(fm0.getMesh().getHiddenCppPointer(),fm1.getMesh().getHiddenCppPointer())
+ self.assertEqual(fm2.getMesh().getHiddenCppPointer(),fm1.getMesh().getHiddenCppPointer())
+ self.assertTrue(fm2.isEqual(fm1,1e-12,1e-12))
+ pass
+
+ # test the correct behaviour when attempting to aggregate two fields whose mesh is null
+ def testSwig2MergeFieldsOnFieldsHavingNoMesh(self):
+ a=DataArrayDouble(4) ; a.iota() ; a*=1.5
+ c=MEDCouplingCMesh() ; c.setCoords(a,a) ; f1=c.getMeasureField(False)
+ f1.setMesh(None) ; f2=f1.deepCpy() ; f2*=2
+ f3=MEDCouplingFieldDouble.MergeFields(f1,f2)
+ daExp=DataArrayDouble([2.25,2.25,2.25,2.25,2.25,2.25,2.25,2.25,2.25,4.5,4.5,4.5,4.5,4.5,4.5,4.5,4.5,4.5])
+ self.assertTrue(f3.getArray().isEqual(daExp,1e-12))
+ self.assertEqual(f3.getTypeOfField(),ON_CELLS)
+ self.assertEqual(f3.getMesh(),None)
+ f4=MEDCouplingFieldDouble.MergeFields([f1,f2])
+ self.assertTrue(f4.getArray().isEqual(daExp,1e-12))
+ self.assertEqual(f4.getTypeOfField(),ON_CELLS)
+ self.assertEqual(f4.getMesh(),None)
+ pass
+
+ # test a simple node to cell convertion of a field
+ def testSwig2NodeToCellDiscretization1(self):
+ f=MEDCouplingFieldDouble(ON_NODES) ; f.setTime(1.1,2,3)
+ a1=DataArrayDouble(4) ; a1.iota()
+ a2=DataArrayDouble(3) ; a2.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(a1,a2)
+ f.setMesh(m)
+ arr=DataArrayDouble([21.,121.,20.,120.,19.,119.,18.,118.,17.,117.,16.,116.,15.,115.,14.,114.,13.,113.,12.,112.,11.,111.,10.,110.],12,2) ; arr.setInfoOnComponents(["aa [km]","bbb [kJ]"])
+ f.setArray(arr) ; f.setName("toto")
+ #
+ f2=f.nodeToCellDiscretization()
+ self.assertEqual(ON_CELLS,f2.getTypeOfField())
+ self.assertEqual("toto",f2.getName())
+ self.assertEqual([1.1,2,3],f2.getTime())
+ self.assertEqual(["aa [km]","bbb [kJ]"],f2.getArray().getInfoOnComponents())
+ self.assertEqual(6,f2.getArray().getNumberOfTuples())
+ self.assertEqual(f.getMesh().getHiddenCppPointer(),f2.getMesh().getHiddenCppPointer())
+ exp=DataArrayDouble([18.5,118.5,17.5,117.5,16.5,116.5,14.5,114.5,13.5,113.5,12.5,112.5],6,2) ; exp.setInfoOnComponents(["aa [km]","bbb [kJ]"])
+ self.assertTrue(f2.getArray().isEqual(exp,1e-13))
+ pass
+
+ def testSwig2NonRegressionBugIntersectMeshes1(self):
+ src=MEDCouplingUMesh("src",2)
+ src.setCoords(DataArrayDouble([-2.5,-3,-2.5,3,2.5,3],3,2))
+ src.allocateCells()
+ src.insertNextCell(NORM_TRI3,[0,1,2])
+ #
+ trg=MEDCouplingUMesh("trg",2)
+ trg.setCoords(DataArrayDouble([-2.5,-3.,0.,-3.,0.,-2.,-2.,0.,-2.25,0.,-2.5,0.,-2.5,-1.5,0.,-2.5,-1.25,-3.,-1.414213562373095,-1.414213562373095],10,2))
+ trg.allocateCells()
+ trg.insertNextCell(NORM_QPOLYG,[2,1,0,5,3,7,8,6,4,9])
+ #
+ a,b,c=MEDCouplingUMesh.Intersect2DMeshes(src,trg,1.0e-8)
+ a.mergeNodes(1e-8)
+ self.assertTrue(a.getCoords().isEqual(DataArrayDouble([-2.5,-3.,-2.5,3.,2.5,3.,0.,-3.,0.,-2.,-2.,0.,-2.25,0.,-2.5,0.,-2.5,-1.5,0.,-2.5,-1.25,-3.,-1.414213562373095,-1.414213562373095,-1.2803687993289596,-1.5364425591947515,-1.8901843996644798,-2.2682212795973755,-1.81117884244736,-0.8483107924994473,-2.5,1.5,0.,3.,0.6098156003355202,0.7317787204026243],18,2),1e-12))
+ self.assertTrue(a.getNodalConnectivity().isEqual(DataArrayInt([32,12,0,7,5,13,8,6,14,32,7,1,2,12,5,15,16,17,14,6])))
+ self.assertTrue(a.getNodalConnectivityIndex().isEqual(DataArrayInt([0,9,20])))
+ self.assertTrue(b.isEqual(DataArrayInt([0,0])))
+ self.assertTrue(c.isEqual(DataArrayInt([0,-1])))
+ pass
+
+ def testSwig2MeshOrientCorrectly2DCells1(self):
+ m=MEDCouplingUMesh("mesh",2)
+ coo=DataArrayDouble([1.,0.,0.5,-0.1,0.,1.,0.,0.,0.07,0.5,0.59,0.5],6,2)
+ m.setCoords(coo)
+ m.allocateCells()
+ m.insertNextCell(NORM_TRI6,[3,0,2,1,5,4])
+ m.insertNextCell(NORM_QPOLYG,[3,0,2,1,5,4])
+ self.assertTrue(DataArrayDouble([-0.58093333350930543,-0.58093333350930543]).isEqual(m.getMeasureField(False).getArray(),1e-12))
+ m.changeSpaceDimension(3)
+ m.orientCorrectly2DCells([0.,0.,-1.],False)
+ #
+ m.checkCoherency()
+ self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([6,3,2,0,4,5,1, 32,3,2,0,4,5,1])))
+ self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,7,14])))
+ m.changeSpaceDimension(2)
+ self.assertTrue(DataArrayDouble([0.58093333350930543,0.58093333350930543]).isEqual(m.getMeasureField(False).getArray(),1e-12))
+ pass
+
+ def testSwig2Hexa8HavingFacesWarped1(self):
+ """ This test is bases on a "error" of interpolation detected. After investigation cell #3 of src is warped that leads to the fact that when trg is
+ intersected with src the sum of intersection volume is greater than the volume of the trg cell.
+ A test that can be done is to split the cell #3 of src into tetrohedrons and by summing all the volumes it does not fit the volume computed of cell#3 unsplitted (expect for
+ GENERAL_24).
+ """
+ srcCoo=DataArrayDouble([0.15694071546650565,0.09383333333333337,6.920842121738133,0.15774332475430292,0.185486666666667,6.920682472824616,0.1585459340420992,0.27713999999999994,6.9205228239111,0.07427195882345167,0.05782666666666668,6.937285959830335,0.06343673343819695,0.11347333333333297,6.939441220162809,0.05260150805294228,0.16911999999999996,6.941596480495282,0.014076262238703396,0.04800666666666667,6.949259628344076,0.014076262238703396,0.07092000000000007,6.949259628344076,0.15407499632681992,0.09383333333333338,6.897607484780063,0.15489234394181514,0.18548666666666702,6.897567331066572,0.15570969155680933,0.27714,6.897527177353081,0.06988819198237989,0.05782666666666669,6.901743317269663,0.05885399917995321,0.11347333333333298,6.9022853924017955,0.047819806377526586,0.16912,6.902827467533927,0.0085871208577874,0.048006666666666684,6.9047548457815076,0.0085871208577874,0.07092000000000008,6.9047548457815076,0.153883333333333,0.09383333333333338,6.820902,0.154701666666667,0.18548666666666702,6.820902,0.15551999999999996,0.27714,6.820902,0.06959499999999999,0.05782666666666669,6.820902,0.058547499999999975,0.11347333333333298,6.820902,0.04749999999999999,0.16912,6.820902],22,3)
+ src=MEDCouplingUMesh("TBmesh3D",3) ; src.setCoords(srcCoo)
+ src.allocateCells()
+ src.insertNextCell(NORM_HEXA8,[0,1,4,3,8,9,12,11])
+ src.insertNextCell(NORM_HEXA8,[1,2,5,4,9,10,13,12])
+ src.insertNextCell(NORM_HEXA8,[4,5,7,6,12,13,15,14])
+ src.insertNextCell(NORM_HEXA8,[8,9,12,11,16,17,20,19])
+ src.insertNextCell(NORM_HEXA8,[9,10,13,12,17,18,21,20])
+ src.checkCoherency2()
+ # trg is useless here but I keep it in case of MEDCouplingRemapper were expected to do something about warped NORM_HEXA8
+ trgCoo=DataArrayDouble([0.0960891897852753,0.105088620541845,6.8598,0.0599574480546212,0.118434267436059,6.8598,0.113514510609589,0.14874473653263,6.8598,0.0831322609794463,0.167319109733883,6.8598,0.0960891897852753,0.105088620541845,6.92146666666667,0.0599574480546212,0.118434267436059,6.92146666666667,0.113514510609589,0.14874473653263,6.92146666666667,0.0831322609794463,0.167319109733883,6.92146666666667],8,3)
+ trg=MEDCouplingUMesh("MESH",3) ; trg.setCoords(trgCoo)
+ trg.allocateCells()
+ trg.insertNextCell(NORM_HEXA8,[0,1,3,2,4,5,7,6])
+ #
+ srcFace=src.buildDescendingConnectivity()[0]
+ conn=MEDCoupling1SGTUMesh(srcFace).getNodalConnectivity() ; conn.rearrange(4)
+ eqFaces=srcFace.computePlaneEquationOf3DFaces()
+ nodeIdInCell=3
+ e=(srcFace.getCoords()[conn[:,nodeIdInCell]]*eqFaces[:,:-1]).sumPerTuple()+eqFaces[:,3]# e represent the error between the expected 'a*X+b*Y+c*Z+d' in eqFaces and 0. Closer e to 0. is closer the 4th point is to the plane built with the 3 first points
+ lambd=-e/(eqFaces[:,:3]**2).sumPerTuple()
+ pts=lambd*eqFaces[:,:-1]+srcFace.getCoords()[conn[:,nodeIdInCell]]#pts represent the projection of the last points of each NORM_QUAD4 to the plane defined by the 3 first points of the NORM_QUAD4 cell
+ shouldBeZero=(pts*eqFaces[:,:-1]).sumPerTuple()+eqFaces[:,3]# this line is useless only to be sure that pts are on the plane.
+ check=(pts-srcFace.getCoords()[conn[:,nodeIdInCell]]).magnitude() # check contains the distance of the last point to its plane
+ idsToTest=check.getIdsNotInRange(0.,1e-10)
+ self.assertTrue(idsToTest.isEqual(DataArrayInt([17,18,19,20,22,23,24])))
+ idsToTest2=idsToTest.getIdsNotInRange(18,22)
+ self.assertTrue(idsToTest2.isEqual(DataArrayInt([0,4,5,6])))
+ idsToTest2.rearrange(2)
+ self.assertTrue(idsToTest2.sumPerTuple().isEqual(DataArrayInt([4,11])))
+ pass
+
+ def testSwig2SortHexa8EachOther1(self):
+ """
+ testing MEDCoupling1SGTUMesh.sortHexa8EachOther method
+ """
+ coords1=DataArrayDouble([(-0.5,0.5,-0.5),(0.5,-0.5,-0.5),(-0.5,-0.5,0.5),(-0.5,-0.5,-0.5),(0.5,-0.5,0.5),(-0.5,0.5,0.5),(0.5,0.5,0.5),(0.5,0.5,-0.5)])
+ m1=MEDCouplingUMesh("m1",3) ; m1.setCoords(coords1)
+ m1.allocateCells() ; m1.insertNextCell(NORM_HEXA8,[7,1,3,0,6,4,2,5])
+ m1.checkCoherency()
+ #
+ m2=m1.deepCpy() ; m2.setName("m2")
+ #
+ trs=[[0.,0.,-1.],[0.,0.,1.],[1.,0.,0.],[0.,-1.,0.],[-1.,0.,0.],[0.,1.,0.]]
+ for i,t in enumerate(trs):
+ for j in xrange(64):
+ j2=(j//16) ; j1=((j%16)//4) ; j0=(j%4)
+ m11=m1.deepCpy()
+ m11.rotate([0.,0.,0.],[0.,0.,1.],float(j0)*pi/2)
+ m11.rotate([0.,0.,0.],[0.,1.,0.],float(j1)*pi/2)
+ m11.rotate([0.,0.,0.],[1.,0.,0.],float(j2)*pi/2)
+ m11.translate(t)
+ #
+ m=MEDCouplingUMesh.MergeUMeshes(m2,m11)
+ m.mergeNodes(1e-12)
+ self.assertEqual(12,m.getNumberOfNodes())
+ m=MEDCoupling1SGTUMesh(m)
+ m.sortHexa8EachOther()
+ tmp0=m.buildUnstructured().tetrahedrize(PLANAR_FACE_6)[0].buildUnstructured()
+ self.assertEqual(20,tmp0.computeSkin().getNumberOfCells())
+ pass
+ pass
+ pass
+
+ def testSwig2normMinComputeAbs1(self):
+ d=DataArrayDouble([4,-5,2,6.1,-7.33,1,-1,3e2,0.07,-0.009,-6,-1e30],4,3)
+ d.setInfoOnComponents(["XX [m]","YYY [km]","ABSJJ [MW]"])
+ d0=d.computeAbs()
+ dExp=d.deepCpy() ; dExp.abs()
+ self.assertTrue(dExp.isEqual(d0,1e-12))
+ e=d0-DataArrayDouble([4,5,2,6.1,7.33,1,1,3e2,0.07,0.009,6,1e30],4,3)
+ self.assertAlmostEqual(0.,e.normMin(),13)
+ self.assertAlmostEqual(0.009,d.normMin(),13)
+ #
+ di=DataArrayInt([3,-12,5,6,14,16,-23,100,23,-1,0,-6],4,3)
+ di.setInfoOnComponents(["XX [m]","YYY [km]","ABSJJ [MW]"])
+ d0i=di.computeAbs()
+ diExp=di.deepCpy() ; diExp.abs()
+ self.assertTrue(diExp.isEqual(d0i))
+ self.assertEqual([3,12,5,6,14,16,23,100,23,1,0,6],d0i.getValues())
+ pass
+
+ def testSwig2GetCellsContainingPointsForNonConvexPolygon1(self):
+ coo=DataArrayDouble([-0.5,-0.5,-0.5,0.5,0.5,0.5,0.5,-0.5,0.,-0.5,0.,0.,0.5,0.,],7,2)
+ m=MEDCouplingUMesh("Intersect2D",2) ; m.setCoords(coo) ; m.allocateCells()
+ m.insertNextCell(NORM_POLYGON,[6,3,4,5])
+ m.insertNextCell(NORM_POLYGON,[4,0,1,2,6,5])
+ m.checkCoherency2()
+ #
+ self.assertTrue(m.getCellsContainingPoint((0.4,-0.4),1e-12).isEqual(DataArrayInt([0])))
+ self.assertTrue(m.getCellsContainingPoint((-0.4,-0.4),1e-12).isEqual(DataArrayInt([1])))
+ self.assertTrue(m.getCellsContainingPoint((0.,-0.4),1e-12).isEqual(DataArrayInt([0,1])))
+ pass
+
+ def testSwig2GetCellsContainingPointsForNonConvexPolygon2(self):
+ coo=DataArrayDouble([-0.5,-0.5,-0.5,0.5,0.5,0.5,0.5,-0.5,-2.0816681711721685e-17,-2.0816681711721685e-17,-0.17677669529663687,0.1767766952966369,0.,0.5,0.5,0.,0.17677669529663684,-0.17677669529663692,0.17677669529663692,0.17677669529663684,-0.17677669529663692,-0.17677669529663687,0.,-0.5,-0.5,0.,0.33838834764831843,-0.3383883476483185,-0.33838834764831843,0.33838834764831843,-0.21213203435596423,0.21213203435596426,0.2121320343559642,-0.2121320343559643,0.21213203435596426,0.2121320343559642,-0.21213203435596423,-0.21213203435596428,0.3560660171779821,-0.35606601717798214,-0.35606601717798214,0.35606601717798214,0.19445436482630052,-0.19445436482630063,-0.19445436482630055,0.19445436482630057,0.,0.27],24,2)
+ m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) ; m.allocateCells()
+ m.insertNextCell(NORM_QPOLYG,[8,5,4,9])
+ m.insertNextCell(NORM_QPOLYG,[5,8,4,10])
+ m.insertNextCell(NORM_QPOLYG,[16,8,5,15,21,9,22,17])
+ m.insertNextCell(NORM_QPOLYG,[15,1,2,3,16,20,6,7,19,17])
+ m.insertNextCell(NORM_QPOLYG,[15,5,8,16,22,10,21,18])
+ m.insertNextCell(NORM_QPOLYG,[16,3,0,1,15,19,11,12,20,18])
+ m.checkCoherency2()
+ self.assertTrue(m.getCellsContainingPoint([0.,0.27],1e-12).isEqual(DataArrayInt([2])))
+ pass
+
+ def testSwig2DAIGetIdsEqualTuple1(self):
+ da=DataArrayInt([0,7,1,2,4,1,2,1,1,2,0,1,2,1,5,1,1,2],9,2)
+ self.assertTrue(da.getIdsEqualTuple([1,2]).isEqual(DataArrayInt([1,4,8])))
+ self.assertTrue(da.getIdsEqualTuple((1,2)).isEqual(DataArrayInt([1,4,8])))
+ self.assertTrue(da.getIdsEqualTuple(DataArrayInt([1,2])).isEqual(DataArrayInt([1,4,8])))
+ da.rearrange(3)
+ self.assertRaises(InterpKernelException,da.getIdsEqualTuple,[1,2])# mismatch nb of compo (3) and nb of elts in input tuple (2)
+ self.assertTrue(da.getIdsEqualTuple([2,0,1]).isEqual(DataArrayInt([3])))
+ self.assertTrue(da.getIdsEqualTuple([2,0,7]).isEqual(DataArrayInt([])))
+ da.rearrange(1)
+ self.assertTrue(da.getIdsEqualTuple(2).isEqual(DataArrayInt([3,6,9,12,17])))
+ self.assertTrue(da.getIdsEqualTuple(2).isEqual(da.getIdsEqual(2)))
+ pass
+
+ def testSwig2GaussNEStaticInfo1(self):
+ self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetWeightArrayFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.16666666666666666,0.16666666666666666,0.16666666666666666]),1e-12))
+ self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetRefCoordsFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.,0.,1.,0.,0.,1.]),1e-12))
+ self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetLocsFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.16666666666666666,0.16666666666666666,0.6666666666666667,0.16666666666666666,0.16666666666666666,0.6666666666666667]),1e-12))
+ pass
+
+ def testSwigReverseNodalConnOnStructuredMesh(self):
+ # 1D - standard
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota()
+ c.setCoordsAt(0,arr)
+ rn,rni=c.getReverseNodalConnectivity()
+ rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
+ self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+ # 1D - limit
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(1) ; arr.iota()
+ c.setCoordsAt(0,arr)
+ rn,rni=c.getReverseNodalConnectivity()
+ rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1])))
+ self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+ # 1D - limit
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(0) ; arr.iota()
+ c.setCoordsAt(0,arr)
+ rn,rni=c.getReverseNodalConnectivity()
+ rn.isEqual(DataArrayInt([]))
+ rni.isEqual(DataArrayInt([0]))
+ # 2D - standard
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota() ; arr2=DataArrayDouble(4) ; arr.iota()
+ c.setCoords(arr,arr2)
+ rn,rni=c.getReverseNodalConnectivity()
+ rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,0,4,0,1,4,5,1,2,5,6,2,3,6,7,3,7,4,8,4,5,8,9,5,6,9,10,6,7,10,11,7,11,8,8,9,9,10,10,11,11])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,8,10,14,18,22,24,26,30,34,38,40,41,43,45,47,48])))
+ self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+ # 2D - limit
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota() ; arr2=DataArrayDouble(1) ; arr.iota()
+ c.setCoords(arr,arr2)
+ rn,rni=c.getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
+ # 2D - limit
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota() ; arr2=DataArrayDouble(1) ; arr.iota()
+ c.setCoords(arr2,arr)
+ rn,rni=c.getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
+ # 3D - standard
+ c=MEDCouplingCMesh() ; arr0=DataArrayDouble(5) ; arr0.iota() ; arr1=DataArrayDouble(3) ; arr1.iota() ; arr2=DataArrayDouble(4) ; arr2.iota()
+ c.setCoords(arr0,arr1,arr2)
+ rn,rni=c.getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,0,4,0,1,4,5,1,2,5,6,2,3,6,7,3,7,4,4,5,5,6,6,7,7,0,8,0,1,8,9,1,2,9,10,2,3,10,11,3,11,0,4,8,12,0,1,4,5,8,9,12,13,1,2,5,6,9,10,13,14,2,3,6,7,10,11,14,15,3,7,11,15,4,12,4,5,12,13,5,6,13,14,6,7,14,15,7,15,8,16,8,9,16,17,9,10,17,18,10,11,18,19,11,19,8,12,16,20,8,9,12,13,16,17,20,21,9,10,13,14,17,18,21,22,10,11,14,15,18,19,22,23,11,15,19,23,12,20,12,13,20,21,13,14,21,22,14,15,22,23,15,23,16,16,17,17,18,18,19,19,16,20,16,17,20,21,17,18,21,22,18,19,22,23,19,23,20,20,21,21,22,22,23,23])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,8,10,14,18,22,24,25,27,29,31,32,34,38,42,46,48,52,60,68,76,80,82,86,90,94,96,98,102,106,110,112,116,124,132,140,144,146,150,154,158,160,161,163,165,167,168,170,174,178,182,184,185,187,189,191,192])))
+ rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+ pass
+
+ def testSwig2CellToNodeDiscretization1(self):
+ m=MEDCouplingCMesh() ; arr0=DataArrayDouble(5) ; arr0.iota() ; arr1=DataArrayDouble(4) ; arr1.iota() ; m.setCoords(arr0,arr1)
+ f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m) ; f.setTime(1.1,5,6)
+ arr=DataArrayDouble(12) ; arr.iota()
+ arr=DataArrayDouble.Meld(arr,arr+100.) ; arr.setInfoOnComponents(["aaa","bbb"])
+ f.setArray(arr)
+ f.checkCoherency()
+ #
+ ref=DataArrayDouble([0.,0.5,1.5,2.5,3.,2.,2.5,3.5,4.5,5.,6.,6.5,7.5,8.5,9.,8.,8.5,9.5,10.5,11.])
+ ref=DataArrayDouble.Meld(ref,ref+100.) ; ref.setInfoOnComponents(["aaa","bbb"])
+ f2=f.cellToNodeDiscretization()
+ f2.checkCoherency()
+ self.assertEqual(f2.getTime()[1:],[5,6])
+ self.assertAlmostEqual(f2.getTime()[0],1.1,15)
+ self.assertEqual(f2.getMesh().getHiddenCppPointer(),m.getHiddenCppPointer())
+ self.assertTrue(f2.getArray().isEqual(ref,1e-12))
+ rn,rni=m.getReverseNodalConnectivity()
+ rni2=(rni.deltaShiftIndex()).convertToDblArr()
+ arr2=(f.getArray()[rn]).accumulatePerChunck(rni)/rni2
+ self.assertTrue(f2.getArray().isEqual(arr2,1e-12))
+ del f2
+ #
+ u=m.buildUnstructured() ; f.setMesh(u) ; del m
+ f3=f.cellToNodeDiscretization()
+ f3.checkCoherency()
+ self.assertEqual(f3.getTime()[1:],[5,6])
+ self.assertAlmostEqual(f3.getTime()[0],1.1,15)
+ self.assertEqual(f3.getMesh().getHiddenCppPointer(),u.getHiddenCppPointer())
+ self.assertTrue(f3.getArray().isEqual(ref,1e-12))
+ pass
+
+ def testSwig2GetMeshSpaceDimensionCMesh1(self):
+ c=MEDCouplingCMesh()
+ arr0=DataArrayDouble([0,1,2])
+ arr1=DataArrayDouble([0])
+ c.setCoords(arr0,arr0,arr0)
+ self.assertEqual(c.getMeshDimension(),3)
+ self.assertEqual(c.getSpaceDimension(),3)
+ #
+ c.setCoords(arr0,arr0,arr1)
+ self.assertEqual(c.getMeshDimension(),2)
+ self.assertEqual(c.getSpaceDimension(),3)
+ #
+ c.setCoords(arr0,arr0)
+ self.assertEqual(c.getMeshDimension(),2)
+ self.assertEqual(c.getSpaceDimension(),2)
+ #
+ c.setCoords(arr0,arr1)
+ self.assertEqual(c.getMeshDimension(),1)
+ self.assertEqual(c.getSpaceDimension(),2)
+ #
+ c.setCoords(arr0)
+ self.assertEqual(c.getMeshDimension(),1)
+ self.assertEqual(c.getSpaceDimension(),1)
+ #
+ c.setCoords(arr1)
+ self.assertEqual(c.getMeshDimension(),0)
+ self.assertEqual(c.getSpaceDimension(),1)
+ pass
+