]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Implement generateGraph() of MEDCouplingUMesh
authorimn <imn@opencascade.com>
Thu, 21 May 2015 14:32:10 +0000 (17:32 +0300)
committerimn <imn@opencascade.com>
Thu, 21 May 2015 14:32:10 +0000 (17:32 +0300)
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDPartitioner/MEDPARTITIONER_Graph.hxx
src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx
src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx
src/MEDPartitioner_Swig/MEDPartitionerCommon.i
src/MEDPartitioner_Swig/MEDPartitionerTest.py

index acc8aaf85dbda29c5697507d030b4ec7e51cd70d..405f9300fc0e9bee339346ca196b806e28b7f072 100644 (file)
@@ -8658,7 +8658,23 @@ DataArrayInt *MEDCouplingUMesh::buildUnionOf3DMesh() const
  */
 MEDCouplingSkyLineArray *MEDCouplingUMesh::generateGraph() const
 {
-  MEDCouplingSkyLineArray* ret=new MEDCouplingSkyLineArray(_nodal_connec_index, _nodal_connec);
+  DataArrayInt* index=DataArrayInt::New();
+  index->alloc(_nodal_connec_index->getNbOfElems(),1);
+  int *indexCurPtr=index->getPointer();
+  int *indexPtr=_nodal_connec_index->getPointer();
+
+  for(int i=0;i<_nodal_connec_index->getNbOfElems();i++)
+         indexCurPtr[i]=indexPtr[i];
+
+  DataArrayInt* value=DataArrayInt::New();
+  value->alloc(_nodal_connec->getNbOfElems(),1);
+  int *valueCurPtr=value->getPointer();
+  int *valuePtr= _nodal_connec->getPointer();
+
+  for(int i=0;i<_nodal_connec->getNbOfElems();i++)
+         valueCurPtr[i]=valuePtr[i];
+
+  MEDCouplingSkyLineArray* ret=new MEDCouplingSkyLineArray(index, value);
   return ret;
 }
 
index c71a11bb7e308e6cc25d391ba7f8c124e7b17f16..e50ba93a2b6abe0e1dcbcfc92606a104cf5e59ca 100644 (file)
@@ -38,7 +38,7 @@ namespace MEDPARTITIONER
   public:
     typedef enum {METIS,SCOTCH} splitter_type;
 
-    Graph() { }
+    Graph();
     //creates a graph from a SKYLINEARRAY
     Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, int* edgeweight=0);
     virtual ~Graph();
@@ -47,7 +47,7 @@ namespace MEDPARTITIONER
     void setVerticesWeights(int *cellweight) { _cell_weight=cellweight; }
     
     //computes partitioning of the graph
-    virtual void partGraph(int ndomain, const std::string&, ParaDomainSelector *sel=0) = 0;
+    virtual void partGraph(int ndomain, const std::string& options_string="", ParaDomainSelector *sel=0) = 0;
     
     //returns the partitioning
     const int *getPart() const { return _partition->getValue(); }
index 7156385c65aaabe0e4491efae5ae842a2d24bae8..fcb6a069f1426b224d573e980bf1c257edea28e2 100644 (file)
@@ -68,7 +68,7 @@ MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const ParaMEDMEM::MEDFileData* fi
       (_input_collection->getMesh()).push_back(CreateEmptyMEDCouplingUMesh()); // or 0 if you want tests;
       ParaMEDMEM::DataArrayInt* empty=ParaMEDMEM::DataArrayInt::New();
       empty->alloc(0,1);
