]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
ParaUMesh.redistributeCells : First tests are OK
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 24 Apr 2020 21:49:15 +0000 (23:49 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 24 Apr 2020 21:49:15 +0000 (23:49 +0200)
src/MEDCoupling/MEDCouplingMemArray.txx
src/MEDCoupling/MEDCouplingUMesh.hxx
src/ParaMEDMEM/CommInterface.hxx
src/ParaMEDMEM/ParaUMesh.cxx
src/ParaMEDMEM/ParaUMesh.hxx
src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i

index 8c6cee0dad736e7f6a274e0e5acb404ac20df904..70aefc7a536aa9365f4d0b88c8289d4f0f303de4 100755 (executable)
@@ -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 <class T>
@@ -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);
index 972a04eb49158367618cc77813fd82faf01d35e2..c09784c41691ae608ee484f895181245e9640325 100644 (file)
@@ -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<UMeshIndexConnectivityFunctor,DataArrayIdType>;
   
index 63904206c9e6a46114c89cd296d2f34daf745449..d795185cce53faba26442249a124f4ea148761dc 100644 (file)
@@ -133,14 +133,25 @@ namespace MEDCoupling
         
       std::vector< const DataArrayT *> arraysBis(FromVecAutoToVecOfConst<DataArrayT>(arrays));
       std::unique_ptr<mcIdType[]> nbOfElems2(new mcIdType[size]),nbOfElems3(new mcIdType[size]);
+      mcIdType nbOfComponents(std::numeric_limits<mcIdType>::max());
       for(int curRk = 0 ; curRk < size ; ++curRk)
       {
-         nbOfElems3[curRk] = arrays[curRk]->getNumberOfTuples();
+        mcIdType curNbOfCompo( ToIdType( arrays[curRk]->getNumberOfComponents() ) );
+        if(nbOfComponents != std::numeric_limits<mcIdType>::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<DataArrayT> cellIdsFromProcs(DataArrayT::New());
-      cellIdsFromProcs->alloc(nbOfCellIdsSum,1);
+      cellIdsFromProcs->alloc(nbOfCellIdsSum/nbOfComponents,nbOfComponents);
       std::unique_ptr<int[]> nbOfElemsInt( CommInterface::ToIntArray<mcIdType>(nbOfElems3,size) ),nbOfElemsOutInt( CommInterface::ToIntArray<mcIdType>(nbOfElems2,size) );
       std::unique_ptr<int[]> 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:
index 02fee725563e0e1504225cc182a7525d4a2334a7..0ceb35565b7cb5b3b4625f98ea52c2e66f4bce99 100644 (file)
@@ -200,17 +200,26 @@ ParaUMesh *ParaUMesh::redistributeCells(const DataArrayIdType *globalCellIds) co
   MCAuto<DataArrayIdType> 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<DataArrayIdType> finalGlobalNodeIds(aggregatedNodeIdsSorted->selectByTupleIdSafe(idxOfSameNodeIds->begin(),idxOfSameNodeIds->end()-1));
   MCAuto<DataArrayDouble> 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<DataArrayIdType> 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<DataArrayIdType> 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<DataArrayIdType> aggregatedCellIds( DataArrayIdType::Aggregate(FromVecAutoToVecOfConst<DataArrayIdType>(globalCellIdsReceived)) );
   MCAuto<DataArrayIdType> aggregatedCellIdsSorted(aggregatedCellIds->copySorted());
   MCAuto<DataArrayIdType> idsIntoAggregatedIds(DataArrayIdType::FindPermutationFromFirstToSecondDuplicate(aggregatedCellIdsSorted,aggregatedCellIds));
+  MCAuto<DataArrayIdType> cellIdsOfSameNodeIds(aggregatedCellIdsSorted->indexOfSameConsecutiveValueGroups());
+  MCAuto<DataArrayIdType> 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<DataArrayIdType> connSorted,indicesSorted;
   {
@@ -218,7 +227,7 @@ ParaUMesh *ParaUMesh::redistributeCells(const DataArrayIdType *globalCellIds) co
     MCAuto<DataArrayIdType> connIndex(DataArrayIdType::AggregateIndexes(FromVecAutoToVecOfConst<DataArrayIdType>(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<MEDCouplingUMesh> mesh(MEDCouplingUMesh::New(_mesh->getName(),_mesh->getMeshDimension()));
   mesh->setConnectivity(connSorted,indicesSorted,true);
   mesh->setCoords(finalCoords);
+  mesh->setDescription(_mesh->getDescription());
   MCAuto<ParaUMesh> ret(ParaUMesh::New(mesh,aggregatedCellIdsSorted,finalGlobalNodeIds));
   return ret.retn();
 }
index 905128bb46304c063bd4a0190567ec0bf5b30fad..5247b3716b6f3fd90d72b5fffd4b267da6dc49ae 100644 (file)
@@ -40,6 +40,9 @@ namespace MEDCoupling
     static ParaUMesh *New(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds);
     MCAuto<DataArrayIdType> 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);
index 46418d15e7eff993a10e1c084c4ec1b269d22cf1..b1fcf01033fa7e298dc9d8a650d67a838a5c86ca 100644 (file)
@@ -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<DataArrayIdType> ret(self->getCellIdsLyingOnNodes(globalNodeIds,fullyIn));