*/
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 <int> cell2cell_index(nbCells+1,0);
+ std::vector <int> cell2cell;
+ cell2cell.reserve(3*nbCells);
+
+ for (int icell=0; icell<nbCells;icell++)
+ {
+ std::map<int,int > counter;
+ for (int iconn=index_ptr[icell]; iconn<index_ptr[icell+1];iconn++)
+ {
+ int inode=conn_ptr[iconn];
+ for (int iconnr=indexr_ptr[inode]; iconnr<indexr_ptr[inode+1];iconnr++)
+ {
+ int icell2=revConn_ptr[iconnr];
+ std::map<int,int>::iterator iter=counter.find(icell2);
+ if (iter!=counter.end()) (iter->second)++;
+ else counter.insert(std::make_pair(icell2,1));
+ }
+ }
+ for (std::map<int,int>::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<nbCells;icell++)
+ cell2cell_index[icell+1]=cell2cell_index[icell]+cell2cell_index[icell+1];
+
+ //filling up index and value to create skylinearray structure
+ MEDCouplingSkyLineArray* array=new MEDCouplingSkyLineArray(cell2cell_index,cell2cell);
+ return array;
}
/*!
MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight)
{
- 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);
+ ParaMEDMEM::MEDCouplingSkyLineArray* arr = new ParaMEDMEM::MEDCouplingSkyLineArray(graph->getIndexArray(), graph->getValueArray());
switch (split)
{
case Graph::METIS:
namespace MEDPARTITIONER
{
+ class Topology;
class MeshCollection;
class ParaDomainSelector;
class Graph;
-
+
class MEDPartitioner
{
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);
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);