From 76b362e4fb01c971fa790b3fd64434a31d64c562 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@uliege.be>
Date: Sun, 20 Sep 2020 19:00:46 +0200
Subject: [PATCH] new meshSize attritbute in GRegion + use BGM_MeshSize in
 Netgen interface

---
 Geo/GRegion.cpp            | 1 +
 Geo/GRegion.h              | 7 +++++++
 Mesh/meshGRegionNetgen.cpp | 9 +++++++--
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/Geo/GRegion.cpp b/Geo/GRegion.cpp
index 7716690c0d..241b19ebde 100644
--- a/Geo/GRegion.cpp
+++ b/Geo/GRegion.cpp
@@ -174,6 +174,7 @@ void GRegion::resetMeshAttributes()
   meshAttributes.method = MESH_UNSTRUCTURED;
   meshAttributes.extrude = 0;
   meshAttributes.QuadTri = NO_QUADTRI;
+  meshAttributes.meshSize = MAX_LC;
 }
 
 SBoundingBox3d GRegion::bounds(bool fast)
diff --git a/Geo/GRegion.h b/Geo/GRegion.h
index 1376baa51b..37e608f959 100644
--- a/Geo/GRegion.h
+++ b/Geo/GRegion.h
@@ -147,8 +147,15 @@ public:
     std::vector<GVertex *> corners;
     // structured/unstructured coupling using pyramids
     int QuadTri;
+    // global mesh size constraint for the volume
+    double meshSize;
   } meshAttributes;
 
+  virtual double getMeshSize() const
+  {
+    return meshAttributes.meshSize;
+  }
+
   // a array for accessing the transfinite vertices using a triplet of
   // indices
   std::vector<std::vector<std::vector<MVertex *> > > transfinite_vertices;
diff --git a/Mesh/meshGRegionNetgen.cpp b/Mesh/meshGRegionNetgen.cpp
index 4e3951a0ca..833f8e13b2 100644
--- a/Mesh/meshGRegionNetgen.cpp
+++ b/Mesh/meshGRegionNetgen.cpp
@@ -14,6 +14,7 @@
 #include "MTriangle.h"
 #include "MTetrahedron.h"
 #include "ExtrudeParams.h"
+#include "BackgroundMeshTools.h"
 #include "Context.h"
 
 #if defined(HAVE_NETGEN)
@@ -317,7 +318,9 @@ void meshGRegionNetgen(GRegion *gr)
   meshNormalsPointOutOfTheRegion(gr);
   std::vector<MVertex *> numberedV;
   Ng_Mesh *ngmesh = buildNetgenStructure(gr, false, numberedV);
-  Ng_GenerateVolumeMesh(ngmesh, CTX::instance()->mesh.lcMax);
+  SPoint3 pt = gr->bounds().center();
+  double lc = BGM_MeshSize(gr, 0, 0, pt.x(), pt.y(), pt.z());
+  Ng_GenerateVolumeMesh(ngmesh, lc);
   TransferVolumeMesh(gr, ngmesh, numberedV);
   Ng_DeleteMesh(ngmesh);
   Ng_Exit();
@@ -351,7 +354,9 @@ void optimizeMeshGRegionNetgen::operator()(GRegion *gr, bool always)
   deMeshGRegion dem;
   dem(gr);
   // optimize mesh
-  Ng_OptimizeVolumeMesh(ngmesh, CTX::instance()->mesh.lcMax);
+  SPoint3 pt = gr->bounds().center();
+  double lc = BGM_MeshSize(gr, 0, 0, pt.x(), pt.y(), pt.z());
+  Ng_OptimizeVolumeMesh(ngmesh, lc);
   TransferVolumeMesh(gr, ngmesh, numberedV);
   Ng_DeleteMesh(ngmesh);
   Ng_Exit();
-- 
GitLab