From 1b0cfb08a90b0a60c07a5ddfe2cca81d20ff7c30 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 25 Jun 2001 13:05:16 +0000
Subject: [PATCH] Reintegration of the old extrusion mesh generator (the new
 one DOES NOT work: it creates duplicate points, etc.). Sorry!

---
 Common/Context.h        |   1 +
 Common/GetOptions.cpp   |   8 +-
 Common/Options.cpp      |   3 +-
 Graphics/Draw.h         |   1 +
 Graphics/Mesh.cpp       |  17 +-
 Mesh/3D_Extrude_Old.cpp | 561 ++++++++++++++++++++++++++++++++++++++++
 Mesh/Create.cpp         |   4 +-
 Mesh/Generator.cpp      |  11 +-
 Mesh/Makefile           |   3 +-
 Mesh/Mesh.h             |   1 +
 Mesh/Print_Mesh.cpp     |  68 +++--
 11 files changed, 650 insertions(+), 28 deletions(-)
 create mode 100644 Mesh/3D_Extrude_Old.cpp

diff --git a/Common/Context.h b/Common/Context.h
index bb455bad1b..ad885c8adc 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -146,6 +146,7 @@ public :
 	cut_planec * z + cut_planed; 
       return val;
     }
+    int oldxtrude, oldxtrude_recombine;
   } mesh;
 
   // post processing options 
diff --git a/Common/GetOptions.cpp b/Common/GetOptions.cpp
index a753849098..2995e74a35 100644
--- a/Common/GetOptions.cpp
+++ b/Common/GetOptions.cpp
@@ -1,4 +1,4 @@
-// $Id: GetOptions.cpp,v 1.25 2001-06-17 21:07:56 geuzaine Exp $
+// $Id: GetOptions.cpp,v 1.26 2001-06-25 13:05:16 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -125,6 +125,12 @@ void Get_Options (int argc, char *argv[], int *nbfiles) {
       else if(!strcmp(argv[i]+1, "3")){ 
         CTX.batch = 3; i++;
       }
+      else if(!strcmp(argv[i]+1, "extrude")){ //old extrusion mesh generator
+        CTX.mesh.oldxtrude = 1; i++;
+      }
+      else if(!strcmp(argv[i]+1, "recombine")){ //old extrusion mesh generator
+        CTX.mesh.oldxtrude_recombine = 1; i++;
+      }
       else if(!strcmp(argv[i]+1, "histogram")){ 
         CTX.mesh.histogram = 1; i++;
       }
diff --git a/Common/Options.cpp b/Common/Options.cpp
index d9ece1b9d5..15608fa177 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.27 2001-06-06 09:39:49 geuzaine Exp $
+// $Id: Options.cpp,v 1.28 2001-06-25 13:05:16 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -93,6 +93,7 @@ void Init_Options(int num){
   CTX.post.draw = 1 ;
   CTX.threads_lock = 0 ; //very primitive locking during mesh generation
   CTX.mesh.histogram = 0 ;
+  CTX.mesh.oldxtrude = CTX.mesh.oldxtrude_recombine = 0; //old extrusion mesh generator
 
   // For motif versions only:
   CTX.overlay = 1 ;
diff --git a/Graphics/Draw.h b/Graphics/Draw.h
index 1f3081e756..e096ba105d 100644
--- a/Graphics/Draw.h
+++ b/Graphics/Draw.h
@@ -66,6 +66,7 @@ void Draw_Vector (int Type, int Fill,
                   double *Offset, double Raise[3][5]);
 void Draw_Mesh_Volumes(void *a, void *b);
 void Draw_Mesh_Surfaces(void *a, void *b);
+void Draw_Mesh_Extruded_Surfaces(void *a, void *b);
 void Draw_Mesh_Curves(void *a, void *b);
 void Draw_Mesh_Points(void *a, void *b);
 void Draw_Simplex_Surfaces (void *a, void *b);
diff --git a/Graphics/Mesh.cpp b/Graphics/Mesh.cpp
index 81d2646fa9..77be47871d 100644
--- a/Graphics/Mesh.cpp
+++ b/Graphics/Mesh.cpp
@@ -1,4 +1,4 @@
-// $Id: Mesh.cpp,v 1.30 2001-06-12 08:29:52 geuzaine Exp $
+// $Id: Mesh.cpp,v 1.31 2001-06-25 13:05:16 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -86,6 +86,8 @@ void Draw_Mesh (Mesh *M) {
        (CTX.mesh.surfaces || CTX.mesh.surfaces_num) &&
        CTX.render_mode != GMSH_SELECT){
       Tree_Action(M->Surfaces, Draw_Mesh_Surfaces);
+      if(CTX.mesh.oldxtrude)//old extrusion algo
+	Tree_Action(M->Surfaces, Draw_Mesh_Extruded_Surfaces);
     }
     /* fall-through! */
   case 1 :  
