diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index 124509f6988b8115d7e696b2e3e477c8a6d0ad31..37686ea6e07787540bba229811d739c18f92c68f 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -710,7 +710,7 @@ void GModel::removeInvisibleElements() } } -int GModel::indexMeshVertices(bool all) +int GModel::indexMeshVertices(bool all, int singlePartition) { std::vector<GEntity*> entities; getEntities(entities); @@ -722,20 +722,35 @@ int GModel::indexMeshVertices(bool all) entities[i]->mesh_vertices[j]->setIndex(-1); // tag all mesh vertices belonging to elements that need to be saved - //with 0 - for(unsigned int i = 0; i < entities.size(); i++) - if(all || entities[i]->physicals.size()) - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) - for(int k = 0; k < entities[i]->getMeshElement(j)->getNumVertices(); k++) - entities[i]->getMeshElement(j)->getVertex(k)->setIndex(0); + // with 0, or with -2 if they need to be taken into account in the + // numbering but need not to be saved (because we save a single + // partition and they are not used in that partition) + for(unsigned int i = 0; i < entities.size(); i++){ + if(all || entities[i]->physicals.size()){ + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + MElement *e = entities[i]->getMeshElement(j); + for(int k = 0; k < e->getNumVertices(); k++){ + if(!singlePartition || e->getPartition() == singlePartition) + e->getVertex(k)->setIndex(0); + else if(e->getVertex(k)->getIndex() == -1) + e->getVertex(k)->setIndex(-2); + } + } + } + } // renumber all the mesh vertices tagged with 0 - int numVertices = 0; + int numVertices = 0, index = 0; for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) - if(!entities[i]->mesh_vertices[j]->getIndex()) - entities[i]->mesh_vertices[j]->setIndex(++numVertices); - + if(!entities[i]->mesh_vertices[j]->getIndex()){ + index++; + numVertices++; + entities[i]->mesh_vertices[j]->setIndex(index); + } + else if(entities[i]->mesh_vertices[j]->getIndex() == -2) + index++; + return numVertices; } diff --git a/Geo/GModel.h b/Geo/GModel.h index 43caee9ce4ade13cb003b85cac625085d5dd7d76..9d7d17a2665f5e7abd53fc320bb148931a3e3f06 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -293,7 +293,7 @@ class GModel // index all the (used) mesh vertices in a continuous sequence, // starting at 1 - int indexMeshVertices(bool all); + int indexMeshVertices(bool all, int singlePartition=0); // scale the mesh by the given factor void scaleMesh(double factor); diff --git a/Geo/GModelIO_Mesh.cpp b/Geo/GModelIO_Mesh.cpp index 290ca40eb84f79f2b18a8f1b97c96507081f7144..e24524e8c33df2278d050cfb0719800ab873573c 100644 --- a/Geo/GModelIO_Mesh.cpp +++ b/Geo/GModelIO_Mesh.cpp @@ -591,7 +591,7 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, // get the number of vertices and index the vertices in a continuous // sequence - int numVertices = indexMeshVertices(saveAll); + int numVertices = indexMeshVertices(saveAll, saveSinglePartition); // FIXME if saveSinglePartition, re-tag some nodes with '0' index // and recompute numVertices @@ -796,19 +796,6 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, fclose(fp); -#if 1 - if(_ghostCells.size()){ - Msg::Info("Wrinting ghost cells in debug file"); - fp = fopen("ghosts.pos", "w"); - fprintf(fp, "View \"ghosts\"{\n"); - for(std::multimap<MElement*, short>::iterator it = _ghostCells.begin(); - it != _ghostCells.end(); it++) - it->first->writePOS(fp, false, true, false, false, false, false); - fprintf(fp, "};\n"); - fclose(fp); - } -#endif - return 1; } @@ -825,10 +812,25 @@ int GModel::writePartitionedMSH(const std::string &baseName, bool binary, sstream << baseName << "_" << std::setw(3) << std::setfill('0') << partition; int startNum = index ? getNumElementsMSH(this, saveAll, partition) : 0; + Msg::Info("Writing partition %d in file '%s'", partition, sstream.str().c_str()); writeMSH(sstream.str(), 2.2, binary, saveAll, saveParametric, scalingFactor, startNum, partition); index++; } + +#if 1 + if(_ghostCells.size()){ + Msg::Info("Writing ghost cells in debug file 'ghosts.pos'"); + FILE *fp = fopen("ghosts.pos", "w"); + fprintf(fp, "View \"ghosts\"{\n"); + for(std::multimap<MElement*, short>::iterator it = _ghostCells.begin(); + it != _ghostCells.end(); it++) + it->first->writePOS(fp, false, true, false, false, false, false); + fprintf(fp, "};\n"); + fclose(fp); + } +#endif + return 1; }