Hi, I am using Gmsh 2.5.0 thgough the C++ API and am not able to figure out how to do the equivalent operation of Coherence; directive of Gmsh scripting language. Since It seemed to me that ReplaceAllDuplicates(); (the function that seemed to do the actual job of Coherence;) did not update the corresponding GModel, I had to destroy the GModel once and re-import the internal structure by
GModel *m = new GModel; m->addVertex(...) ... ReplaceAllDuplicates(); m->destroy(); m->importGEOInternals(); which is obviously not efficient and discards some internal attributes. Besides I had to modify the Gmsh source as attached in order to deal with embedded entities. Do I have to do this way, or am I overlooking something? Takuya Takuya OSHIMA, Ph.D. Faculty of Engineering, Niigata University 8050 Ikarashi-Ninocho, Nishi-ku, Niigata, 950-2181, JAPAN
>From 800dfdf511d0928529562754e0ea8f4dc392cde6 Mon Sep 17 00:00:00 2001 From: Takuya OSHIMA <[email protected]> Date: Fri, 12 Aug 2011 16:04:43 +0900 Subject: [PATCH 2/4] Fixed corresponding GEO_Internal structure not updated when inserting embedded vertex/edge --- Geo/GFace.h | 4 ++-- Geo/gmshFace.cpp | 26 ++++++++++++++++++++++++++ Geo/gmshFace.h | 5 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Geo/GFace.h b/Geo/GFace.h index 63deb6a..dfba2a5 100644 --- a/Geo/GFace.h +++ b/Geo/GFace.h @@ -75,8 +75,8 @@ class GFace : public GEntity int numRegions() const { int num=0; if(r1) num++; if(r2) num++; return num; } // add embedded vertices/edges - void addEmbeddedVertex(GVertex *v){ embedded_vertices.push_back(v); } - void addEmbeddedEdge(GEdge *e){ embedded_edges.push_back(e); } + virtual void addEmbeddedVertex(GVertex *v){ embedded_vertices.push_back(v); } + virtual void addEmbeddedEdge(GEdge *e){ embedded_edges.push_back(e); } // delete the edge from the face (the edge is supposed to be a free // edge in the face, not part of any edge loops--use with caution!) diff --git a/Geo/gmshFace.cpp b/Geo/gmshFace.cpp index 1f47b02..e12b9bc 100644 --- a/Geo/gmshFace.cpp +++ b/Geo/gmshFace.cpp @@ -5,7 +5,9 @@ #include <stdlib.h> #include "GModel.h" +#include "gmshEdge.h" #include "gmshFace.h" +#include "gmshVertex.h" #include "meshGFace.h" #include "meshGEdge.h" #include "Geo.h" @@ -396,3 +398,27 @@ bool gmshFace::buildSTLTriangulation(bool force) return true; */ } + +void gmshFace::addEmbeddedVertex(GVertex *gv) +{ + GFace::addEmbeddedVertex(gv); + if(!s->EmbeddedPoints) + s->EmbeddedPoints = List_Create(4, 4, sizeof(Vertex *)); + Vertex *v = FindPoint(gv->tag()); + if(v) + List_Add(s->EmbeddedPoints, &v); + else + Msg::Error("Unknown point %d", gv->tag()); +} + +void gmshFace::addEmbeddedEdge(GEdge *ge) +{ + GFace::addEmbeddedEdge(ge); + if (!s->EmbeddedCurves) + s->EmbeddedCurves = List_Create(4, 4, sizeof(Curve *)); + Curve *c = FindCurve(ge->tag()); + if(c) + List_Add(s->EmbeddedCurves, &c); + else + Msg::Error("Unknown curve %d", ge->tag()); +} diff --git a/Geo/gmshFace.h b/Geo/gmshFace.h index fa22990..41adbda 100644 --- a/Geo/gmshFace.h +++ b/Geo/gmshFace.h @@ -9,6 +9,9 @@ #include "Geo.h" #include "GFace.h" +class gmshVertex; +class gmshEdge; + class gmshFace : public GFace { protected: Surface *s; @@ -34,6 +37,8 @@ class gmshFace : public GFace { void *getNativePtr() const { return s; } virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface=true) const; virtual void resetMeshAttributes(); + virtual void addEmbeddedVertex(GVertex *v); + virtual void addEmbeddedEdge(GEdge *e); }; #endif -- 1.7.6
>From ea01e6c9da6a37b3c5fb4f25770c56123441afdf Mon Sep 17 00:00:00 2001 From: Takuya OSHIMA <[email protected]> Date: Fri, 12 Aug 2011 19:46:16 +0900 Subject: [PATCH 3/4] Fixed broken coherence of embedded vertices/edges when ReplaceAllDuplicates() is performed --- Geo/Geo.cpp | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) diff --git a/Geo/Geo.cpp b/Geo/Geo.cpp index a3173f0..9ef580d 100644 --- a/Geo/Geo.cpp +++ b/Geo/Geo.cpp @@ -2836,6 +2836,16 @@ static void ReplaceDuplicatePoints() else List_Write(s->TrsfPoints, j, pv2); } + // replace embedded points + if(s->EmbeddedPoints){ + for(int j = 0; j < List_Nbr(s->EmbeddedPoints); j++){ + pv = (Vertex **)List_Pointer(s->EmbeddedPoints, j); + if(!(pv2 = (Vertex **)Tree_PQuery(allNonDuplicatedPoints, pv))) + Msg::Error("Weird point %d in Coherence", (*pv)->Num); + else + List_Write(s->EmbeddedPoints, j, pv2); + } + } } List_Delete(All); @@ -2959,6 +2969,19 @@ static void ReplaceDuplicateCurves() s->Extrude->geo.Source = (*pc2)->Num; } } + // replace embedded curves + if(s->EmbeddedCurves){ + for(int j = 0; j < List_Nbr(s->EmbeddedCurves); j++) { + pc = (Curve **)List_Pointer(s->EmbeddedCurves, j); + if(!(pc2 = (Curve **)Tree_PQuery(allNonDuplicatedCurves, pc))) + Msg::Error("Weird curve %d in Coherence", (*pc)->Num); + else { + List_Write(s->EmbeddedCurves, j, pc2); + // arghhh: check compareTwoCurves! + End_Curve(*pc2); + } + } + } } List_Delete(All); -- 1.7.6
_______________________________________________ gmsh mailing list [email protected] http://www.geuz.org/mailman/listinfo/gmsh
