Commit 71f1c9d4 by Christophe Geuzaine

Merge branch 'ghostCells' into 'master'

Ghost cells See merge request !69
parents d89d82f3 a4ed608c
Pipeline #1080 passed with stage
in 35 minutes 2 seconds
......@@ -263,7 +263,7 @@ void CreateOutputFile(const std::string &fileName, int format,
break;
case FORMAT_MSH:
if(GModel::current()->getMeshPartitions().size() &&
if(GModel::current()->getNumPartitions() &&
CTX::instance()->mesh.partitionSplitMeshFiles){
std::vector<std::string> splitName = SplitFileName(name);
splitName[0] += splitName[1];
......@@ -278,7 +278,7 @@ void CreateOutputFile(const std::string &fileName, int format,
CTX::instance()->mesh.saveAll, CTX::instance()->mesh.saveParametric,
CTX::instance()->mesh.scalingFactor);
}
if(GModel::current()->getMeshPartitions().size() &&
if(GModel::current()->getNumPartitions() &&
CTX::instance()->mesh.partitionSaveTopologyFile){
std::vector<std::string> splitName = SplitFileName(name);
splitName[0] += splitName[1] + "_topology.pro";
......
......@@ -6322,9 +6322,7 @@ double opt_mesh_zone_definition(OPT_ARGS_NUM)
CTX::instance()->mesh.zoneDefinition = (int)val;
if( (CTX::instance()->mesh.zoneDefinition < 0 ||
CTX::instance()->mesh.zoneDefinition > 2) ||
(CTX::instance()->mesh.zoneDefinition == 1 &&
GModel::current()->getMinPartitionSize() +
GModel::current()->getMaxPartitionSize() == 0) )
(CTX::instance()->mesh.zoneDefinition == 1) )
CTX::instance()->mesh.zoneDefinition = 0;
}
return CTX::instance()->mesh.zoneDefinition;
......
......@@ -249,9 +249,8 @@ class VisibilityList { // singleton
}
}
else if(type == MeshPartitions){
std::set<int> part = m->getMeshPartitions();
for(std::set<int>::const_iterator it = part.begin(); it != part.end(); ++it)
_entities.push_back(new VisPartition(*it));
for(int part = 0; part < m->getNumPartitions(); part++)
_entities.push_back(new VisPartition(part));
}
std::sort(_entities.begin(), _entities.end(), VisLessThan());
}
......
......@@ -208,9 +208,9 @@ class GEdge : public GEntity {
std::vector<MLine*> lines;
virtual void addLine(MLine *line){ lines.push_back(line); }
virtual void addElement(int type, MElement *e);
virtual void removeElement(int type, MElement *e);
void addLine(MLine *line){ lines.push_back(line); }
void addElement(int type, MElement *e);
void removeElement(int type, MElement *e);
virtual void discretize(double tol, std::vector<SPoint3> &dpts, std::vector<double> &ts);
SPoint3 closestPoint (SPoint3 &p, double tolerance);
......
......@@ -122,7 +122,10 @@ class GEntity {
PartitionVertex,
PartitionCurve,
PartitionSurface,
PartitionVolume
PartitionVolume,
GhostCurve,
GhostSurface,
GhostVolume
};
enum MeshGenerationStatus {
......
......@@ -330,8 +330,8 @@ class GFace : public GEntity {
void addTriangle(MTriangle *t){ triangles.push_back(t); }
void addQuadrangle(MQuadrangle *q){ quadrangles.push_back(q); }
void addPolygon(MPolygon *p){ polygons.push_back(p); }
virtual void addElement(int type, MElement *e);
virtual void removeElement(int type, MElement *e);
void addElement(int type, MElement *e);
void removeElement(int type, MElement *e);
// get the boundary layer columns
BoundaryLayerColumns *getColumns () {return &_columns;}
......
......@@ -27,6 +27,10 @@
#include "discreteFace.h"
#include "discreteEdge.h"
#include "discreteVertex.h"
#include "partitionRegion.h"
#include "partitionFace.h"
#include "partitionEdge.h"
#include "partitionVertex.h"
#include "gmshSurface.h"
#include "SmoothData.h"
#include "Context.h"
......@@ -70,7 +74,6 @@ GModel::GModel(std::string name)
_fields(0), _currentMeshEntity(0),
normals(0)
{
partitionSize[0] = 0; partitionSize[1] = 0;
// hide all other models
for(unsigned int i = 0; i < list.size(); i++)
......@@ -1407,23 +1410,9 @@ void GModel::scaleMesh(double factor)
}
}
void GModel::recomputeMeshPartitions()
{
meshPartitions.clear();
std::vector<GEntity*> entities;
getEntities(entities);
for(unsigned int i = 0; i < entities.size(); i++){
for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){
int part = entities[i]->getMeshElement(j)->getPartition();
if(part) meshPartitions.insert(part);
}
}
}
int GModel::deleteMeshPartitions()
{
#if defined(HAVE_MESH)
meshPartitions.clear();
return UnpartitionMesh(this);
#else
Msg::Error("Mesh module not compiled");
......@@ -1431,19 +1420,18 @@ int GModel::deleteMeshPartitions()
#endif
}
int GModel::partitionMesh(int numPart)
{
#if defined(HAVE_MESH) && (defined(HAVE_METIS))
int ier = deleteMeshPartitions();
if(ier != 0) return ier;
opt_mesh_partition_num(0, GMSH_SET, numPart);
if(numPart > 0){
ier = PartitionMesh(this);
int ier = PartitionMesh(this);
return ier;
}
else{
return 1;
}
return ier;
#else
Msg::Error("Mesh module not compiled");
return 1;
......@@ -1453,7 +1441,6 @@ int GModel::partitionMesh(int numPart)
int GModel::convertOldPartitioningToNewOne()
{
#if defined(HAVE_MESH) && (defined(HAVE_METIS))
opt_mesh_partition_num(0, GMSH_SET, meshPartitions.size());
int ier = ConvertOldPartitioningToNewOne(this);
return ier;
#else
......@@ -1863,7 +1850,6 @@ GModel *GModel::createGModel(std::map<int, MVertex*> &vertexMap,
if(physical[i] && (!physicals[dim].count(elementary[i]) ||
!physicals[dim][elementary[i]].count(physical[i])))
physicals[dim][elementary[i]][physical[i]] = "unnamed";
if(partition[i]) gm->getMeshPartitions().insert(partition[i]);
}
// store the elements in their associated elementary entity. If the
......@@ -1904,9 +1890,6 @@ GModel *GModel::createGModel
for(int iV = 0; iV < me->getNumVertices(); iV++) {
vertexMap[me->getVertex(iV)->getNum()] = me->getVertex(iV);
}
if(me->getPartition()) {
gm->getMeshPartitions().insert(me->getPartition());
}
std::vector<int> entityPhysicals = entityToPhysicalsMap[entity];
for(unsigned int i = 0; i < entityPhysicals.size(); i++) {
physicals[me->getDim()][entity][entityPhysicals[i]] = "unnamed";
......
......@@ -85,9 +85,10 @@ class GModel {
std::vector<MElement*> _elementVectorCache;
std::map<int, MElement*> _elementMapCache;
std::map<int, int> _elementIndexCache;
// ghost cell information (stores partitions for each element acting
// as a ghost cell)
// /!\ Use only for compatibility with mesh format msh2 and msh3
std::multimap<MElement*, short> _ghostCells;
// an octree for fast mesh element lookup
......@@ -163,8 +164,7 @@ class GModel {
std::map<std::pair<int, int>, std::string> physicalNames, elementaryNames;
// the set of all used mesh partition numbers
std::set<int> meshPartitions;
int partitionSize[2];
unsigned int numPartitions;
public:
GModel(std::string name="");
......@@ -454,9 +454,8 @@ class GModel {
void removeInvisibleElements();
// the list of partitions
std::set<int> &getMeshPartitions() { return meshPartitions; }
void recomputeMeshPartitions();
unsigned int getNumPartitions() const { return meshPartitions.size(); };
unsigned int getNumPartitions() const { return numPartitions; }
void setNumPartitions(unsigned int npart){ numPartitions = npart; }
// delete all the partitions
int deleteMeshPartitions();
......@@ -467,14 +466,10 @@ class GModel {
int convertOldPartitioningToNewOne();
// write the partitioned topology file
int writePartitionedTopology(std::string &name);
// store/recall min and max partitions size
void setMinPartitionSize(const int pSize) { partitionSize[0] = pSize; }
void setMaxPartitionSize(const int pSize) { partitionSize[1] = pSize; }
int getMinPartitionSize() const { return partitionSize[0]; }
int getMaxPartitionSize() const { return partitionSize[1]; }
// /!\ Use only for compatibility with mesh format msh2 and msh3
std::multimap<MElement*, short> &getGhostCells(){ return _ghostCells; }
void addGhostCells(MElement* elm, short partition) { _ghostCells.insert(std::pair<MElement*,short>(elm, partition)); }
// perform various coherence tests on the mesh
void checkMeshCoherence(double tolerance);
......
......@@ -330,7 +330,7 @@ int GModel::readDIFF(const std::string &name)
if(physical && (!physicals[dim].count(reg) ||
!physicals[dim][reg].count(physical)))
physicals[dim][reg][physical] = "unnamed";
if(partition) getMeshPartitions().insert(partition);
if(partition > getNumPartitions()) setNumPartitions(partition);
if(numElements > 100000)
Msg::ProgressMeter(i + 1, numElements, true, "Reading elements");
......
......@@ -86,7 +86,7 @@ static MElement *createElementMSH2(GModel *m, int num, int typeMSH, int physical
if(physical && (!physicals[dim].count(reg) || !physicals[dim][reg].count(physical)))
physicals[dim][reg][physical] = "unnamed";
if(part) m->getMeshPartitions().insert(part);
if(part > m->getNumPartitions()) m->setNumPartitions(part);
return e;
}
......@@ -959,9 +959,7 @@ int GModel::_writePartitionedMSH2(const std::string &baseName, bool binary,
{
int numElements;
int startNum = 0;
for(std::set<int>::iterator it = meshPartitions.begin();
it != meshPartitions.end(); it++){
int partition = *it;
for(int partition = 0; partition < getNumPartitions(); partition++){
std::ostringstream sstream;
sstream << baseName << "_" << partition << ".msh";
......
......@@ -742,9 +742,7 @@ int GModel::_writePartitionedMSH3(const std::string &baseName, double version,
return 0;
}
for(std::set<int>::iterator it = meshPartitions.begin();
it != meshPartitions.end(); it++){
int partition = *it;
for(int partition = 0; partition < getNumPartitions(); partition++){
std::ostringstream sstream;
sstream << baseName << "_" << std::setw(6) << std::setfill('0') << partition;
Msg::Info("Writing partition %d in file '%s'", partition, sstream.str().c_str());
......
......@@ -140,8 +140,8 @@ class GRegion : public GEntity {
void addPyramid(MPyramid *p){ pyramids.push_back(p); }
void addPolyhedron(MPolyhedron *p){ polyhedra.push_back(p); }
void addTrihedron(MTrihedron *t){ trihedra.push_back(t); }
virtual void addElement(int type, MElement *e);
virtual void removeElement(int type, MElement *e);
void addElement(int type, MElement *e);
void removeElement(int type, MElement *e);
// get the boundary layer columns
BoundaryLayerColumns *getColumns () { return &_columns; }
......
......@@ -93,8 +93,8 @@ class GVertex : public GEntity
std::vector<MPoint*> points;
void addPoint(MPoint *p){ points.push_back(p); }
virtual void addElement(int type, MElement *e);
virtual void removeElement(int type, MElement *e);
void addElement(int type, MElement *e);
void removeElement(int type, MElement *e);
};
#endif
......@@ -1915,8 +1915,8 @@ MElement *MElementFactory::create(int num, int type, const std::vector<int> &dat
MElement *element = create(type, vertices, num, part, false, parent);
for(unsigned int j = 0; j < ghosts.size(); j++)
model->getGhostCells().insert(std::pair<MElement*, short>(element, ghosts[j]));
if(part) model->getMeshPartitions().insert(part);
//model->getGhostCells().insert(std::pair<MElement*, short>(element, ghosts[j]));
if(part > model->getNumPartitions()) model->setNumPartitions(part);
return element;
}
......
......@@ -1515,7 +1515,7 @@ GModel *buildCutMesh(GModel *gm, gLevelset *ls,
elementSplitMesh(e, RPN, verticesLs, gmEntities[i], gm, numEle, vertexMap,
newParents, newDomains, elements, physicals, newElemTags,
newPhysTags, borderElemTags, borderPhysTags);
cutGM->getMeshPartitions().insert(e->getPartition());
if(e->getPartition() > cutGM->getNumPartitions()) cutGM->setNumPartitions(e->getPartition());
}
}
return cutGM;
......@@ -1545,7 +1545,7 @@ GModel *buildCutMesh(GModel *gm, gLevelset *ls,
newVertices, newParents, newDomains, borders, elements, physicals,
newElemTags, newPhysTags, borderElemTags, borderPhysTags, cp,
lines, triangles, quads, tetras, hexas);
cutGM->getMeshPartitions().insert(e->getPartition());
if(e->getPartition() > cutGM->getNumPartitions()) cutGM->setNumPartitions(e->getPartition());
}
// Create elementary and physical for non connected border lines
......
......@@ -9,8 +9,8 @@
#include "GModel.h"
#include "GFace.h"
#include "discreteEdge.h"
#include "MEdge.h"
#include "MTriangle.h"
#include "MElementCut.h"
#include "MEdge.h"
#include "MLine.h"
......
// Gmsh - Copyright (C) 1997-2018 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@onelab.info>.
#ifndef _GHOST_EDGE_H_
#define _GHOST_EDGE_H_
#include "GModel.h"
#include "discreteEdge.h"
#include "MLine.h"
class ghostEdge : public discreteEdge {
private:
unsigned int _partitions;
std::map<MElement*, unsigned int> _ghostCells;
bool _saveMesh;
bool _haveMesh;
public:
ghostEdge(GModel *model, const int num, const unsigned int partitions)
: discreteEdge(model, num, NULL, NULL), _partitions(partitions), _ghostCells(), _saveMesh(false),
_haveMesh(false) {}
virtual ~ghostEdge()
{
if(!_haveMesh){
lines.clear();
mesh_vertices.clear();
}
}
virtual GeomType geomType() const { return GhostCurve; }
virtual void setPartition(const unsigned int partitions) { _partitions = partitions; }
virtual unsigned int getPartition() const { return _partitions; }
bool saveMesh() const { return _saveMesh; }
void saveMesh(bool saveMesh) { _saveMesh = saveMesh; }
bool haveMesh() const { return _haveMesh; }
void haveMesh(bool haveMesh) { _haveMesh = haveMesh; }
virtual std::map<MElement*, unsigned int> &getGhostCells() { return _ghostCells; }
void addLine(MLine *l, unsigned int onWhichPartition)
{
GEdge::addLine(l);
_ghostCells.insert(std::pair<MElement*, unsigned int>(l,onWhichPartition));
model()->addGhostCells(l,onWhichPartition);
}
void addElement(int type, MElement *e, unsigned int onWhichPartition)
{
GEdge::addElement(type, e);
_ghostCells.insert(std::pair<MElement*, unsigned int>(e,onWhichPartition));
model()->addGhostCells(e,onWhichPartition);
}
};
#endif
// Gmsh - Copyright (C) 1997-2018 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@onelab.info>.
#ifndef _GHOST_FACE_H_
#define _GHOST_FACE_H_
#include "GModel.h"
#include "discreteFace.h"
#include "MTriangle.h"
#include "MQuadrangle.h"
#include "MElementCut.h"
class ghostFace : public discreteFace {
private:
unsigned int _partitions;
std::map<MElement*, unsigned int> _ghostCells;
bool _saveMesh;
bool _haveMesh;
public:
ghostFace(GModel *model, const int num, const unsigned int partitions)
: discreteFace(model, num), _partitions(partitions), _ghostCells(), _saveMesh(false),
_haveMesh(false) {}
virtual ~ghostFace()
{
if(!_haveMesh){
triangles.clear();
quadrangles.clear();
polygons.clear();
mesh_vertices.clear();
}
}
virtual GeomType geomType() const { return GhostSurface; }
virtual void setPartition(const unsigned int partitions) { _partitions = partitions; }
virtual unsigned int getPartition() const { return _partitions; }
bool saveMesh() const { return _saveMesh; }
void saveMesh(bool saveMesh) { _saveMesh = saveMesh; }
bool haveMesh() const { return _haveMesh; }
void haveMesh(bool haveMesh) { _haveMesh = haveMesh; }
virtual std::map<MElement*, unsigned int> &getGhostCells() { return _ghostCells; }
void addTriangle(MTriangle *t, unsigned int onWhichPartition)
{
GFace::addTriangle(t);
_ghostCells.insert(std::pair<MElement*, unsigned int>(t,onWhichPartition));
model()->addGhostCells(t,onWhichPartition);
}
void addQuadrangle(MQuadrangle *q, unsigned int onWhichPartition)
{
GFace::addQuadrangle(q);
_ghostCells.insert(std::pair<MElement*, unsigned int>(q,onWhichPartition));
model()->addGhostCells(q,onWhichPartition);
}
void addPolygon(MPolygon *p, unsigned int onWhichPartition)
{
GFace::addPolygon(p);
_ghostCells.insert(std::pair<MElement*, unsigned int>(p,onWhichPartition));
model()->addGhostCells(p,onWhichPartition);
}
void addElement(int type, MElement *e, unsigned int onWhichPartition)
{
GFace::addElement(type, e);
_ghostCells.insert(std::pair<MElement*, unsigned int>(e,onWhichPartition));
model()->addGhostCells(e,onWhichPartition);
}
};
#endif
// Gmsh - Copyright (C) 1997-2018 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@onelab.info>.
#ifndef _GHOST_REGION_H_
#define _GHOST_REGION_H_
#include "GModel.h"
#include "discreteRegion.h"
#include "MTetrahedron.h"
#include "MHexahedron.h"
#include "MPrism.h"
#include "MPyramid.h"
#include "MTrihedron.h"
#include "MElementCut.h"
class ghostRegion : public discreteRegion {
private:
unsigned int _partitions;
std::map<MElement*, unsigned int> _ghostCells;
bool _saveMesh;
bool _haveMesh;
public:
ghostRegion(GModel *model, const int num, const unsigned int partitions)
: discreteRegion(model, num), _partitions(partitions), _ghostCells(), _saveMesh(false),
_haveMesh(false) {}
virtual ~ghostRegion()
{
if(!_haveMesh){
tetrahedra.clear();
hexahedra.clear();
prisms.clear();
pyramids.clear();
trihedra.clear();
polyhedra.clear();
mesh_vertices.clear();
}
}
virtual GeomType geomType() const { return GhostVolume; }
virtual void setPartition(const unsigned int partitions) { _partitions = partitions; }
virtual unsigned int getPartition() const { return _partitions; }
bool saveMesh() const { return _saveMesh; }
void saveMesh(bool saveMesh) { _saveMesh = saveMesh; }
bool haveMesh() const { return _haveMesh; }
void haveMesh(bool haveMesh) { _haveMesh = haveMesh; }
virtual std::map<MElement*, unsigned int> &getGhostCells() { return _ghostCells; }
void addTetrahedron(MTetrahedron *t, unsigned int onWhichPartition)
{
GRegion::addTetrahedron(t);
_ghostCells.insert(std::pair<MElement*, unsigned int>(t,onWhichPartition));
model()->addGhostCells(t,onWhichPartition);
}
void addHexahedron(MHexahedron *h, unsigned int onWhichPartition)
{
GRegion::addHexahedron(h);
_ghostCells.insert(std::pair<MElement*, unsigned int>(h,onWhichPartition));
model()->addGhostCells(h,onWhichPartition);
}
void addPrism(MPrism *p, unsigned int onWhichPartition)
{
GRegion::addPrism(p);
_ghostCells.insert(std::pair<MElement*, unsigned int>(p,onWhichPartition));
model()->addGhostCells(p,onWhichPartition);
}
void addPyramid(MPyramid *p, unsigned int onWhichPartition)
{
GRegion::addPyramid(p);
_ghostCells.insert(std::pair<MElement*, unsigned int>(p,onWhichPartition));
model()->addGhostCells(p,onWhichPartition);
}
void addPolyhedron(MPolyhedron *p, unsigned int onWhichPartition)
{
GRegion::addPolyhedron(p);
_ghostCells.insert(std::pair<MElement*, unsigned int>(p,onWhichPartition));
model()->addGhostCells(p,onWhichPartition);
}
void addTrihedron(MTrihedron *t, unsigned int onWhichPartition)
{
GRegion::addTrihedron(t);
_ghostCells.insert(std::pair<MElement*, unsigned int>(t,onWhichPartition));
model()->addGhostCells(t,onWhichPartition);
}
void addElement(int type, MElement *e, unsigned int onWhichPartition)
{
GRegion::addElement(type, e);
_ghostCells.insert(std::pair<MElement*, unsigned int>(e,onWhichPartition));
model()->addGhostCells(e,onWhichPartition);
}
};
#endif
......@@ -127,7 +127,7 @@ PView *GMSH_SimplePartitionPlugin::execute(PView *v)
}
}
}
m->recomputeMeshPartitions();
m->setNumPartitions(numSlices);
// partition lower dimension elements
Msg::Info("Partitioning lower dimension elements");
......
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