From 776403675bdf8de365bb9a328f0b5318a71584cb Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Fri, 21 Nov 2008 10:28:33 +0000
Subject: [PATCH] fix -part + Refine->RefineMesh

---
 Common/CommandLine.cpp | 30 +++++++++++++++---------------
 Common/Context.h       |  5 +++--
 Common/Gmsh.cpp        | 26 +++++++++++++++-----------
 Common/Options.cpp     |  2 +-
 Fltk/Callbacks.cpp     |  8 ++++----
 Fltk/GUI.cpp           |  2 +-
 Mesh/Generator.h       |  1 +
 Mesh/HighOrder.h       |  1 -
 Mesh/Refine.cpp        |  2 +-
 Numeric/Makefile       | 10 +++++-----
 10 files changed, 46 insertions(+), 41 deletions(-)

diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp
index 581fa46929..7c61c3bbdb 100644
--- a/Common/CommandLine.cpp
+++ b/Common/CommandLine.cpp
@@ -172,7 +172,15 @@ void Get_Options(int argc, char *argv[])
 
     if(argv[i][0] == '-') {
 
-      if(!strcmp(argv[i] + 1, "")) {
+      if(!strcmp(argv[i] + 1, "socket")) {
+        i++;        
+        if(argv[i] != NULL)
+          CTX.solver.socket_name = argv[i++];
+        else
+	  Msg::Fatal("Missing string");
+        CTX.batch = -3;
+      }
+      else if(!strcmp(argv[i] + 1, "")) {
         CTX.batch = -2;
         i++;
       }
@@ -196,24 +204,16 @@ void Get_Options(int argc, char *argv[])
         CTX.batch = 4;
         i++;
       }
-      else if(!strcmp(argv[i] + 1, "new")) {
-        CTX.files.push_back("-new");
-        i++;
-      }
-      else if(!strcmp(argv[i] + 1, "socket")) {
-        i++;        
-        if(argv[i] != NULL)
-          CTX.solver.socket_name = argv[i++];
-        else
-	  Msg::Fatal("Missing string");
-        CTX.batch = 5;
-      }
       else if(!strcmp(argv[i] + 1, "refine")) {
-        CTX.batch = 6;
+        CTX.batch = 5;
         i++;
       }
       else if(!strcmp(argv[i] + 1, "part")) {
-        CTX.batch = 7;
+        CTX.batch_after_mesh = 1;
+        i++;
+      }
+      else if(!strcmp(argv[i] + 1, "new")) {
+        CTX.files.push_back("-new");
         i++;
       }
       else if(!strcmp(argv[i] + 1, "pid")) {
diff --git a/Common/Context.h b/Common/Context.h
index 2a8af88c06..b9b71aa800 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -64,8 +64,9 @@ class Context_T {
   int field_size[2]; // size of the field window on the screen
   int file_chooser_position[2]; // position of the file chooser window on the screen
   int system_menu_bar; // use the system menu bar on MacOS?
-  int batch; // 0=full gfx; -1=write geo; -2=check coherence; 1,2,3=batch mesh; 
-             // 4=adapt; 5=server daemon; 6=refine; 7=partition
+  int batch; // -3=server daemon; -2=check coherence; -1=write geo; 0=full gfx;
+             // 1=1D mesh; 2=2D mesh; 3=3D mesh; 4=adapt mesh; 5=refine mesh;
+  int batch_after_mesh; // 1=partition mesh
   int initial_context; // 0=automatic; 1=geom; 2=mesh; 3=solver; 4=post 
   int nopopup; // never popup dialogs in scripts (use default values instead)
   int non_modal_windows; // make all windows "non modal"
diff --git a/Common/Gmsh.cpp b/Common/Gmsh.cpp
index 2035233997..83c11bf6cc 100644
--- a/Common/Gmsh.cpp
+++ b/Common/Gmsh.cpp
@@ -101,24 +101,28 @@ int GmshBatch()
   }
 #endif
 
-  if(CTX.batch == 5)
+  if(CTX.batch == -3){
     GmshDaemon(CTX.solver.socket_name);
-  else if(CTX.batch == 4) {
-    AdaptMesh(GModel::current());
-    CreateOutputFile(CTX.output_filename, CTX.mesh.format);
   }
-  else if(CTX.batch > 0) {
-    GModel::current()->mesh(CTX.batch);
+  else if(CTX.batch == -2){
+    GModel::current()->checkMeshCoherence(CTX.geom.tolerance);
+  }
+  else if(CTX.batch == -1){
+    CreateOutputFile(CTX.output_filename, FORMAT_GEO);
+  }
+  else if(CTX.batch > 0){
+    if(CTX.batch < 4)
+      GModel::current()->mesh(CTX.batch);
+    else if(CTX.batch == 4)
+      AdaptMesh(GModel::current());
+    else if(CTX.batch == 5)
+      RefineMesh(GModel::current());
 #if defined(HAVE_CHACO) || defined(HAVE_METIS)
-    if(CTX.batch == 7)
+    if(CTX.batch_after_mesh == 1)
       PartitionMesh(GModel::current(), CTX.mesh.partition_options);
 #endif
     CreateOutputFile(CTX.output_filename, CTX.mesh.format);
   }
-  else if(CTX.batch == -1)
-    CreateOutputFile(CTX.output_filename, FORMAT_GEO);
-  else if(CTX.batch == -2)
-    GModel::current()->checkMeshCoherence(CTX.geom.tolerance);
 
   return 1;
 }
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 069c909f1e..ccf8dbb8a1 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -456,7 +456,7 @@ void Init_Options(int num)
   Init_Options_Safe(num);
 
   // The following defaults cannot be set by the user 
-  CTX.batch = 0;
+  CTX.batch = CTX.batch_after_mesh = 0;
   CTX.output_filename = NULL;
   CTX.bgm_filename = NULL;
   CTX.lc = 1.0;
diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index 722009cf37..858e64c002 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -3830,10 +3830,10 @@ void mesh_optimize_cb(CALLBACK_ARGS)
 
 void mesh_refine_cb(CALLBACK_ARGS)
 {
-	Refine(GModel::current(), CTX.mesh.second_order_linear);
-	CTX.mesh.changed |= (ENT_LINE | ENT_SURFACE | ENT_VOLUME);
-	Draw();
-	Msg::StatusBar(2, false, " ");
+  RefineMesh(GModel::current(), CTX.mesh.second_order_linear);
+  CTX.mesh.changed |= (ENT_LINE | ENT_SURFACE | ENT_VOLUME);
+  Draw();
+  Msg::StatusBar(2, false, " ");
 }
 
 void mesh_optimize_netgen_cb(CALLBACK_ARGS)
diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index 8e7f766535..fa715c6135 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -315,7 +315,7 @@ Context_Item menu_mesh[] = {
 #if defined(HAVE_FOURIER_MODEL)
   {"Reparameterize",   (Fl_Callback *)mesh_parameterize_cb} , 
 #endif
-  {"Reclassify",   (Fl_Callback *)mesh_classify_cb} , 
+  //  {"Reclassify",   (Fl_Callback *)mesh_classify_cb} , 
   {"Save",         (Fl_Callback *)mesh_save_cb} ,
   {0} 
 };  
diff --git a/Mesh/Generator.h b/Mesh/Generator.h
index bef74f51ad..182b7032d8 100644
--- a/Mesh/Generator.h
+++ b/Mesh/Generator.h
@@ -13,5 +13,6 @@ void AdaptMesh(GModel *m);
 void GenerateMesh(GModel *m, int dimension);
 void OptimizeMesh(GModel *m);
 void OptimizeMeshNetgen(GModel *m);
+void RefineMesh(GModel *m, bool linear=true);
 
 #endif
diff --git a/Mesh/HighOrder.h b/Mesh/HighOrder.h
index 54a9592f19..9bd6778804 100644
--- a/Mesh/HighOrder.h
+++ b/Mesh/HighOrder.h
@@ -22,6 +22,5 @@ typedef std::map<MFace, std::vector<MVertex*>, Less_Face> faceContainer;
 
 void SetOrder1(GModel *m);
 void SetOrderN(GModel *m, int order, bool linear=true, bool incomplete=false);
-void Refine(GModel *m, bool linear=true);
 
 #endif
diff --git a/Mesh/Refine.cpp b/Mesh/Refine.cpp
index 54228cea61..23cca401aa 100644
--- a/Mesh/Refine.cpp
+++ b/Mesh/Refine.cpp
@@ -214,7 +214,7 @@ static void Subdivide(GRegion *gr)
   gr->deleteVertexArrays();
 }
 
-void Refine(GModel *m, bool linear)
+void RefineMesh(GModel *m, bool linear)
 {
   Msg::StatusBar(1, true, "Generating refined mesh ...");
   double t1 = Cpu();
diff --git a/Numeric/Makefile b/Numeric/Makefile
index d7feb8c59c..bf6789622b 100644
--- a/Numeric/Makefile
+++ b/Numeric/Makefile
@@ -56,10 +56,9 @@ NumericEmbedded.o: NumericEmbedded.cpp NumericEmbedded.h \
   ../Common/GmshMessage.h
 gmshAssembler.o: gmshAssembler.cpp ../Geo/MVertex.h ../Geo/SPoint2.h \
   ../Geo/SPoint3.h gmshAssembler.h gmshLinearSystem.h
-gmshTermOfFormulation.o: gmshTermOfFormulation.cpp \
-  gmshTermOfFormulation.h ../Common/GmshMatrix.h gmshFunction.h \
-  ../Common/Gmsh.h ../Common/GmshMessage.h ../Geo/GModel.h \
-  ../Geo/GVertex.h ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
+gmshTermOfFormulation.o: gmshTermOfFormulation.cpp ../Common/Gmsh.h \
+  ../Common/GmshMessage.h ../Geo/GModel.h ../Geo/GVertex.h \
+  ../Geo/GEntity.h ../Geo/Range.h ../Geo/SPoint3.h \
   ../Geo/SBoundingBox3d.h ../Geo/SPoint3.h ../Geo/GPoint.h \
   ../Geo/SPoint2.h ../Geo/GEdge.h ../Geo/GEntity.h ../Geo/GVertex.h \
   ../Geo/SVector3.h ../Geo/SPoint3.h ../Geo/SPoint3.h ../Geo/SPoint2.h \
@@ -69,7 +68,8 @@ gmshTermOfFormulation.o: gmshTermOfFormulation.cpp \
   ../Geo/SBoundingBox3d.h ../Geo/MElement.h ../Common/GmshDefines.h \
   ../Geo/MVertex.h ../Geo/SPoint2.h ../Geo/SPoint3.h ../Geo/MEdge.h \
   ../Geo/MVertex.h ../Geo/SVector3.h ../Geo/MFace.h ../Geo/MVertex.h \
-  ../Geo/SVector3.h ../Numeric/FunctionSpace.h gmshLinearSystem.h \
+  ../Geo/SVector3.h ../Numeric/FunctionSpace.h ../Common/GmshMatrix.h \
+  gmshTermOfFormulation.h gmshFunction.h gmshLinearSystem.h \
   gmshAssembler.h
 gmshLaplace.o: gmshLaplace.cpp gmshLaplace.h gmshTermOfFormulation.h \
   ../Common/GmshMatrix.h ../Common/Gmsh.h ../Common/GmshMessage.h \
-- 
GitLab