]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Make it templated
authorAnthony Geay <anthony.geay@edf.fr>
Mon, 27 Apr 2020 22:12:14 +0000 (00:12 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 27 Apr 2020 22:12:14 +0000 (00:12 +0200)
src/ParaMEDMEM/ParaUMesh.cxx
src/ParaMEDMEM/ParaUMesh.hxx
src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i

index 7e3060892ffd450b1d87173a3848f24cfb9c5716..e5ea86c62f76a7a4adb8747ca2be2cf20d644cce 100644 (file)
@@ -133,81 +133,22 @@ MCAuto<DataArrayIdType> ParaUMesh::getCellIdsLyingOnNodes(const DataArrayIdType
 
 DataArrayIdType *ParaUMesh::redistributeCellField(const DataArrayIdType *globalCellIds, const DataArrayIdType *fieldValueToRed) const
 {
-  MPI_Comm comm(MPI_COMM_WORLD);
-  CommInterface ci;
-  std::unique_ptr<mcIdType[]> allGlobalCellIds,allGlobalCellIdsIndex;
-  int size(ci.allGatherArrays(comm,globalCellIds,allGlobalCellIds,allGlobalCellIdsIndex));
-  // Prepare ParaUMesh parts to be sent : compute for each proc the contribution of current rank.
-  std::vector< MCAuto<DataArrayIdType> > globalCellIdsToBeSent(size);
-  std::vector< MCAuto<DataArrayIdType> > fieldToBeSent(size);
-  for(int curRk = 0 ; curRk < size ; ++curRk)
-  {
-    mcIdType offset(allGlobalCellIdsIndex[curRk]);
-    MCAuto<DataArrayIdType> globalCellIdsOfCurProc(DataArrayIdType::New());
-    globalCellIdsOfCurProc->useArray(allGlobalCellIds.get()+offset,false,DeallocType::CPP_DEALLOC,allGlobalCellIdsIndex[curRk+1]-offset,1);
-    // the key call is here : compute for rank curRk the cells to be sent
-    MCAuto<DataArrayIdType> globalCellIdsCaptured(_cell_global->buildIntersection(globalCellIdsOfCurProc));// OK for the global cellIds
-    MCAuto<DataArrayIdType> localCellIdsCaptured(_cell_global->findIdForEach(globalCellIdsCaptured->begin(),globalCellIdsCaptured->end()));
-    globalCellIdsToBeSent[curRk] = globalCellIdsCaptured;
-    fieldToBeSent[curRk] = fieldValueToRed->selectByTupleIdSafe(localCellIdsCaptured->begin(),localCellIdsCaptured->end());
-  }
-  // Receive
-  std::vector< MCAuto<DataArrayIdType> > globalCellIdsReceived;
-  ci.allToAllArrays(comm,globalCellIdsToBeSent,globalCellIdsReceived);
-  std::vector< MCAuto<DataArrayIdType> > fieldValueReceived;
-  ci.allToAllArrays(comm,fieldToBeSent,fieldValueReceived);
-  // use globalCellIdsReceived to reorganize everything
-  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
-  //
-  MCAuto<DataArrayIdType> fieldAggregated(DataArrayIdType::Aggregate(FromVecAutoToVecOfConst<DataArrayIdType>(fieldValueReceived)));
-  MCAuto<DataArrayIdType> ret(fieldAggregated->selectByTupleIdSafe(n2o_cells->begin(),n2o_cells->end()));
-  return ret.retn();
+  return this->redistributeCellFieldT<mcIdType>(globalCellIds,fieldValueToRed);
+}
+
+DataArrayDouble *ParaUMesh::redistributeCellField(const DataArrayIdType *globalCellIds, const DataArrayDouble *fieldValueToRed) const
+{
+  return this->redistributeCellFieldT<double>(globalCellIds,fieldValueToRed);
 }
 
 DataArrayIdType *ParaUMesh::redistributeNodeField(const DataArrayIdType *globalCellIds, const DataArrayIdType *fieldValueToRed) const
 {
-  MPI_Comm comm(MPI_COMM_WORLD);
-  CommInterface ci;
-  std::unique_ptr<mcIdType[]> allGlobalCellIds,allGlobalCellIdsIndex;
-  int size(ci.allGatherArrays(comm,globalCellIds,allGlobalCellIds,allGlobalCellIdsIndex));
-  // Prepare ParaUMesh parts to be sent : compute for each proc the contribution of current rank.
-  std::vector< MCAuto<DataArrayIdType> > globalNodeIdsToBeSent(size);
-  std::vector< MCAuto<DataArrayIdType> > fieldToBeSent(size);
-  for(int curRk = 0 ; curRk < size ; ++curRk)
-  {
-    mcIdType offset(allGlobalCellIdsIndex[curRk]);
-    MCAuto<DataArrayIdType> globalCellIdsOfCurProc(DataArrayIdType::New());
-    globalCellIdsOfCurProc->useArray(allGlobalCellIds.get()+offset,false,DeallocType::CPP_DEALLOC,allGlobalCellIdsIndex[curRk+1]-offset,1);
-    // the key call is here : compute for rank curRk the cells to be sent
-    MCAuto<DataArrayIdType> globalCellIdsCaptured(_cell_global->buildIntersection(globalCellIdsOfCurProc));// OK for the global cellIds
-    MCAuto<DataArrayIdType> localCellIdsCaptured(_cell_global->findIdForEach(globalCellIdsCaptured->begin(),globalCellIdsCaptured->end()));
-    MCAuto<MEDCouplingUMesh> meshPart(_mesh->buildPartOfMySelf(localCellIdsCaptured->begin(),localCellIdsCaptured->end(),true));
-    MCAuto<DataArrayIdType> o2n(meshPart->zipCoordsTraducer());// OK for the mesh
-    MCAuto<DataArrayIdType> n2o(o2n->invertArrayO2N2N2O(meshPart->getNumberOfNodes()));
-    MCAuto<DataArrayIdType> globalNodeIdsPart(_node_global->selectByTupleIdSafe(n2o->begin(),n2o->end())); // OK for the global nodeIds
-    globalNodeIdsToBeSent[curRk] = globalNodeIdsPart;
-    fieldToBeSent[curRk] = fieldValueToRed->selectByTupleIdSafe(n2o->begin(),n2o->end());
-  }
-  // Receive
-  std::vector< MCAuto<DataArrayIdType> > globalNodeIdsReceived;
-  ci.allToAllArrays(comm,globalNodeIdsToBeSent,globalNodeIdsReceived);
-  std::vector< MCAuto<DataArrayIdType> > fieldValueReceived;
-  ci.allToAllArrays(comm,fieldToBeSent,fieldValueReceived);
-  // firstly deal with nodes.
-  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> fieldAggregated(DataArrayIdType::Aggregate(FromVecAutoToVecOfConst<DataArrayIdType>(fieldValueReceived)));
-  MCAuto<DataArrayIdType> ret(fieldAggregated->selectByTupleIdSafe(n2o_nodes->begin(),n2o_nodes->end()));
-  //
-  return ret.retn();
+  return this->redistributeNodeFieldT<mcIdType>(globalCellIds,fieldValueToRed);
+}
+
+DataArrayDouble *ParaUMesh::redistributeNodeField(const DataArrayIdType *globalCellIds, const DataArrayDouble *fieldValueToRed) const
+{
+  return this->redistributeNodeFieldT<double>(globalCellIds,fieldValueToRed);
 }
 
 /*!
index d8a938718854d03a98712288382f52d6dde8ee1f..ec404a6535c5e4fcf9cbb9a64017afb9530765e6 100644 (file)
@@ -40,7 +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;
+    DataArrayDouble *redistributeCellField(const DataArrayIdType *globalCellIds, const DataArrayDouble *fieldValueToRed) const;
     DataArrayIdType *redistributeCellField(const DataArrayIdType *globalCellIds, const DataArrayIdType *fieldValueToRed) const;
+    DataArrayDouble *redistributeNodeField(const DataArrayIdType *globalCellIds, const DataArrayDouble *fieldValueToRed) const;
     DataArrayIdType *redistributeNodeField(const DataArrayIdType *globalCellIds, const DataArrayIdType *fieldValueToRed) const;
     MEDCouplingUMesh *getMesh() { return _mesh; }
     DataArrayIdType *getGlobalCellIds() { return _cell_global; }
@@ -55,5 +57,88 @@ namespace MEDCoupling
     MCAuto<MEDCouplingUMesh> _mesh;
     MCAuto<DataArrayIdType> _cell_global;
     MCAuto<DataArrayIdType> _node_global;
+  private:
+    template<class T>
+    typename Traits<T>::ArrayType *redistributeCellFieldT(const DataArrayIdType *globalCellIds, const typename Traits<T>::ArrayType *fieldValueToRed) const
+    {
+      using DataArrayT = typename Traits<T>::ArrayType;
+      MPI_Comm comm(MPI_COMM_WORLD);
+      CommInterface ci;
+      std::unique_ptr<mcIdType[]> allGlobalCellIds,allGlobalCellIdsIndex;
+      int size(ci.allGatherArrays(comm,globalCellIds,allGlobalCellIds,allGlobalCellIdsIndex));
+      // Prepare ParaUMesh parts to be sent : compute for each proc the contribution of current rank.
+      std::vector< MCAuto<DataArrayIdType> > globalCellIdsToBeSent(size);
+      std::vector< MCAuto<DataArrayT> > fieldToBeSent(size);
+      for(int curRk = 0 ; curRk < size ; ++curRk)
+      {
+        mcIdType offset(allGlobalCellIdsIndex[curRk]);
+        MCAuto<DataArrayIdType> globalCellIdsOfCurProc(DataArrayIdType::New());
+        globalCellIdsOfCurProc->useArray(allGlobalCellIds.get()+offset,false,DeallocType::CPP_DEALLOC,allGlobalCellIdsIndex[curRk+1]-offset,1);
+        // the key call is here : compute for rank curRk the cells to be sent
+        MCAuto<DataArrayIdType> globalCellIdsCaptured(_cell_global->buildIntersection(globalCellIdsOfCurProc));// OK for the global cellIds
+        MCAuto<DataArrayIdType> localCellIdsCaptured(_cell_global->findIdForEach(globalCellIdsCaptured->begin(),globalCellIdsCaptured->end()));
+        globalCellIdsToBeSent[curRk] = globalCellIdsCaptured;
+        fieldToBeSent[curRk] = fieldValueToRed->selectByTupleIdSafe(localCellIdsCaptured->begin(),localCellIdsCaptured->end());
+      }
+      // Receive
+      std::vector< MCAuto<DataArrayIdType> > globalCellIdsReceived;
+      ci.allToAllArrays(comm,globalCellIdsToBeSent,globalCellIdsReceived);
+      std::vector< MCAuto<DataArrayT> > fieldValueReceived;
+      ci.allToAllArrays(comm,fieldToBeSent,fieldValueReceived);
+      // use globalCellIdsReceived to reorganize everything
+      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
+      //
+      MCAuto<DataArrayT> fieldAggregated(DataArrayT::Aggregate(FromVecAutoToVecOfConst<DataArrayT>(fieldValueReceived)));
+      MCAuto<DataArrayT> ret(fieldAggregated->selectByTupleIdSafe(n2o_cells->begin(),n2o_cells->end()));
+      return ret.retn();
+    }
+    
+    template<class T>
+    typename Traits<T>::ArrayType *redistributeNodeFieldT(const DataArrayIdType *globalCellIds, const typename Traits<T>::ArrayType *fieldValueToRed) const
+    {
+      using DataArrayT = typename Traits<T>::ArrayType;
+      MPI_Comm comm(MPI_COMM_WORLD);
+      CommInterface ci;
+      std::unique_ptr<mcIdType[]> allGlobalCellIds,allGlobalCellIdsIndex;
+      int size(ci.allGatherArrays(comm,globalCellIds,allGlobalCellIds,allGlobalCellIdsIndex));
+      // Prepare ParaUMesh parts to be sent : compute for each proc the contribution of current rank.
+      std::vector< MCAuto<DataArrayIdType> > globalNodeIdsToBeSent(size);
+      std::vector< MCAuto<DataArrayT> > fieldToBeSent(size);
+      for(int curRk = 0 ; curRk < size ; ++curRk)
+      {
+        mcIdType offset(allGlobalCellIdsIndex[curRk]);
+        MCAuto<DataArrayIdType> globalCellIdsOfCurProc(DataArrayIdType::New());
+        globalCellIdsOfCurProc->useArray(allGlobalCellIds.get()+offset,false,DeallocType::CPP_DEALLOC,allGlobalCellIdsIndex[curRk+1]-offset,1);
+        // the key call is here : compute for rank curRk the cells to be sent
+        MCAuto<DataArrayIdType> globalCellIdsCaptured(_cell_global->buildIntersection(globalCellIdsOfCurProc));// OK for the global cellIds
+        MCAuto<DataArrayIdType> localCellIdsCaptured(_cell_global->findIdForEach(globalCellIdsCaptured->begin(),globalCellIdsCaptured->end()));
+        MCAuto<MEDCouplingUMesh> meshPart(_mesh->buildPartOfMySelf(localCellIdsCaptured->begin(),localCellIdsCaptured->end(),true));
+        MCAuto<DataArrayIdType> o2n(meshPart->zipCoordsTraducer());// OK for the mesh
+        MCAuto<DataArrayIdType> n2o(o2n->invertArrayO2N2N2O(meshPart->getNumberOfNodes()));
+        MCAuto<DataArrayIdType> globalNodeIdsPart(_node_global->selectByTupleIdSafe(n2o->begin(),n2o->end())); // OK for the global nodeIds
+        globalNodeIdsToBeSent[curRk] = globalNodeIdsPart;
+        fieldToBeSent[curRk] = fieldValueToRed->selectByTupleIdSafe(n2o->begin(),n2o->end());
+      }
+      // Receive
+      std::vector< MCAuto<DataArrayIdType> > globalNodeIdsReceived;
+      ci.allToAllArrays(comm,globalNodeIdsToBeSent,globalNodeIdsReceived);
+      std::vector< MCAuto<DataArrayT> > fieldValueReceived;
+      ci.allToAllArrays(comm,fieldToBeSent,fieldValueReceived);
+      // firstly deal with nodes.
+      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<DataArrayT> fieldAggregated(DataArrayT::Aggregate(FromVecAutoToVecOfConst<DataArrayT>(fieldValueReceived)));
+      MCAuto<DataArrayT> ret(fieldAggregated->selectByTupleIdSafe(n2o_nodes->begin(),n2o_nodes->end()));
+      //
+      return ret.retn();
+    }
   };
 }
index 4c1ff6dae6be0ed062c9ab24ab5abbf4e78d7f50..d2eb770f41dfcdb014366aa57aeffaf70cb26e6c 100644 (file)
@@ -163,7 +163,9 @@ namespace MEDCoupling
     static ParaUMesh *New(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds);
     ParaUMesh *redistributeCells(const DataArrayIdType *globalCellIds) const;
     DataArrayIdType *redistributeCellField(const DataArrayIdType *globalCellIds, const DataArrayIdType *fieldValueToRed) const;
+    DataArrayDouble *redistributeCellField(const DataArrayIdType *globalCellIds, const DataArrayDouble *fieldValueToRed) const;
     DataArrayIdType *redistributeNodeField(const DataArrayIdType *globalCellIds, const DataArrayIdType *fieldValueToRed) const;
+    DataArrayDouble *redistributeNodeField(const DataArrayIdType *globalCellIds, const DataArrayDouble *fieldValueToRed) const;
     %extend
     {
       ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds)