From 0837416f9a8a18c6c9c95fda397a441ee556a92c Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 16 Aug 2024 17:47:35 +0200 Subject: [PATCH] [EDF29571] : Fix problem of performance of MEDCoupling1GTUMesh::getCellsContainingPoints --- src/MEDCoupling/MEDCoupling1GTUMesh.cxx | 9 +++++++++ src/MEDCoupling/MEDCoupling1GTUMesh.hxx | 3 ++- .../MEDCouplingBasicsTest7.py | 20 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index d55be5584..cdcb07682 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -344,6 +344,15 @@ void MEDCoupling1GTUMesh::getCellsContainingPoint(const double *pos, double eps, return m->getCellsContainingPoint(pos,eps,elts); } +/*! + * to improve perf ! + */ +void MEDCoupling1GTUMesh::getCellsContainingPoints(const double *pos, mcIdType nbOfPoints, double eps, MCAuto& elts, MCAuto& eltsIndex) const +{// See EDF29571 + MCAuto m(buildUnstructured()); + m->getCellsContainingPoints(pos,nbOfPoints,eps,elts,eltsIndex); +} + MEDCouplingFieldDouble *MEDCoupling1GTUMesh::buildOrthogonalField() const { MCAuto m=buildUnstructured(); diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx index 97329f11e..1e637c670 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx @@ -61,7 +61,8 @@ namespace MEDCoupling MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getMeasureField(bool isAbs) const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const; MEDCOUPLING_EXPORT mcIdType getCellContainingPoint(const double *pos, double eps) const; - MEDCOUPLING_EXPORT void getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const; + MEDCOUPLING_EXPORT void getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const override; + MEDCOUPLING_EXPORT void getCellsContainingPoints(const double *pos, mcIdType nbOfPoints, double eps, MCAuto& elts, MCAuto& eltsIndex) const override; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildOrthogonalField() const; MEDCOUPLING_EXPORT DataArrayIdType *getCellsInBoundingBox(const double *bbox, double eps) const; MEDCOUPLING_EXPORT DataArrayIdType *getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py index 4ce8081f2..e7202640f 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py @@ -1471,6 +1471,26 @@ class MEDCouplingBasicsTest7(unittest.TestCase): # only the third point is inside self.assertTrue(b.isEqual(DataArrayInt([0,0,0,1]))) + def testSGTUMeshGetCellsContainingPts1(self): + """ + EDF29571 : Fix problem of perfomance of GTUMesh::getCellsContainingPts + """ + arr = DataArrayDouble(31) ; arr.iota() + m = MEDCouplingCMesh() ; m.setCoords(arr,arr,arr) + m = m.buildUnstructured() + m2 = MEDCoupling1SGTUMesh( m ) + pts = m[:100].computeCellCenterOfMass() + a = datetime.now() + a1,b1 = m.getCellsContainingPoints(pts,1e-5) + b = datetime.now() + a2,b2 = m2.getCellsContainingPoints(pts,1e-5) + c = datetime.now() + ref = b-a + toTest = c-a + self.assertTrue( toTest < 10*ref ) + + + if __name__ == '__main__': unittest.main() -- 2.39.2