]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
WIP
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 24 Apr 2020 15:05:43 +0000 (17:05 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 24 Apr 2020 15:05:43 +0000 (17:05 +0200)
src/ParaMEDMEM/ParaUMesh.cxx
src/ParaMEDMEM/ParaUMesh.hxx
src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i

index 8b95aebcc8bb01cced26f6965a979e23a541c82a..02fee725563e0e1504225cc182a7525d4a2334a7 100644 (file)
 
 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<const BigMemoryObject *> 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<DataArrayIdType> ParaUMesh::getCellIdsLyingOnNodes(const DataArrayIdType
 
 /*!
  */
-MCAuto<ParaUMesh> 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> ParaUMesh::redistributeCells(const DataArrayIdType *globalCell
     std::vector<const DataArrayDouble *> coordsToBeSent(UMeshCoordsIterator(0,&meshPartsToBeSent2),UMeshCoordsIterator(meshPartsToBeSent2.size(),&meshPartsToBeSent2));
     ci.allToAllArrays(comm,FromVecConstToVecAuto<DataArrayDouble>(coordsToBeSent),coordsReceived);
   }
-  // Sort it all !
+  /////// Sort it all !
+  // firstly deal with nodes.
+  MCAuto<DataArrayDouble> coords( DataArrayDouble::Aggregate(FromVecAutoToVecOfConst<DataArrayDouble>(coordsReceived)) );
+  MCAuto<DataArrayIdType> aggregatedNodeIds( DataArrayIdType::Aggregate(FromVecAutoToVecOfConst<DataArrayIdType>(globalNodeIdsReceived)) );
+  MCAuto<DataArrayIdType> aggregatedNodeIdsSorted(aggregatedNodeIds->copySorted());
+  MCAuto<DataArrayIdType> nodeIdsIntoAggregatedIds(DataArrayIdType::FindPermutationFromFirstToSecondDuplicate(aggregatedNodeIdsSorted,aggregatedNodeIds));
+  MCAuto<DataArrayIdType> idxOfSameNodeIds(aggregatedNodeIdsSorted->indexOfSameConsecutiveValueGroups());
+  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()));
+  // 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());
+  }
+  // thirdly renumber cells
   MCAuto<DataArrayIdType> aggregatedCellIds( DataArrayIdType::Aggregate(FromVecAutoToVecOfConst<DataArrayIdType>(globalCellIdsReceived)) );
   MCAuto<DataArrayIdType> aggregatedCellIdsSorted(aggregatedCellIds->copySorted());
+  MCAuto<DataArrayIdType> idsIntoAggregatedIds(DataArrayIdType::FindPermutationFromFirstToSecondDuplicate(aggregatedCellIdsSorted,aggregatedCellIds));
+  // TODO : check coordsReceived==globalCellIds
+  MCAuto<DataArrayIdType> connSorted,indicesSorted;
+  {
+    MCAuto<DataArrayIdType> conn(DataArrayIdType::Aggregate(FromVecAutoToVecOfConst<DataArrayIdType>(connectivityReceived)));
+    MCAuto<DataArrayIdType> connIndex(DataArrayIdType::AggregateIndexes(FromVecAutoToVecOfConst<DataArrayIdType>(connectivityIndexReceived))); 
+    {
+      DataArrayIdType *indicesSortedTmp(nullptr),*valuesSortedTmp(nullptr);
+      DataArrayIdType::ExtractFromIndexedArrays(idsIntoAggregatedIds->begin(),idsIntoAggregatedIds->end(),conn,connIndex,valuesSortedTmp,indicesSortedTmp);
+      indicesSorted = indicesSortedTmp; connSorted=valuesSortedTmp;
+    }
+  }
+  // finalize all
+  MCAuto<MEDCouplingUMesh> mesh(MEDCouplingUMesh::New(_mesh->getName(),_mesh->getMeshDimension()));
+  mesh->setConnectivity(connSorted,indicesSorted,true);
+  mesh->setCoords(finalCoords);
+  MCAuto<ParaUMesh> ret(ParaUMesh::New(mesh,aggregatedCellIdsSorted,finalGlobalNodeIds));
+  return ret.retn();
 }
index 3d0bff3920bed5a7f2471bf37dafd35af1c0ad6c..905128bb46304c063bd4a0190567ec0bf5b30fad 100644 (file)
@@ -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<DataArrayIdType> getCellIdsLyingOnNodes(const DataArrayIdType *globalNodeIds, bool fullyIn) const;
-    MCAuto<ParaUMesh> 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<const BigMemoryObject *> getDirectChildrenWithNull() const override;
   private:
     MCAuto<MEDCouplingUMesh> _mesh;
     MCAuto<DataArrayIdType> _cell_global;
index 5bdcc0533cad39dcb0dc31d39773d5ee981592ae..46418d15e7eff993a10e1c084c4ec1b269d22cf1 100644 (file)
@@ -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<DataArrayIdType> ret(self->getCellIdsLyingOnNodes(globalNodeIds,fullyIn));