From 279affc44c72fe1572bb5d3c52eac673c759a839 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Fri, 8 Jan 2010 16:40:43 +0000 Subject: [PATCH] only save the vertices used in each partition --- Geo/GModel.cpp | 37 ++++++++++++++++++++++++++----------- Geo/GModel.h | 2 +- Geo/GModelIO_Mesh.cpp | 30 ++++++++++++++++-------------- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index 124509f698..37686ea6e0 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 43caee9ce4..9d7d17a266 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 290ca40eb8..e24524e8c3 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; } -- GitLab