I will stil have to do more testing but problem seems to have been
solved. In case anyone is interested the attached is the modification
I made to the 2.5.0 source. The useage is to set givenVerticesOnly
attribute to the GFace/GEdge instances where you want to create mesh
only from given (embedded) vertices.

  GFace *f0 = m->addPlanarFace(edges);
  f0->meshAttributes.givenVerticesOnly = 1;

Takuya

Takuya OSHIMA, Ph.D.
Faculty of Engineering, Niigata University
8050 Ikarashi-Ninocho, Nishi-ku, Niigata, 950-2181, JAPAN

From: Takuya OSHIMA <[email protected]>
Subject: [Gmsh] Generating triangle mesh only from given point cloud and 
outline edges via the API
Date: Mon, 08 Aug 2011 22:56:53 +0900 (JST)

> Hi,
> 
> I want to attain something similar to an old post:
> http://www.geuz.org/pipermail/gmsh/2008/003655.html
> 
> which is in my case generating a triangle mesh from (and only from)
> existing nodes and outline edges via the Gmsh library API. Now that
> Gmsh 2.5.0 supports embedded vertices, I managed to write a small
> demonstration code as shown below.
> 
> I thought using a huge characteristic length would work to suppress
> addition of generated vertices, but in reality it didn't. Is there any
> way I can suppress the addition of generated vertices? If someone
> points me where to start, I wouldn't mind modifying the Gmsh source.
> 
> Thanks,
> Takuya
> 
> Takuya OSHIMA, Ph.D.
> Faculty of Engineering, Niigata University
> 8050 Ikarashi-Ninocho, Nishi-ku, Niigata, 950-2181, JAPAN
> 
> // Create square surface mesh with triangular elements
> 
> #include "Gmsh.h"
> #include "GModel.h"
> 
> #include <math.h>
> #include <iostream>
> 
> int main(int argc, char **argv)
> {
>   const double lc = MAXFLOAT;
>   const int nDivs = 10;
>   GmshInitialize(argc, argv);
> 
>   GModel *m = new GModel;
>   m->setFactory("Gmsh");
> 
>   // Add boundary vertices and edges of outline polygon
>   std::vector<std::vector<GEdge *> > edges(1);
>   GVertex *v, *v0;
>   for(int i = 0; i < nDivs; ++i)
>     {
>     GVertex *vOld;
>     if(i == 0)
>       {
>       vOld = v0 = m->addVertex(0., 0., 0., lc);
>       }
>     else
>       {
>       vOld = v;
>       }
>     v = m->addVertex((i + 1.0) / nDivs, 0., 0., lc);
>     edges[0].push_back(m->addLine(vOld, v));
>     }
>   for(int i = 0; i < nDivs; ++i)
>     {
>     GVertex *vOld = v;
>     v = m->addVertex(1.0, (i + 1.0) / nDivs, 0., lc);
>     edges[0].push_back(m->addLine(vOld, v));
>     }
>   for(int i = 0; i < nDivs; ++i)
>     {
>     GVertex *vOld = v;
>     v = m->addVertex(1.0 - (i + 1.0) / nDivs, 1.0, 0., lc);
>     edges[0].push_back(m->addLine(vOld, v));
>     }
>   for(int i = 0; i < nDivs; ++i)
>     {
>     GVertex *vOld = v;
>     v = ((i == nDivs - 1)
>         ? v0: m->addVertex(0., 1.0 - (i + 1.0) / nDivs, 0., lc));
>     edges[0].push_back(m->addLine(vOld, v));
>     }
> 
>   // Create surface
>   GFace *f0 = m->addPlanarFace(edges);
> 
>   // Add point cloud inside the polygon as embedded vertices
>   // -- I want to have only those given vertices inside the outline edges!
>   GVertex *v1 = m->addVertex(0.3, 0.3, 0., lc);
>   f0->addEmbeddedVertex(v1);
>   v1 = m->addVertex(0.8, 0.2, 0., lc);
>   f0->addEmbeddedVertex(v1);
>   v1 = m->addVertex(0.4, 0.7, 0., lc);
>   f0->addEmbeddedVertex(v1);
>   v1 = m->addVertex(0.7, 0.6, 0., lc);
>   f0->addEmbeddedVertex(v1);
> 
>   // Create mesh
>   m->mesh(2);
>   m->writeMSH("test.msh");
> 
>   delete m;
> 
>   GmshFinalize();
> }
> 
> 
commit a46481a62aec532aadfaa0943f04bf583f976340
Author: Takuya OSHIMA <[email protected]>
Date:   Fri Aug 12 12:12:44 2011 +0900

    Add givenVerticesOnly option that creates edge/surface mesh only from given vertices

