From 1f469c088456124cb42164c52d72fef7861cf75e Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Thu, 3 Jul 2008 18:15:29 +0000 Subject: [PATCH] added set/getCurrentMeshEntity for better error reporting in client code --- Geo/GModel.cpp | 6 +++--- Geo/GModel.h | 8 ++++++++ Mesh/meshGEdge.cpp | 6 ++++-- Mesh/meshGFace.cpp | 6 +++++- Mesh/meshGRegion.cpp | 8 +++++++- Mesh/meshGRegion.h | 1 + Mesh/meshGRegionExtruded.cpp | 4 +++- utils/misc/driverOCC.cpp | 23 +++++++++++++++++++---- 8 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index c136917ffc..6435db5733 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -1,4 +1,4 @@ -// $Id: GModel.cpp,v 1.93 2008-07-03 17:06:01 geuzaine Exp $ +// $Id: GModel.cpp,v 1.94 2008-07-03 18:15:29 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -43,8 +43,8 @@ std::vector<GModel*> GModel::list; int GModel::_current = -1; GModel::GModel(std::string name) - : _geo_internals(0), _occ_internals(0), _fields(0), - modelName(name), normals(0) + : _geo_internals(0), _occ_internals(0), _fm_internals(0), _fields(0), + _currentMeshEntity(0), modelName(name), normals(0) { list.push_back(this); diff --git a/Geo/GModel.h b/Geo/GModel.h index b064de5ed8..69b236f02d 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -66,6 +66,9 @@ class GModel // loop over all vertices connected to elements and associate geo entity void _associateEntityWithMeshVertices(); + // entity that is currently being meshed + GEntity *_currentMeshEntity; + // index of the current model static int _current; @@ -145,6 +148,7 @@ class GModel void remove(GEdge *e); void remove(GVertex *v); + // Snap vertices on model edges by using geometry tolerance void snapVertices(); // Get a vector containing all the entities in the model @@ -204,6 +208,10 @@ class GModel // scale the mesh by the given factor void scaleMesh(double factor); + // set/get entity that is currently being meshed (for error reporting) + int setCurrentMeshEntity(GEntity *e){ _currentMeshEntity = e; } + GEntity *getCurrentMeshEntity(){ return _currentMeshEntity; } + // Deletes all invisble mesh elements void removeInvisibleElements(); diff --git a/Mesh/meshGEdge.cpp b/Mesh/meshGEdge.cpp index fb4ad73a69..15729f03ca 100644 --- a/Mesh/meshGEdge.cpp +++ b/Mesh/meshGEdge.cpp @@ -1,4 +1,4 @@ -// $Id: meshGEdge.cpp,v 1.66 2008-07-01 14:24:07 geuzaine Exp $ +// $Id: meshGEdge.cpp,v 1.67 2008-07-03 18:15:29 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -279,6 +279,8 @@ void deMeshGEdge::operator() (GEdge *ge) void meshGEdge::operator() (GEdge *ge) { + ge->model()->setCurrentMeshEntity(ge); + if(ge->geomType() == GEntity::DiscreteCurve) return; if(ge->geomType() == GEntity::BoundaryLayerCurve) return; if(ge->meshAttributes.Method == MESH_NONE) return; @@ -288,7 +290,7 @@ void meshGEdge::operator() (GEdge *ge) if(MeshExtrudedCurve(ge)) return; - Msg::Info("Meshing curve %d (%s)", ge->tag(),ge->getTypeString().c_str()); + Msg::Info("Meshing curve %d (%s)", ge->tag(), ge->getTypeString().c_str()); // Create a list of integration points List_T *Points = List_Create(10, 10, sizeof(IntPoint)); diff --git a/Mesh/meshGFace.cpp b/Mesh/meshGFace.cpp index 359523254c..0d50915425 100644 --- a/Mesh/meshGFace.cpp +++ b/Mesh/meshGFace.cpp @@ -1,4 +1,4 @@ -// $Id: meshGFace.cpp,v 1.139 2008-07-03 17:06:04 geuzaine Exp $ +// $Id: meshGFace.cpp,v 1.140 2008-07-03 18:15:29 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -1301,6 +1301,8 @@ const int debugSurface = -1; void meshGFace::operator() (GFace *gf) { + gf->model()->setCurrentMeshEntity(gf); + if (debugSurface >= 0 && gf->tag() != debugSurface){ gf->meshStatistics.status = GFace::DONE; return; @@ -1372,6 +1374,8 @@ static bool shouldRevert(MEdge &reference, std::vector<T*> &elements) void orientMeshGFace::operator()(GFace *gf) { + gf->model()->setCurrentMeshEntity(gf); + if(gf->geomType() == GEntity::ProjectionFace) return; // surface orientions in OCC are not consistent with the orientation diff --git a/Mesh/meshGRegion.cpp b/Mesh/meshGRegion.cpp index 7465b3fb1f..81511767d3 100644 --- a/Mesh/meshGRegion.cpp +++ b/Mesh/meshGRegion.cpp @@ -1,4 +1,4 @@ -// $Id: meshGRegion.cpp,v 1.55 2008-07-01 14:24:07 geuzaine Exp $ +// $Id: meshGRegion.cpp,v 1.56 2008-07-03 18:15:29 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -555,6 +555,8 @@ void meshNormalsPointOutOfTheRegion(GRegion *gr) void meshGRegion::operator() (GRegion *gr) { + gr->model()->setCurrentMeshEntity(gr); + if(gr->geomType() == GEntity::DiscreteVolume) return; if(gr->meshAttributes.Method == MESH_NONE) return; @@ -600,6 +602,8 @@ void meshGRegion::operator() (GRegion *gr) void optimizeMeshGRegionNetgen::operator() (GRegion *gr) { + gr->model()->setCurrentMeshEntity(gr); + if(gr->geomType() == GEntity::DiscreteVolume) return; // don't optimize transfinite or extruded meshes @@ -627,6 +631,8 @@ void optimizeMeshGRegionNetgen::operator() (GRegion *gr) void optimizeMeshGRegionGmsh::operator() (GRegion *gr) { + gr->model()->setCurrentMeshEntity(gr); + if(gr->geomType() == GEntity::DiscreteVolume) return; // don't optimize extruded meshes diff --git a/Mesh/meshGRegion.h b/Mesh/meshGRegion.h index 9e1c061fe6..88e4461031 100644 --- a/Mesh/meshGRegion.h +++ b/Mesh/meshGRegion.h @@ -30,6 +30,7 @@ class GEdge; class MVertex; class MLine; class MTriangle; + // Create the mesh of the region class meshGRegion { public : diff --git a/Mesh/meshGRegionExtruded.cpp b/Mesh/meshGRegionExtruded.cpp index 1e0af3f04b..7a0f5594e9 100644 --- a/Mesh/meshGRegionExtruded.cpp +++ b/Mesh/meshGRegionExtruded.cpp @@ -1,4 +1,4 @@ -// $Id: meshGRegionExtruded.cpp,v 1.27 2008-06-27 18:00:52 geuzaine Exp $ +// $Id: meshGRegionExtruded.cpp,v 1.28 2008-07-03 18:15:29 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -193,6 +193,8 @@ static void insertAllVertices(GRegion *gr, void meshGRegionExtruded::operator() (GRegion *gr) { + gr->model()->setCurrentMeshEntity(gr); + if(gr->geomType() == GEntity::DiscreteVolume) return; ExtrudeParams *ep = gr->meshAttributes.extrude; diff --git a/utils/misc/driverOCC.cpp b/utils/misc/driverOCC.cpp index 3cc2f1b440..75dee3da04 100644 --- a/utils/misc/driverOCC.cpp +++ b/utils/misc/driverOCC.cpp @@ -14,10 +14,23 @@ #include <gmsh/MElement.h> class mymsg : public GmshMessage{ +private: + GModel *_model; public: + mymsg(GModel *model) : _model(model), GmshMessage() {} void operator()(std::string level, std::string msg) { printf("level=%s msg=%s\n", level.c_str(), msg.c_str()); + + if(level == "Fatal" || level == "Error"){ + GEntity *e = _model->getCurrentMeshEntity(); + if(e){ + printf("error occurred while meshing entity:\n"); + printf(" tag=%d\n", e->tag()); + printf(" dimension=%d\n", e->dim()); + printf(" native pointer=%p\n", e->getNativePtr()); + } + } if(level == "Fatal") throw "Fatal error in Gmsh"; } }; @@ -30,13 +43,15 @@ int main(int argc, char **argv) BRepTools::Read(shape, argv[1], builder); BRepTools::Clean(shape); - // initialize gmsh and set a message callback + // initialize gmsh GmshInitialize(argc, argv); - mymsg c; - GmshSetMessageHandler(&c); - // create a model, import the shape, and mesh it + // create a model and set error handler GModel m; + mymsg c(&m); + GmshSetMessageHandler(&c); + + // import the shape, and mesh it m.importOCCShape((void*)&shape, 0); try{ m.mesh(2); -- GitLab