From: Anthony Geay Date: Fri, 24 Apr 2020 15:05:43 +0000 (+0200) Subject: WIP X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1b95c8f572917e3ba15f139986738bddb0bb0c9d;p=tools%2Fmedcoupling.git WIP --- diff --git a/src/ParaMEDMEM/ParaUMesh.cxx b/src/ParaMEDMEM/ParaUMesh.cxx index 8b95aebcc..02fee7255 100644 --- a/src/ParaMEDMEM/ParaUMesh.cxx +++ b/src/ParaMEDMEM/ParaUMesh.cxx @@ -37,6 +37,11 @@ using namespace MEDCoupling; +ParaUMesh *ParaUMesh::New(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds) +{ + return new ParaUMesh(mesh,globalCellIds,globalNodeIds); +} + ParaUMesh::ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds) { _mesh.takeRef(mesh); @@ -52,6 +57,16 @@ ParaUMesh::ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, Dat throw INTERP_KERNEL::Exception("ParaUMesh constructor : mismatch between # cells and len of global # cells."); } +std::size_t ParaUMesh::getHeapMemorySizeWithoutChildren() const +{ + return 0; +} + +std::vector ParaUMesh::getDirectChildrenWithNull() const +{ + return {_mesh,_cell_global,_node_global}; +} + /*! * This method computes the cells part of distributed mesh lying on \a globalNodeIds nodes. * The input \a globalNodeIds are not supposed to reside on the current process. @@ -118,7 +133,7 @@ MCAuto ParaUMesh::getCellIdsLyingOnNodes(const DataArrayIdType /*! */ -MCAuto ParaUMesh::redistributeCells(const DataArrayIdType *globalCellIds) const +ParaUMesh *ParaUMesh::redistributeCells(const DataArrayIdType *globalCellIds) const { MPI_Comm comm(MPI_COMM_WORLD); CommInterface ci; @@ -175,7 +190,42 @@ MCAuto ParaUMesh::redistributeCells(const DataArrayIdType *globalCell std::vector coordsToBeSent(UMeshCoordsIterator(0,&meshPartsToBeSent2),UMeshCoordsIterator(meshPartsToBeSent2.size(),&meshPartsToBeSent2)); ci.allToAllArrays(comm,FromVecConstToVecAuto(coordsToBeSent),coordsReceived); } - // Sort it all ! + /////// Sort it all ! + // firstly deal with nodes. + MCAuto coords( DataArrayDouble::Aggregate(FromVecAutoToVecOfConst(coordsReceived)) ); + MCAuto aggregatedNodeIds( DataArrayIdType::Aggregate(FromVecAutoToVecOfConst(globalNodeIdsReceived)) ); + MCAuto aggregatedNodeIdsSorted(aggregatedNodeIds->copySorted()); + MCAuto nodeIdsIntoAggregatedIds(DataArrayIdType::FindPermutationFromFirstToSecondDuplicate(aggregatedNodeIdsSorted,aggregatedNodeIds)); + MCAuto idxOfSameNodeIds(aggregatedNodeIdsSorted->indexOfSameConsecutiveValueGroups()); + MCAuto n2o_nodes(nodeIdsIntoAggregatedIds->selectByTupleIdSafe(idxOfSameNodeIds->begin(),idxOfSameNodeIds->end()-1));//new == new ordering so that global node ids are sorted . old == coarse ordering implied by the aggregation + MCAuto finalGlobalNodeIds(aggregatedNodeIdsSorted->selectByTupleIdSafe(idxOfSameNodeIds->begin(),idxOfSameNodeIds->end()-1)); + MCAuto finalCoords(coords->selectByTupleIdSafe(n2o_nodes->begin(),n2o_nodes->end())); + // secondly renumbering of node ids in connectivityReceived + for(int curRk = 0 ; curRk < size ; ++curRk) + { + auto current(globalNodeIdsReceived[curRk]); + MCAuto aa(finalGlobalNodeIds->findIdForEach(current->begin(),current->end())); + connectivityReceived[curRk]->transformWithIndArr(aa->begin(),aa->end()); + } + // thirdly renumber cells MCAuto aggregatedCellIds( DataArrayIdType::Aggregate(FromVecAutoToVecOfConst(globalCellIdsReceived)) ); MCAuto aggregatedCellIdsSorted(aggregatedCellIds->copySorted()); + MCAuto idsIntoAggregatedIds(DataArrayIdType::FindPermutationFromFirstToSecondDuplicate(aggregatedCellIdsSorted,aggregatedCellIds)); + // TODO : check coordsReceived==globalCellIds + MCAuto connSorted,indicesSorted; + { + MCAuto conn(DataArrayIdType::Aggregate(FromVecAutoToVecOfConst(connectivityReceived))); + MCAuto connIndex(DataArrayIdType::AggregateIndexes(FromVecAutoToVecOfConst(connectivityIndexReceived))); + { + DataArrayIdType *indicesSortedTmp(nullptr),*valuesSortedTmp(nullptr); + DataArrayIdType::ExtractFromIndexedArrays(idsIntoAggregatedIds->begin(),idsIntoAggregatedIds->end(),conn,connIndex,valuesSortedTmp,indicesSortedTmp); + indicesSorted = indicesSortedTmp; connSorted=valuesSortedTmp; + } + } + // finalize all + MCAuto mesh(MEDCouplingUMesh::New(_mesh->getName(),_mesh->getMeshDimension())); + mesh->setConnectivity(connSorted,indicesSorted,true); + mesh->setCoords(finalCoords); + MCAuto ret(ParaUMesh::New(mesh,aggregatedCellIdsSorted,finalGlobalNodeIds)); + return ret.retn(); } diff --git a/src/ParaMEDMEM/ParaUMesh.hxx b/src/ParaMEDMEM/ParaUMesh.hxx index 3d0bff392..905128bb4 100644 --- a/src/ParaMEDMEM/ParaUMesh.hxx +++ b/src/ParaMEDMEM/ParaUMesh.hxx @@ -34,13 +34,18 @@ namespace MEDCoupling * * This class is very specific to the requirement of parallel code computations. */ - class ParaUMesh + class ParaUMesh : public RefCountObject { public: - ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds); + static ParaUMesh *New(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds); MCAuto getCellIdsLyingOnNodes(const DataArrayIdType *globalNodeIds, bool fullyIn) const; - MCAuto redistributeCells(const DataArrayIdType *globalCellIds) const; + ParaUMesh *redistributeCells(const DataArrayIdType *globalCellIds) const; + protected: virtual ~ParaUMesh() { } + ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds); + std::string getClassName() const override { return "ParaUMesh"; } + std::size_t getHeapMemorySizeWithoutChildren() const override; + std::vector getDirectChildrenWithNull() const override; private: MCAuto _mesh; MCAuto _cell_global; diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i b/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i index 5bdcc0533..46418d15e 100644 --- a/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i +++ b/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i @@ -58,12 +58,16 @@ using namespace ICoCo; %rename(ICoCoMEDField) ICoCo::MEDField; %include "ICoCoMEDField.hxx" +%newobject MEDCoupling::ParaUMesh::New; %newobject MEDCoupling::ParaUMesh::getCellIdsLyingOnNodes; +%newobject MEDCoupling::ParaUMesh::redistributeCells; +%newobject MEDCoupling::ParaSkyLineArray::New; %newobject MEDCoupling::ParaSkyLineArray::equiRedistribute; %newobject MEDCoupling::ParaSkyLineArray::getSkyLineArray; %newobject MEDCoupling::ParaSkyLineArray::getGlobalIdsArray; %feature("unref") ParaSkyLineArray "$this->decrRef();" +%feature("unref") ParaUMesh "$this->decrRef();" %nodefaultctor; @@ -148,12 +152,18 @@ namespace MEDCoupling } }; - class ParaUMesh + class ParaUMesh : public RefCountObject { public: - ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds); + static ParaUMesh *New(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds); + ParaUMesh *redistributeCells(const DataArrayIdType *globalCellIds) const; %extend { + ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds) + { + return ParaUMesh::New(mesh,globalCellIds,globalNodeIds); + } + DataArrayIdType *getCellIdsLyingOnNodes(const DataArrayIdType *globalNodeIds, bool fullyIn) const { MCAuto ret(self->getCellIdsLyingOnNodes(globalNodeIds,fullyIn));