From c31aefa7570684946155d733ed70a40d0daa238c Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 31 Dec 2019 10:28:23 +0100 Subject: [PATCH] Deal with 2D/0D pointlocator into Remapper --- src/MEDCoupling/MEDCouplingRemapper.cxx | 9 +++++ .../MEDCouplingRemapperTest.py | 37 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingRemapper.cxx b/src/MEDCoupling/MEDCouplingRemapper.cxx index b52977152..884132a50 100755 --- a/src/MEDCoupling/MEDCouplingRemapper.cxx +++ b/src/MEDCoupling/MEDCouplingRemapper.cxx @@ -527,6 +527,15 @@ int MEDCouplingRemapper::prepareInterpKernelOnlyUU() } } } + else if(srcMeshDim==2 && trgMeshDim==0 && srcSpaceDim==2) + { + if(getIntersectionType()!=INTERP_KERNEL::PointLocator) + throw INTERP_KERNEL::Exception("Invalid interpolation requested between 2D and 0D ! Select PointLocator as intersection type !"); + MEDCouplingNormalizedUnstructuredMesh<2,2> source_mesh_wrapper(src_mesh); + MEDCouplingNormalizedUnstructuredMesh<2,2> target_mesh_wrapper(target_mesh); + INTERP_KERNEL::Interpolation2D interpolation(*this); + nbCols=interpolation.interpolateMeshes(source_mesh_wrapper,target_mesh_wrapper,_matrix,method); + } else if(srcMeshDim==1 && trgMeshDim==2 && srcSpaceDim==2) { if(getIntersectionType()==INTERP_KERNEL::PointLocator) diff --git a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py index 63bf0ee7f..773e0a147 100644 --- a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py @@ -1302,7 +1302,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(abs(res-ref)/ref<1e-12) pass - def test3D0DP1P1(self): + def test3D0DPointLocator(self): """ For pointlocator fans, Remapper support following intersection IntersectionType == PointLocator @@ -1319,7 +1319,6 @@ class MEDCouplingBasicsTest(unittest.TestCase): rem.setIntersectionType(PointLocator) rem.prepare(src,trg,"P1P1") self.checkMatrix(rem.getCrudeMatrix(),[{0:0.23,1:0.4,2:0.3,3:0.07}],src.getNumberOfNodes(),1e-12) - self.checkMatrix(rem.getCrudeMatrix(),[{0:0.23,1:0.4,2:0.3,3:0.07}],src.getNumberOfNodes(),1e-12) # P1P0 rem=MEDCouplingRemapper() rem.setIntersectionType(PointLocator) @@ -1336,6 +1335,40 @@ class MEDCouplingBasicsTest(unittest.TestCase): rem.prepare(src,trg,"P0P0") self.checkMatrix(rem.getCrudeMatrix(),[{0:1.0}],src.getNumberOfCells(),1e-12) pass + + def test2D0DPointLocator(self): + """ + For pointlocator fans, Remapper support following intersection + IntersectionType == PointLocator + - source == 2D + - target == 0D + """ + src = MEDCouplingUMesh("src",2) + src.allocateCells() + src.setCoords( DataArrayDouble([(0,0),(1,0),(0,1)]) ) + src.insertNextCell(NORM_TRI3,[0,1,2]) + trg = MEDCouplingUMesh.Build0DMeshFromCoords( DataArrayDouble([(0.4,0.3)]) ) + # P1P1 + rem=MEDCouplingRemapper() + rem.setIntersectionType(PointLocator) + rem.prepare(src,trg,"P1P1") + self.checkMatrix(rem.getCrudeMatrix(),[{0:0.3,1:0.4,2:0.3}],src.getNumberOfNodes(),1e-12) + # P1P0 + rem=MEDCouplingRemapper() + rem.setIntersectionType(PointLocator) + rem.prepare(src,trg,"P1P0") + self.checkMatrix(rem.getCrudeMatrix(),[{0:0.3,1:0.4,2:0.3}],src.getNumberOfNodes(),1e-12) + # P0P1 + rem=MEDCouplingRemapper() + rem.setIntersectionType(PointLocator) + rem.prepare(src,trg,"P0P1") + self.checkMatrix(rem.getCrudeMatrix(),[{0:1.0}],src.getNumberOfNodes(),1e-12) + # P0P0 + rem=MEDCouplingRemapper() + rem.setIntersectionType(PointLocator) + rem.prepare(src,trg,"P0P0") + self.checkMatrix(rem.getCrudeMatrix(),[{0:1.0}],src.getNumberOfNodes(),1e-12) + pass def checkMatrix(self,mat1,mat2,nbCols,eps): self.assertEqual(len(mat1),len(mat2)) -- 2.39.2