From e89845c2d56b510d90a82648e11f8a224af2295f Mon Sep 17 00:00:00 2001
From: Kilian Verhetsel <kilian.verhetsel@student.uclouvain.be>
Date: Sat, 10 Dec 2016 13:40:16 +0000
Subject: [PATCH] Compute quality of hexahedra using jacobianBasedQuality

---
 Mesh/yamakawa.cpp | 11 +----------
 Mesh/yamakawa.h   | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/Mesh/yamakawa.cpp b/Mesh/yamakawa.cpp
index f2b91b8129..f64db2efda 100644
--- a/Mesh/yamakawa.cpp
+++ b/Mesh/yamakawa.cpp
@@ -716,8 +716,6 @@ void Recombinator::pattern1() {
               for (std::set<MVertex*>::iterator it4 = bin4.begin(); it4 != bin4.end(); it4++) {
                 MVertex* s = *it4;
                 Hex* hex = new Hex(a, b, q, c, d, p, s, r);
-                double quality = min_scaled_jacobian(*hex);
-                hex->set_quality(quality);
 
                 add_or_free_potential_hex(hex);
               }
@@ -766,13 +764,9 @@ void Recombinator::pattern2() {
         if (r != 0 && q != 0) {
           // 2 possible hexes
           Hex* hex = new Hex(a, s, b, c, d, r, q, p);
-          double quality = min_scaled_jacobian(*hex);
-          hex->set_quality(quality);
           add_or_free_potential_hex(hex);
 
           Hex* hex2 = new Hex(a, c, d, s, b, p, q, r);
-          quality = min_scaled_jacobian(*hex2);
-          hex2->set_quality(quality);
           add_or_free_potential_hex(hex2);
         }
       }
@@ -848,8 +842,6 @@ void Recombinator::pattern3() {
 
           if (c1 && c2 && c3 && c4 && c5 && c6 && c7 && c8 && c9 && c10) {
             Hex* hex = new Hex(p, c, r, b, q, d, s, a);
-            double quality = min_scaled_jacobian(*hex);
-            hex->set_quality(quality);
             add_or_free_potential_hex(hex);
           }
         } // copy paste alert
@@ -889,8 +881,7 @@ void Recombinator::pattern3() {
 
           if (c1 && c2 && c3 && c4 && c5 && c6 && c7 && c8 && c9 && c10) {
             Hex* hex = new Hex(p, b, r, a, q, c, s, d);
-            double quality = min_scaled_jacobian(*hex);
-            hex->set_quality(quality);
+
             add_or_free_potential_hex(hex);
           }
         }
diff --git a/Mesh/yamakawa.h b/Mesh/yamakawa.h
index 2a4c24ad70..0387bb943d 100644
--- a/Mesh/yamakawa.h
+++ b/Mesh/yamakawa.h
@@ -11,6 +11,8 @@
 
 #include "GRegion.h"
 #include "MVertex.h"
+#include "MHexahedron.h"
+#include "qualityMeasuresJacobian.h"
 #include <set>
 #include <map>
 #include <iterator>
@@ -38,13 +40,23 @@ private:
     }
   }
 
+  void compute_quality() {
+    MHexahedron elt(vertices_);
+    quality = jacobianBasedQuality::minScaledJacobian(&elt, false, true);
+  }
+
+  void initialize() {
+    set_hash();
+    compute_quality();
+  }
+
 public:
   Hex() : quality(0.), hash(0.) {}
 
   Hex(const std::vector<MVertex*>& vertices):
     quality(0.), hash(0), vertices_(vertices)
   {
-    set_hash();
+    initialize();
   }
   Hex(MVertex* a2, MVertex* b2, MVertex* c2, MVertex* d2, MVertex* e2, MVertex* f2, MVertex* g2, MVertex* h2) :
     quality(0.)
@@ -57,13 +69,12 @@ public:
     vertices_.push_back(f2);
     vertices_.push_back(g2);
     vertices_.push_back(h2);
-    set_hash();
+    initialize();
   }
 
   ~Hex() {};
 
   double get_quality() const { return quality; }
-  void set_quality(double new_quality) { quality = new_quality; }
 
   MVertex* getVertex(unsigned int i) const {
     if (i < 8) {
-- 
GitLab