Commit ceb1fb9d authored by Christophe Geuzaine's avatar Christophe Geuzaine

make ghost cells optional

parent 81ab62dc
Pipeline #1085 failed with stage
in 59 minutes and 47 seconds
......@@ -84,6 +84,7 @@ std::vector<std::pair<std::string, std::string> > GetUsage()
"Weight of a triangle/quad/etc. during partitioning"));
s.push_back(mp("-part_split", "Save mesh partitions in separate files"));
s.push_back(mp("-part_[no_]topo", "Create the partition topology"));
s.push_back(mp("-part_[no_]ghosts", "Create ghost cells"));
s.push_back(mp("-part_topo_pro", "Save the partition topology .pro file"));
s.push_back(mp("-save_all", "Save all elements (discard physical group definitions)"));
s.push_back(mp("-save_parametric", "Save vertices with their parametric coordinates"));
......@@ -468,6 +469,14 @@ void GetOptions(int argc, char *argv[], bool readConfigFiles)
opt_mesh_partition_create_topology(0, GMSH_SET, 0.);
i++;
}
else if(!strcmp(argv[i] + 1, "part_ghosts")){
opt_mesh_partition_create_ghost_cells(0, GMSH_SET, 1.);
i++;
}
else if(!strcmp(argv[i] + 1, "part_no_ghosts")){
opt_mesh_partition_create_ghost_cells(0, GMSH_SET, 0.);
i++;
}
else if(!strcmp(argv[i] + 1, "new")) {
CTX::instance()->files.push_back("-new");
i++;
......
......@@ -1109,7 +1109,7 @@ StringXNumber MeshOptions_Number[] = {
{ F|O, "PartitionTopology" , opt_mesh_partition_create_topology , 1 ,
"Create boundary entities between partitions" },
{ F|O, "PartitionGhostCells" , opt_mesh_partition_create_ghost_cells , 0 ,
"Create boundary entities between partitions" },
"Create partition ghost cells" },
{ F|O, "PartitionSplitMeshFiles" , opt_mesh_partition_split_mesh_files , 0 ,
"Write one file for each mesh partition" },
{ F|O, "PartitionTopologyFile" , opt_mesh_partition_save_topology_file , 0 ,
......
......@@ -225,7 +225,7 @@ static void readMSH4Entities(GModel *const model, FILE* fp, bool partition,
if(partition){
int numPartitions = 0;
int ghostSize = 0;
int *ghostTags;
int *ghostTags = 0;
if(binary){
if(fread(&numPartitions, sizeof(int), 1, fp) != 1){
......@@ -238,16 +238,15 @@ static void readMSH4Entities(GModel *const model, FILE* fp, bool partition,
fclose(fp);
return;
}
if(swap) SwapBytes((char*)&ghostSize, sizeof(int), 1);
ghostTags = new int[2*ghostSize];
if(fread(ghostTags, sizeof(int), 2*ghostSize, fp) != 2*ghostSize){
fclose(fp);
return;
if(ghostSize){
ghostTags = new int[2*ghostSize];
if(fread(ghostTags, sizeof(int), 2*ghostSize, fp) != 2*ghostSize){
fclose(fp);
return;
}
if(swap) SwapBytes((char*)ghostTags, sizeof(int), 2*ghostSize);
}
if(swap) SwapBytes((char*)ghostTags, sizeof(int), 2*ghostSize);
}
else{
if(fscanf(fp, "%d", &numPartitions) != 1){
......@@ -259,12 +258,13 @@ static void readMSH4Entities(GModel *const model, FILE* fp, bool partition,
fclose(fp);
return;
}
ghostTags = new int[2*ghostSize];
for(unsigned int i = 0; i < 2*ghostSize; i+=2){
if(fscanf(fp, "%d %d", &ghostTags[i], &ghostTags[i+1]) != 2){
fclose(fp);
return;
if(ghostSize){
ghostTags = new int[2*ghostSize];
for(unsigned int i = 0; i < 2*ghostSize; i+=2){
if(fscanf(fp, "%d %d", &ghostTags[i], &ghostTags[i+1]) != 2){
fclose(fp);
return;
}
}
}
}
......@@ -1321,7 +1321,7 @@ static void readMSH4GhostElements(GModel *const model, FILE* fp,
}
}
std::vector<GEntity*> ghostEntities(model->getNumPartitions(), NULL);
std::vector<GEntity*> ghostEntities(model->getNumPartitions(), 0);
std::vector<GEntity*> entities;
model->getEntities(entities);
for(unsigned int i = 0; i < entities.size(); i++){
......@@ -1725,27 +1725,32 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition,
//write the ghostentities' tag
unsigned int ghostSize = ghost.size();
int *tags = new int[2*ghostSize];
int index = 0;
for(std::set<GEntity*, GEntityLessThan>::iterator it = ghost.begin();
it != ghost.end(); ++it){
if((*it)->geomType() == GEntity::GhostCurve){
tags[index] = (*it)->tag();
tags[++index] = static_cast<ghostEdge*>(*it)->getPartition();
}
else if((*it)->geomType() == GEntity::GhostSurface){
tags[index] = (*it)->tag();
tags[++index] = static_cast<ghostFace*>(*it)->getPartition();
}
else if((*it)->geomType() == GEntity::GhostVolume){
tags[index] = (*it)->tag();
tags[++index] = static_cast<ghostRegion*>(*it)->getPartition();
int *tags = 0;
if(ghostSize){
tags = new int[2*ghostSize];
int index = 0;
for(std::set<GEntity*, GEntityLessThan>::iterator it = ghost.begin();
it != ghost.end(); ++it){
if((*it)->geomType() == GEntity::GhostCurve){
tags[index] = (*it)->tag();
tags[++index] = static_cast<ghostEdge*>(*it)->getPartition();
}
else if((*it)->geomType() == GEntity::GhostSurface){
tags[index] = (*it)->tag();
tags[++index] = static_cast<ghostFace*>(*it)->getPartition();
}
else if((*it)->geomType() == GEntity::GhostVolume){
tags[index] = (*it)->tag();
tags[++index] = static_cast<ghostRegion*>(*it)->getPartition();
}
index++;
}
index++;
}
fwrite(&ghostSize, sizeof(int), 1, fp);
fwrite(tags, sizeof(int), 2*ghostSize, fp);
if(tags){
fwrite(tags, sizeof(int), 2*ghostSize, fp);
delete [] tags;
}
}
unsigned long verticesSize = vertices.size();
unsigned long edgesSize = edges.size();
......@@ -1872,28 +1877,33 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition,
//write the ghostentities' tag
unsigned int ghostSize = ghost.size();
int *tags = new int[2*ghostSize];
int index = 0;
for(std::set<GEntity*, GEntityLessThan>::iterator it = ghost.begin();
it != ghost.end(); ++it){
if((*it)->geomType() == GEntity::GhostCurve){
tags[index] = (*it)->tag();
tags[++index] = static_cast<ghostEdge*>(*it)->getPartition();
}
else if((*it)->geomType() == GEntity::GhostSurface){
tags[index] = (*it)->tag();
tags[++index] = static_cast<ghostFace*>(*it)->getPartition();
}
else if((*it)->geomType() == GEntity::GhostVolume){
tags[index] = (*it)->tag();
tags[++index] = static_cast<ghostRegion*>(*it)->getPartition();
int *tags = 0;
if(ghostSize){
tags = new int[2*ghostSize];
int index = 0;
for(std::set<GEntity*, GEntityLessThan>::iterator it = ghost.begin();
it != ghost.end(); ++it){
if((*it)->geomType() == GEntity::GhostCurve){
tags[index] = (*it)->tag();
tags[++index] = static_cast<ghostEdge*>(*it)->getPartition();
}
else if((*it)->geomType() == GEntity::GhostSurface){
tags[index] = (*it)->tag();
tags[++index] = static_cast<ghostFace*>(*it)->getPartition();
}
else if((*it)->geomType() == GEntity::GhostVolume){
tags[index] = (*it)->tag();
tags[++index] = static_cast<ghostRegion*>(*it)->getPartition();
}
index++;
}
index++;
}
fprintf(fp, "%d\n", ghostSize);
for(unsigned int i = 0; i < 2*ghostSize; i+=2){
fprintf(fp, "%d %d\n", tags[i], tags[i+1]);
if(tags){
for(unsigned int i = 0; i < 2*ghostSize; i+=2){
fprintf(fp, "%d %d\n", tags[i], tags[i+1]);
}
delete [] tags;
}
}
fprintf(fp, "%lu %lu %lu %lu\n",
......@@ -2357,7 +2367,8 @@ static void writeMSH4Elements(GModel *const model, FILE *fp, bool partitioned,
}
for(GModel::eiter it = edges.begin(); it != edges.end(); ++it){
if(!saveAll && (*it)->physicals.size() == 0 && (*it)->geomType() != GEntity::GhostCurve) continue;
if(!saveAll && (*it)->physicals.size() == 0 &&
(*it)->geomType() != GEntity::GhostCurve) continue;
numElements += (*it)->lines.size();
for(unsigned int i = 0; i < (*it)->lines.size(); i++)
......@@ -2367,7 +2378,8 @@ static void writeMSH4Elements(GModel *const model, FILE *fp, bool partitioned,
}
for(GModel::fiter it = faces.begin(); it != faces.end(); ++it){
if(!saveAll && (*it)->physicals.size() == 0 && (*it)->geomType() != GEntity::GhostSurface) continue;
if(!saveAll && (*it)->physicals.size() == 0 &&
(*it)->geomType() != GEntity::GhostSurface) continue;
numElements += (*it)->triangles.size();
for(unsigned int i = 0; i < (*it)->triangles.size(); i++)
......@@ -2383,8 +2395,8 @@ static void writeMSH4Elements(GModel *const model, FILE *fp, bool partitioned,
}
for(GModel::riter it = regions.begin(); it != regions.end(); ++it){
if(!saveAll && (*it)->physicals.size() == 0 && (*it)->geomType() !=
GEntity::GhostVolume) continue;
if(!saveAll && (*it)->physicals.size() == 0 &&
(*it)->geomType() != GEntity::GhostVolume) continue;
numElements += (*it)->tetrahedra.size();
for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++)
......@@ -2715,7 +2727,7 @@ int GModel::_writePartitionedMSH4(const std::string &baseName, double version,
std::vector<GEntity*> entities;
getEntities(entities);
std::set<GEntity*> entitiesSet;
GEntity *ghostEntity;
GEntity *ghostEntity = 0;
for(unsigned int j = 0; j < entities.size(); j++){
switch(entities[j]->geomType()){
case GEntity::PartitionVolume:
......@@ -2805,12 +2817,14 @@ int GModel::_writePartitionedMSH4(const std::string &baseName, double version,
tmp->_associateEntityWithMeshVertices();
tmp->pruneMeshVertexAssociations();
for(unsigned int j = 0; j < ghostEntity->getNumMeshElements(); j++){
for(unsigned int k = 0; k < ghostEntity->getMeshElement(j)->getNumVertices(); k++){
if(entitiesSet.find(ghostEntity->getMeshElement(j)->getVertex(k)->onWhat()) ==
entitiesSet.end()){
ghostEntity->addMeshVertex(ghostEntity->getMeshElement(j)->getVertex(k));
ghostEntity->getMeshElement(j)->getVertex(k)->setEntity(ghostEntity);
if(ghostEntity){
for(unsigned int j = 0; j < ghostEntity->getNumMeshElements(); j++){
for(unsigned int k = 0; k < ghostEntity->getMeshElement(j)->getNumVertices(); k++){
if(entitiesSet.find(ghostEntity->getMeshElement(j)->getVertex(k)->onWhat()) ==
entitiesSet.end()){
ghostEntity->addMeshVertex(ghostEntity->getMeshElement(j)->getVertex(k));
ghostEntity->getMeshElement(j)->getVertex(k)->setEntity(ghostEntity);
}
}
}
}
......
......@@ -2585,9 +2585,11 @@ int PartitionMesh(GModel *const model)
movePeriodicNodesFromParentToPartitionEntities(model);
graph.clearDualGraph();
createDualGraph(graph, true);
graph.assignGhostCells();
if(CTX::instance()->mesh.partitionCreateGhostCells){
graph.clearDualGraph();
createDualGraph(graph, true);
graph.assignGhostCells();
}
return 0;
}
......@@ -2876,9 +2878,11 @@ int ConvertOldPartitioningToNewOne(GModel *const model)
movePeriodicNodesFromParentToPartitionEntities(model);
graph.clearDualGraph();
createDualGraph(graph, false);
graph.assignGhostCells();
if(CTX::instance()->mesh.partitionCreateTopology){
graph.clearDualGraph();
createDualGraph(graph, false);
graph.assignGhostCells();
}
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment