From: imn Date: Thu, 21 May 2015 14:43:12 +0000 (+0300) Subject: Implement generateGraph() of MEDCouplingUMesh X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fa6ed28f84eb6a4afebee68a4908a680b4928643;p=tools%2Fmedcoupling.git Implement generateGraph() of MEDCouplingUMesh --- diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 405f9300f..674d4182d 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -8658,24 +8658,67 @@ DataArrayInt *MEDCouplingUMesh::buildUnionOf3DMesh() const */ MEDCouplingSkyLineArray *MEDCouplingUMesh::generateGraph() const { - 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; + int meshDim = this->getMeshDimension(); + ParaMEDMEM::DataArrayInt* indexr=ParaMEDMEM::DataArrayInt::New(); + ParaMEDMEM::DataArrayInt* revConn=ParaMEDMEM::DataArrayInt::New(); + int nbNodes=getNumberOfNodes(); + this->getReverseNodalConnectivity(revConn,indexr); + const int* indexr_ptr=indexr->getConstPointer(); + const int* revConn_ptr=revConn->getConstPointer(); + + const ParaMEDMEM::DataArrayInt* index; + const ParaMEDMEM::DataArrayInt* conn; + conn=this->getNodalConnectivity(); + index=this->getNodalConnectivityIndex(); + int nbCells=this->getNumberOfCells(); + const int* index_ptr=index->getConstPointer(); + const int* conn_ptr=conn->getConstPointer(); + + //creating graph arcs (cell to cell relations) + //arcs are stored in terms of (index,value) notation + // 0 3 5 6 6 + // 1 2 3 2 3 3 + // means 6 arcs (0,1), (0,2), (0,3), (1,2), (1,3), (2,3) + // in present version arcs are not doubled but reflexive (1,1) arcs are present for each cell + + //warning here one node have less than or equal effective number of cell with it + //but cell could have more than effective nodes + //because other equals nodes in other domain (with other global inode) + std::vector cell2cell_index(nbCells+1,0); + std::vector cell2cell; + cell2cell.reserve(3*nbCells); + + for (int icell=0; icell counter; + for (int iconn=index_ptr[icell]; iconn::iterator iter=counter.find(icell2); + if (iter!=counter.end()) (iter->second)++; + else counter.insert(std::make_pair(icell2,1)); + } + } + for (std::map::const_iterator iter=counter.begin(); + iter!=counter.end(); iter++) + if (iter->second >= meshDim) + { + cell2cell_index[icell+1]++; + cell2cell.push_back(iter->first); + } + } + indexr->decrRef(); + revConn->decrRef(); + cell2cell_index[0]=0; + for (int icell=0; icellgetValue(); } diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx index fcb6a069f..a7676bb6c 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx @@ -157,18 +157,8 @@ ParaMEDMEM::MEDFileData* MEDPARTITIONER::MEDPartitioner::convertToMEDFileData(Me MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight) { - 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); + ParaMEDMEM::MEDCouplingSkyLineArray* arr = new ParaMEDMEM::MEDCouplingSkyLineArray(graph->getIndexArray(), graph->getValueArray()); switch (split) { case Graph::METIS: diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx index ac5f8d97f..24df096f9 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx @@ -35,10 +35,11 @@ namespace ParaMEDMEM namespace MEDPARTITIONER { + class Topology; class MeshCollection; class ParaDomainSelector; class Graph; - + class MEDPartitioner { public: @@ -46,7 +47,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=Graph::METIS, int* edgeweight=0); + MEDPARTITIONER::Graph* Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, 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 eafe7b39c..7c1e34e91 100644 --- a/src/MEDPartitioner_Swig/MEDPartitionerCommon.i +++ b/src/MEDPartitioner_Swig/MEDPartitionerCommon.i @@ -32,7 +32,6 @@ #include "MEDPARTITIONER_MEDPartitioner.hxx" #include "MEDPARTITIONER.hxx" -#include "MEDPARTITIONER_SkyLineArray.hxx" #include "MEDPARTITIONER_Graph.hxx" #include "MEDPARTITIONER_MetisGraph.hxx" #include "MEDPARTITIONER_ScotchGraph.hxx" diff --git a/src/MEDPartitioner_Swig/MEDPartitionerTest.py b/src/MEDPartitioner_Swig/MEDPartitionerTest.py index b711a74a3..4f23061f6 100644 --- a/src/MEDPartitioner_Swig/MEDPartitionerTest.py +++ b/src/MEDPartitioner_Swig/MEDPartitionerTest.py @@ -34,11 +34,8 @@ class MEDPartitionerTest(unittest.TestCase): d=MEDFileData.New("/dn20/salome/imn/SALOME7YA/MED_BUILD/src/MEDLoader/Swig/splitted_blade1.med") #mfd1 = MEDFileData.New() p=MEDPartitioner.New(d,2); - #p=MEDPartitioner.New("/dn20/salome/imn/SALOME7YA/MED_BUILD/src/MEDLoader/Swig/splitted_blade1.med"); - mm=m.generateGraph() - part=p.Graph(mm) + part=MEDPartitioner.Graph(m.generateGraph()) part.partGraph(2) - #part2.partGraph(2) #a=part.getGraph() #n2o,o2n=ren.renumber(a,b) pass