From 41d2f401526d437f4204bf0a3e58ae80513842f0 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 1 Apr 2008 12:47:10 +0000
Subject: [PATCH] - replaced "Mesh.ContrainedBackgroundMesh" by
 "Mesh.CharacteristicLengthFromPoints" and  
 "Mesh.CharacteristicLengthExtendFromBoundary"

- fixed MED IO when numComp > 9
---
 Common/CommandLine.cpp     |  7 +----
 Common/Context.h           |  4 +--
 Common/DefaultOptions.h    | 12 +++++----
 Common/Options.cpp         | 45 ++++++++++++++++++--------------
 Common/Options.h           |  5 ++--
 Fltk/Callbacks.cpp         |  4 +--
 Fltk/GUI.cpp               | 10 +++----
 Graphics/Post.cpp          |  4 +--
 Mesh/BackgroundMesh.cpp    | 53 +++++++++++++++++++-------------------
 Mesh/meshGFaceBDS.cpp      |  4 +--
 Post/PViewDataGModelIO.cpp | 11 +++++---
 11 files changed, 83 insertions(+), 76 deletions(-)

diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp
index 9e2e1c1f9f..c07a85098f 100644
--- a/Common/CommandLine.cpp
+++ b/Common/CommandLine.cpp
@@ -1,4 +1,4 @@
-// $Id: CommandLine.cpp,v 1.126 2008-03-26 09:37:49 remacle Exp $
+// $Id: CommandLine.cpp,v 1.127 2008-04-01 12:47:09 geuzaine Exp $
 //
 // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
 //
@@ -96,7 +96,6 @@ void Print_Usage(const char *name)
   Msg(DIRECT, "                          below which a swap is allowed");
   Msg(DIRECT, "  -rand float           Set random perturbation factor");
   Msg(DIRECT, "  -bgm file             Load background mesh from file");
-  Msg(DIRECT, "  -constrain            Constrain background mesh with characteristic lengths");
 #if defined(HAVE_FLTK)
   Msg(DIRECT, "Post-processing options:");
   Msg(DIRECT, "  -noview               Hide all views on startup");
@@ -290,10 +289,6 @@ void Get_Options(int argc, char *argv[])
           exit(1);
         }
       }
-      else if(!strcmp(argv[i] + 1, "constrain")) {
-        CTX.mesh.constrained_bgmesh = 1;
-        i++;
-      }
       else if(!strcmp(argv[i] + 1, "convert")) {
         i++;
         CTX.terminal = 1;
diff --git a/Common/Context.h b/Common/Context.h
index 95ae3fb68e..0ccd53443d 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -167,14 +167,14 @@ class Context_T {
     int optimize, optimize_netgen, refine_steps;
     int quality_type, label_type;
     double quality_inf, quality_sup, radius_inf, radius_sup;
-    double scaling_factor, lc_factor, rand_factor, lc_integration_precision,lc_min,lc_max;
+    double scaling_factor, lc_factor, rand_factor, lc_integration_precision, lc_min, lc_max;
+    int lc_from_points, lc_from_curvature, lc_extend_from_boundary;
     int dual, draw_skin_only;
     int light, light_two_side, light_lines;
     int format, nb_smoothing, algo2d, algo3d, algo_recombine;
     int order, second_order_linear, second_order_incomplete;
     int smooth_internal_edges, c1_continuity;
     int min_circ_points, min_curv_points;
-    int constrained_bgmesh, lc_from_curvature;
     double normals, tangents, explode;
     int color_carousel;
     int use_cut_plane, cut_plane_draw_intersect, cut_plane_only_volume;
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index f2b936ed1c..b57189ae0f 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -911,18 +911,20 @@ StringXNumber MeshOptions_Number[] = {
 
   { F|O, "C1Continuity" , opt_mesh_c1 , 0. ,
     "Impose C1 continuity to high order meshes (only valid in 2D plane and ElemenOrder = 2)" },
+  { F|O, "CharacteristicLengthExtendFromBoundary" , opt_mesh_lc_extend_from_boundary, 1. ,
+    "Extend characteristic lengths from the boundaries inside the surface/volume" },
   { F|O, "CharacteristicLengthFactor" , opt_mesh_lc_factor , 1.0 ,
     "Factor applied to all characteristic lengths" },
   { F|O, "CharacteristicLengthMin" , opt_mesh_lc_min, 0.0 ,
-    "Minimum mesh size" },
+    "Minimum characteristic length" },
   { F|O, "CharacteristicLengthMax" , opt_mesh_lc_max, 1.e22 ,
-    "Maximum mesh size" },
+    "Maximum characteristic length" },
   { F|O, "CharacteristicLengthFromCurvature" , opt_mesh_lc_from_curvature , 0. ,
-    "Compute characteritic lenghts automatically from curvatures" },
+    "Compute characteristic lengths from curvature" },
+  { F|O, "CharacteristicLengthFromPoints" , opt_mesh_lc_from_points , 1. ,
+    "Compute characteristic lengths from values given at geometry points" },
   { F|O, "ColorCarousel" , opt_mesh_color_carousel , 1. ,
     "Mesh coloring (0=by element type, 1=by elementary entity, 2=by physical entity, 3=by partition)" },
