+
+ def testRemapperAMR1(self):
+ """ This test is the origin of the ref values for MEDCouplingBasicsTest.testAMR2"""
+ coarse=DataArrayDouble(35) ; coarse.iota(0) #X=5,Y=7
+ fine=DataArrayDouble(3*2*4*4) ; fine.iota(0) #X=3,Y=2 refined by 4
+ MEDCouplingIMesh.CondenseFineToCoarse([5,7],fine,[(1,4),(2,4)],[4,4],coarse)
+ #
+ m=MEDCouplingCartesianAMRMesh("mesh",2,[6,8],[0.,0.],[1.,1.])
+ trgMesh=m.buildUnstructured()
+ m.addPatch([(1,4),(2,4)],[4,4])
+ srcMesh=m[0].getMesh().buildUnstructured()
+ srcField=MEDCouplingFieldDouble(ON_CELLS)
+ fine2=DataArrayDouble(3*2*4*4) ; fine2.iota(0) ; srcField.setArray(fine2)
+ srcField.setMesh(srcMesh) ; srcField.setNature(ExtensiveMaximum)
+ #
+ trgField=MEDCouplingFieldDouble(ON_CELLS)
+ coarse2=DataArrayDouble(35) ; coarse2.iota(0) ; trgField.setArray(coarse2)
+ trgField.setMesh(trgMesh) ; trgField.setNature(ExtensiveMaximum)
+ #
+ rem=MEDCouplingRemapper()
+ rem.prepare(srcMesh,trgMesh,"P0P0")
+ rem.partialTransfer(srcField,trgField)
+ #
+ self.assertTrue(coarse.isEqual(trgField.getArray(),1e-12))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings() and MEDCouplingHasSciPyBindings(),"requires numpy AND scipy")
+ def test1DPointLocator1(self):
+ """This test focuses on PointLocator for P1P1 in 1D and 2DCurve."""
+ from numpy import array
+ from scipy.sparse import diags,csr_matrix,identity
+ ## basic case 1D
+ arrS=DataArrayInt.Range(0,11,1).convertToDblArr()
+ arrT=DataArrayDouble([0.1,1.7,5.5,9.6])
+ mS=MEDCouplingCMesh() ; mS.setCoords(arrS)
+ mT=MEDCouplingCMesh() ; mT.setCoords(arrT)
+ rem=MEDCouplingRemapper()
+ rem.setIntersectionType(PointLocator)
+ self.assertEqual(rem.prepare(mS.buildUnstructured(),mT.buildUnstructured(),"P1P1"),1)
+ m=rem.getCrudeCSRMatrix()
+ rowSum=m.sum(axis=1)
+ m=diags(array(1/rowSum.transpose()),[0])*m
+ # expected matrix
+ row=array([0,0,1,1,2,2,3,3])
+ col=array([0,1,1,2,5,6,9,10])
+ data=array([0.9,0.1,0.3,0.7,0.5,0.5,0.4,0.6])
+ mExp0=csr_matrix((data,(row,col)),shape=(4,11))
+ # compute diff and check
+ diff=abs(m-mExp0)
+ self.assertAlmostEqual(diff.sum(),0.,14)
+ ## full specific case 1D where target=source
+ rem=MEDCouplingRemapper()
+ rem.setIntersectionType(PointLocator)
+ self.assertEqual(rem.prepare(mS.buildUnstructured(),mS.buildUnstructured(),"P1P1"),1)
+ m=rem.getCrudeCSRMatrix()
+ rowSum=m.sum(axis=1)
+ m=diags(array(1/rowSum.transpose()),[0])*m
+ # expected matrix
+ mExp1=identity(11)
+ diff=abs(m-mExp1)
+ self.assertAlmostEqual(diff.sum(),0.,14)
+ ## case where some points in target are not in source
+ arrT=DataArrayDouble([-0.2,0.1,1.7,5.5,10.3])
+ mT=MEDCouplingCMesh() ; mT.setCoords(arrT)
+ mT=mT.buildUnstructured()
+ rem=MEDCouplingRemapper()
+ rem.setIntersectionType(PointLocator)
+ self.assertEqual(rem.prepare(mS.buildUnstructured(),mT,"P1P1"),1)
+ m=rem.getCrudeCSRMatrix()
+ row=array([1,1,2,2,3,3])
+ col=array([0,1,1,2,5,6])
+ data=array([0.9,0.1,0.3,0.7,0.5,0.5])
+ mExp2=csr_matrix((data,(row,col)),shape=(5,11))
+ diff=abs(m-mExp2)
+ self.assertAlmostEqual(diff.sum(),0.,14)
+ ## basic case 2D Curve
+ arrS=DataArrayInt.Range(0,11,1).convertToDblArr()
+ arrT=DataArrayDouble([0.1,1.7,5.5,9.6])
+ mS=MEDCouplingCMesh() ; mS.setCoords(arrS)
+ mT=MEDCouplingCMesh() ; mT.setCoords(arrT)
+ mS=mS.buildUnstructured() ; mS.changeSpaceDimension(2)
+ mT=mT.buildUnstructured() ; mT.changeSpaceDimension(2)
+ mS.rotate([-1.,-1.],1.2)
+ mT.rotate([-1.,-1.],1.2)
+ rem=MEDCouplingRemapper()
+ rem.setIntersectionType(PointLocator)
+ self.assertEqual(rem.prepare(mS,mT,"P1P1"),1)
+ m=rem.getCrudeCSRMatrix()
+ rowSum=m.sum(axis=1)
+ m=diags(array(1/rowSum.transpose()),[0])*m
+ diff=abs(m-mExp0)
+ self.assertAlmostEqual(diff.sum(),0.,14)
+ pass
+
+ def test3D2Dand2D3DPointLocator1(self):
+ """ Non regression test solving SIGSEGV when using 3D<->3Dsurf pointlocator."""
+ arrX=DataArrayDouble([0,1,2])
+ arrY=DataArrayDouble([0,1])
+ arrZ=DataArrayDouble([0,1])
+ ms=MEDCouplingCMesh() ; ms.setCoords(arrX,arrY,arrZ)
+ ms=ms.buildUnstructured() ; ms.setName("source")
+ #
+ mt=MEDCouplingUMesh("target",2) ; mt.allocateCells()
+ mt.insertNextCell(NORM_TRI3,[0,4,6])
+ mt.insertNextCell(NORM_TRI3,[1,5,7])
+ mt.setCoords(ms.getCoords()[:])
+ mt.zipCoords()
+ #
+ rem=MEDCouplingRemapper()
+ rem.setIntersectionType(PointLocator)
+ rem.prepare(ms,mt,"P0P0")
+ self.assertEqual(rem.getCrudeMatrix(),[{0: 1.0}, {1: 1.0}])
+ rem2=MEDCouplingRemapper()
+ rem2.setIntersectionType(PointLocator)
+ ##
+ # 2D to 3D with point locator does not make sense:
+ ##
+ self.assertRaises(InterpKernelException, rem2.prepare,mt,ms,"P0P0")
+ pass
+
+ def test2D1Dand1D2DPointLocator1(self):
+ arrX=DataArrayDouble([0,1,2])
+ arrY=DataArrayDouble([0,1])
+ ms=MEDCouplingCMesh() ; ms.setCoords(arrX,arrY) ; ms=ms.buildUnstructured()
+ mt=MEDCouplingUMesh("target",1) ; mt.setCoords(ms.getCoords()[:])
+ mt.allocateCells()
+ mt.insertNextCell(NORM_SEG2,[0,4]) ; mt.insertNextCell(NORM_SEG2,[1,5])
+ rem=MEDCouplingRemapper()
+ rem.setIntersectionType(PointLocator)
+ rem.prepare(ms,mt,"P0P0")
+ self.assertEqual(rem.getCrudeMatrix(),[{0:1.},{1:1.}])
+ rem=MEDCouplingRemapper()
+ rem.setIntersectionType(PointLocator)
+ rem.prepare(mt,ms,"P0P0")
+ self.assertEqual(rem.getCrudeMatrix(),[{0:1.},{1:1.}])
+ pass
+
+ def test3D1DPointLocatorBBoxAdjusted(self):
+ """ In case a 1D segment lies exactly on the interface between two 2D (or 3D) faces, the default
+ bounding box logic will make it non-intersecting with the surrounding 2D (or 3D) faces.
+ Test bounding box adjustment allowing to widen the BB to capture this.
+ """
+ m = MEDCouplingCMesh("source")
+ di, dd = DataArrayInt, DataArrayDouble
+ m.setCoordsAt(0, dd([0.0, 1.0, 2.0]))
+ m.setCoordsAt(1, dd([0.0, 1.0]))
+ m.setCoordsAt(2, dd([0.0, 1.0]))
+ m3d = m.buildUnstructured()
+ m1d = MEDCouplingUMesh("target", 1)
+ m1d.setCoords(dd([1.0,0.5,0.2 , 1.0,0.5,0.8], 2,3))
+ m1d.setConnectivity(di([NORM_SEG2, 0, 1]), di([0,3]))
+
+ rem = MEDCouplingRemapper()
+ rem.setPrecision(1e-12)
+ rem.setIntersectionType(PointLocator)
+ rem.prepare(m3d, m1d,"P0P1")
+ self.assertEqual(rem.getCrudeMatrix(), [{0: 1.0, 1: 1.0}, {0: 1.0, 1: 1.0}])
+
+ rem = MEDCouplingRemapper()
+ rem.setPrecision(1e-12)
+ rem.setIntersectionType(PointLocator)
+ rem.setBoundingBoxAdjustment(0.0)
+ rem.setBoundingBoxAdjustmentAbs(0.0)
+ rem.prepare(m3d, m1d,"P0P1")
+ self.assertEqual(rem.getCrudeMatrix(), [{}, {}])
+ pass
+
+ def testPointLocator3DTo2D(self):
+ """Target mesh has spaceDim==3 and meshDim==2. Source has spaceDim==3 and meshDim==3. Here we are on pointlocator alg.
+ The test evaluates on each nodes of target mesh the bary coor into source mesh."""
+ src=MEDCouplingCMesh()
+ arr=DataArrayDouble([0,1,2])
+ src.setCoords(arr,arr,arr)
+ src=src.buildUnstructured()
+ src.simplexize(PLANAR_FACE_5)
+ fsrc=MEDCouplingFieldDouble(ON_NODES) ; fsrc.setMesh(src)
+ fsrc.setArray(DataArrayDouble([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]))
+ #
+ trg=MEDCouplingCMesh()
+ arr=DataArrayDouble([0,1])
+ trg.setCoords(arr,arr)
+ trg=trg.buildUnstructured()
+ trg.changeSpaceDimension(3,0.)
+ trg.translate([0.5,0.5,0.5])
+ #
+ arrTrg=fsrc.getValueOnMulti(trg.getCoords())
+ ftrg=MEDCouplingFieldDouble(ON_NODES)
+ ftrg.setMesh(trg)
+ ftrg.setArray(arrTrg)
+ ftrg.checkConsistencyLight()
+ ftrg.setNature(IntensiveMaximum)
+ #
+ fsrc.setNature(IntensiveMaximum)
+ remap=MEDCouplingRemapper()
+ remap.setIntersectionType(PointLocator)
+ self.assertEqual(remap.prepare(src,trg,"P1P1"),1)
+ ftrg2=remap.transferField(fsrc,1e300)
+ self.assertTrue(ftrg.isEqual(ftrg2,1e-12,1e-12))
+ pass
+
+ def testExtrudedOnDiffZLev1(self):
+ """Non regression bug : This test is base on P0P0 ExtrudedExtruded. This test checks that if the input meshes are not based on a same plane // OXY the interpolation works"""
+ arrX=DataArrayDouble([0,1]) ; arrY=DataArrayDouble([0,1]) ; arrZ=DataArrayDouble([0,1,2])
+ src=MEDCouplingCMesh() ; src.setCoords(arrX,arrY,arrZ)
+ arrX=DataArrayDouble([0.5,1.5]) ; arrY=DataArrayDouble([0.5,1.5]) ; arrZ=DataArrayDouble([0.5,2])
+ trg=MEDCouplingCMesh() ; trg.setCoords(arrX,arrY,arrZ)
+ #
+ src=MEDCouplingMappedExtrudedMesh(src) ; trg=MEDCouplingMappedExtrudedMesh(trg)
+ pt1=src.getMesh2D().getCoords().getHiddenCppPointer() ; pt2=trg.getMesh2D().getCoords().getHiddenCppPointer()
+ #
+ rem=MEDCouplingRemapper()
+ rem.prepare(src,trg,"P0P0")
+ self.checkMatrix(rem.getCrudeMatrix(),[{0:0.125,1:0.25}],src.getNumberOfCells(),1e-12)
+ #
+ self.assertEqual(src.getMesh2D().getSpaceDimension(),3)
+ self.assertEqual(trg.getMesh2D().getSpaceDimension(),3)
+ self.assertEqual(src.getMesh2D().getCoords().getHiddenCppPointer(),pt1)
+ self.assertEqual(trg.getMesh2D().getCoords().getHiddenCppPointer(),pt2)
+ #
+ rem2=MEDCouplingRemapper()
+ rem2.setIntersectionType(Geometric2D)
+ rem2.prepare(src,trg,"P0P0")
+ self.checkMatrix(rem2.getCrudeMatrix(),[{0:0.125,1:0.25}],src.getNumberOfCells(),1e-12)
+ pass
+
+ def testP0P0WithHEXGP12(self):
+ """ Test that HEXGP12 are correctly remapped (elements with polygonal faces were not properly handled) """
+ # From Astrid, two disjoint hexagonal prisms:
+ coo1 = [-4.991193077144312, 8.644999999999998, 0.0, -9.982386154288623, 6.112246755425186e-16, 0.0, -4.991193077144315, -8.644999999999998, 0.0, 4.991193077144309, -8.645000000000005, 0.0, 9.982386154288626, 1.1651321638577316e-15, 0.0, 4.991193077144314, 8.645, 0.0, -4.991193077144312, 8.644999999999998, 7.561799999999991, -9.982386154288623, 6.112246755425186e-16, 7.561799999999991, -4.991193077144315, -8.644999999999998, 7.561799999999991, 4.991193077144309, -8.645000000000005, 7.561799999999991, 9.982386154288626, 1.1651321638577316e-15, 7.561799999999991, 4.991193077144314, 8.645, 7.561799999999991]
+ coo2 = [-4.991193077144313, -8.645, 0.0, -9.982386154288626, -1.3992140779350848e-15, 0.0, -19.964772308577256, 0.0, 0.0, -24.95596538572157, -8.644999999999998, 0.0, -19.96477230857726, -17.289999999999996, 0.0, -9.982386154288626, -17.289999999999996, 0.0, -4.991193077144313, -8.645, 5.041200000000004, -9.982386154288626, -1.3992140779350848e-15, 5.041200000000004, -19.964772308577256, 0.0, 5.041200000000004, -24.95596538572157, -8.644999999999998, 5.041200000000004, -19.96477230857726, -17.289999999999996, 5.041200000000004, -9.982386154288626, -17.289999999999996, 5.041200000000004]
+ conn1 = [31, 0, 5, 4, 3, 2, 1, -1, 11, 6, 7, 8, 9, 10, -1, 1, 7, 6, 0, -1, 2, 8, 7, 1, -1, 3, 9, 8, 2, -1, 4, 10, 9, 3, -1, 5, 11, 10, 4, -1, 0, 6, 11, 5]
+ cI1 = [0, 44]
+ conn2 = [31, 0, 5, 4, 3, 2, 1, -1, 6, 7, 8, 9, 10, 11, -1, 0, 1, 7, 6, -1, 1, 2, 8, 7, -1, 2, 3, 9, 8, -1, 3, 4, 10, 9, -1, 4, 5, 11, 10, -1, 5, 0, 6, 11]
+ cI2 = [0, 44]
+ mTgt = MEDCouplingUMesh("target", 3)
+ mSrc = MEDCouplingUMesh("src", 3)
+ mTgt.setCoords(DataArrayDouble(coo1, len(coo1) // 3, 3))
+ mSrc.setCoords(DataArrayDouble(coo2, len(coo2) // 3, 3))
+ mTgt.setConnectivity(DataArrayInt(conn1), DataArrayInt(cI1))
+ mSrc.setConnectivity(DataArrayInt(conn2), DataArrayInt(cI2))
+
+ # Recognize the HEXGP12:
+ mTgt.unPolyze()
+ mSrc.unPolyze()
+
+ rmp = MEDCouplingRemapper()
+ rmp.setIntersectionType(Triangulation)
+ rmp.prepare(mSrc, mTgt, "P0P0")
+ mat = rmp.getCrudeMatrix()
+ self.assertEqual(len(mat[0]), 0)
+ self.assertEqual(len(mat), 1)
+ pass
+
+ def testP0P0KillerTet(self):
+ """ The killer tetrahedron detected by LMEC!"""
+ mesh = MEDCouplingUMesh('SupportOf_ECHIA1_Tin', 3)
+# # was OK:
+# coo = DataArrayDouble([(-4.50135,1.95352,4.59608),(-4.50409,1.86642,4.54551), (-4.55175,1.92167,4.64844),(-4.58813,1.94795,4.5283)])
+ # was KO:
+ coo = DataArrayDouble([(-4.501352938826142847,1.953517433537110159,4.596082552008083688),(-4.504092113061189728,1.866415526007169978,4.545507396150389567),(-4.551750368181751050,1.921669328035479962,4.648439577911889664),(-4.588131417812300050,1.947948377683889953,4.528298931319220344)])
+ mesh.setCoords(coo)
+ c = DataArrayInt([14, 2, 0, 3, 1]); cI = DataArrayInt([0, 5])
+ mesh.setConnectivity(c, cI)
+ mesh_src, mesh_tgt = mesh.deepCopy(), mesh.deepCopy()
+ field_src = mesh_src.fillFromAnalytic(ON_CELLS, 1, "1")
+ field_src.setNature(IntensiveMaximum)
+ rmp = MEDCouplingRemapper()
+ rmp.setIntersectionType(Triangulation)
+ rmp.prepare(mesh_src, mesh_tgt, "P0P0")
+ self.assertEqual(1, len(rmp.getCrudeMatrix()))
+ self.assertEqual(1, len(rmp.getCrudeMatrix()[0]))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings() and MEDCouplingHasSciPyBindings(),"requires numpy AND scipy AND C++11")
+ def testP1P1PL3DSpaceFrom1DTo0D(self):
+ from scipy.sparse import csr_matrix
+ from numpy import array
+
+ def generateTrg(eps):
+ trgArr=DataArrayDouble([(0.5,0.5,0.5),(0.2,0.2,0.2),(0.9,0.9,0.9),(0.7+eps*sqrt(3),0.7-eps*sqrt(3),0.7)])
+ trg=MEDCouplingUMesh("trg",0) ; trg.setCoords(trgArr)
+ trg.allocateCells()
+ RenumTrg=[2,3,0,1]
+ for rt in RenumTrg:
+ trg.insertNextCell(NORM_POINT1,[rt])
+ return trg
+
+ srcArr=DataArrayDouble([(0.,0.,1.),(0.,0.,0.),(1.,1.,1.)])
+ src=MEDCouplingUMesh("src",1) ; src.setCoords(srcArr)
+ src.allocateCells()
+ src.insertNextCell(NORM_SEG2,[1,2])
+ #
+ trg=generateTrg(1e-7)# trg point 3 of trg cell 1 is NOT closer enough to source edge #1 -> not intercepted
+ #
+ rem=MEDCouplingRemapper()
+ rem.setIntersectionType(PointLocator)
+ self.assertEqual(rem.prepare(src,trg,"P1P1"),1)
+ mat=rem.getCrudeCSRMatrix()
+ row=array([2,2, 0,0, 1,1]) # here no ref to point 3 !
+ col=array([1,2, 1,2, 1,2])
+ data=array([0.1,0.9, 0.5,0.5, 0.8,0.2])
+ mExp=csr_matrix((data,(row,col)),shape=(4,3))
+ delta=abs(mExp-mat)
+ self.assertAlmostEqual(delta.sum(),0.,14)
+ #
+ trg=generateTrg(1e-14) # trg point 3 of trg cell 1 is closer enough to source edge #1 -> intercepted
+ rem=MEDCouplingRemapper()
+ rem.setIntersectionType(PointLocator)
+ self.assertEqual(rem.prepare(src,trg,"P1P1"),1)
+ mat=rem.getCrudeCSRMatrix()
+ row=array([2,2, 3,3, 0,0, 1,1]) # here ref to target point 3
+ col=array([1,2, 1,2, 1,2, 1,2])
+ data=array([0.1,0.9, 0.3,0.7, 0.5,0.5, 0.8,0.2])
+ mExp2=csr_matrix((data,(row,col)),shape=(4,3))
+ delta2=abs(mExp2-mat)
+ self.assertAlmostEqual(delta2.sum(),0.,14)
+ pass
+
+ def testSetMatrix1(self):
+ """ Remapper has now setCrudeMatrix method to reload matrix to skip prepare phase """
+ cooS=DataArrayDouble([1,1, 7,1, 7,2, 1,2],4,2)
+ cooT=DataArrayDouble([0,0, 3,0, 3,3, 0,3, 6,0, 12,0, 12,3, 6,3],8,2)
+ ms=MEDCouplingUMesh("source",2) ; ms.allocateCells(1) ; ms.insertNextCell(NORM_QUAD4,[0,1,2,3]) ; ms.setCoords(cooS)
+ mt=MEDCouplingUMesh("target",2) ; mt.allocateCells(2) ; mt.insertNextCell(NORM_QUAD4,[0,1,2,3]) ; mt.insertNextCell(NORM_QUAD4,[4,5,6,7]) ; mt.setCoords(cooT)
+ rem=MEDCouplingRemapper()
+ self.assertEqual(rem.prepare(ms,mt,"P0P0"),1) # [{0: 2.0}, {0: 1.0}]
+ fs=MEDCouplingFieldDouble(ON_CELLS)
+ fs.setMesh(ms)
+ fs.setArray(DataArrayDouble([10]))
+ fs.checkConsistencyLight()
+ #
+ fs.setNature(ExtensiveConservation)
+ self.assertTrue(rem.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([20./3,10./3.]),1e-12))# sum is equal to 10. First value is twice than second value
+ #
+ fs.setNature(ExtensiveMaximum)
+ self.assertTrue(rem.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([20./6.,10./6.]),1e-12))#sum is equal to 5 (10/2. because only half part on input cell is intercepted by the target cells). First value is twice than second value
+ #
+ fs.setNature(IntensiveConservation)
+ self.assertTrue(rem.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([2./9.*10.,1./18.*10.]),1e-12))#
+ #
+ fs.setNature(IntensiveMaximum)
+ self.assertTrue(rem.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([10.,10.]),1e-12))#
+ ####
+ rem2=MEDCouplingRemapper()
+ rem2.setCrudeMatrix(ms,mt,"P0P0",rem.getCrudeMatrix())
+ fs.setNature(ExtensiveConservation)
+ self.assertTrue(rem2.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([20./3,10./3.]),1e-12))
+ #
+ fs.setNature(ExtensiveMaximum)
+ self.assertTrue(rem2.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([20./6.,10./6.]),1e-12))
+ #
+ fs.setNature(IntensiveConservation)
+ self.assertTrue(rem2.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([2./9.*10.,1./18.*10.]),1e-12))
+ #
+ fs.setNature(IntensiveMaximum)
+ self.assertTrue(rem2.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([10.,10.]),1e-12))
+ #
+ srcFt=MEDCouplingFieldTemplate.New(ON_CELLS);
+ trgFt=MEDCouplingFieldTemplate.New(ON_CELLS);
+ srcFt.setMesh(ms);
+ trgFt.setMesh(mt);
+ rem3=MEDCouplingRemapper()
+ rem3.setCrudeMatrixEx(srcFt,trgFt,rem.getCrudeMatrix())
+ fs.setNature(ExtensiveConservation)
+ self.assertTrue(rem3.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([20./3,10./3.]),1e-12))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings() and MEDCouplingHasSciPyBindings(),"requires numpy AND scipy")
+ def testSetMatrix2(self):
+ """ Remapper has now setCrudeMatrix method to reload matrix to skip prepare phase. Same as testSetMatrix1 but with CSR scipy matrix """
+ arrx_s=DataArrayDouble(6) ; arrx_s.iota()
+ arry_s=DataArrayDouble(6) ; arry_s.iota()
+ ms=MEDCouplingCMesh() ; ms.setCoords(arrx_s,arry_s)
+ ms=ms.buildUnstructured()
+ #
+ arrx_t=DataArrayDouble([2.5,4.5,5.5])
+ arry_t=DataArrayDouble([2.5,3.5,5.5])
+ mt=MEDCouplingCMesh() ; mt.setCoords(arrx_t,arry_t)
+ mt=mt.buildUnstructured()
+ #
+ rem=MEDCouplingRemapper()
+ self.assertEqual(rem.prepare(ms,mt,"P0P0"),1)
+ #
+ fs=MEDCouplingFieldDouble(ON_CELLS)
+ fs.setMesh(ms)
+ arr=DataArrayDouble(25) ; arr.iota()
+ fs.setArray(arr)
+ fs.checkConsistencyLight()
+ #
+ fs.setNature(ExtensiveConservation)
+ self.assertTrue(rem.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([54.25,11.75,79.25,16.75]),1e-12))
+ mat=rem.getCrudeCSRMatrix()
+ rem2=MEDCouplingRemapper()
+ rem2.setCrudeMatrix(ms,mt,"P0P0",mat)
+ self.assertTrue(rem2.transferField(fs,1e300).getArray().isEqual(DataArrayDouble([54.25,11.75,79.25,16.75]),1e-12))
+ pass
+
+ def testSmallTetraCell(self):
+ """This test is a non regression test. When using tetra/tetra P0P0 interpolation on very small cells the
+ 3x3 matrix in the TetraAffine contains very small values and so the determinant is small (cubic).
+ So the tetra was detected as flat. Now the infinite norm of matrix is considered to establish if matrix is inversible or not."""
+ coords = [(-0.019866666666666668, 0.02, 0.002), (-0.020000073463967143, 0.019999926535763005, 0.0018666666666666673), (-0.020000073463967143, 0.019999926535763005, 0.002), (-0.020000072974206463, 0.019866593202430387, 0.002)]
+ m=MEDCouplingUMesh("mesh",3)
+ m.allocateCells()
+ m.insertNextCell(NORM_TETRA4,[0,1,2,3])
+ m.setCoords(DataArrayDouble(coords))
+ rem=MEDCouplingRemapper()
+ rem.setPrecision(1e-12)
+ rem.prepare(m,m,"P0P0")
+ mat=rem.getCrudeMatrix()
+ self.assertTrue(len(mat)==1)
+ self.assertTrue(len(mat[0])==1)
+ self.assertTrue(list(mat[0].keys())==[0])
+ res=list(mat[0].values())[0]
+ ref=float(m.getMeasureField(True).getArray())
+ self.assertTrue(abs(res-ref)/ref<1e-12)
+ pass
+
+ def checkMatrix(self,mat1,mat2,nbCols,eps):
+ self.assertEqual(len(mat1),len(mat2))
+ for i in range(len(mat1)):
+ self.assertTrue(max(mat2[i].keys())<nbCols)
+ self.assertTrue(max(mat1[i].keys())<nbCols)
+ self.assertTrue(min(mat2[i].keys())>=0)
+ self.assertTrue(min(mat1[i].keys())>=0)
+ s1=set(mat1[i].keys()) ; s2=set(mat2[i].keys())
+ for elt in s1.intersection(s2):
+ self.assertTrue(abs(mat1[i][elt]-mat2[i][elt])<eps)
+ pass
+ for elt in s1.difference(s2):
+ self.assertTrue(abs(mat1[i][elt])<eps)
+ pass
+ for elt in s2.difference(s1):
+ self.assertTrue(abs(mat2[i][elt])<eps)
+ pass
+ pass
+ pass
+