From 4b2f166aaa5d7c22d6ce1c7b4d3c32670b17a62d Mon Sep 17 00:00:00 2001 From: Anida KHIZAR Date: Wed, 28 Oct 2020 13:07:40 +0100 Subject: [PATCH] reusing variables that have already been calculated instead of using costly methods twice --- .../MEDCouplingUMesh_intersection.cxx | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingUMesh_intersection.cxx b/src/MEDCoupling/MEDCouplingUMesh_intersection.cxx index 5dfd06e27..a3c26a380 100644 --- a/src/MEDCoupling/MEDCouplingUMesh_intersection.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh_intersection.cxx @@ -1837,36 +1837,35 @@ void MEDCouplingUMesh::Intersect2DMeshWith1DLine(const MEDCouplingUMesh *mesh2D, MCAuto cells,cellsIndex; mesh2D->getCellsContainingPoints(centerOfMassRet1->begin(),centerOfMassRet1->getNumberOfTuples(),eps,cells,cellsIndex); MCAuto cellsIndex2(DataArrayIdType::New()); cellsIndex2->alloc(0,1); - if (cellsIndex->getNumberOfTuples() > 1) - cellsIndex2 = cellsIndex->deltaShiftIndex(); - MCAuto idsInRet1With2Contacts(cellsIndex2->findIdsEqual(2)); - - MCAuto realIdsInDesc2D(desc1->deepCopy()); - realIdsInDesc2D->abs(); realIdsInDesc2D->applyLin(1,-1); - realIdsInDesc2D=realIdsInDesc2D->buildUnique(); - const mcIdType *cRet1(ret1->getNodalConnectivity()->begin()),*ciRet1(ret1->getNodalConnectivityIndex()->begin()); - for(const mcIdType *it=idsInRet1With2Contacts->begin();it!=idsInRet1With2Contacts->end();it++) - { - // b- find the edge that the 2 cells in m1Desc have in common: - // this is the edge which is collinear with the one in ret1 - const mcIdType* cellId1 = cells->begin() + cellsIndex->begin()[*it]; - const mcIdType* cellId2 = cells->begin() + cellsIndex->begin()[*it]+1; - - std::set s1(realIdsInDesc2D->begin()+dd2->begin()[*cellId1], realIdsInDesc2D->begin()+dd2->begin()[*cellId1+1]); - std::set s2(realIdsInDesc2D->begin()+dd2->begin()[*cellId2], realIdsInDesc2D->begin()+dd2->begin()[*cellId2+1]); - mcIdType commonEdgeId; - std::set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(), &commonEdgeId); - - // c- find correct orientation for commonEdgeId - const mcIdType* firstNodeInColinearEdgeRet1 = cRet1 + ciRet1[*it]+1; - const mcIdType* secondNodeInColinearEdgeRet1 = cRet1 + ciRet1[*it]+2; - std::vector v; v.push_back(commonEdgeId); - if(IsColinearOfACellOf(intersectEdge1, v, *firstNodeInColinearEdgeRet1,*secondNodeInColinearEdgeRet1,commonEdgeId)) - { - idsInRet1Colinear->pushBackSilent(*it); - idsInDescMesh2DForIdsInRetColinear->pushBackSilent(commonEdgeId); - } - } + if (cellsIndex->getNumberOfTuples() > 1) + cellsIndex2 = cellsIndex->deltaShiftIndex(); + MCAuto idsInRet1With2Contacts(cellsIndex2->findIdsEqual(2)); + + MCAuto realIdsInDesc2D(desc1->deepCopy()); + realIdsInDesc2D->abs(); realIdsInDesc2D->applyLin(1,-1); + const mcIdType *cRet1(ret1->getNodalConnectivity()->begin()),*ciRet1(ret1->getNodalConnectivityIndex()->begin()); + for(const mcIdType *it=idsInRet1With2Contacts->begin();it!=idsInRet1With2Contacts->end();it++) + { + // b- find the edge that the 2 cells in m1Desc have in common: + // this is the edge which is collinear with the one in ret1 + const mcIdType* cellId1 = cells->begin() + cellsIndex->begin()[*it]; + const mcIdType* cellId2 = cells->begin() + cellsIndex->begin()[*it]+1; + + std::set s1(realIdsInDesc2D->begin()+dd2->begin()[*cellId1], realIdsInDesc2D->begin()+dd2->begin()[*cellId1+1]); + std::set s2(realIdsInDesc2D->begin()+dd2->begin()[*cellId2], realIdsInDesc2D->begin()+dd2->begin()[*cellId2+1]); + mcIdType commonEdgeId; + std::set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(), &commonEdgeId); + + // c- find correct orientation for commonEdgeId + const mcIdType* firstNodeInColinearEdgeRet1 = cRet1 + ciRet1[*it]+1; + const mcIdType* secondNodeInColinearEdgeRet1 = cRet1 + ciRet1[*it]+2; + std::vector v; v.push_back(commonEdgeId); + if(IsColinearOfACellOf(intersectEdge1, v, *firstNodeInColinearEdgeRet1,*secondNodeInColinearEdgeRet1,commonEdgeId)) + { + idsInRet1Colinear->pushBackSilent(*it); + idsInDescMesh2DForIdsInRetColinear->pushBackSilent(commonEdgeId); + } + } MCAuto ret3(DataArrayIdType::New()); ret3->alloc(ret1->getNumberOfCells()*2,1); ret3->fillWithValue(std::numeric_limits::max()); ret3->rearrange(2); MCAuto idsInRet1NotColinear(idsInRet1Colinear->buildComplement(ret1->getNumberOfCells())); @@ -1887,9 +1886,11 @@ void MEDCouplingUMesh::Intersect2DMeshWith1DLine(const MEDCouplingUMesh *mesh2D, } // MCAuto ret1NonCol(static_cast(ret1->buildPartOfMySelf(idsInRet1NotColinear->begin(),idsInRet1NotColinear->end()))); - MCAuto baryRet1(ret1NonCol->computeCellCenterOfMass()); - MCAuto elts,eltsIndex; - mesh2D->getCellsContainingPoints(baryRet1->begin(),baryRet1->getNumberOfTuples(),eps,elts,eltsIndex); + MCAuto baryRet1(centerOfMassRet1->selectByTupleId(idsInRet1NotColinear->begin(), idsInRet1NotColinear->end())); + DataArrayIdType *out(0),*outi(0); + DataArrayIdType::ExtractFromIndexedArrays(idsInRet1NotColinear->begin(),idsInRet1NotColinear->end(),cells,cellsIndex,out,outi); + MCAuto elts(out),eltsIndex(outi); + MCAuto eltsIndex2(DataArrayIdType::New()); eltsIndex2->alloc(0,1); if (eltsIndex->getNumberOfTuples() > 1) eltsIndex2 = eltsIndex->deltaShiftIndex(); -- 2.39.2