-  { F|O, "ConstrainedBackgroundMesh" , opt_mesh_constrained_bgmesh, 0. ,
-    "Should the background mesh be constrained by the characteristic lengths associated with the geometry?" },
   { F,   "CpuTime" , opt_mesh_cpu_time , 0. , 
     "CPU time (in seconds) for the generation of the current mesh (read-only)" },
   { F,   "CutPlane" , opt_mesh_use_cut_plane , 0 ,
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 0523456f85..6437ee5b59 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.389 2008-03-20 11:44:02 geuzaine Exp $
+// $Id: Options.cpp,v 1.390 2008-04-01 12:47:10 geuzaine Exp $
 //
 // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
 //
@@ -4362,6 +4362,31 @@ double opt_mesh_lc_from_curvature(OPT_ARGS_NUM)
   return CTX.mesh.lc_from_curvature;
 }
 
+double opt_mesh_lc_from_points(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET)
+    CTX.mesh.lc_from_points = (int)val;
+#if defined(HAVE_FLTK)
+  if(WID && (action & GMSH_GUI))
+    WID->mesh_butt[5]->value(CTX.mesh.lc_from_points);
+#endif
+  return CTX.mesh.lc_from_points;
+}
+
+double opt_mesh_lc_extend_from_boundary(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET)
+    CTX.mesh.lc_extend_from_boundary = val;
+  return CTX.mesh.lc_extend_from_boundary;
+}
+
+double opt_mesh_lc_integration_precision(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET)
+    CTX.mesh.lc_integration_precision = val;
+  return CTX.mesh.lc_integration_precision;
+}
+
 double opt_mesh_rand_factor(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET)
@@ -4871,13 +4896,6 @@ double opt_mesh_nb_smoothing(OPT_ARGS_NUM)
   return CTX.mesh.nb_smoothing;
 }
 
-double opt_mesh_lc_integration_precision(OPT_ARGS_NUM)
-{
-  if(action & GMSH_SET)
-    CTX.mesh.lc_integration_precision = val;
-  return CTX.mesh.lc_integration_precision;
-}
-
 double opt_mesh_algo2d(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET){
@@ -4961,17 +4979,6 @@ double opt_mesh_min_curv_points(OPT_ARGS_NUM)
   return CTX.mesh.min_curv_points;
 }
 
-double opt_mesh_constrained_bgmesh(OPT_ARGS_NUM)
-{
-  if(action & GMSH_SET)
-    CTX.mesh.constrained_bgmesh = (int)val;
-#if defined(HAVE_FLTK)
-  if(WID && (action & GMSH_GUI))
-    WID->mesh_butt[5]->value(CTX.mesh.constrained_bgmesh);
-#endif
-  return CTX.mesh.constrained_bgmesh;
-}
-
 double opt_mesh_order(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET)
diff --git a/Common/Options.h b/Common/Options.h
index b9e499fc26..05aaa1c8a2 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -441,6 +441,9 @@ double opt_mesh_lc_min(OPT_ARGS_NUM);
 double opt_mesh_lc_max(OPT_ARGS_NUM);
 double opt_mesh_lc_factor(OPT_ARGS_NUM);
 double opt_mesh_lc_from_curvature(OPT_ARGS_NUM);
+double opt_mesh_lc_from_points(OPT_ARGS_NUM);
+double opt_mesh_lc_extend_from_boundary(OPT_ARGS_NUM);
+double opt_mesh_lc_integration_precision(OPT_ARGS_NUM);
 double opt_mesh_rand_factor(OPT_ARGS_NUM);
 double opt_mesh_quality_inf(OPT_ARGS_NUM);
 double opt_mesh_quality_sup(OPT_ARGS_NUM);
