From: Anthony Geay Date: Wed, 8 Feb 2017 14:57:45 +0000 (+0100) Subject: Tools for partitioning and neighbor computation X-Git-Tag: V8_3_0a2~22 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fcbfef1f7ddb45c7c8301650a12cd165cb2dc5f8;p=tools%2Fmedcoupling.git Tools for partitioning and neighbor computation --- diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 40318b00b..39bf67ac5 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -864,6 +864,30 @@ void MEDCouplingUMesh::computeNeighborsOfCells(DataArrayInt *&neighbors, DataArr ComputeNeighborsOfCellsAdv(desc,descIndx,revDesc,revDescIndx,neighbors,neighborsIndx); } +void MEDCouplingUMesh::computeCellNeighborhoodFromNodesOne(const DataArrayInt *nodeNeigh, const DataArrayInt *nodeNeighI, MCAuto& cellNeigh, MCAuto& cellNeighIndex) const +{ + if(!nodeNeigh || !nodeNeighI) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::computeCellNeighborhoodFromNodesOne : null pointer !"); + checkConsistencyLight(); + nodeNeigh->checkAllocated(); nodeNeighI->checkAllocated(); + nodeNeigh->checkNbOfComps(1,"MEDCouplingUMesh::computeCellNeighborhoodFromNodesOne : node neigh"); + nodeNeighI->checkNbOfComps(1,"MEDCouplingUMesh::computeCellNeighborhoodFromNodesOne : node neigh index"); + nodeNeighI->checkNbOfTuples(1+getNumberOfNodes(),"MEDCouplingUMesh::computeCellNeighborhoodFromNodesOne : invalid length"); + int nbCells(getNumberOfCells()); + const int *c(_nodal_connec->begin()),*ci(_nodal_connec_index->begin()),*ne(nodeNeigh->begin()),*nei(nodeNeighI->begin()); + cellNeigh=DataArrayInt::New(); cellNeigh->alloc(0,1); cellNeighIndex=DataArrayInt::New(); cellNeighIndex->alloc(1,1); cellNeighIndex->setIJ(0,0,0); + for(int i=0;i s; + for(const int *it=c+ci[i]+1;it!=c+ci[i+1];it++) + if(*it>=0) + s.insert(ne+nei[*it],ne+nei[*it+1]); + s.erase(i); + cellNeigh->insertAtTheEnd(s.begin(),s.end()); + cellNeighIndex->pushBackSilent(cellNeigh->getNumberOfTuples()); + } +} + /*! * This method is called by MEDCouplingUMesh::computeNeighborsOfCells. This methods performs the algorithm * of MEDCouplingUMesh::computeNeighborsOfCells. @@ -11658,20 +11682,31 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSpreadZonesWithPoly() const */ std::vector MEDCouplingUMesh::partitionBySpreadZone() const { - int nbOfCellsCur=getNumberOfCells(); - std::vector ret; - if(nbOfCellsCur<=0) - return ret; DataArrayInt *neigh=0,*neighI=0; computeNeighborsOfCells(neigh,neighI); MCAuto neighAuto(neigh),neighIAuto(neighI); + return PartitionBySpreadZone(neighAuto,neighIAuto); +} + +std::vector MEDCouplingUMesh::PartitionBySpreadZone(const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn) +{ + if(!arrIn || !arrIndxIn) + throw INTERP_KERNEL::Exception("PartitionBySpreadZone : null input pointers !"); + arrIn->checkAllocated(); arrIndxIn->checkAllocated(); + int nbOfTuples(arrIndxIn->getNumberOfTuples()); + if(arrIn->getNumberOfComponents()!=1 || arrIndxIn->getNumberOfComponents()!=1 || nbOfTuples<1) + throw INTERP_KERNEL::Exception("PartitionBySpreadZone : invalid arrays in input !"); + int nbOfCellsCur(nbOfTuples-1); + std::vector ret; + if(nbOfCellsCur<=0) + return ret; std::vector fetchedCells(nbOfCellsCur,false); std::vector< MCAuto > ret2; int seed=0; while(seed >::iterator it=ret2.begin();it!=ret2.end();it++) diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index dec512eb0..2241c267e 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -125,6 +125,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT MEDCouplingUMesh *buildDescendingConnectivity2(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const; MEDCOUPLING_EXPORT MEDCouplingUMesh *explodeMeshIntoMicroEdges(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const; MEDCOUPLING_EXPORT void computeNeighborsOfCells(DataArrayInt *&neighbors, DataArrayInt *&neighborsIdx) const; + MEDCOUPLING_EXPORT void computeCellNeighborhoodFromNodesOne(const DataArrayInt *nodeNeigh, const DataArrayInt *nodeNeighI, MCAuto& cellNeigh, MCAuto& cellNeighIndex) const; MEDCOUPLING_EXPORT static void ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, const DataArrayInt *descI, const DataArrayInt *revDesc, const DataArrayInt *revDescI, DataArrayInt *&neighbors, DataArrayInt *&neighborsIdx); MEDCOUPLING_EXPORT void computeNeighborsOfNodes(DataArrayInt *&neighbors, DataArrayInt *&neighborsIdx) const; @@ -267,6 +268,7 @@ namespace MEDCoupling DataArrayInt* &arrOut, DataArrayInt* &arrIndexOut); MEDCOUPLING_EXPORT static void SetPartOfIndexedArraysSameIdxSlice(int start, int end, int step, DataArrayInt *arrInOut, const DataArrayInt *arrIndxIn, const DataArrayInt *srcArr, const DataArrayInt *srcArrIndex); + MEDCOUPLING_EXPORT static std::vector PartitionBySpreadZone(const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn); MEDCOUPLING_EXPORT static DataArrayInt *ComputeSpreadZoneGradually(const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn); MEDCOUPLING_EXPORT static DataArrayInt *ComputeSpreadZoneGraduallyFromSeed(const int *seedBg, const int *seedEnd, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, int nbOfDepthPeeling, int& nbOfDepthPeelingPerformed); MEDCOUPLING_EXPORT static void FindCommonCellsAlg(int compType, int startCellId, const DataArrayInt *nodal, const DataArrayInt *nodalI, const DataArrayInt *revNodal, const DataArrayInt *revNodalI, diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 78f3867d3..99bfc86c7 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -2156,6 +2156,16 @@ namespace MEDCoupling return ret; } + static PyObject *PartitionBySpreadZone(const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn) throw(INTERP_KERNEL::Exception) + { + std::vector retCpp(MEDCouplingUMesh::PartitionBySpreadZone(arrIn,arrIndxIn)); + int sz=retCpp.size(); + PyObject *ret=PyList_New(sz); + for(int i=0;i cellNeigh,cellNeighIndex; + self->computeCellNeighborhoodFromNodesOne(nodeNeigh,nodeNeighI,cellNeigh,cellNeighIndex); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(cellNeigh.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cellNeighIndex.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + static PyObject *ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, const DataArrayInt *descI, const DataArrayInt *revDesc, const DataArrayInt *revDescI) throw(INTERP_KERNEL::Exception) { DataArrayInt *neighbors=0,*neighborsIdx=0;