From 44f2054e7bae311ba1e2fd541dcc504950b3402c Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Fri, 15 Jun 2012 13:12:34 +0000
Subject: [PATCH] cleanup

---
 Mesh/Field.cpp                 |  38 ++++++-----
 Mesh/meshGEdge.cpp             |  10 +--
 Mesh/meshGFace.cpp             |  47 ++++++-------
 Mesh/meshGFaceBoundaryLayers.h | 116 +++++++++++++++++----------------
 4 files changed, 111 insertions(+), 100 deletions(-)

diff --git a/Mesh/Field.cpp b/Mesh/Field.cpp
index ec8ecff864..83278e98a2 100644
--- a/Mesh/Field.cpp
+++ b/Mesh/Field.cpp
@@ -1687,7 +1687,8 @@ class AttractorField : public Field
         ((points.size()) ? points.size() :
          n_nodes_by_edge * n_nodes_by_edge * faces_id.size());
 
-      printf("%d points found in points clouds (%d edges)\n",totpoints, edges_id.size());
+      Msg::Info("%d points found in points clouds (%d edges)", totpoints,
+                (int)edges_id.size());
 
       if(totpoints){
         zeronodes = annAllocPts(totpoints, 3);
@@ -1927,17 +1928,17 @@ void BoundaryLayerField::operator() (AttractorField *cc, double dist,
     if (dist < thickness){
       SVector3 t1 = e->firstDer(pp.first.u);
       double crv = e->curvature(pp.first.u);
-      double rho = 1./crv;
       const double b = lc_t;
       const double h = lc_n;
-      double oneOverD2 = .5/(b*b) * (1. + sqrt (1. + ( 4.*crv*crv*b*b*b*b/ (h*h*beta*beta))));
-      metr = buildMetricTangentToCurve(t1,sqrt(1./oneOverD2),lc_n);
+      double oneOverD2 = .5/(b * b) *
+        (1. + sqrt (1. + (4. * crv * crv * b * b * b * b / (h * h * beta * beta))));
+      metr = buildMetricTangentToCurve(t1, sqrt(1. / oneOverD2), lc_n);
       return;
     }
     else {
       GPoint p = e->point(pp.first.u);
-      SVector3 t2 = SVector3(p.x() -x,p.y() -y,p.z() -z);
-      metr = buildMetricTangentToCurve(t2,lc_t,lc_n);
+      SVector3 t2 = SVector3(p.x() - x, p.y() - y, p.z() - z);
+      metr = buildMetricTangentToCurve(t2, lc_t, lc_n);
       return;
     }
   }
@@ -1945,18 +1946,19 @@ void BoundaryLayerField::operator() (AttractorField *cc, double dist,
     GFace *gf = GModel::current()->getFaceByTag(pp.first.ent);
     if (dist < thickness){
       double cmin, cmax;
-      SVector3 dirMax,dirMin;
-      cmax = gf->curvatures(SPoint2(pp.first.u,pp.first.v),&dirMax, &dirMin, &cmax,&cmin);
+      SVector3 dirMax, dirMin;
+      cmax = gf->curvatures(SPoint2(pp.first.u, pp.first.v),
+                            &dirMax, &dirMin, &cmax, &cmin);
       const double b = lc_t;
       const double h = lc_n;
-      double rhoMin = 1./cmin;
-      double rhoMax = 1./cmax;
-      double oneOverD2_min = .5/(b*b) * (1. + sqrt (1. + ( 4.*cmin*cmin*b*b*b*b/ (h*h*beta*beta))));
-      double oneOverD2_max = .5/(b*b) * (1. + sqrt (1. + ( 4.*cmax*cmax*b*b*b*b/ (h*h*beta*beta))));
-      double dmin = sqrt(1./oneOverD2_min);
-      double dmax = sqrt(1./oneOverD2_max);
-      dmin = std::min(dmin,dmax*tgt_aniso_ratio);
-      metr = buildMetricTangentToSurface(dirMin,dirMax,dmin,dmax,lc_n);
+      double oneOverD2_min = .5/(b * b) *
+        (1. + sqrt(1. + (4. * cmin * cmin * b * b * b * b / (h * h * beta * beta))));
+      double oneOverD2_max = .5/(b * b) *
+        (1. + sqrt(1. + (4. * cmax * cmax * b * b * b * b / (h * h * beta * beta))));
+      double dmin = sqrt(1. / oneOverD2_min);
+      double dmax = sqrt(1. / oneOverD2_max);
+      dmin = std::min(dmin, dmax * tgt_aniso_ratio);
+      metr = buildMetricTangentToSurface(dirMin, dirMax, dmin, dmax, lc_n);
       return;
     }
     else {
@@ -2009,7 +2011,9 @@ void BoundaryLayerField::operator() (double x, double y, double z,
       _closest_point = CLOSEST;
     }
   }
-  if (iIntersect)for (int i=0;i<hop.size();i++)v = intersection_conserve_mostaniso(v,hop[i]);
+  if (iIntersect)
+    for (unsigned int i = 0; i < hop.size(); i++)
+      v = intersection_conserve_mostaniso(v, hop[i]);
   metr = v;
 }
 #endif
diff --git a/Mesh/meshGEdge.cpp b/Mesh/meshGEdge.cpp
index 064dd8ac2f..88ecbba4c8 100644
--- a/Mesh/meshGEdge.cpp
+++ b/Mesh/meshGEdge.cpp
@@ -36,14 +36,14 @@ static double smoothPrimitive(GEdge *ge, double alpha,
 
     // use a gauss-seidel iteration; iterate forward and then backward;
     // convergence is usually very fast
-    for (int i=1; i< Points.size(); i++){
+    for (unsigned int i = 1; i < Points.size(); i++){
       double dh = (Points[i].xp/Points[i].lc - Points[i-1].xp/Points[i-1].lc);
       double dt = Points[i].t - Points[i-1].t;
       double dhdt =  dh/dt;
       if (dhdt / Points[i].xp > (alpha - 1.)*1.01){
 	double hnew = Points[i-1].xp / Points[i-1].lc + dt * (alpha-1) * Points[i].xp;
 	Points[i].lc = Points[i].xp / hnew;
-	count1 ++;
+	count1++;
       }
     }
 
@@ -64,7 +64,7 @@ static double smoothPrimitive(GEdge *ge, double alpha,
   }
 
   // recompute the primitive
-  for (int i = 1; i < Points.size(); i++){
+  for (int i = 1; i < (int)Points.size(); i++){
     IntPoint &pt2 = Points[i];
     IntPoint &pt1 = Points[i-1];
     pt2.p = pt1.p + (pt2.t - pt1.t) * 0.5 * (pt2.lc + pt1.lc);
@@ -273,6 +273,7 @@ void deMeshGEdge::operator() (GEdge *ge)
   ge->meshStatistics.status = GEdge::PENDING;
 }
 
+/*
 static void printFandPrimitive(int tag, std::vector<IntPoint> &Points)
 {
   char name[256];
@@ -287,6 +288,7 @@ static void printFandPrimitive(int tag, std::vector<IntPoint> &Points)
   }
   fclose(f);
 }
+*/
 
 void meshGEdge::operator() (GEdge *ge)
 {
@@ -374,7 +376,7 @@ void meshGEdge::operator() (GEdge *ge)
                       CTX::instance()->mesh.lcIntegrationPrecision);
 
     // we should maybe provide an option to disable the smoothing
-    for (int i = 0; i < Points.size(); i++){
+    for (unsigned int i = 0; i < Points.size(); i++){
       IntPoint &pt = Points[i];
       SVector3 der = ge->firstDer(pt.t);
       pt.xp = der.norm();
diff --git a/Mesh/meshGFace.cpp b/Mesh/meshGFace.cpp
index d5a5c6b885..4f8698d1a1 100644
--- a/Mesh/meshGFace.cpp
+++ b/Mesh/meshGFace.cpp
@@ -95,8 +95,8 @@ static void copyMesh(GFace *source, GFace *target)
     MVertex *vs = it->first;
     MVertex *vt = it->second;
     if (vs->onWhat()->dim() == 1){
-      bool success1 = reparamMeshVertexOnFace(vs, source, param_source[count]);
-      bool success2 = reparamMeshVertexOnFace(vt, target, param_target[count++]);
+      reparamMeshVertexOnFace(vs, source, param_source[count]);
+      reparamMeshVertexOnFace(vt, target, param_target[count++]);
       if (count == 2) break;
     }
   }
@@ -138,14 +138,14 @@ static void copyMesh(GFace *source, GFace *target)
       vt[j] = vs2vt[vs];
       if (!vt[j]){
 	SPoint2 p;
-	bool success = reparamMeshVertexOnFace(vs, source, p);
+	reparamMeshVertexOnFace(vs, source, p);
 	const double U =   c * (p.x()-s1u) + s * (p.y()-s1v) + t1u;
 	const double V =  -s * (p.x()-s1u) + c * (p.y()-s1v) + t1v;
 	for (std::list<GEdge*>::iterator it = edges.begin(); it != edges.end(); ++it){
 	  GEdge *te = *it;
 	  for (unsigned k = 0; k < te->lines.size(); k++){
 	    MVertex *gotcha = te->lines[k]->getVertex(0);
-	    bool success2 = reparamMeshVertexOnFace(gotcha, target, p);
+	    reparamMeshVertexOnFace(gotcha, target, p);
 	    const double D = sqrt((U - p.x()) * (U - p.x()) + (V - p.y()) * (V - p.y()));
 	    if (D < 1.e-9){
 	      vt[j] = gotcha;
@@ -450,16 +450,16 @@ void filterOverlappingElements(int dim, std::vector<MElement*> &e,
 {
   eout.clear();
   MElementOctree octree (e);
-  for (int i=0;i<e.size();++i){
+  for (unsigned int i = 0; i < e.size(); ++i){
     MElement *el = e[i];
     bool intersection = false;
     for (int j=0;j<el->getNumVertices();++j){
       MVertex *v = el->getVertex(j);
-      std::vector<MElement *> inters = octree.findAll(v->x(),v->y(),v->z(),dim);
+      std::vector<MElement *> inters = octree.findAll(v->x(), v->y(), v->z(), dim);
       std::vector<MElement *> inters2;
-      for (int k=0;k<inters.size();k++){
+      for (unsigned int k = 0; k < inters.size(); k++){
 	bool found = false;
-	for (int l=0;l<inters[k]->getNumVertices();l++){
+	for (int l = 0; l < inters[k]->getNumVertices(); l++){
 	  if (inters[k]->getVertex(l) == v)found = true;
 	}
 	if (!found)inters2.push_back(inters[k]);
@@ -502,8 +502,8 @@ void modifyInitialMeshForTakingIntoAccountBoundaryLayers(GFace *gf)
       MEdge dv(v1,v2);
       addOrRemove(v1,v2,bedges);
 
-      for (int SIDE = 0 ; SIDE < _columns->_normals.count(dv) ; SIDE ++){
-	edgeColumn ec =  _columns->getColumns(v1,v2,SIDE);
+      for (unsigned int SIDE = 0 ; SIDE < _columns->_normals.count(dv); SIDE ++){
+	edgeColumn ec =  _columns->getColumns(v1, v2, SIDE);
 	const BoundaryLayerData & c1 = ec._c1;
 	const BoundaryLayerData & c2 = ec._c2;
 	int N = std::min(c1._column.size(),c2._column.size());
@@ -581,25 +581,26 @@ void modifyInitialMeshForTakingIntoAccountBoundaryLayers(GFace *gf)
   fclose(ff2);
 
   std::vector<MElement*> els,newels,oldels;
-  for (int i=0;i<blQuads.size();i++)els.push_back(blQuads[i]);
+  for (unsigned int i = 0; i < blQuads.size();i++) els.push_back(blQuads[i]);
   filterOverlappingElements (2,els,newels,oldels);
   blQuads.clear();
-  for (int i=0;i<newels.size();i++)blQuads.push_back((MQuadrangle*)newels[i]);
-  for (int i=0;i<oldels.size();i++)delete oldels[i];
+  for (unsigned int i = 0; i < newels.size(); i++)
+    blQuads.push_back((MQuadrangle*)newels[i]);
+  for (unsigned int i = 0; i < oldels.size(); i++) delete oldels[i];
 
-  for (int i=0;i<blQuads.size();i++){
+  for (unsigned int i = 0; i < blQuads.size();i++){
     addOrRemove(blQuads[i]->getVertex(0),blQuads[i]->getVertex(1),bedges);
     addOrRemove(blQuads[i]->getVertex(1),blQuads[i]->getVertex(2),bedges);
     addOrRemove(blQuads[i]->getVertex(2),blQuads[i]->getVertex(3),bedges);
     addOrRemove(blQuads[i]->getVertex(3),blQuads[i]->getVertex(0),bedges);
-    for (int j=0;j<4;j++)
+    for (int j = 0; j < 4; j++)
       if(blQuads[i]->getVertex(j)->onWhat() == gf)verts.insert(blQuads[i]->getVertex(j));
   }
-  for (int i=0;i<blTris.size();i++){
+  for (unsigned int i = 0; i < blTris.size(); i++){
     addOrRemove(blTris[i]->getVertex(0),blTris[i]->getVertex(1),bedges);
     addOrRemove(blTris[i]->getVertex(1),blTris[i]->getVertex(2),bedges);
     addOrRemove(blTris[i]->getVertex(2),blTris[i]->getVertex(0),bedges);
-    for (int j=0;j<3;j++)
+    for (int j = 0; j < 3; j++)
       if(blTris[i]->getVertex(j)->onWhat() == gf)verts.insert(blTris[i]->getVertex(j));
   }
 
@@ -713,7 +714,7 @@ bool meshGenerator(GFace *gf, int RECUR_ITER,
     for(std::set<MVertex*>::iterator it = all_vertices.begin();
 	it != all_vertices.end(); it++){
       vv[i++] = *it;
-    }    
+    }
     gf->triangles.push_back(new MTriangle(vv[0], vv[1], vv[2]));
     gf->meshStatistics.status = GFace::DONE;
     return true;
@@ -1184,6 +1185,7 @@ static inline double dist2(const SPoint2 &p1, const SPoint2 &p2)
   return dx * dx + dy * dy;
 }
 
+/*
 static void printMesh1d(int iEdge, int seam, std::vector<SPoint2> &m)
 {
   printf("Mesh1D for edge %d seam %d\n", iEdge, seam);
@@ -1191,6 +1193,7 @@ static void printMesh1d(int iEdge, int seam, std::vector<SPoint2> &m)
     printf("%12.5E %12.5E\n", m[i].x(), m[i].y());
   }
 }
+*/
 
 static bool buildConsecutiveListOfVertices(GFace *gf, GEdgeLoop &gel,
                                            std::vector<BDS_Point*> &result,
@@ -1484,7 +1487,7 @@ static bool meshGeneratorPeriodic(GFace *gf, bool debug = true)
     for(std::map<BDS_Point*, MVertex*>::iterator it = recoverMap.begin();
 	it != recoverMap.end(); it++){
       vv[i++] = it->second;
-    }    
+    }
     gf->triangles.push_back(new MTriangle(vv[0], vv[1], vv[2]));
     gf->meshStatistics.status = GFace::DONE;
     return true;
@@ -2018,7 +2021,7 @@ void partitionAndRemesh(GFaceCompound *gf)
     GFace *gfc =  gf->model()->getFaceByTag(numf + NF + i );
     meshGFace mgf;
     mgf(gfc);
-  
+
     for(unsigned int j = 0; j < gfc->triangles.size(); ++j){
       MTriangle *t = gfc->triangles[j];
       std::vector<MVertex *> v(3);
@@ -2128,8 +2131,8 @@ void orientMeshGFace::operator()(GFace *gf)
   //do sthg for compound face
   if(gf->geomType() == GEntity::CompoundSurface ) {
     GFaceCompound *gfc = (GFaceCompound*) gf;
-  
-    std::list<GFace*> comp = gfc->getCompounds(); 
+
+    std::list<GFace*> comp = gfc->getCompounds();
     MTriangle *lt = (*comp.begin())->triangles[0];
     SPoint2 c0 = gfc->getCoordinates(lt->getVertex(0));
     SPoint2 c1 = gfc->getCoordinates(lt->getVertex(1));
diff --git a/Mesh/meshGFaceBoundaryLayers.h b/Mesh/meshGFaceBoundaryLayers.h
index 385fb73c5b..2bca7ca129 100644
--- a/Mesh/meshGFaceBoundaryLayers.h
+++ b/Mesh/meshGFaceBoundaryLayers.h
@@ -17,82 +17,82 @@ class GFace;
 
 struct BoundaryLayerData
 {
-  BoundaryLayerData (const SVector3 & dir,
-		     std::vector<MVertex*> column,
-		     std::vector<SMetric3> metrics)
-  : _n(dir), _column(column),_metrics(metrics)
-  {
-
-  }
   SVector3 _n;
   std::vector<MVertex*> _column;
   std::vector<SMetric3> _metrics;
+  BoundaryLayerData(){}
+  BoundaryLayerData(const SVector3 & dir,
+                    std::vector<MVertex*> column,
+                    std::vector<SMetric3> metrics)
+    : _n(dir), _column(column), _metrics(metrics){}
 };
 
 struct BoundaryLayerFan
 {
   MEdge _e1, _e2;
   bool sense;
-  BoundaryLayerFan (MEdge e1, MEdge e2 , bool s = true)
-  : _e1(e1),_e2(e2) , sense (s)
-  {}
+  BoundaryLayerFan(MEdge e1, MEdge e2 , bool s = true)
+    : _e1(e1),_e2(e2) , sense (s){}
 };
 
 struct edgeColumn {
-  const BoundaryLayerData & _c1, &_c2;
-  edgeColumn (const BoundaryLayerData & c1, const BoundaryLayerData & c2) : _c1(c1),_c2(c2){}
+  const BoundaryLayerData &_c1, &_c2;
+  edgeColumn(const BoundaryLayerData &c1, const BoundaryLayerData &c2)
+    : _c1(c1), _c2(c2){}
 };
 
 class BoundaryLayerColumns
 {
-  std::multimap<MVertex*,BoundaryLayerData>  _data;
-  std::map<MVertex*,BoundaryLayerFan> _fans;
+  std::multimap<MVertex*, BoundaryLayerData>  _data;
+  std::map<MVertex*, BoundaryLayerFan> _fans;
 public:
-  typedef  std::multimap<MVertex*,BoundaryLayerData>::iterator iter;
-  typedef  std::map<MVertex*,BoundaryLayerFan>::iterator iterf;
-  std::multimap<MVertex*,MVertex*> _non_manifold_edges;
-  std::multimap<MEdge,SVector3,Less_Edge> _normals;
-  iter begin() {return _data.begin();}
-  iter end() {return _data.end();}
-  iterf beginf() {return _fans.begin();}
-  iterf endf() {return _fans.end();}
-  BoundaryLayerColumns ()
+  typedef std::multimap<MVertex*,BoundaryLayerData>::iterator iter;
+  typedef std::map<MVertex*, BoundaryLayerFan>::iterator iterf;
+  std::multimap<MVertex*, MVertex*> _non_manifold_edges;
+  std::multimap<MEdge, SVector3, Less_Edge> _normals;
+  iter begin() { return _data.begin(); }
+  iter end() { return _data.end(); }
+  iterf beginf() { return _fans.begin(); }
+  iterf endf() { return _fans.end(); }
+  BoundaryLayerColumns (){}
+  inline void addColumn(const SVector3 &dir, MVertex* v,
+                        std::vector<MVertex*> _column,
+                        std::vector<SMetric3> _metrics)
   {
-  }
-  inline void addColumn (const SVector3 &dir, MVertex* v,
-		  std::vector<MVertex*> _column,
-		  std::vector<SMetric3> _metrics){
     _data.insert (std::make_pair(v,BoundaryLayerData(dir, _column,_metrics)));
   }
-  inline void addFan (MVertex *v, MEdge e1, MEdge e2, bool s){
+  inline void addFan(MVertex *v, MEdge e1, MEdge e2, bool s)
+  {
     _fans.insert(std::make_pair(v,BoundaryLayerFan(e1,e2,s)));
   }
-
-  inline const BoundaryLayerData & getColumn ( MVertex *v, MEdge e ){
+  inline const BoundaryLayerData &getColumn(MVertex *v, MEdge e)
+  {
     std::map<MVertex*,BoundaryLayerFan>::const_iterator it = _fans.find(v);
-    int N =  getNbColumns (v) ;
-    if (N == 1) return getColumn(v,0);
+    int N = getNbColumns(v) ;
+    if (N == 1) return getColumn(v, 0);
     Equal_Edge aaa;
     if (it != _fans.end()){
-      if (aaa(it->second._e1,e))
-	return getColumn ( v, 0 );
+      if (aaa(it->second._e1, e))
+	return getColumn(v, 0);
       else
-	return  getColumn ( v, N-1 );
+	return getColumn(v, N-1);
     }
-    else Msg::Error("CANNOT HANDLE EMBEDDED LINES IN BLs");
+    Msg::Error("Cannot handle embedded lines in boundary layers");
+    static BoundaryLayerData error;
+    return error;
   }
-
-  inline edgeColumn getColumns ( MVertex *v1, MVertex *v2 , int side ){
+  inline edgeColumn getColumns(MVertex *v1, MVertex *v2 , int side)
+  {
     Equal_Edge aaa;
-    MEdge e(v1,v2);
+    MEdge e(v1, v2);
     std::map<MVertex*,BoundaryLayerFan>::const_iterator it1 = _fans.find(v1);
     std::map<MVertex*,BoundaryLayerFan>::const_iterator it2 = _fans.find(v2);
-    int N1 =  getNbColumns (v1) ;
-    int N2 =  getNbColumns (v2) ;
+    int N1 = getNbColumns(v1) ;
+    int N2 = getNbColumns(v2) ;
 
     int nbSides = _normals.count(e);
 
-    //    if (nbSides != 1)printf("I'm here %d sides\n",nbSides);
+    // if (nbSides != 1)printf("I'm here %d sides\n",nbSides);
     // Standard case, only two extruded columns from the two vertices
     if (N1 == 1 && N2 == 1) return edgeColumn(getColumn(v1,0),getColumn(v2,0));
     // one fan on
@@ -127,16 +127,17 @@ public:
 
       Msg::Error ("Impossible Boundary Layer Configuration : one side and no fans");
       // FIXME WRONG
-      return N1 ? edgeColumn (getColumn (v1,0),getColumn(v1,0)) : edgeColumn (getColumn (v2,0),getColumn(v2,0));
+      return N1 ? edgeColumn (getColumn (v1,0),getColumn(v1,0)) :
+        edgeColumn (getColumn (v2,0),getColumn(v2,0));
     }
     else if (nbSides == 2){
       if (it1 == _fans.end() && it2 == _fans.end() ){
 	if (N1 != 2 || N2 != 2){
 	  Msg::Error ("Impossible Boundary Layer Configuration");
 	  // FIXME WRONG
-	  return N1 ? edgeColumn (getColumn (v1,0),getColumn(v1,0)) : edgeColumn (getColumn (v2,0),getColumn(v2,0));
+	  return N1 ? edgeColumn (getColumn (v1,0),getColumn(v1,0)) :
+            edgeColumn (getColumn (v2,0),getColumn(v2,0));
 	}
-	//	printf("coucou side %d %d %d\n",side,N1,N2);
 	const BoundaryLayerData & c10 = getColumn(v1,0);
 	const BoundaryLayerData & c11 = getColumn(v1,1);
 	const BoundaryLayerData & c20 = getColumn(v2,0);
@@ -151,21 +152,22 @@ public:
 	}
       }
     }
-    else {
-      Msg::Error ("Not yet Done in BoundaryLayerData");
-    }
-  }
 
-  inline int getNbColumns (MVertex *v) {
-    return _data.count (v);
+    Msg::Error("Not yet Done in BoundaryLayerData");
+    static BoundaryLayerData error;
+    static edgeColumn error2(error, error);
+    return error2;
   }
-  inline const BoundaryLayerData & getColumn ( MVertex *v, int iColumn ){
+  inline int getNbColumns(MVertex *v) { return _data.count(v); }
+  inline const BoundaryLayerData &getColumn(MVertex *v, int iColumn)
+  {
     int count = 0;
-    for ( std::multimap<MVertex*,BoundaryLayerData> :: iterator itm  = _data.lower_bound(v);
-	  itm != _data.upper_bound(v); ++itm)
-      {
-	if (count++ == iColumn) return itm->second;
-      }
+    for(std::multimap<MVertex*,BoundaryLayerData>::iterator itm  = _data.lower_bound(v);
+        itm != _data.upper_bound(v); ++itm){
+      if (count++ == iColumn) return itm->second;
+    }
+    static BoundaryLayerData error;
+    return error;
   }
   void filterPoints();
 };
-- 
GitLab