From 9a679e1cb8408f6e8900d0dff3c859bd88485d8b Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 24 Apr 2020 23:49:15 +0200 Subject: [PATCH] ParaUMesh.redistributeCells : First tests are OK --- src/MEDCoupling/MEDCouplingMemArray.txx | 4 +--- src/MEDCoupling/MEDCouplingUMesh.hxx | 2 +- src/ParaMEDMEM/CommInterface.hxx | 16 ++++++++++++++-- src/ParaMEDMEM/ParaUMesh.cxx | 14 ++++++++++++-- src/ParaMEDMEM/ParaUMesh.hxx | 3 +++ src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i | 24 ++++++++++++++++++++++++ 6 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 8c6cee0da..70aefc7a5 100755 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -5736,7 +5736,7 @@ struct NotInRange * - \a return is : [0, 1, 3, 5, 6, 8, 11, 12] * * \return a newly allocated array containing the indexed array format of groups by same consecutive value. - * \throw if \a this is not allocated or if \a this has not exactly one component or if number of tuples is equal to 0. + * \throw if \a this is not allocated or if \a this has not exactly one component. * \sa DataArrayInt::buildUnique, MEDCouplingSkyLineArray::groupPacks */ template @@ -5745,8 +5745,6 @@ struct NotInRange this->checkAllocated(); if(this->getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::indexOfSameConsecutiveValueGroups : only single component allowed !"); - if(this->getNumberOfTuples()==0) - throw INTERP_KERNEL::Exception("DataArrayInt::indexOfSameConsecutiveValueGroups : number of tuples must be > 0 !"); const T *pt(this->begin()); const T *const ptEnd(this->end()) , * const ptBg(this->begin()); const T *oldPt(pt); diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 972a04eb4..c09784c41 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -456,7 +456,7 @@ namespace MEDCoupling my_reference operator*() const { T tt; return tt((*_data)[_num]); } }; - struct UMeshIndexConnectivityFunctor { const DataArrayIdType *operator()(const MEDCouplingUMesh *um) { return um->getNodalConnectivity(); } }; + struct UMeshIndexConnectivityFunctor { const DataArrayIdType *operator()(const MEDCouplingUMesh *um) { return um->getNodalConnectivityIndex(); } }; using UMeshConnectivityIndexIterator = UMeshGenIterator; diff --git a/src/ParaMEDMEM/CommInterface.hxx b/src/ParaMEDMEM/CommInterface.hxx index 63904206c..d795185cc 100644 --- a/src/ParaMEDMEM/CommInterface.hxx +++ b/src/ParaMEDMEM/CommInterface.hxx @@ -133,14 +133,25 @@ namespace MEDCoupling std::vector< const DataArrayT *> arraysBis(FromVecAutoToVecOfConst(arrays)); std::unique_ptr nbOfElems2(new mcIdType[size]),nbOfElems3(new mcIdType[size]); + mcIdType nbOfComponents(std::numeric_limits::max()); for(int curRk = 0 ; curRk < size ; ++curRk) { - nbOfElems3[curRk] = arrays[curRk]->getNumberOfTuples(); + mcIdType curNbOfCompo( ToIdType( arrays[curRk]->getNumberOfComponents() ) ); + if(nbOfComponents != std::numeric_limits::max()) + { + if( nbOfComponents != curNbOfCompo ) + throw INTERP_KERNEL::Exception("AllToAllArrays : internal error ! Nb of components is not homogeneous !"); + } + else + { + nbOfComponents = curNbOfCompo; + } + nbOfElems3[curRk] = arrays[curRk]->getNbOfElems(); } this->allToAll(nbOfElems3.get(),1,MPI_ID_TYPE,nbOfElems2.get(),1,MPI_ID_TYPE,comm); mcIdType nbOfCellIdsSum(std::accumulate(nbOfElems2.get(),nbOfElems2.get()+size,0)); MCAuto cellIdsFromProcs(DataArrayT::New()); - cellIdsFromProcs->alloc(nbOfCellIdsSum,1); + cellIdsFromProcs->alloc(nbOfCellIdsSum/nbOfComponents,nbOfComponents); std::unique_ptr nbOfElemsInt( CommInterface::ToIntArray(nbOfElems3,size) ),nbOfElemsOutInt( CommInterface::ToIntArray(nbOfElems2,size) ); std::unique_ptr offsetsIn( CommInterface::ComputeOffset(nbOfElemsInt,size) ), offsetsOut( CommInterface::ComputeOffset(nbOfElemsOutInt,size) ); { @@ -154,6 +165,7 @@ namespace MEDCoupling for(int curRk = 0 ; curRk < size ; ++curRk) { arraysOut[curRk] = DataArrayT::NewFromArray(cellIdsFromProcs->begin()+offsetsOutIdType[curRk],cellIdsFromProcs->begin()+offsetsOutIdType[curRk]+nbOfElems2[curRk]); + arraysOut[curRk]->rearrange(nbOfComponents); } } public: diff --git a/src/ParaMEDMEM/ParaUMesh.cxx b/src/ParaMEDMEM/ParaUMesh.cxx index 02fee7255..0ceb35565 100644 --- a/src/ParaMEDMEM/ParaUMesh.cxx +++ b/src/ParaMEDMEM/ParaUMesh.cxx @@ -200,17 +200,26 @@ ParaUMesh *ParaUMesh::redistributeCells(const DataArrayIdType *globalCellIds) co 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())); + finalCoords->copyStringInfoFrom(*_mesh->getCoords()); // 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()); + // work on connectivityReceived[curRk] with transformWithIndArr but do not forget type of cells that should be excluded ! + auto connectivityToModify(connectivityReceived[curRk]); + auto connectivityIndex(connectivityIndexReceived[curRk]); + MCAuto types(connectivityToModify->selectByTupleIdSafe(connectivityIndex->begin(),connectivityIndex->end()-1)); + connectivityToModify->setPartOfValuesSimple3(0,connectivityIndex->begin(),connectivityIndex->end()-1,0,1,1); + connectivityToModify->transformWithIndArr(aa->begin(),aa->end()); + connectivityToModify->setPartOfValues3(types,connectivityIndex->begin(),connectivityIndex->end()-1,0,1,1,true); } // thirdly renumber cells MCAuto aggregatedCellIds( DataArrayIdType::Aggregate(FromVecAutoToVecOfConst(globalCellIdsReceived)) ); MCAuto aggregatedCellIdsSorted(aggregatedCellIds->copySorted()); MCAuto idsIntoAggregatedIds(DataArrayIdType::FindPermutationFromFirstToSecondDuplicate(aggregatedCellIdsSorted,aggregatedCellIds)); + MCAuto cellIdsOfSameNodeIds(aggregatedCellIdsSorted->indexOfSameConsecutiveValueGroups()); + MCAuto n2o_cells(idsIntoAggregatedIds->selectByTupleIdSafe(cellIdsOfSameNodeIds->begin(),cellIdsOfSameNodeIds->end()-1));//new == new ordering so that global cell ids are sorted . old == coarse ordering implied by the aggregation // TODO : check coordsReceived==globalCellIds MCAuto connSorted,indicesSorted; { @@ -218,7 +227,7 @@ ParaUMesh *ParaUMesh::redistributeCells(const DataArrayIdType *globalCellIds) co MCAuto connIndex(DataArrayIdType::AggregateIndexes(FromVecAutoToVecOfConst(connectivityIndexReceived))); { DataArrayIdType *indicesSortedTmp(nullptr),*valuesSortedTmp(nullptr); - DataArrayIdType::ExtractFromIndexedArrays(idsIntoAggregatedIds->begin(),idsIntoAggregatedIds->end(),conn,connIndex,valuesSortedTmp,indicesSortedTmp); + DataArrayIdType::ExtractFromIndexedArrays(n2o_cells->begin(),n2o_cells->end(),conn,connIndex,valuesSortedTmp,indicesSortedTmp); indicesSorted = indicesSortedTmp; connSorted=valuesSortedTmp; } } @@ -226,6 +235,7 @@ ParaUMesh *ParaUMesh::redistributeCells(const DataArrayIdType *globalCellIds) co MCAuto mesh(MEDCouplingUMesh::New(_mesh->getName(),_mesh->getMeshDimension())); mesh->setConnectivity(connSorted,indicesSorted,true); mesh->setCoords(finalCoords); + mesh->setDescription(_mesh->getDescription()); MCAuto ret(ParaUMesh::New(mesh,aggregatedCellIdsSorted,finalGlobalNodeIds)); return ret.retn(); } diff --git a/src/ParaMEDMEM/ParaUMesh.hxx b/src/ParaMEDMEM/ParaUMesh.hxx index 905128bb4..5247b3716 100644 --- a/src/ParaMEDMEM/ParaUMesh.hxx +++ b/src/ParaMEDMEM/ParaUMesh.hxx @@ -40,6 +40,9 @@ namespace MEDCoupling static ParaUMesh *New(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds); MCAuto getCellIdsLyingOnNodes(const DataArrayIdType *globalNodeIds, bool fullyIn) const; ParaUMesh *redistributeCells(const DataArrayIdType *globalCellIds) const; + MEDCouplingUMesh *getMesh() { return _mesh; } + DataArrayIdType *getGlobalCellIds() { return _cell_global; } + DataArrayIdType *getGlobalNodeIds() { return _node_global; } protected: virtual ~ParaUMesh() { } ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds); diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i b/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i index 46418d15e..b1fcf0103 100644 --- a/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i +++ b/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i @@ -59,6 +59,9 @@ using namespace ICoCo; %include "ICoCoMEDField.hxx" %newobject MEDCoupling::ParaUMesh::New; +%newobject MEDCoupling::ParaUMesh::getMesh; +%newobject MEDCoupling::ParaUMesh::getGlobalCellIds; +%newobject MEDCoupling::ParaUMesh::getGlobalNodeIds; %newobject MEDCoupling::ParaUMesh::getCellIdsLyingOnNodes; %newobject MEDCoupling::ParaUMesh::redistributeCells; %newobject MEDCoupling::ParaSkyLineArray::New; @@ -164,6 +167,27 @@ namespace MEDCoupling return ParaUMesh::New(mesh,globalCellIds,globalNodeIds); } + MEDCouplingUMesh *getMesh() + { + MEDCouplingUMesh *ret(self->getMesh()); + if(ret) ret->incrRef(); + return ret; + } + + DataArrayIdType *getGlobalCellIds() + { + DataArrayIdType *ret(self->getGlobalCellIds()); + if(ret) ret->incrRef(); + return ret; + } + + DataArrayIdType *getGlobalNodeIds() + { + DataArrayIdType *ret(self->getGlobalNodeIds()); + if(ret) ret->incrRef(); + return ret; + } + DataArrayIdType *getCellIdsLyingOnNodes(const DataArrayIdType *globalNodeIds, bool fullyIn) const { MCAuto ret(self->getCellIdsLyingOnNodes(globalNodeIds,fullyIn)); -- 2.39.2