@@ -136,6 +138,13 @@ void Draw_Mesh_Surfaces (void *a,void *b){
   Tree_Action((*s)->Simplexes, Draw_Simplex_Surfaces);
 }
 
+void Draw_Mesh_Extruded_Surfaces(void *a, void *b){
+  Volume **v;
+  v = (Volume**)a;
+  Tree_Action((*v)->Simp_Surf, Draw_Simplex_Surfaces);
+}
+
+
 void Draw_Mesh_Curves (void *a, void *b){
   Curve **c;
   c = (Curve**)a;
@@ -573,9 +582,9 @@ void Draw_Hexahedron_Volume (void *a, void *b){
     glColor4ubv((GLubyte*)&CTX.color.mesh.hexahedron);
 
   for (i=0 ; i<8 ; i++) {
-    X[i] = Xc + CTX.mesh.explode * 0.99 * ((*h)->V[i]->Pos.X - Xc);
-    Y[i] = Yc + CTX.mesh.explode * 0.99 * ((*h)->V[i]->Pos.Y - Yc);
-    Z[i] = Zc + CTX.mesh.explode * 0.99 * ((*h)->V[i]->Pos.Z - Zc);
+    X[i] = Xc + CTX.mesh.explode * ((*h)->V[i]->Pos.X - Xc);
+    Y[i] = Yc + CTX.mesh.explode * ((*h)->V[i]->Pos.Y - Yc);
+    Z[i] = Zc + CTX.mesh.explode * ((*h)->V[i]->Pos.Z - Zc);
   }
 
   glBegin(GL_LINE_LOOP);
diff --git a/Mesh/3D_Extrude_Old.cpp b/Mesh/3D_Extrude_Old.cpp
new file mode 100644
index 0000000000..172fdc231c
--- /dev/null
+++ b/Mesh/3D_Extrude_Old.cpp
@@ -0,0 +1,561 @@
+// $Id: 3D_Extrude_Old.cpp,v 1.1 2001-06-25 13:05:16 geuzaine Exp $
+
+// This is the old extrusion mesh generator -> only available through
+// command line options -extrude (w/o -recombine). This mesh generator
+// pre-supposes a definition of surfaces in the XY plane, and will
+// extrude everything along the Z axis, taking parameters
+// interactively from standard input, e.g.
+//
+// gmsh test -extrude -recombine < params.ext
+//
+// All geometrical entities are automatically numbered:
+//
+//         volumes: 3 * 10^6 + layer * 10^3 + surf->num
+// New XY surfaces: 2 * 10^6 + layer * 10^3 + surf->num
+//  perp. surfaces: 1 * 10^6 + layer * 10^3 + curve->num
+//     perp. lines: 4 * 10^6 + layer * 10^3 + point->Num
+//
+// WARNING:
+//
+// The is no way to save XY generated lines or other entities for the
+// moment
+
+#include "Gmsh.h"
+#include "Const.h"
+#include "Geo.h"
+#include "CAD.h"
+#include "Mesh.h"
+#include "Context.h"
+#include "Create.h"
+
+extern Context_T CTX ;
+extern Mesh   *LOCAL, *THEM;
+extern int     CurrentNodeNumber; 
+
+
+#define NB_LAYER_MAX 100
+
+static Tree_T *Tree_Ares, *Tree_Swaps;
+
+FILE          *file;
+Mesh          *THEm;
+Surface       *THES;
+Volume        *THEV;
+int            TEST_IS_ALL_OK, NbLayer;
+int            NbElmLayer [NB_LAYER_MAX];
+int            ZonLayer   [NB_LAYER_MAX];
+int            LineLayer  [NB_LAYER_MAX];
+int            SurfLayer  [NB_LAYER_MAX+1];
+double         hLayer     [NB_LAYER_MAX];
+
+typedef struct {
+  int a,b;
+}nxn;
+
+static int compnxn(const void *a, const void *b){
+  nxn *q,*w;
+  q = (nxn*)a;
+  w = (nxn*)b;
+  if(q->a > w->a)return 1;
+  if(q->a < w->a)return -1;
+  if(q->b > w->b)return 1;
+  if(q->b < w->b)return -1;
+  return 0;
+}
+
+static void InitExtrudeParams (void){
+  int i;
+  printf("Number of layers: ");
+  scanf("%d",&NbLayer);
+  if(NbLayer >NB_LAYER_MAX)
+    Msg(GERROR, "Max number of layer exceeded");
+  fprintf(file, "%d\n", NbLayer); fflush(file);
+  for(i=0;i<NbLayer;i++){
+    printf("Number of elements in layer %d: ",i+1);
+    scanf("%d",&NbElmLayer[i]);
+    fprintf(file, "%d\n", NbElmLayer[i]);fflush(file);
+    printf("Depth of layer %d: ",i+1);
+    scanf("%lf",&hLayer[i]);
+    fprintf(file, "%g\n", hLayer[i]);fflush(file);
+  }
+  Tree_Ares = Tree_Create(sizeof(nxn),compnxn);
+  Tree_Swaps = Tree_Create(sizeof(nxn),compnxn);
+}
+
+static int are_exist(Vertex *v1,Vertex *v2, Tree_T *t){
+  nxn n;
+  n.a = IMAX(v1->Num,v2->Num);
+  n.b = IMIN(v1->Num,v2->Num);
+  return Tree_Search(t,&n);
+}
+
+static void are_cree(Vertex *v1,Vertex *v2, Tree_T *t){
+  nxn n;
+  n.a = IMAX(v1->Num,v2->Num);
+  n.b = IMIN(v1->Num,v2->Num);
+  Tree_Replace(t,&n);
+}
+
+static void are_del(Vertex *v1,Vertex *v2, Tree_T *t){
+  nxn n;
+  n.a = IMAX(v1->Num,v2->Num);
+  n.b = IMIN(v1->Num,v2->Num);
+  Tree_Suppress(t,&n);
+}
+
+
+static void Extrude_Simplex_Phase1 (void *data , void *dum){
+  
+  Simplex **pS , *s;
+  int i,j,k;
+  Vertex *v1,*v2,*v3,*v4,*v5,*v6;
+
+  pS = (Simplex**)data;
+  s = *pS;
+
+  k = 0;
+  for(i=0;i<NbLayer;i++){
+    for(j=0;j<NbElmLayer[i];j++){
+      List_Read(s->V[0]->Extruded_Points,k,&v1);
+      List_Read(s->V[1]->Extruded_Points,k,&v2);
+      List_Read(s->V[2]->Extruded_Points,k,&v3);
+      List_Read(s->V[0]->Extruded_Points,k+1,&v4);
+      List_Read(s->V[1]->Extruded_Points,k+1,&v5);
+      List_Read(s->V[2]->Extruded_Points,k+1,&v6);
+      k++;
+      if(!are_exist(v1,v5,Tree_Ares))are_cree(v2,v4,Tree_Ares);
+      if(!are_exist(v5,v3,Tree_Ares))are_cree(v2,v6,Tree_Ares);
+      if(!are_exist(v4,v3,Tree_Ares))are_cree(v1,v6,Tree_Ares);
+    }
+  }  
+}
+
+static void Extrude_Simplex_Phase3 (void *data , void *dum){
+  
+  Simplex **pS , *s, *news;
+  Prism   *newp;
+  Hexahedron *newh;
+  int i,j,k;
+  Vertex *v1,*v2,*v3,*v4,*v5,*v6,*v7,*v8;
+
+  pS = (Simplex**)data;
+  s = *pS;
+
+  if(s->V[3] && !CTX.mesh.oldxtrude_recombine){
+    Msg(GERROR, "Non recombined extrusion impossible with quadrangles (use -recombine)");
+  }
+
+  k = 0;
+  for(i=0;i<=NbLayer;i++){
+    if(SurfLayer[i]){
+      List_Read(s->V[0]->Extruded_Points,k,&v1);
+      List_Read(s->V[1]->Extruded_Points,k,&v2);
+      List_Read(s->V[2]->Extruded_Points,k,&v3);      
+      news = Create_Simplex(v1,v2,v3,NULL);
+      if(s->V[3]){
+	List_Read(s->V[3]->Extruded_Points,k,&v4);
+	news->V[3] = v4;
+      }
+      news->iEnt = SurfLayer[i];
+      Tree_Add(THEV->Simp_Surf,&news);
+    }
+    for(j=0;j<NbElmLayer[i];j++){
+      k++;
+    }
+  }
+  
+  k = 0;
+  for(i=0;i<NbLayer;i++){
+    for(j=0;j<NbElmLayer[i];j++){
+
+      if(s->V[3]){
+	List_Read(s->V[0]->Extruded_Points,k,&v1);
+	List_Read(s->V[1]->Extruded_Points,k,&v2);
+	List_Read(s->V[2]->Extruded_Points,k,&v3);
+	List_Read(s->V[3]->Extruded_Points,k,&v4);
+	List_Read(s->V[0]->Extruded_Points,k+1,&v5);
+	List_Read(s->V[1]->Extruded_Points,k+1,&v6);
+	List_Read(s->V[2]->Extruded_Points,k+1,&v7);
+	List_Read(s->V[3]->Extruded_Points,k+1,&v8);
+      }
+      else{
+	List_Read(s->V[0]->Extruded_Points,k,&v1);
+	List_Read(s->V[1]->Extruded_Points,k,&v2);
+	List_Read(s->V[2]->Extruded_Points,k,&v3);
+	List_Read(s->V[0]->Extruded_Points,k+1,&v4);
+	List_Read(s->V[1]->Extruded_Points,k+1,&v5);
+	List_Read(s->V[2]->Extruded_Points,k+1,&v6);
+      }
+
+      k++;
+      if(ZonLayer[i]){
+	if(CTX.mesh.oldxtrude_recombine){
+	  if(s->V[3]){
+	    newh = Create_Hexahedron(v1,v2,v3,v4,v5,v6,v7,v8);
+	    newh->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Hexahedra,&newh);
+	  }
+	  else{
+	    newp = Create_Prism(v1,v2,v3,v4,v5,v6);
+	    newp->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Prisms,&newp);
+	  }
+	}
+	else{
+	  if(are_exist(v4,v2,Tree_Ares) && 
+	     are_exist(v5,v3,Tree_Ares) && 
+	     are_exist(v4,v3,Tree_Ares) ){
+	    news = Create_Simplex(v1,v2,v3,v4);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	    news = Create_Simplex(v4,v5,v6,v3);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	    news = Create_Simplex(v2,v4,v5,v3);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	  }
+	  if(are_exist(v4,v2,Tree_Ares) && 
+	     are_exist(v2,v6,Tree_Ares) && 
+	     are_exist(v4,v3,Tree_Ares) ){
+	    news = Create_Simplex(v1,v2,v3,v4);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	    news = Create_Simplex(v4,v5,v6,v2);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	    news = Create_Simplex(v4,v2,v6,v3);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	  }
+	  if(are_exist(v4,v2,Tree_Ares) && 
+	     are_exist(v2,v6,Tree_Ares) && 
+	     are_exist(v6,v1,Tree_Ares) ){
+	    news = Create_Simplex(v1,v2,v3,v6);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	    news = Create_Simplex(v4,v5,v6,v2);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	    news = Create_Simplex(v2,v4,v6,v1);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	  }
+	  if(are_exist(v5,v1,Tree_Ares) && 
+	     are_exist(v5,v3,Tree_Ares) && 
+	     are_exist(v4,v3,Tree_Ares)  ){
+	    news = Create_Simplex(v1,v2,v3,v5);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	    news = Create_Simplex(v4,v5,v6,v3);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	    news = Create_Simplex(v1,v4,v5,v3);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	  }
+	  if(are_exist(v5,v1,Tree_Ares) && 
+	     are_exist(v5,v3,Tree_Ares) && 
+	     are_exist(v6,v1,Tree_Ares)  ){
+	    news = Create_Simplex(v1,v2,v3,v5);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	    news = Create_Simplex(v4,v5,v6,v1);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	    news = Create_Simplex(v1,v3,v5,v6);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	  }
+	  if(are_exist(v5,v1,Tree_Ares) && 
+	     are_exist(v2,v6,Tree_Ares) && 
+	     are_exist(v6,v1,Tree_Ares)  ){
+	    news = Create_Simplex(v1,v2,v3,v6);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	    news = Create_Simplex(v4,v5,v6,v1);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	    news = Create_Simplex(v1,v2,v5,v6);
+	    news->iEnt = ZonLayer[i];
+	    Tree_Add(THEV->Simplexes,&news);
+	  }
+	}
+      }
+    }
+  }  
+}
+
+static void Extrude_Simplex_Phase2 (void *data , void *dum){
+  
+  Simplex **pS , *s;
+  int i,j,k;
+  Vertex *v1,*v2,*v3,*v4,*v5,*v6;
+
+  pS = (Simplex**)data;
+  s = *pS;
+
+  k = 0;
+  for(i=0;i<NbLayer;i++){
+    for(j=0;j<NbElmLayer[i];j++){
+      List_Read(s->V[0]->Extruded_Points,k,&v1);
+      List_Read(s->V[1]->Extruded_Points,k,&v2);
+      List_Read(s->V[2]->Extruded_Points,k,&v3);
+      List_Read(s->V[0]->Extruded_Points,k+1,&v4);
+      List_Read(s->V[1]->Extruded_Points,k+1,&v5);
+      List_Read(s->V[2]->Extruded_Points,k+1,&v6);
+      k++;
+      if(are_exist(v4,v2,Tree_Ares) && are_exist(v5,v3,Tree_Ares) && are_exist(v1,v6,Tree_Ares)){
+	TEST_IS_ALL_OK++;
+	if(!are_exist(v4,v2,Tree_Swaps)){
+	  are_del(v4,v2,Tree_Ares);
+	  are_cree(v1,v5,Tree_Ares);
+	  are_cree(v1,v5,Tree_Swaps);
+	  are_cree(v4,v2,Tree_Swaps);
+	}
+	else if(!are_exist(v5,v3,Tree_Swaps)){
+	  are_del(v5,v3,Tree_Ares);
+	  are_cree(v2,v6,Tree_Ares);
+	  are_cree(v5,v3,Tree_Swaps);
+	  are_cree(v2,v6,Tree_Swaps);
+	}
+	else if(!are_exist(v1,v6,Tree_Swaps)){
+	  are_del(v1,v6,Tree_Ares);
+	  are_cree(v4,v3,Tree_Ares);
+	  are_cree(v1,v6,Tree_Swaps);
+	  are_cree(v4,v3,Tree_Swaps);
+	}
+      }
+      else if(are_exist(v1,v5,Tree_Ares) && are_exist(v2,v6,Tree_Ares) && are_exist(v4,v3,Tree_Ares)){
+	TEST_IS_ALL_OK++;
+	if(!are_exist(v1,v5,Tree_Swaps)){
+	  are_del(v1,v5,Tree_Ares);
+	  are_cree(v4,v2,Tree_Ares);
+	  are_cree(v1,v5,Tree_Swaps);
+	  are_cree(v4,v2,Tree_Swaps);
+	}
+	else if(!are_exist(v2,v6,Tree_Swaps)){
+	  are_del(v2,v6,Tree_Ares);
+	  are_cree(v5,v3,Tree_Ares);
+	  are_cree(v5,v3,Tree_Swaps);
+	  are_cree(v2,v6,Tree_Swaps);
+	}
+	else if(!are_exist(v4,v3,Tree_Swaps)){
+	  are_del(v4,v3,Tree_Ares);
+	  are_cree(v1,v6,Tree_Ares);
+	  are_cree(v1,v6,Tree_Swaps);
+	  are_cree(v4,v3,Tree_Swaps);
+	}	
+      }
+    }
+  }  
+}
+
+static void Extrude_Vertex (void *data , void *dum){
+
+  Vertex **pV , *v, *newv;
+  int i,j;
+  double h;
+
+  pV = (Vertex**)data;
+  v = *pV;
+  if(v->Extruded_Points)return;
+  v->Extruded_Points = List_Create(NbLayer,1,sizeof(Vertex*));
+  List_Add(v->Extruded_Points,&v);
+  h = 0.0;
+  for(i=0;i<NbLayer;i++){
+    for(j=0;j<NbElmLayer[i];j++){
+      h += hLayer[i]/(double)NbElmLayer[i];
+      newv = Create_Vertex(++CurrentNodeNumber,v->Pos.X,v->Pos.Y,v->Pos.Z + h, v->lc , v->u );
+      Tree_Add(THEM->Vertices,&newv);
+      List_Add(v->Extruded_Points,&newv);
+    }
+  }
+}
+
+
+static void Extrude_Surface1 (void *data , void *dum){
+  Surface **pS , *s;
+  if(!NbLayer)return;
+  pS = (Surface**)data;
+  s = THES = *pS;
+
+  Tree_Action(s->Vertices,Extrude_Vertex);
+  if(!CTX.mesh.oldxtrude_recombine) Tree_Action(s->Simplexes,Extrude_Simplex_Phase1);
+}
+
+static void Extrude_Surface2 (void *data , void *dum){
+  Surface **pS , *s;
+  if(!NbLayer)return;
+  pS = (Surface**)data;
+  s = THES = *pS;
+
+  Tree_Action(s->Simplexes,Extrude_Simplex_Phase2);
+}
+
+
+static void Extrude_Surface3 (void *data , void *dum){
+  Surface **pS , *s;
+  int i;
+  if(!NbLayer)return;
+  pS = (Surface**)data;
+  s = THES = *pS;
+
+  /* Numerotation automatique des entites physiques */
+  printf("Extruding Surface %d \n",s->Num);
+  for(i=0;i<NbLayer;i++){
+    ZonLayer[i] = (int)(3 * 1.e6) + (int) ((i+1) * 1.e3) + s->Num ;
+  }
+  SurfLayer[0] = s->Num ;
+  for(i=0;i<NbLayer;i++){
+    SurfLayer[i+1] = (int)(2 * 1.e6) + (int)((i+1) * 1.e3) + s->Num ;
+  }
+
+  Tree_Action(s->Simplexes,Extrude_Simplex_Phase3);
+}
+
+
+static void Extrude_Seg(Vertex *V1, Vertex *V2){
+
+  int i,j,k;
+  Vertex *v1,*v2,*v3,*v4;
+  Simplex *s;
+
+  k = 0;
+  for(i=0;i<NbLayer;i++){
+    for(j=0;j<NbElmLayer[i];j++){
+      List_Read(V1->Extruded_Points,k,&v1);
+      List_Read(V2->Extruded_Points,k,&v2);
+      List_Read(V1->Extruded_Points,k+1,&v3);
+      List_Read(V2->Extruded_Points,k+1,&v4);
+      if(SurfLayer[i]){
+	if(CTX.mesh.oldxtrude_recombine){
+	  s = Create_Simplex(v1,v2,v4,NULL);
+	  s->V[3] = v3;
+	  s->iEnt = SurfLayer[i];
+	  Tree_Add(THEV->Simp_Surf,&s);
+	}
+	else{
+	  if(are_exist(v3,v2,Tree_Ares)){
+	    s = Create_Simplex(v3,v2,v1,NULL);
+	    s->iEnt = SurfLayer[i];
+	    Tree_Add(THEV->Simp_Surf,&s);
+	    s = Create_Simplex(v3,v4,v2,NULL);
+	    s->iEnt = SurfLayer[i];
+	    Tree_Add(THEV->Simp_Surf,&s);
+	  }
+	  else{
+	    s = Create_Simplex(v3,v4,v1,NULL);
+	    s->iEnt = SurfLayer[i];
+	    Tree_Add(THEV->Simp_Surf,&s);
+	    s = Create_Simplex(v1,v4,v2,NULL);
+	    s->iEnt = SurfLayer[i];
+	    Tree_Add(THEV->Simp_Surf,&s);
+	  }
+	}
+      }
+      k++;
+    }
+  }  
+
+}
+
+static void Extrude_Curve (void *data , void *dum){
+  Curve **pC , *c;
+  Vertex *v1,*v2;
+  int i;
+  if(!NbLayer)return;
+  pC = (Curve**)data;
+  c = *pC;
+  
+  if (c->Num < 0) return;
+
+  /* Numerotation automatique des entites physiques */
+  printf("Extruding Curve %d \n",c->Num);
+  for(i=0;i<NbLayer;i++){
+    SurfLayer[i] = (int)(1 * 1.e6) + (int)((i+1) * 1.e3) + c->Num ;
+  }
+
+  for(i=0;i<List_Nbr(c->Vertices)-1;i++){
+    List_Read(c->Vertices,i,&v1);
+    List_Read(c->Vertices,i+1,&v2);
+    Extrude_Seg(v1,v2);
+  } 
+}
+
+static void Extrude_Pnt(Vertex *V1){
+  int i,j,k;
+  Vertex *v1,*v2;
+  Simplex *s;
+
+  k = 0;
+  for(i=0;i<NbLayer;i++){
+    for(j=0;j<NbElmLayer[i];j++){
+      List_Read(V1->Extruded_Points,k,&v1);
+      List_Read(V1->Extruded_Points,k+1,&v2);
+      if(LineLayer[i]){
+	s = Create_Simplex(v1,v2,NULL,NULL);
+	s->iEnt = LineLayer[i];
+	Tree_Add(THEV->Simp_Surf,&s);
+      }
+      k++;
+    }
+  }  
+  
+}
+
+static void Extrude_Point (void *data , void *dum){
+  Vertex **pV, *v, **pV2;
+  int i;
+
+  if(!NbLayer)return;
+  pV = (Vertex**)data;
+  v = *pV;
+  
+  /* Numerotation automatique des entites physiques */
+  printf("Extruding Vertex %d \n",v->Num);
+  for(i=0;i<NbLayer;i++){
+    LineLayer[i] = (int)(4 * 1.e6) + (int)((i+1) * 1.e3) + v->Num ;
+  }
+
+  if((pV2 = (Vertex**)Tree_PQuery(THEM->Vertices, pV))){
+    Extrude_Vertex(pV2, NULL);
+    Extrude_Pnt(*pV2);
+  }
+
+}
+
+void Extrude_Mesh_Old(Mesh *M){
+  int j;
+  Mesh MM;
+
+  file = fopen("xtrude","w");
+
+  InitExtrudeParams();
+  LOCAL = &MM;
+  THEM  = M;
+
+  Create_BgMesh (WITHPOINTS, .2, LOCAL);
+
+  Tree_Left(M->Volumes,&THEV);
+  Tree_Action(M->Surfaces, Extrude_Surface1);
+
+  if(!CTX.mesh.oldxtrude_recombine){
+    j = TEST_IS_ALL_OK;
+    do{
+      TEST_IS_ALL_OK=0;
+      Tree_Action ( M->Surfaces , Extrude_Surface2 );
+      printf("%d swaps\n",TEST_IS_ALL_OK);
+      if(TEST_IS_ALL_OK == j)break;
+      j = TEST_IS_ALL_OK;
+    }while(TEST_IS_ALL_OK);
+  }
+
+  Tree_Action ( M->Surfaces , Extrude_Surface3 );
+  Tree_Action ( M->Curves , Extrude_Curve );
+  Tree_Action ( M->Points , Extrude_Point );
+
+  fclose(file);
+
+}
+
diff --git a/Mesh/Create.cpp b/Mesh/Create.cpp
index 92f1af057a..ac64a9cfc8 100644
--- a/Mesh/Create.cpp
+++ b/Mesh/Create.cpp
@@ -1,4 +1,4 @@
-// $Id: Create.cpp,v 1.20 2001-06-07 14:20:08 remacle Exp $
+// $Id: Create.cpp,v 1.21 2001-06-25 13:05:16 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "Const.h"
@@ -590,6 +590,7 @@ Volume * Create_Volume (int Num, int Typ, int Mat){
   pV->Vertices = Tree_Create (sizeof (Vertex *), compareVertex);
   pV->Hexahedra = Tree_Create (sizeof (Hexahedron *), compareHexahedron);
   pV->Prisms = Tree_Create (sizeof (Prism *), comparePrism);
+  pV->Simp_Surf = Tree_Create(sizeof(Simplex*),compareSimplex);// for old extrusion mesh generator
   pV->Extrude = NULL;
   pV->Edges = NULL;
   pV->Faces = NULL;
@@ -603,6 +604,7 @@ void Free_Volume(void *a, void *b){
     List_Delete(pV->Surfaces); //surfaces freed elsewhere
     Tree_Action(pV->Simplexes, Free_Simplex);
     Tree_Delete(pV->Simplexes);
+    Tree_Delete(pV->Simp_Surf); // for old extrusion mesh generator
     Tree_Delete(pV->Vertices); //vertices freed elsewhere
     Tree_Action(pV->Hexahedra, Free_Hexahedron);
     Tree_Delete(pV->Hexahedra);
diff --git a/Mesh/Generator.cpp b/Mesh/Generator.cpp
index 89b76d1855..369f1f0193 100644
--- a/Mesh/Generator.cpp
+++ b/Mesh/Generator.cpp
@@ -1,4 +1,4 @@
-// $Id: Generator.cpp,v 1.20 2001-06-07 14:20:08 remacle Exp $
+// $Id: Generator.cpp,v 1.21 2001-06-25 13:05:16 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "Const.h"
@@ -114,7 +114,14 @@ void Maillage_Dimension_3 (Mesh * M){
   }
   List_Delete (list);
   Tree_Insert (M->Volumes, &v);
-  Tree_Action (M->Volumes, Maillage_Volume);
+
+  if(CTX.mesh.oldxtrude){//old automatic extrusion algorithm
+    void Extrude_Mesh_Old(Mesh *M);
+    Extrude_Mesh_Old(M);
+  }
+  else{
+    Tree_Action (M->Volumes, Maillage_Volume);
+  }
 
   t2 = Cpu();
 
diff --git a/Mesh/Makefile b/Mesh/Makefile
index fb0f12a90b..efebe398bd 100644
--- a/Mesh/Makefile
+++ b/Mesh/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.21 2001-05-22 11:34:08 geuzaine Exp $
+# $Id: Makefile,v 1.22 2001-06-25 13:05:16 geuzaine Exp $
 #
 # Makefile for "libMesh.a"
 #
@@ -41,6 +41,7 @@ SRC = 1D_Mesh.cpp \
         3D_SMesh.cpp \
         3D_BGMesh.cpp \
         3D_Extrude.cpp \
+        3D_Extrude_Old.cpp \
         3D_Coherence.cpp \
         3D_Divide.cpp \
         3D_Bricks.cpp \
diff --git a/Mesh/Mesh.h b/Mesh/Mesh.h
index 448fc59635..153f9d6a4b 100644
--- a/Mesh/Mesh.h
+++ b/Mesh/Mesh.h
@@ -262,6 +262,7 @@ typedef struct {
   Tree_T *Edges;
   Tree_T *Faces;
   Tree_T *Simplexes;
+  Tree_T *Simp_Surf;//for old extrusion mesh generator
   Tree_T *Hexahedra;
   Tree_T *Prisms;
 }Volume;
diff --git a/Mesh/Print_Mesh.cpp b/Mesh/Print_Mesh.cpp
index c6b6b07493..64f8296975 100644
--- a/Mesh/Print_Mesh.cpp
+++ b/Mesh/Print_Mesh.cpp
@@ -1,4 +1,4 @@
-// $Id: Print_Mesh.cpp,v 1.21 2001-06-02 16:24:51 geuzaine Exp $
+// $Id: Print_Mesh.cpp,v 1.22 2001-06-25 13:05:16 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "Const.h"
@@ -32,7 +32,8 @@ extern Context_T CTX ;
 
 static FILE *mshfile;
 static int MSH_NODE_NUM;
-static int MSH_VOL_NUM, MSH_ELEMENT_NUM, MSH_ADD;
+static int MSH_VOL_NUM, MSH_SUR_NUM, MSH_LIN_NUM;
+static int MSH_ELEMENT_NUM, MSH_ADD;
 static int MSH_PHYSICAL_NUM, MSH_PHYSICAL_ORI;
 
 void print_msh_node (void *a, void *b){
@@ -85,6 +86,12 @@ void add_msh_simplex (void *a, void *b){
   if (MSH_VOL_NUM && (MSH_VOL_NUM != (*S)->iEnt))
     return;
 
+  if (MSH_SUR_NUM && (MSH_SUR_NUM != (*S)->iEnt))
+    return;
+
+  if (MSH_LIN_NUM && (MSH_LIN_NUM != (*S)->iEnt))
+    return;
+
   if (!MSH_ADD){
     MSH_ELEMENT_NUM++;
     return;
@@ -251,7 +258,7 @@ void add_msh_elements (Mesh * M){
   for (i = 0; i < List_Nbr (M->PhysicalGroups); i++){
     List_Read (M->PhysicalGroups, i, &p);
     MSH_PHYSICAL_NUM = p->Num;
-    MSH_VOL_NUM = 0;
+    MSH_VOL_NUM = MSH_SUR_NUM = MSH_LIN_NUM = 0;
 
     switch (p->Typ){
 
@@ -267,28 +274,53 @@ void add_msh_elements (Mesh * M){
       break;
 
     case MSH_PHYSICAL_LINE:
+      if(CTX.mesh.oldxtrude){//for old extrusion mesh generator
+	for (k = 0; k < List_Nbr (ListVolumes); k++){
+	  List_Read (ListVolumes, k, &pV);
+	  for (j = 0; j < List_Nbr (p->Entities); j++){
+	    List_Read (p->Entities, j, &Num);
+	    MSH_LIN_NUM = abs (Num);
+	    MSH_PHYSICAL_ORI = sign (Num);
+	    Tree_Action (pV->Simp_Surf, add_msh_simplex);
+	  }
+	}
+	break;//done
+      }
+      
       for (j = 0; j < List_Nbr (p->Entities); j++){
-        pc = &c;
-        List_Read (p->Entities, j, &Num);
-        pc->Num = abs (Num);
-        MSH_PHYSICAL_ORI = sign (Num);
-        if (Tree_Query (M->Curves, &pc))
-          Tree_Action (pc->Simplexes, add_msh_simplex);
+	pc = &c;
+	List_Read (p->Entities, j, &Num);
+	pc->Num = abs (Num);
+	MSH_PHYSICAL_ORI = sign (Num);
+	if (Tree_Query (M->Curves, &pc))
+	  Tree_Action (pc->Simplexes, add_msh_simplex);
       }
       break;
-
+      
     case MSH_PHYSICAL_SURFACE:
-      for (j = 0; j < List_Nbr (p->Entities); j++){
-        ps = &s;
-        List_Read (p->Entities, j, &Num);
-        ps->Num = abs (Num);
-        MSH_PHYSICAL_ORI = sign (Num);
-        if (Tree_Query (M->Surfaces, &ps)){
-          Tree_Action (ps->Simplexes, add_msh_simplex);
+      if(CTX.mesh.oldxtrude){//for old extrusion mesh generator
+	for (k = 0; k < List_Nbr (ListVolumes); k++){
+	  List_Read (ListVolumes, k, &pV);
+	  for (j = 0; j < List_Nbr (p->Entities); j++){
+	    List_Read (p->Entities, j, &Num);
+	    MSH_SUR_NUM = abs (Num);
+	    MSH_PHYSICAL_ORI = sign (Num);
+	    Tree_Action (pV->Simp_Surf, add_msh_simplex);
+	  }
 	}
+	break;//done
+      }
+      
+      for (j = 0; j < List_Nbr (p->Entities); j++){
+	ps = &s;
+	List_Read (p->Entities, j, &Num);
+	ps->Num = abs (Num);
+	MSH_PHYSICAL_ORI = sign (Num);
+	if (Tree_Query (M->Surfaces, &ps))
+	  Tree_Action (ps->Simplexes, add_msh_simplex);
       }
       break;
-
+      
     case MSH_PHYSICAL_VOLUME:
       for (k = 0; k < List_Nbr (ListVolumes); k++){
         List_Read (ListVolumes, k, &pV);
-- 
GitLab