From 8ac92fc3af775ee3d874bab1244ad8edb2688f7f Mon Sep 17 00:00:00 2001
From: Koen Hillewaert <koen.hillewaert@cenaero.be>
Date: Thu, 27 Oct 2016 11:39:20 +0000
Subject: [PATCH] removed bug in the alignment of periodic boundaries for high
 order meshes

---
 Geo/GModelIO_MSH2.cpp |  1 +
 Geo/MTriangle.cpp     |  2 --
 Mesh/HighOrder.cpp    | 20 ++++++++++++++------
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/Geo/GModelIO_MSH2.cpp b/Geo/GModelIO_MSH2.cpp
index e15b4dfa5e..c9f0b9efb3 100644
--- a/Geo/GModelIO_MSH2.cpp
+++ b/Geo/GModelIO_MSH2.cpp
@@ -899,6 +899,7 @@ int GModel::_writeMSH2(const std::string &name, double version, bool binary,
 
   // get the number of vertices and index the vertices in a continuous
   // sequence
+  
   int numVertices = indexMeshVertices(saveAll, saveSinglePartition, renumberVertices);
 
   // get the number of elements we need to save
diff --git a/Geo/MTriangle.cpp b/Geo/MTriangle.cpp
index cbd3a2b3ae..48cd869369 100644
--- a/Geo/MTriangle.cpp
+++ b/Geo/MTriangle.cpp
@@ -277,8 +277,6 @@ void MTriangle::reorient(int rot,bool swap) {
 
 void MTriangle6::reorient(int rot, bool swap) {
   
-  Msg::Info("Reorienting triangle 6 with rot %d and swap %d",
-            rot,swap ? 1:0);
   if (rot == 0 && !swap) return;
 
   MTriangle::reorient(rot,swap);
diff --git a/Mesh/HighOrder.cpp b/Mesh/HighOrder.cpp
index 04a4b5999c..de7d9376db 100644
--- a/Mesh/HighOrder.cpp
+++ b/Mesh/HighOrder.cpp
@@ -1325,6 +1325,7 @@ static void updatePeriodicEdgesAndFaces(GModel *m)
 
     if (src != NULL && src != tgt) {
 
+      std::map<MVertex*,MVertex*> &v2v = tgt->correspondingVertices;
       std::map<MVertex*,MVertex*> &p2p = tgt->correspondingHOPoints;
       p2p.clear();
 
@@ -1350,8 +1351,6 @@ static void updatePeriodicEdgesAndFaces(GModel *m)
 
         for (int iVtx=0;iVtx<2;iVtx++) {
           MVertex* vtx = tgtLine->getVertex(iVtx);
-          std::map<MVertex*,MVertex*>& v2v =
-            vtx->onWhat()->correspondingVertices;
           std::map<MVertex*,MVertex*>::iterator tIter = v2v.find(vtx);
           if (tIter == v2v.end()) {
             Msg::Error("Cannot find periodic counterpart of vertex %d"
@@ -1389,6 +1388,7 @@ static void updatePeriodicEdgesAndFaces(GModel *m)
       Msg::Info("Constructing high order periodicity for face connection %d - %d",
                 tgt->tag(),src->tag());
 
+      std::map<MVertex*,MVertex*> &v2v = tgt->correspondingVertices;
       std::map<MVertex*,MVertex*> &p2p = tgt->correspondingHOPoints;
       p2p.clear();
 
@@ -1417,10 +1417,18 @@ static void updatePeriodicEdgesAndFaces(GModel *m)
         std::vector<MVertex*> vtcs;
         for (int iVtx=0;iVtx<nbVtcs;iVtx++) {
           MVertex* vtx = tgtElmt->getVertex(iVtx);
-          GEntity* ge = vtx->onWhat();
-          if (ge->meshMaster() == ge) throw;
-          std::map<MVertex*,MVertex*>& v2v = ge->correspondingVertices;
-          vtcs.push_back(v2v[vtx]);
+
+          std::map<MVertex*,MVertex*>::iterator tIter = v2v.find(vtx);
+          if (tIter == v2v.end()) {
+            Msg::Error("Cannot find periodic counterpart of vertex %d"
+                       " of surface %d on surface %d",
+                       vtx->getNum(),tgt->tag(),src->tag());
+          }
+          else vtcs.push_back(tIter->second);
+          // GEntity* ge = vtx->onWhat();
+          // if (ge->meshMaster() == ge) throw;
+          // std::map<MVertex*,MVertex*>& v2v = ge->correspondingVertices;
+          //vtcs.push_back(v2v[vtx]);
         }
 
         std::map<MFace,MElement*>::iterator srcIter = srcFaces.find(MFace(vtcs));
-- 
GitLab