-          (_input_collection->getCellFamilyIds()).push_back(empty);
+         (_input_collection->getCellFamilyIds()).push_back(empty);
     }
     try
     {
@@ -157,28 +157,38 @@ ParaMEDMEM::MEDFileData* MEDPARTITIONER::MEDPartitioner::convertToMEDFileData(Me
 
 MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight)
 {
-  // MEDPARTITIONER::SkyLineArray* r=0;
-  // MEDPARTITIONER::Graph* cellGraph = 0;
-  // switch (split)
-  //     {
-  //     case Graph::METIS:
-  //       if ( !cellGraph )
-  //       {
-  // #ifdef MED_ENABLE_METIS
-  //         cellGraph=new METISGraph(r,edgeweight);
-  // #endif
-  //       }
-  //       if ( !cellGraph )
-  //         throw INTERP_KERNEL::Exception("MeshCollection::createPartition : PARMETIS/METIS is not available. Check your products, please.");
-  //       break;
-  //     case Graph::SCOTCH:
-  // #ifdef MED_ENABLE_SCOTCH
-  //       cellGraph=new SCOTCHGraph(r,edgeweight);
-  // #else
-  //       throw INTERP_KERNEL::Exception("MeshCollection::createPartition : SCOTCH is not available. Check your products, please.");
-  // #endif
-  //       break;
-  //     }
-  // return cellGraph;
+  MEDPARTITIONER::SkyLineArray* arr=0;
+  MEDPARTITIONER::Graph* cellGraph=0;
+  std::vector<int> index,value;
+  int *arrIndex = (const_cast<ParaMEDMEM::DataArrayInt*>(graph->getIndex()))->getPointer();
+  int *arrValue = (const_cast<ParaMEDMEM::DataArrayInt*>(graph->getValue()))->getPointer();
+  for(int i=0;i<graph->getNumberOf();i++) {
+    index.push_back(arrIndex[i]);
+  }
+  for(int i=0;i<graph->getLength();i++) {
+    value.push_back(arrValue[i]);
+  }
+  arr = new SkyLineArray(index,value);
+  switch (split)
+  {
+    case Graph::METIS:
+      if ( !cellGraph )
+      {
+        #ifdef MED_ENABLE_METIS
+          cellGraph=new METISGraph(arr,edgeweight);
+        #endif
+      }
+      if ( !cellGraph )
+        throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : PARMETIS/METIS is not available. Check your products, please.");
+    break;
+    case Graph::SCOTCH:
+      #ifdef MED_ENABLE_SCOTCH
+        cellGraph=new SCOTCHGraph(arr,edgeweight);
+      #else
+        throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : SCOTCH is not available. Check your products, please.");
+      #endif
+    break;
+  }
+  return cellGraph;
 
 }
index 24df096f90fb138115e5c80610c4409f2dc22967..ac5f8d97fefefda32db0a6d563d9847f336b1fd6 100644 (file)
@@ -35,11 +35,10 @@ namespace ParaMEDMEM
 
 namespace MEDPARTITIONER
 {
-  class Topology;
   class MeshCollection;
   class ParaDomainSelector;
   class Graph;
-  
+
   class MEDPartitioner
   {
   public:
@@ -47,7 +46,7 @@ namespace MEDPARTITIONER
     static MEDPartitioner *New(const ParaMEDMEM::MEDFileData* filedata, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false);
     void Write(const std::string& filename);
     ParaMEDMEM::MEDFileData* getMEDFileData();
-    MEDPARTITIONER::Graph* Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight=0);
+    MEDPARTITIONER::Graph* Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split=Graph::METIS, int* edgeweight=0);
   private:
     MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory);
     MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory);
index c7e3753f0106f397e0c7d91067a368f5e5ab7265..eafe7b39cda4fcb72842c04db6255b4579931787 100644 (file)
 #include "MEDFileData.hxx"
 
 #include "MEDPARTITIONER_MEDPartitioner.hxx"
-
+#include "MEDPARTITIONER.hxx"
+#include "MEDPARTITIONER_SkyLineArray.hxx"
 #include "MEDPARTITIONER_Graph.hxx"
+#include "MEDPARTITIONER_MetisGraph.hxx"
+#include "MEDPARTITIONER_ScotchGraph.hxx"
 
 using namespace ParaMEDMEM;
 using namespace INTERP_KERNEL;
@@ -53,6 +56,7 @@ using namespace MEDPARTITIONER;
 %nodefaultctor;
 
 %newobject MEDPARTITIONER::MEDPartitioner::New;
+%newobject MEDPARTITIONER::MEDPartitioner::Graph;
 
 %rename (InterpKernelException) INTERP_KERNEL::Exception;
 
@@ -66,7 +70,7 @@ public:
     static MEDPartitioner *New(const ParaMEDMEM::MEDFileData* filedata, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception);
     void Write(const std::string& filename) throw(INTERP_KERNEL::Exception);
     ParaMEDMEM::MEDFileData* getMEDFileData() throw(INTERP_KERNEL::Exception);
-    MEDPARTITIONER::Graph* Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight=0) throw(INTERP_KERNEL::Exception);
+    MEDPARTITIONER::Graph* Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split=Graph::METIS, int* edgeweight=0) throw(INTERP_KERNEL::Exception);
   %extend
   {
     MEDPartitioner(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception)
@@ -78,4 +82,12 @@ public:
       return MEDPartitioner::New(fileData,ndomains,library,creates_boundary_faces, create_joints, mesure_memory);
     }
   }
+};
+namespace MEDPARTITIONER
+{ 
+  class Graph
+  {
+  public:
+    virtual void partGraph(int ndomain, const std::string& options_string="", ParaDomainSelector *sel=0) throw(INTERP_KERNEL::Exception);
+  };
 };
\ No newline at end of file
index a50adb6c79509794b299ad96dc2b964e8aae1251..b711a74a3032dc66dc815d172ed558a6ab43cecb 100644 (file)
@@ -35,8 +35,10 @@ class MEDPartitionerTest(unittest.TestCase):
        #mfd1 = MEDFileData.New()
         p=MEDPartitioner.New(d,2);
         #p=MEDPartitioner.New("/dn20/salome/imn/SALOME7YA/MED_BUILD/src/MEDLoader/Swig/splitted_blade1.med");
-        #part=MEDPartitioner.Graph(m.generateGraph())
-        #part.partGraph(2)
+        mm=m.generateGraph()
+        part=p.Graph(mm)
+        part.partGraph(2)
+        #part2.partGraph(2)
         #a=part.getGraph()
         #n2o,o2n=ren.renumber(a,b)
     pass