From: eap Date: Tue, 26 May 2015 15:18:28 +0000 (+0300) Subject: 0022875: Sort cells by type after fusion X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=705d047653f3d076f56cfc9e85bf3a70e00e5b14;p=tools%2Fmedcoupling.git 0022875: Sort cells by type after fusion --- diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx index 15b7549e0..2c2fc93c9 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx @@ -109,7 +109,7 @@ void MEDPARTITIONER::MEDPartitioner::Write(const std::string& filename) ParaMEDMEM::MEDFileData* MEDPARTITIONER::MEDPartitioner::getMEDFileData() { - return _output_collection->getDriver()->getMEDFileData(); + return _output_collection->retrieveDriver()->getMEDFileData(); } MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight) @@ -117,24 +117,24 @@ MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(ParaMEDMEM::MEDCoup MEDPARTITIONER::Graph* cellGraph=0; ParaMEDMEM::MEDCouplingSkyLineArray* arr = new ParaMEDMEM::MEDCouplingSkyLineArray(graph->getIndexArray(), graph->getValueArray()); switch (split) - { + { case Graph::METIS: if ( !cellGraph ) - { - #ifdef MED_ENABLE_METIS + { +#ifdef MED_ENABLE_METIS cellGraph=new METISGraph(arr,edgeweight); - #endif - } +#endif + } if ( !cellGraph ) throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : PARMETIS/METIS is not available. Check your products, please."); - break; + 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; - } +#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_MeshCollection.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx index d4dbaa2c5..b35661505 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx @@ -105,7 +105,9 @@ MEDPARTITIONER::MeshCollection::MeshCollection(MeshCollection& initialCollection _joint_finder(0) { std::vector > > new2oldIds(initialCollection.getTopology()->nbDomain()); - castCellMeshes(initialCollection, new2oldIds); + std::vector o2nRenumber; + + castCellMeshes(initialCollection, new2oldIds, o2nRenumber ); //defining the name for the collection and the underlying meshes setName(initialCollection.getName()); @@ -186,17 +188,19 @@ MEDPARTITIONER::MeshCollection::MeshCollection(MeshCollection& initialCollection buildBoundaryFaces(); //building the connect zones necessary for writing joints - buildConnectZones( nodeMapping, initialCollection.getTopology()->nbDomain() ); + buildConnectZones( nodeMapping, o2nRenumber, initialCollection.getTopology()->nbDomain() ); } /*! Creates the meshes using the topology underlying he mesh collection and the mesh data coming from the ancient collection \param initialCollection collection from which the data is extracted to create the new meshes + \param [out] o2nRenumber returns for each new domain a permutation array returned by sortCellsInMEDFileFrmt() */ void MEDPARTITIONER::MeshCollection::castCellMeshes(MeshCollection& initialCollection, - std::vector > >& new2oldIds) + std::vector > >& new2oldIds, + std::vector & o2nRenumber) { if (MyGlobals::_Verbose>10) std::cout << "proc " << MyGlobals::_Rank << " : castCellMeshes" << std::endl; @@ -207,6 +211,7 @@ void MEDPARTITIONER::MeshCollection::castCellMeshes(MeshCollection& initialColle int nbOldDomain=initialCollection.getTopology()->nbDomain(); _mesh.resize(nbNewDomain); + o2nRenumber.resize(nbNewDomain,0); int rank=MyGlobals::_Rank; //splitting the initial domains into smaller bits std::vector > splitMeshes; @@ -270,22 +275,23 @@ void MEDPARTITIONER::MeshCollection::castCellMeshes(MeshCollection& initialColle for (int inew=0; inew meshes; - + for (int i=0; i<(int)splitMeshes[inew].size(); i++) - if (splitMeshes[inew][i]!=0) + if (splitMeshes[inew][i]!=0) if (splitMeshes[inew][i]->getNumberOfCells()>0) meshes.push_back(splitMeshes[inew][i]); - if (!isParallelMode()||_domain_selector->isMyDomain(inew)) + if (!isParallelMode()||_domain_selector->isMyDomain(inew)) + { + if (meshes.size()==0) { - if (meshes.size()==0) - { _mesh[inew]=CreateEmptyMEDCouplingUMesh(); std::cout << "WARNING : castCellMeshes fusing : no meshes try another number of processors" << std::endl; } else { _mesh[inew]=ParaMEDMEM::MEDCouplingUMesh::MergeUMeshes(meshes); + o2nRenumber[inew]=_mesh[inew]->sortCellsInMEDFileFrmt(); bool areNodesMerged; int nbNodesMerged; if (meshes.size()>1) @@ -294,7 +300,6 @@ void MEDPARTITIONER::MeshCollection::castCellMeshes(MeshCollection& initialColle array->decrRef(); // array is not used in this case } _mesh[inew]->zipCoords(); - } } for (int i=0;i<(int)splitMeshes[inew].size();i++) @@ -306,7 +311,7 @@ void MEDPARTITIONER::MeshCollection::castCellMeshes(MeshCollection& initialColle } /*! - \param initialCollection source mesh collection + \param initialCollection source mesh collection \param nodeMapping structure containing the correspondency between nodes in the initial collection and the node(s) in the new collection */ void MEDPARTITIONER::MeshCollection::createNodeMapping( MeshCollection& initialCollection, NodeMapping& nodeMapping) @@ -973,6 +978,26 @@ namespace ids12->rearrange( 1 ); // make one component return ids12; } + + //================================================================================ + /*! + * \brief Renumber ids according to mesh->sortCellsInMEDFileFrmt() + * \param [in,out] ids - cell ids to renumber + * \param [in] o2nRenumber - renumbering array in "Old to New" mode + */ + //================================================================================ + + void renumber( DataArrayInt* ids, const DataArrayInt* o2nRenumber ) + { + if ( !ids || !o2nRenumber ) + return; + int * id = ids->getPointer(); + const int * o2n = o2nRenumber->getConstPointer(); + for ( ; id < ids->end(); ++id ) + { + *id = o2n[ *id ]; + } + } } //================================================================================ @@ -984,6 +1009,7 @@ namespace //================================================================================ void MEDPARTITIONER::MeshCollection::buildConnectZones( const NodeMapping& nodeMapping, + const std::vector & o2nRenumber, int nbInitialDomains) { if ( !MyGlobals::_Create_Joints || _topology->nbDomain() < 2 ) @@ -1100,6 +1126,10 @@ void MEDPARTITIONER::MeshCollection::buildConnectZones( const NodeMapping& nodeM ids1 = ids12->selectByTupleId2( 0, corrArray->getLength()+1, 2 ); ids2 = ids12->selectByTupleId2( 1, corrArray->getLength()+1, 2 ); + // renumber cells according to mesh->sortCellsInMEDFileFrmt() + renumber( ids1, o2nRenumber[ cz->getLocalDomainNumber() ]); + renumber( ids2, o2nRenumber[ cz->getDistantDomainNumber() ]); + // check nb cell types std::set types1, types2; types1 = mesh1->getTypesOfPart( ids1->begin(), ids1->end() ); diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx index 0ce114712..8a04e0117 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx @@ -143,7 +143,8 @@ namespace MEDPARTITIONER std::multimap,std::pair >& nodeMapping); void castCellMeshes(MeshCollection& initialCollection, - std::vector > >& new2oldIds); + std::vector > >& new2oldIds, + std::vector & o2nRenumber); //creates faces on the new collection void castFaceMeshes(MeshCollection& initialCollection, @@ -151,7 +152,9 @@ namespace MEDPARTITIONER std::vector > >& new2oldIds); //constructing connect zones - void buildConnectZones( const NodeMapping& nodeMapping, int nbInitialDomains ); + void buildConnectZones( const NodeMapping& nodeMapping, + const std::vector & o2nRenumber, + int nbInitialDomains ); // Find faces common with neighbor domains and put them in groups void buildBoundaryFaces();