diff --git a/Geo/GEdge.cpp b/Geo/GEdge.cpp
index 11a8a33..5a398e8 100644
--- a/Geo/GEdge.cpp
+++ b/Geo/GEdge.cpp
@@ -85,6 +85,7 @@ void GEdge::resetMeshAttributes()
   meshAttributes.extrude = 0;
   meshAttributes.meshSize = MAX_LC;
   meshAttributes.minimumMeshSegments = 1;
+  meshAttributes.givenVerticesOnly = 0;
 }
 
 void GEdge::addFace(GFace *e)
diff --git a/Geo/GEdge.h b/Geo/GEdge.h
index f27407a..321db4c 100644
--- a/Geo/GEdge.h
+++ b/Geo/GEdge.h
@@ -187,6 +187,8 @@ class GEdge : public GEntity {
     int minimumMeshSegments;
     // the extrusion parameters (if any)
     ExtrudeParams *extrude;
+    // do we create mesh only from given vertices?
+    int givenVerticesOnly;
   } meshAttributes ;
 
   typedef enum {PENDING, DONE, FAILED} meshGenerationStatus;
diff --git a/Geo/GFace.cpp b/Geo/GFace.cpp
index 5b2a64f..645018a 100644
--- a/Geo/GFace.cpp
+++ b/Geo/GFace.cpp
@@ -135,6 +135,7 @@ void GFace::resetMeshAttributes()
   meshAttributes.transfiniteArrangement = 0;
   meshAttributes.transfiniteSmoothing = -1;
   meshAttributes.extrude = 0;
+  meshAttributes.givenVerticesOnly = 0;
 }
 
 SBoundingBox3d GFace::bounds() const
diff --git a/Geo/GFace.h b/Geo/GFace.h
index 71e76f2..63deb6a 100644
--- a/Geo/GFace.h
+++ b/Geo/GFace.h
@@ -267,6 +267,8 @@ class GFace : public GEntity
     // the extrusion parameters (if any)
     ExtrudeParams *extrude;
     // edge loops
+    // do we create mesh only from given vertices?
+    int givenVerticesOnly;
   } meshAttributes ;
 
   typedef enum {PENDING, DONE, FAILED} meshGenerationStatus;
diff --git a/Mesh/meshGEdge.cpp b/Mesh/meshGEdge.cpp
index 6462f33..e599eeb 100644
--- a/Mesh/meshGEdge.cpp
+++ b/Mesh/meshGEdge.cpp
@@ -357,7 +357,7 @@ void meshGEdge::operator() (GEdge *ge)
   // Integrate detJ/lc du 
   double a;
   int N;
-  if (ge->degenerate(0)){
+  if (ge->degenerate(0) || ge->meshAttributes.givenVerticesOnly){
     a = 0.;
     N = 1;
   }
diff --git a/Mesh/meshGFace.cpp b/Mesh/meshGFace.cpp
index a1737ba..2c8c617 100644
--- a/Mesh/meshGFace.cpp
+++ b/Mesh/meshGFace.cpp
@@ -802,14 +802,35 @@ static bool meshGenerator(GFace *gf, int RECUR_ITER,
     gf->model()->add(ge);
   }
 
-  gf->triangles.clear();
-  gf->quadrangles.clear();
+  if(!gf->meshAttributes.givenVerticesOnly){
+    gf->triangles.clear();
+    gf->quadrangles.clear();
+  }
 
   int nb_swap;
   //outputScalarField(m->triangles, "beforeswop.pos",1);
   Msg::Debug("Delaunizing the initial mesh");
   delaunayizeBDS(gf, *m, nb_swap);
   //outputScalarField(m->triangles, "afterswop.pos",0);
+  if(gf->meshAttributes.givenVerticesOnly){
+    computeMeshSizeFieldAccuracy(gf, *m, gf->meshStatistics.efficiency_index,
+				 gf->meshStatistics.longest_edge_length,
+				 gf->meshStatistics.smallest_edge_length,
+				 gf->meshStatistics.nbEdge,
+				 gf->meshStatistics.nbGoodLength);
+    gf->meshStatistics.status = GFace::DONE;
+    delete m;
+    if((CTX::instance()->mesh.recombineAll || gf->meshAttributes.recombine) && 
+       !CTX::instance()->mesh.optimizeLloyd)
+      recombineIntoQuads(gf);
+    computeElementShapes(gf, gf->meshStatistics.worst_element_shape,
+                         gf->meshStatistics.average_element_shape,
+			 gf->meshStatistics.best_element_shape,
+			 gf->meshStatistics.nbTriangle,
+			 gf->meshStatistics.nbGoodQuality);
+    Msg::Debug("Finishing without adding internal points");
+    return true;
+  }
   Msg::Debug("Starting to add internal points");
 
   // start mesh generation
_______________________________________________
gmsh mailing list
[email protected]
http://www.geuz.org/mailman/listinfo/gmsh

Reply via email to