@@ -481,12 +484,10 @@ double opt_mesh_bdf_field_format(OPT_ARGS_NUM);
 double opt_mesh_nb_smoothing(OPT_ARGS_NUM);
 double opt_mesh_algo2d(OPT_ARGS_NUM);
 double opt_mesh_algo3d(OPT_ARGS_NUM);
-double opt_mesh_lc_integration_precision(OPT_ARGS_NUM);
 double opt_mesh_recombine_algo(OPT_ARGS_NUM);
 double opt_mesh_min_circ_points(OPT_ARGS_NUM);
 double opt_mesh_allow_swap_edge_angle(OPT_ARGS_NUM);
 double opt_mesh_min_curv_points(OPT_ARGS_NUM);
-double opt_mesh_constrained_bgmesh(OPT_ARGS_NUM);
 double opt_mesh_order(OPT_ARGS_NUM);
 double opt_mesh_c1(OPT_ARGS_NUM);
 double opt_mesh_smooth_internal_edges(OPT_ARGS_NUM);
diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index 286eb8cea9..36895499d6 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.576 2008-03-29 10:19:35 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.577 2008-04-01 12:47:10 geuzaine Exp $
 //
 // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
 //
@@ -1105,13 +1105,13 @@ void mesh_options_ok_cb(CALLBACK_ARGS)
 
   opt_mesh_reverse_all_normals(0, GMSH_SET, WID->mesh_butt[0]->value());
   opt_mesh_lc_from_curvature(0, GMSH_SET, WID->mesh_butt[1]->value());
+  opt_mesh_lc_from_points(0, GMSH_SET, WID->mesh_butt[5]->value());
   opt_mesh_optimize(0, GMSH_SET, WID->mesh_butt[2]->value());
   opt_mesh_optimize_netgen(0, GMSH_SET, WID->mesh_butt[24]->value());
   opt_mesh_order(0, GMSH_SET, WID->mesh_value[3]->value());
   opt_mesh_smooth_internal_edges(0, GMSH_SET, WID->mesh_butt[3]->value());
   opt_mesh_second_order_incomplete(0, GMSH_SET, WID->mesh_butt[4]->value());
   opt_mesh_c1(0, GMSH_SET, WID->mesh_butt[21]->value());
-  opt_mesh_constrained_bgmesh(0, GMSH_SET, WID->mesh_butt[5]->value());
   opt_mesh_points(0, GMSH_SET, WID->mesh_butt[6]->value());
   opt_mesh_lines(0, GMSH_SET, WID->mesh_butt[7]->value());
   opt_mesh_triangles(0, GMSH_SET, WID->mesh_menu_butt->menu()[0].value() ? 1 : 0);
diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index 956160d5e2..81288a109d 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -1,4 +1,4 @@
-// $Id: GUI.cpp,v 1.671 2008-03-29 22:58:45 geuzaine Exp $
+// $Id: GUI.cpp,v 1.672 2008-04-01 12:47:10 geuzaine Exp $
 //
 // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
 //
@@ -2455,11 +2455,11 @@ void GUI::create_option_window()
       mesh_value[2]->align(FL_ALIGN_RIGHT);
       mesh_value[2]->callback(mesh_options_ok_cb);
 
-      mesh_value[25] = new Fl_Value_Input(L + 2 * WB, 2 * WB + 6 * BH, IW, BH, "Minimum mesh size");
+      mesh_value[25] = new Fl_Value_Input(L + 2 * WB, 2 * WB + 6 * BH, IW, BH, "Minimum characteristic length");
       mesh_value[25]->align(FL_ALIGN_RIGHT);
       mesh_value[25]->callback(mesh_options_ok_cb);
 
-      mesh_value[26] = new Fl_Value_Input(L + 2 * WB, 2 * WB + 7 * BH, IW, BH, "Maximum mesh size");
+      mesh_value[26] = new Fl_Value_Input(L + 2 * WB, 2 * WB + 7 * BH, IW, BH, "Maximum characteristic length");
       mesh_value[26]->align(FL_ALIGN_RIGHT);
       mesh_value[26]->callback(mesh_options_ok_cb);
 
