From 4da6476e7ced82529945c44173b6706de88cd178 Mon Sep 17 00:00:00 2001
From: Emilie Marchandise <emilie.marchandise@uclouvain.be>
Date: Tue, 6 Dec 2011 16:00:04 +0000
Subject: [PATCH] improved adaptMesh in 2D with bamg

---
 Geo/GModel.cpp         | 21 +++++++++++++--------
 Mesh/meshGFace.cpp     |  5 ++++-
 Mesh/meshGFaceBamg.cpp | 10 +++++-----
 Mesh/meshMetric.cpp    |  2 +-
 4 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp
index c917d75e71..97a0d34f74 100644
--- a/Geo/GModel.cpp
+++ b/Geo/GModel.cpp
@@ -33,6 +33,7 @@
 #include "MVertexPositionSet.h"
 #include "OpenFile.h"
 #include "CreateFile.h"
+#include "Options.h"
 
 #if defined(HAVE_MESH)
 #include "Field.h"
@@ -518,10 +519,10 @@ int GModel::mesh(int dimension)
 int GModel::adaptMesh(int technique, simpleFunction<double> *f, std::vector<double> parameters)
 {
 #if defined(HAVE_MESH)
-  mesh(getDim());
-  meshMetric *mm; 
 
-  
+  if (getNumMeshElements() == 0) mesh(getDim());
+  meshMetric *mm; 
+ 
   int ITER = 0;
   while(1){
     std::vector<MElement*> elements;
@@ -565,23 +566,27 @@ int GModel::adaptMesh(int technique, simpleFunction<double> *f, std::vector<doub
     mm->setAsBackgroundMesh (this);
     if (getDim() == 2){
       for (fiter fit = firstFace(); fit != lastFace(); ++fit){
-	meshGFaceBamg(*fit);
-	if(_octree)delete _octree;
+	if((*fit)->geomType() != GEntity::DiscreteSurface){
+	  opt_mesh_lc_from_points(0, GMSH_SET, 0);
+	  meshGFaceBamg(*fit);
+	  laplaceSmoothing(*fit,CTX::instance()->mesh.nbSmoothing);
+	}
+	if(_octree) delete _octree;
 	_octree = 0;
       }
     }
     else if (getDim() == 3){
       for (riter rit = firstRegion(); rit != lastRegion(); ++rit){
 	refineMeshMMG(*rit);
-	if(_octree)delete _octree;
+	if(_octree) delete _octree;
 	_octree = 0;
       }
     }
     delete mm;
-    if (++ITER > niter)break;
+    if (++ITER > niter) break;
 
   }
-    
+
   return 0;
 #else
   Msg::Error("Mesh module not compiled");
diff --git a/Mesh/meshGFace.cpp b/Mesh/meshGFace.cpp
index ba6203e8c3..3d570f7854 100644
--- a/Mesh/meshGFace.cpp
+++ b/Mesh/meshGFace.cpp
@@ -1123,6 +1123,7 @@ bool meshGenerator(GFace *gf, int RECUR_ITER,
       bowyerWatson(gf);
     else {
       bowyerWatson(gf);
+      printf("in bamg *** \n");
       meshGFaceBamg(gf);
     }
     laplaceSmoothing(gf,CTX::instance()->mesh.nbSmoothing);
@@ -1722,8 +1723,10 @@ static bool meshGeneratorPeriodic(GFace *gf, bool debug = true)
     else if(CTX::instance()->mesh.algo2d == ALGO_2D_DELAUNAY ||
             CTX::instance()->mesh.algo2d == ALGO_2D_AUTO)
       bowyerWatson(gf);
-    else 
+    else {
+      printf("in bamg \n");
       meshGFaceBamg(gf);
+    }
     laplaceSmoothing(gf,CTX::instance()->mesh.nbSmoothing);
   }
   
diff --git a/Mesh/meshGFaceBamg.cpp b/Mesh/meshGFaceBamg.cpp
index 79990250de..8146aac4fe 100644
--- a/Mesh/meshGFaceBamg.cpp
+++ b/Mesh/meshGFaceBamg.cpp
@@ -194,12 +194,12 @@ void meshGFaceBamg(GFace *gf)
   int nT = gf->triangles.size();
   //  meshGFaceBamg_ ( gf , 0, true);
   for (int i = 1; i < 14; i++){
-    //    char name[245];
-    //    sprintf(name,"hop%d.msh",i);
-    //    GModel::current()->writeMSH(name);
+    //char name[245];
+    //sprintf(name,"hop%d.msh",i);
+    //GModel::current()->writeMSH(name);
     meshGFaceBamg_(gf, i, false);
-    //    sprintf(name,"hap%d.msh",i);
-    //    GModel::current()->writeMSH(name);
+    //sprintf(name,"hap%d.msh",i);
+    //GModel::current()->writeMSH(name);
     
     int nTnow = gf->triangles.size();
     if (fabs((double)(nTnow - nT)) < 0.01 * nT) break;
diff --git a/Mesh/meshMetric.cpp b/Mesh/meshMetric.cpp
index fb76fed447..830813f6fc 100644
--- a/Mesh/meshMetric.cpp
+++ b/Mesh/meshMetric.cpp
@@ -110,7 +110,7 @@ void meshMetric::computeMetric(std::vector<MElement*> &e){
   v2t_cont adj;
   buildVertexToElement (e,adj);
 
-  printf("%d elements are considered\n",e.size());
+  printf("%d elements are considered in the metric \n",e.size());
 
   computeValues(adj);
   computeHessian(adj);
-- 
GitLab