From ad3b32a2979bdec0e622ce51eb217b88790d0c85 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 15 Nov 2017 11:08:52 +0100
Subject: [PATCH] fix extrusion layers in API + add C++ version of t3.geo

---
 Common/gmsh.cpp   |  8 +++++++-
 demos/api/t16.cpp |  3 ++-
 demos/api/t3.cpp  | 49 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 2 deletions(-)
 create mode 100644 demos/api/t3.cpp

diff --git a/Common/gmsh.cpp b/Common/gmsh.cpp
index da226984d9..7b63332cb8 100644
--- a/Common/gmsh.cpp
+++ b/Common/gmsh.cpp
@@ -651,7 +651,13 @@ static ExtrudeParams *getExtrudeParams(const std::vector<int> &numElements,
     e->mesh.ExtrudeMesh = true;
     e->mesh.NbElmLayer = numElements;
     e->mesh.hLayer = heights;
-    if(e->mesh.hLayer.empty()) e->mesh.hLayer.push_back(1.);
+    if(e->mesh.hLayer.empty()){
+      e->mesh.NbLayer = 1;
+      e->mesh.hLayer.push_back(1.);
+    }
+    else{
+      e->mesh.NbLayer = heights.size();
+    }
     e->mesh.Recombine = recombine;
   }
   return e;
diff --git a/demos/api/t16.cpp b/demos/api/t16.cpp
index d97e4294f4..9d13e81759 100644
--- a/demos/api/t16.cpp
+++ b/demos/api/t16.cpp
@@ -31,8 +31,9 @@ int main(int argc, char **argv)
   double lcar2 = .0005;
   double lcar3 = .055;
 
-  gmshModelGetEntities(ov);
+  gmshModelGetEntities(ov, 0);
   gmshModelSetMeshSize(ov, lcar1);
+
   gmshModelGetBoundary(holes, ov, false, false, true);
   gmshModelSetMeshSize(ov, lcar3);
 
diff --git a/demos/api/t3.cpp b/demos/api/t3.cpp
new file mode 100644
index 0000000000..d615534108
--- /dev/null
+++ b/demos/api/t3.cpp
@@ -0,0 +1,49 @@
+#include <cmath>
+#include <gmsh.h>
+
+// this reimplements gmsh/tutorial/t3.geo
+
+int main(int argc, char **argv)
+{
+  gmshInitialize(argc, argv);
+  gmshOptionSetNumber("General.Terminal", 1);
+
+  gmshModelCreate("t2");
+
+  // copy/paste from t1.cpp
+  double lc = 1e-2;
+  int o;
+  gmshModelGeoAddPoint(1, 0, 0, 0, o, lc);
+  gmshModelGeoAddPoint(2, .1, 0,  0, o, lc);
+  gmshModelGeoAddPoint(3, .1, .3, 0, o, lc);
+  gmshModelGeoAddPoint(4, 0,  .3, 0, o, lc);
+
+  gmshModelGeoAddLine(1, 1, 2, o);
+  gmshModelGeoAddLine(2, 3, 2, o);
+  gmshModelGeoAddLine(3, 3, 4, o);
+  gmshModelGeoAddLine(4, 4, 1, o);
+
+  gmshModelGeoAddLineLoop(1, {4, 1, -2, 3}, o);
+  gmshModelGeoAddPlaneSurface(1, {1}, o);
+  gmshModelAddPhysicalGroup(0, 1, {1, 2});
+  gmshModelAddPhysicalGroup(1, 2, {1, 2});
+  gmshModelAddPhysicalGroup(2, 6, {1});
+  gmshModelSetPhysicalName(2, 6, "My surface");
+  // end copy/paste
+
+  double h = 0.1, angle = 90.;
+
+  std::vector<std::pair<int, int> > ov;
+  gmshModelGeoExtrude({{2,1}}, 0, 0, h, ov, {8,2}, {0.5,1});
+  gmshModelGeoRevolve({{2,28}}, -0.1,0,0.1, 0,1,0, -M_PI/2, ov, {7});
+  gmshModelGeoTwist({{2,50}}, 0,0.15,0.25, -2*h,0,0, 1,0,0, angle*M_PI/180.,
+                    ov, {10}, {}, true);
+  gmshModelAddPhysicalGroup(3, 101, {1, 2, ov[1].second});
+
+  gmshModelGeoSynchronize();
+  gmshModelMesh(3);
+  gmshExport("t3.msh");
+  gmshFinalize();
+
+  return 0;
+}
-- 
GitLab