From 0e23264d3dc3e52831919f14e8a8cc7eefb37eb9 Mon Sep 17 00:00:00 2001 From: karadaniz Date: Thu, 15 Feb 2024 15:53:27 +0100 Subject: [PATCH] [spns#34841] Intersect2DMeshWith1DLine : throw exception if any node within mesh1D is connected to more than two edges --- src/MEDCoupling/MEDCouplingUMesh_intersection.cxx | 14 ++++++++++++++ src/MEDCoupling_Swig/MEDCouplingIntersectTest.py | 12 +++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/MEDCoupling/MEDCouplingUMesh_intersection.cxx b/src/MEDCoupling/MEDCouplingUMesh_intersection.cxx index 8b569163d..036af8970 100644 --- a/src/MEDCoupling/MEDCouplingUMesh_intersection.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh_intersection.cxx @@ -1791,8 +1791,22 @@ void MEDCouplingUMesh::Intersect2DMeshWith1DLine(const MEDCouplingUMesh *mesh2D, { if(!mesh2D || !mesh1D) throw INTERP_KERNEL::Exception("MEDCouplingUMesh::Intersect2DMeshWith1DLine : input meshes must be not NULL !"); + mesh2D->checkFullyDefined(); mesh1D->checkFullyDefined(); + + { // (In a scope to free mem early) + // Check if any node within mesh1D is connected to more than two edges + DataArrayIdType *mesh1DDesc1(DataArrayIdType::New()),*mesh1DDescIndx1(DataArrayIdType::New()),*mesh1DRevDesc1(DataArrayIdType::New()),*mesh1DRevDescIndx1(DataArrayIdType::New()); + MCAuto m1dd1(mesh1DDesc1),m1dd2(mesh1DDescIndx1),m1dd3(mesh1DRevDesc1),m1dd4(mesh1DRevDescIndx1); + MCAuto mesh1Desc(mesh1D->buildDescendingConnectivity(mesh1DDesc1,mesh1DDescIndx1,mesh1DRevDesc1,mesh1DRevDescIndx1)); + MCAuto dsi=mesh1DRevDescIndx1->deltaShiftIndex(); + MCAuto tpls = dsi->findIdsGreaterOrEqualTo(3); + if(tpls->getNumberOfTuples() != 0) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::Intersect2DMeshWith1DLine : Certain nodes of the 1D mesh are connected to more than 2 edges !\ + If the 1D mesh consists of mutiple lines, make sure those lines are not overlapping. "); + } + const std::vector& compNames(mesh2D->getCoords()->getInfoOnComponents()); if(mesh2D->getMeshDimension()!=2 || mesh2D->getSpaceDimension()!=2 || mesh1D->getMeshDimension()!=1 || mesh1D->getSpaceDimension()!=2) throw INTERP_KERNEL::Exception("MEDCouplingUMesh::Intersect2DMeshWith1DLine works with mesh2D with spacedim=meshdim=2 and mesh1D with meshdim=1 spaceDim=2 !"); diff --git a/src/MEDCoupling_Swig/MEDCouplingIntersectTest.py b/src/MEDCoupling_Swig/MEDCouplingIntersectTest.py index 42e4c3489..a67c8be96 100644 --- a/src/MEDCoupling_Swig/MEDCouplingIntersectTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingIntersectTest.py @@ -1293,7 +1293,17 @@ class MEDCouplingIntersectTest(unittest.TestCase): self.assertEqual(resToSelf.getValues(), [0, 1, 1]) self.assertEqual(mapLeftRight.getValues(), [-1, -1, 1, 0, 1, 2, -1, -1]) - + def testSwig2Intersect2DMeshWith1DLine22(self): + """ Simple check that an execption is thrown if 1D mesh is not a single line (one point + connected to more than 2 edges. """ + m2 = MEDCouplingCMesh.New() + da = DataArrayDouble(3) + da.iota() + m2.setCoords(da, da) + m2 = m2.buildUnstructured() + m1,_,_,_,_ = m2.buildDescendingConnectivity() # m1 will have it central point connected to 4 edges + # MEDCouplingUMesh.Intersect2DMeshWith1DLine(m2, m1, 1.0e-8) + self.assertRaises(InterpKernelException, MEDCouplingUMesh.Intersect2DMeshWith1DLine, m2, m1, 1.0e-8) def testSwig2Conformize2D1(self): eps = 1.0e-8 -- 2.39.2