From: eap Date: Tue, 26 May 2015 13:35:06 +0000 (+0300) Subject: test MEDCouplingUMesh::generateGraph + debug X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=86810189817f98e3004e0a7c1f51df84d1ef6a1d;p=tools%2Fmedcoupling.git test MEDCouplingUMesh::generateGraph + debug --- diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx index 9719cb04d..87f1bae2d 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx @@ -45,7 +45,9 @@ MEDCouplingSkyLineArray::MEDCouplingSkyLineArray( const std::vector& index, const std::vector& value ): _index( DataArrayInt::New() ), _value( DataArrayInt::New() ) { + _index->reserve( index.size() ); _index->insertAtTheEnd( index.begin(), index.end() ); + _value->reserve( value.size() ); _value->insertAtTheEnd( value.begin(), value.end() ); } @@ -68,3 +70,33 @@ DataArrayInt* MEDCouplingSkyLineArray::getValueArray() const { return ((MEDCouplingSkyLineArray*)this)->_value; } + +std::string MEDCouplingSkyLineArray::simpleRepr() const +{ + std::ostringstream oss; + oss << "MEDCouplingSkyLineArray" << std::endl; + oss << " Nb of items: " << getNumberOf() << std::endl; + oss << " Nb of values: " << getLength() << std::endl; + oss << " Index:" << std::endl; + oss << " "; + const int * i = _index->begin(); + for ( ; i != _index->end(); ++i ) + oss << *i << " "; + oss << std::endl; + oss << " Value:" << std::endl; + oss << " "; + const int * v = _value->begin(); + int cnt = 0; + for ( i = _index->begin(); v != _value->end(); ++v, ++cnt ) + { + if ( cnt == *i ) + { + oss << "| "; + ++i; + } + oss << *v << " "; + } + oss << std::endl; + + return oss.str(); +} diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx index 06826f803..c12dc6b68 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx @@ -49,6 +49,8 @@ namespace ParaMEDMEM DataArrayInt* getIndexArray() const; DataArrayInt* getValueArray() const; + + std::string simpleRepr() const; }; } # endif diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 7d9e5426e..05e86db3e 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -8669,55 +8669,55 @@ MEDCouplingSkyLineArray *MEDCouplingUMesh::generateGraph() const const ParaMEDMEM::DataArrayInt* index; const ParaMEDMEM::DataArrayInt* conn; - conn=this->getNodalConnectivity(); + conn=this->getNodalConnectivity(); // it includes a type as the 1st element!!! 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 + //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) + //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)); - } + std::map counter; + for (int iconn=index_ptr[icell]+1; 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); + } } - 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; icell& v1, const std::vector& v2, double eps); }; -} -namespace ParaMEDMEM -{ + class MEDCouplingSkyLineArray { public: @@ -1153,6 +1151,13 @@ namespace ParaMEDMEM int getLength() const; DataArrayInt* getIndexArray() const; DataArrayInt* getValueArray() const; + %extend + { + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + } }; } diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx index d7f93fe53..15b7549e0 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx @@ -42,7 +42,8 @@ MEDPARTITIONER::MEDPartitioner *MEDPARTITIONER::MEDPartitioner::New(const ParaME return new MEDPartitioner(filedata,ndomains,library,creates_boundary_faces, create_joints, mesure_memory); } -MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory) +MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory): + _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 ) { MyGlobals::_World_Size=1; MyGlobals::_Rank=0; @@ -60,7 +61,8 @@ MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const std::string& filename, int parallelizer.evaluateMemory(); } -MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory) +MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory): + _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 ) { MyGlobals::_World_Size=1; MyGlobals::_Rank=0; @@ -79,15 +81,21 @@ MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const ParaMEDMEM::MEDFileData* fi parallelizer.evaluateMemory(); } +MEDPARTITIONER::MEDPartitioner::~MEDPartitioner() +{ + delete _input_collection; _input_collection = 0; + delete _output_collection; _output_collection = 0; + delete _new_topology; _new_topology = 0; +} + void MEDPARTITIONER::MEDPartitioner::createPartitionCollection(int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory) { - ParallelTopology* aPT = (ParallelTopology*) _input_collection->getTopology(); - std::auto_ptr< Topology > new_topo; + //ParallelTopology* aPT = (ParallelTopology*) _input_collection->getTopology(); if (library == "metis") - new_topo.reset( _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::METIS)); + _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::METIS); else - new_topo.reset(_input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH)); - _output_collection=new MeshCollection(*_input_collection,new_topo.get(),false,false); + _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH); + _output_collection=new MeshCollection(*_input_collection,_new_topology,false,false); _output_collection->filterFaceOnCell(); } diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx index 96e030cca..c656cb852 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx @@ -20,8 +20,6 @@ #ifndef __MEDPARTITIONER_MEDPARTITIONER_HXX__ #define __MEDPARTITIONER_MEDPARTITIONER_HXX__ -#include "MEDFileData.hxx" -#include "MEDCouplingSkyLineArray.hxx" #include "MEDPARTITIONER_Graph.hxx" #include @@ -31,6 +29,7 @@ namespace ParaMEDMEM { class DataArrayInt; class MEDFileData; + class MEDCouplingSkyLineArray; } namespace MEDPARTITIONER @@ -48,12 +47,18 @@ namespace MEDPARTITIONER 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(); + 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); + ParaMEDMEM::MEDFileData *convertToMEDFileData(MeshCollection* meshcollection); void createPartitionCollection(int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory); + + private: MeshCollection* _input_collection; MeshCollection* _output_collection; + Topology* _new_topology; }; } #endif diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx index e3a268032..bf8700d62 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx @@ -215,15 +215,16 @@ ParaMEDMEM::MEDFileMesh* MeshCollectionDriver::getMesh(int idomain) const } else { - finalMeshName=(_collection->getMesh())[idomain]->getName(); + finalMeshName=(_collection->getMesh())[idomain]->getName(); } cellMesh->setName(finalMeshName); mfm->setMeshAtLevel( 0, cellMesh ); - + faceMesh->checkCoherency(); if (faceMesh->getNumberOfCells()>0) { faceMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-10); + faceMesh->setName(finalMeshName); mfm->setMeshAtLevel( -1, faceMesh ); } @@ -307,6 +308,8 @@ ParaMEDMEM::MEDFileMesh* MeshCollectionDriver::getMesh(int idomain) const } mfm->setJoints( joints ); } + + return mfm; } ParaMEDMEM::MEDCouplingFieldDouble* MeshCollectionDriver::getField(std::string key, std::string description, ParaMEDMEM::DataArrayDouble* data, ParaMEDMEM::MEDFileMesh* mfm, int idomain) const diff --git a/src/MEDPartitioner_Swig/MEDPartitionerCommon.i b/src/MEDPartitioner_Swig/MEDPartitionerCommon.i index 1d85c3d57..b853a3af3 100644 --- a/src/MEDPartitioner_Swig/MEDPartitionerCommon.i +++ b/src/MEDPartitioner_Swig/MEDPartitionerCommon.i @@ -63,28 +63,28 @@ using namespace MEDPARTITIONER; class MEDPartitioner { public: - static MEDPartitioner *New(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); - 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=Graph::METIS, int* edgeweight=0) throw(INTERP_KERNEL::Exception); + static MEDPartitioner *New(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); + 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=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) - { - return MEDPartitioner::New(filename,ndomains,library,creates_boundary_faces, create_joints, mesure_memory); - } + { + return MEDPartitioner::New(filename,ndomains,library,creates_boundary_faces, create_joints, mesure_memory); + } MEDPartitioner(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) - { - return MEDPartitioner::New(fileData,ndomains,library,creates_boundary_faces, create_joints, mesure_memory); - } + { + 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 +};