@@ -2483,11 +2483,11 @@ void GUI::create_option_window()
       Fl_Group *o = new Fl_Group(L + WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Advanced");
       o->hide();
 
-      mesh_butt[1] = new Fl_Check_Button(L + 2 * WB, 2 * WB + 1 * BH, BW, BH, "Compute characteritic lengths from curvatures" );
+      mesh_butt[1] = new Fl_Check_Button(L + 2 * WB, 2 * WB + 1 * BH, BW, BH, "Compute characteristic lengths from curvature" );
       mesh_butt[1]->type(FL_TOGGLE_BUTTON);
       mesh_butt[1]->callback(mesh_options_ok_cb);
 
-      mesh_butt[5] = new Fl_Check_Button(L + 2 * WB, 2 * WB + 2 * BH, BW, BH, "Constrain background mesh with other length fields");
+      mesh_butt[5] = new Fl_Check_Button(L + 2 * WB, 2 * WB + 2 * BH, BW, BH, "Compute characteristic lengths from values at points");
       mesh_butt[5]->type(FL_TOGGLE_BUTTON);
       mesh_butt[5]->callback(mesh_options_ok_cb);
 
diff --git a/Graphics/Post.cpp b/Graphics/Post.cpp
index e168246e9f..14a37d448e 100644
--- a/Graphics/Post.cpp
+++ b/Graphics/Post.cpp
@@ -1,4 +1,4 @@
-// $Id: Post.cpp,v 1.161 2008-03-31 16:04:41 geuzaine Exp $
+// $Id: Post.cpp,v 1.162 2008-04-01 12:47:10 geuzaine Exp $
 //
 // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
 //
@@ -910,7 +910,7 @@ void addElementsInArrays(PView *p, bool preprocessNormalsOnly)
       for(int j = 0; j < numNodes; j++)
         opt->TmpBBox += SPoint3(xyz[j][0], xyz[j][1], xyz[j][2]);
       
-      if(opt->ShowElement) 
+      if(opt->ShowElement && !data->useGaussPoints()) 
         addOutlineElement(p, numEdges, xyz, preprocessNormalsOnly);
       
       if(opt->IntervalsType != PViewOptions::Numeric){
diff --git a/Mesh/BackgroundMesh.cpp b/Mesh/BackgroundMesh.cpp
index a7b8c4f199..8d087366ba 100644
--- a/Mesh/BackgroundMesh.cpp
+++ b/Mesh/BackgroundMesh.cpp
@@ -1,4 +1,4 @@
-// $Id: BackgroundMesh.cpp,v 1.48 2008-03-28 22:18:48 remacle Exp $
+// $Id: BackgroundMesh.cpp,v 1.49 2008-04-01 12:47:10 geuzaine Exp $
 //
 // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
 //
@@ -151,48 +151,47 @@ static double LC_MVertex_PNTS(GEntity *ge, double U, double V)
 // This is the only function that is used by the meshers
 double BGM_MeshSize(GEntity *ge, double U, double V, double X, double Y, double Z)
 {
+  // default lc (mesh size == size of the domain)
   double l1 = CTX.lc;
+
+  // lc from points
   double l2 = MAX_LC;
+  if(CTX.mesh.lc_from_points && ge->dim() < 2) 
+    l2 = LC_MVertex_PNTS(ge, U, V);
+
+  // lc from curvature
   double l3 = MAX_LC;
-  double lc;
+  if(CTX.mesh.lc_from_curvature && ge->dim() < 3)
+    l3 = LC_MVertex_CURV(ge, U, V);
 
+  // lc from fields
+  double l4 = MAX_LC;
   FieldManager &fields = *GModel::current()->getFields();
   if(fields.background_field > 0){
     Field *f = fields.get(fields.background_field);
-    if(f) l3 = (*f)(X, Y, Z);
-  }
-  
-  if(l3 < MAX_LC && !CTX.mesh.constrained_bgmesh){
-    // use the fields unconstrained by other characteristic lengths
-    lc = l3 * CTX.mesh.lc_factor;
-  }
-  else{
-    if(ge->dim() < 2) 
-      l2 = LC_MVertex_PNTS(ge, U, V);
-    lc = std::min(std::min(l1, l2), l3) * CTX.mesh.lc_factor;
-    if(CTX.mesh.lc_from_curvature && ge->dim() <= 2)
-      lc = std::min(lc, LC_MVertex_CURV(ge, U, V));
+    if(f) l4 = (*f)(X, Y, Z);
   }
 
-  lc = std::max(lc, CTX.mesh.lc_min * CTX.mesh.lc_factor);
-  lc = std::min(lc, CTX.mesh.lc_max * CTX.mesh.lc_factor);
+  // take the minimum, then contrain by lc_min and lc_max
+  double lc = std::min(std::min(std::min(l1, l2), l3), l4);
+  lc = std::max(lc, CTX.mesh.lc_min);
+  lc = std::min(lc, CTX.mesh.lc_max);
 
   if(lc <= 0.){
-    Msg(GERROR, "Incorrect char. length lc = %g: using default instead", lc);
-    return l1 * CTX.mesh.lc_factor;
+    Msg(GERROR, "Wrong characteristic length lc = %g", lc);
+    lc = l1;
   }
-  
-  return lc;
+
+  return lc * CTX.mesh.lc_factor;
 }
 
-// We extend the 1d mesh in surfaces if no background mesh exists (in
-// this case, it is the only way to have something smooth). We do it
-// also if CTX.mesh.constrained_bgmesh is true;
 bool Extend1dMeshIn2dSurfaces()
 {
-  if(GModel::current()->getFields()->background_field!=-1)return false;
-  if(CTX.mesh.constrained_bgmesh) return true;
-  return true;
+  // never extend the 1d mesh in surfaces if there is a background
+  // field
+  if(GModel::current()->getFields()->background_field != -1) return false;
+
+  return CTX.mesh.lc_extend_from_boundary ? true : false;
 }
 
 bool Extend2dMeshIn3dVolumes()
diff --git a/Mesh/meshGFaceBDS.cpp b/Mesh/meshGFaceBDS.cpp
index 603bd9afa7..4b235f2421 100644
--- a/Mesh/meshGFaceBDS.cpp
+++ b/Mesh/meshGFaceBDS.cpp
@@ -1,4 +1,4 @@
-// $Id: meshGFaceBDS.cpp,v 1.11 2008-03-29 21:36:30 geuzaine Exp $
+// $Id: meshGFaceBDS.cpp,v 1.12 2008-04-01 12:47:10 geuzaine Exp $
 //
 // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
 //
@@ -551,7 +551,7 @@ void gmshRefineMeshBDS(GFace *gf, BDS_Mesh &m, const int NIT,
         ++it;
       }
       if (!ne) L = 1.e22;
-      if(!CTX.mesh.constrained_bgmesh)
+      if(CTX.mesh.lc_from_points)
         (*itp)->lc() = L;
       (*itp)->lcBGM() = L;
       ++itp;
diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp
index df76dee838..cec828a50f 100644
--- a/Post/PViewDataGModelIO.cpp
+++ b/Post/PViewDataGModelIO.cpp
@@ -1,4 +1,4 @@
-// $Id: PViewDataGModelIO.cpp,v 1.31 2008-03-31 21:17:37 geuzaine Exp $
+// $Id: PViewDataGModelIO.cpp,v 1.32 2008-04-01 12:47:10 geuzaine Exp $
 //
 // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
 //
@@ -175,7 +175,10 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex)
   Msg(INFO, "Reading %d-component field <<%s>>", numComp, name);
   setName(name);
 
-  int numCompMsh = (numComp == 1) ? 1 : (numComp < 3) ? 3 : 9;
+  int numCompMsh = 
+    (numComp <= 1) ? 1 : (numComp <= 3) ? 3 : (numComp <= 9) ? 9 : numComp;
+
+  if(numCompMsh > 9) Msg(WARNING, "More than 9 components in field");
 
   // the ordering of the elements in the following lists is important:
   // it should match the ordering of the MSH element types (when
@@ -259,7 +262,7 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex)
 	mult = ngauss;
 	setType(GaussPointData);
       }
-      
+
       // only a guess, since several element types may be combined
       _steps[step]->resizeData(numVal / mult);
 
@@ -275,7 +278,7 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex)
 
       // read Gauss point data (if locname is MED_GAUSS_ELNO, the
       // points are the element vertices)
-      if(ngauss != MED_NOPG && std::string(locname) != MED_GAUSS_ELNO){
+      if(_type == GaussPointData && std::string(locname) != MED_GAUSS_ELNO){
 	std::vector<med_float> refcoo((ele % 100) * (ele / 100));
 	std::vector<med_float> gscoo(ngauss * ele / 100);
 	std::vector<med_float> wg(ngauss);
-- 
GitLab