From 358436b1f39be19e36bf4974533f0d7e3a377d36 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Fri, 17 Feb 2017 19:05:19 +0000 Subject: [PATCH] occ mesh size constraint on points --- Geo/GModelIO_OCC.cpp | 10 ++++++++-- Geo/GModelIO_OCC.h | 12 ++++++------ Geo/OCCVertex.cpp | 10 +++++----- Geo/OCCVertex.h | 8 ++++---- Parser/Gmsh.tab.cpp | 4 ++-- Parser/Gmsh.y | 4 ++-- demos/boolean/simple.geo | 13 +++++-------- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/Geo/GModelIO_OCC.cpp b/Geo/GModelIO_OCC.cpp index a18d52b757..a266a0af7d 100644 --- a/Geo/GModelIO_OCC.cpp +++ b/Geo/GModelIO_OCC.cpp @@ -243,7 +243,8 @@ int OCC_Internals::getMaxTag(int dim) const return ret; } -void OCC_Internals::addVertex(int tag, double x, double y, double z) +void OCC_Internals::addVertex(int tag, double x, double y, double z, + double meshSize) { if(tag > 0 && _tagVertex.IsBound(tag)){ Msg::Error("OpenCASCADE vertex with tag %d already exists", tag); @@ -266,6 +267,8 @@ void OCC_Internals::addVertex(int tag, double x, double y, double z) } if(tag <= 0) tag = getMaxTag(0) + 1; bind(result, tag); + if(meshSize > 0 && meshSize < MAX_LC) + meshAttributes[0][tag].size = meshSize; } void OCC_Internals::addLine(int tag, int startTag, int endTag) @@ -1788,7 +1791,10 @@ void OCC_Internals::synchronize(GModel *model) tag = vTagMax + 1; vTagMax++; } - model->add(new OCCVertex(model, tag, vertex)); + std::map<int, meshAttribute>::iterator it = + meshAttributes[0].find(tag); + double lc = (it == meshAttributes[0].end()) ? MAX_LC : it->second.size; + model->add(new OCCVertex(model, tag, vertex, lc)); } } diff --git a/Geo/GModelIO_OCC.h b/Geo/GModelIO_OCC.h index b77c1388d1..cf5dc52a78 100644 --- a/Geo/GModelIO_OCC.h +++ b/Geo/GModelIO_OCC.h @@ -37,13 +37,13 @@ class OCC_Internals { TopTools_DataMapOfIntegerShape _tagWire, _tagShell; // internal mesh attributes, linked to tags - class meshAttributes { + class meshAttribute { public: - meshAttributes() : size(0.), extrude(0) {} + meshAttribute() : size(MAX_LC), extrude(0) {} double size; ExtrudeParams *extrude; }; - std::map<int, meshAttributes> meshAttibutes[4]; + std::map<int, meshAttribute> meshAttributes[4]; // add a shape and all its subshapes to _vmap, _emap, ..., _somap void _addShapeToMaps(TopoDS_Shape shape); @@ -75,7 +75,7 @@ class OCC_Internals { void reset() { for(int i = 0; i < 6; i++) _maxTagConstraints[i] = 0; - for(int i = 0; i < 4; i++) meshAttibutes[i].clear(); + for(int i = 0; i < 4; i++) meshAttributes[i].clear(); _somap.Clear(); _shmap.Clear(); _fmap.Clear(); _wmap.Clear(); _emap.Clear(); _vmap.Clear(); _vertexTag.Clear(); _edgeTag.Clear(); _faceTag.Clear(); _solidTag.Clear(); @@ -120,7 +120,7 @@ class OCC_Internals { int getMaxTag(int dim) const; // add shapes - void addVertex(int tag, double x, double y, double z); + void addVertex(int tag, double x, double y, double z, double meshSize=MAX_LC); void addLine(int tag, int startTag, int endTag); void addCircleArc(int tag, int startTag, int centerTag, int endTag); void addCircle(int tag, double x, double y, double z, double r, double angle1, @@ -254,7 +254,7 @@ public: void reset(){} void setTagConstraints(int dim, int val){} int getMaxTag(int dim) const { return 0; } - void addVertex(int tag, double x, double y, double z){} + void addVertex(int tag, double x, double y, double z, double meshSize=MAX_LC){} void addLine(int tag, int startTag, int endTag){} void addCircleArc(int tag, int startTag, int centerTag, int endTag){} void addCircle(int tag, double x, double y, double z, double r, double angle1, diff --git a/Geo/OCCVertex.cpp b/Geo/OCCVertex.cpp index 131f3f6872..dcc24fe453 100644 --- a/Geo/OCCVertex.cpp +++ b/Geo/OCCVertex.cpp @@ -15,20 +15,20 @@ #include "GModelIO_OCC.h" -OCCVertex::OCCVertex(GModel *m, int num, TopoDS_Vertex _v) - : GVertex(m, num), v(_v) +OCCVertex::OCCVertex(GModel *m, int num, TopoDS_Vertex v, double lc) + : GVertex(m, num, lc), _v(v) { max_curvature = -1; - gp_Pnt pnt = BRep_Tool::Pnt(v); + gp_Pnt pnt = BRep_Tool::Pnt(_v); _x = pnt.X(); _y = pnt.Y(); _z = pnt.Z(); - model()->getOCCInternals()->bind(v, num); + model()->getOCCInternals()->bind(_v, num); } OCCVertex::~OCCVertex() { - model()->getOCCInternals()->unbind(v, tag()); + model()->getOCCInternals()->unbind(_v, tag()); } void OCCVertex::setPosition(GPoint &p) diff --git a/Geo/OCCVertex.h b/Geo/OCCVertex.h index ac4fd21d15..2e49204046 100644 --- a/Geo/OCCVertex.h +++ b/Geo/OCCVertex.h @@ -15,12 +15,12 @@ class OCCVertex : public GVertex { protected: - TopoDS_Vertex v; + TopoDS_Vertex _v; double _x, _y, _z; mutable double max_curvature; double max_curvature_of_surfaces() const; public: - OCCVertex(GModel *m, int num, TopoDS_Vertex _v); + OCCVertex(GModel *m, int num, TopoDS_Vertex v, double lc=MAX_LC); virtual ~OCCVertex(); virtual GPoint point() const { return GPoint(x(), y(), z()); } virtual double x() const { return _x; } @@ -28,9 +28,9 @@ class OCCVertex : public GVertex { virtual double z() const { return _z; } virtual void setPosition(GPoint &p); ModelType getNativeType() const { return OpenCascadeModel; } - void * getNativePtr() const { return (void*)&v; } + void *getNativePtr() const { return (void*)&_v; } virtual SPoint2 reparamOnFace(const GFace *gf, int) const; - TopoDS_Vertex getShape() { return v; } + TopoDS_Vertex getShape() { return _v; } }; #endif diff --git a/Parser/Gmsh.tab.cpp b/Parser/Gmsh.tab.cpp index 88338ea08d..1277e9954a 100644 --- a/Parser/Gmsh.tab.cpp +++ b/Parser/Gmsh.tab.cpp @@ -8063,11 +8063,11 @@ yyreduce: double x = CTX::instance()->geom.scalingFactor * (yyvsp[(6) - (7)].v)[0]; double y = CTX::instance()->geom.scalingFactor * (yyvsp[(6) - (7)].v)[1]; double z = CTX::instance()->geom.scalingFactor * (yyvsp[(6) - (7)].v)[2]; + double lc = CTX::instance()->geom.scalingFactor * (yyvsp[(6) - (7)].v)[3]; if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){ - GModel::current()->getOCCInternals()->addVertex(num, x, y, z); + GModel::current()->getOCCInternals()->addVertex(num, x, y, z, lc); } else{ - double lc = CTX::instance()->geom.scalingFactor * (yyvsp[(6) - (7)].v)[3]; if(lc == 0.) lc = MAX_LC; // no mesh size given at the point Vertex *v; if(!myGmshSurface) diff --git a/Parser/Gmsh.y b/Parser/Gmsh.y index 35aeb93416..83f1952052 100644 --- a/Parser/Gmsh.y +++ b/Parser/Gmsh.y @@ -1735,11 +1735,11 @@ Shape : double x = CTX::instance()->geom.scalingFactor * $6[0]; double y = CTX::instance()->geom.scalingFactor * $6[1]; double z = CTX::instance()->geom.scalingFactor * $6[2]; + double lc = CTX::instance()->geom.scalingFactor * $6[3]; if(factory == "OpenCASCADE" && GModel::current()->getOCCInternals()){ - GModel::current()->getOCCInternals()->addVertex(num, x, y, z); + GModel::current()->getOCCInternals()->addVertex(num, x, y, z, lc); } else{ - double lc = CTX::instance()->geom.scalingFactor * $6[3]; if(lc == 0.) lc = MAX_LC; // no mesh size given at the point Vertex *v; if(!myGmshSurface) diff --git a/demos/boolean/simple.geo b/demos/boolean/simple.geo index 27e757daf5..c49e9a9d57 100644 --- a/demos/boolean/simple.geo +++ b/demos/boolean/simple.geo @@ -1,13 +1,10 @@ SetFactory("OpenCASCADE"); -Mesh.Algorithm = 6; -Mesh.CharacteristicLengthMin = 0.1; -Mesh.CharacteristicLengthMax = 0.1; - -Point(1) = {0,0,0}; -Point(2) = {1,0,0}; -Point(3) = {1,1,0}; -Point(4) = {0,1,0}; +lc = 0.1; +Point(1) = {0,0,0, lc}; +Point(2) = {1,0,0, lc}; +Point(3) = {1,1,0, lc}; +Point(4) = {0,1,0, lc/10}; Line(1) = {1,2}; Line(2) = {2,3}; Line(3) = {3,4}; -- GitLab