Salome HOME
Fix: getCellsContainingPoints() in case of polyhedron with a face containing colinear...
[tools/medcoupling.git] / src / MEDPartitioner / MEDPARTITIONER_MetisGraph.cxx
index 5f89b9573ba69d1f07ab7803c48f3f26efbd4d4a..e9a339acb698e44556d81e0310268b7ea4824ccc 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #include "MEDPARTITIONER_ParaDomainSelector.hxx"
 #include "MEDPARTITIONER_Utils.hxx"
 
+#include "MEDCouplingSkyLineArray.hxx"
 #include "InterpKernelException.hxx"
 
 #include <iostream>
 
-#ifdef MED_ENABLE_METIS
 extern "C"
 {
-#include "metis.h"
+#include "MEDPARTITIONER_metis.h"
 }
-#endif
 
 using namespace MEDPARTITIONER;
 
@@ -38,7 +37,7 @@ METISGraph::METISGraph():Graph()
 {
 }
 
-METISGraph::METISGraph(MEDPARTITIONER::SkyLineArray* graph, int* edgeweight)
+METISGraph::METISGraph(MEDCoupling::MEDCouplingSkyLineArray* graph, int* edgeweight)
   :Graph(graph,edgeweight)
 {
 }
@@ -56,10 +55,17 @@ void METISGraph::partGraph(int ndomain,
     std::cout << "proc " << MyGlobals::_Rank << " : METISGraph::partGraph" << std::endl;
   
   //number of graph vertices
-  int n=_graph->getNumberOf();
+  int n=FromIdType<int>(_graph->getNumberOf());
   //graph
+#ifdef MEDCOUPLING_USE_64BIT_IDS
+  std::vector<int> indexVec( _graph->getIndex(), _graph->getIndexArray()->end() );
+  std::vector<int> valueVec( _graph->getValues(), _graph->getValuesArray()->end() );
+  int * xadj=indexVec.data();
+  int * adjncy=valueVec.data();
+#else
   int * xadj=const_cast<int*>(_graph->getIndex());
-  int * adjncy=const_cast<int*>(_graph->getValue());
+  int * adjncy=const_cast<int*>(_graph->getValues());
+#endif
   //constraints
   int * vwgt=_cell_weight;
   int * adjwgt=_edge_weight;
@@ -77,7 +83,7 @@ void METISGraph::partGraph(int ndomain,
     #define PMV3_OPTION_PSR 3
     seems no changes int options[4]={1,0,33,0}; //test for a random seed of 33
   */
-  int options[4]={0,0,0,0};
+  int options[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
 #if !defined(MED_ENABLE_METIS)
   throw INTERP_KERNEL::Exception("METISGraph::partGraph : METIS is not available. Check your products, please.");
 #else
@@ -90,31 +96,31 @@ void METISGraph::partGraph(int ndomain,
       if (MyGlobals::_Verbose>10) 
         std::cout << "METISGraph::partGraph METIS_PartGraph METIS_PartGraph(RecursiveOrKway)" << std::endl;
       if (options_string != "k")
-        METIS_PartGraphRecursive(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
-                                  &base, &nparts, options, &edgecut, partition);
+        MEDPARTITIONER_METIS_PartGraphRecursive(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
+                                                &base, &nparts, options, &edgecut, partition);
       else
-        METIS_PartGraphKway(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
-                            &base, &nparts, options, &edgecut, partition);
+        MEDPARTITIONER_METIS_PartGraphKway(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
+                                           &base, &nparts, options, &edgecut, partition);
     }
   else  //force this case because METIS send all 1 in value
     {
       for (int i=0; i<n; i++)
         partition[i]=0;
     }
-  vector<int> index(n+1);
-  vector<int> value(n);
+  vector<mcIdType> index(n+1);
+  vector<mcIdType> value(n);
   index[0]=0;
   for (int i=0; i<n; i++)
     {
       index[i+1]=index[i]+1;
-      value[i]=partition[i];
+      value[i]=ToIdType(partition[i]);
     }
   delete [] partition;
 
   //creating a skylinearray with no copy of the index and partition array
   //the fifth argument true specifies that only the pointers are passed 
   //to the object
-  _partition = new MEDPARTITIONER::SkyLineArray(index,value);
+  _partition = MEDCoupling::MEDCouplingSkyLineArray::New(index,value);
 #endif
 }