From: imn Date: Thu, 21 May 2015 14:32:10 +0000 (+0300) Subject: Implement generateGraph() of MEDCouplingUMesh X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4b2b38291534deaefe28cef4da8be03f5547cd45;p=tools%2Fmedcoupling.git Implement generateGraph() of MEDCouplingUMesh --- diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index acc8aaf85..405f9300f 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -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; } diff --git a/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx b/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx index c71a11bb7..e50ba93a2 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx @@ -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(); } diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx index 7156385c6..fcb6a069f 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx @@ -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 index,value; + int *arrIndex = (const_cast(graph->getIndex()))->getPointer(); + int *arrValue = (const_cast(graph->getValue()))->getPointer(); + for(int i=0;igetNumberOf();i++) { + index.push_back(arrIndex[i]); + } + for(int i=0;igetLength();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; } diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx index 24df096f9..ac5f8d97f 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx @@ -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); diff --git a/src/MEDPartitioner_Swig/MEDPartitionerCommon.i b/src/MEDPartitioner_Swig/MEDPartitionerCommon.i index c7e3753f0..eafe7b39c 100644 --- a/src/MEDPartitioner_Swig/MEDPartitionerCommon.i +++ b/src/MEDPartitioner_Swig/MEDPartitionerCommon.i @@ -31,8 +31,11 @@ #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 diff --git a/src/MEDPartitioner_Swig/MEDPartitionerTest.py b/src/MEDPartitioner_Swig/MEDPartitionerTest.py index a50adb6c7..b711a74a3 100644 --- a/src/MEDPartitioner_Swig/MEDPartitionerTest.py +++ b/src/MEDPartitioner_Swig/MEDPartitionerTest.py @@ -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