From 3d8f0f66517dd25966cd26a9bf7c9e90a117bd01 Mon Sep 17 00:00:00 2001
From: Michel Rasquin <michel.rasquin@cenaero.be>
Date: Thu, 26 Jan 2017 22:34:42 +0000
Subject: [PATCH] Bug fixed for compatibility with paraview plugin

---
 Common/Context.cpp        | 1 +
 Common/Context.h          | 1 +
 Common/DefaultOptions.h   | 3 +++
 Common/Options.cpp        | 8 ++++++++
 Common/Options.h          | 1 +
 Geo/GModelIO_MSH2.cpp     | 2 +-
 doc/texinfo/opt_mesh.texi | 5 +++++
 7 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/Common/Context.cpp b/Common/Context.cpp
index a705736136..2fbfe7d5b7 100644
--- a/Common/Context.cpp
+++ b/Common/Context.cpp
@@ -108,6 +108,7 @@ CTX::CTX() : gamepad(0)
   mesh.minCircPoints = mesh.order = 0;
   mesh.secondOrderLinear = mesh.secondOrderIncomplete = 0;
   mesh.preserveNumberingMsh2 = 1;
+  mesh.ignorePeriodicity= 1;
   mesh.lightLines = 2;
 }
 
diff --git a/Common/Context.h b/Common/Context.h
index 94b93e8be2..79db244c15 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -60,6 +60,7 @@ struct contextMeshOptions {
   int ignorePartBound;
   int NewtonConvergenceTestXYZ;
   int preserveNumberingMsh2;
+  int ignorePeriodicity;
 };
 
 struct contextGeometryOptions {
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index bce2c93adf..bab4d50592 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -1197,6 +1197,9 @@ StringXNumber MeshOptions_Number[] = {
   { F|O, "PreserveNumberingMsh2" , opt_mesh_preserve_numbering_msh2 , 0. ,
     "Preserve element numbering in MSH2 format (will break meshes with multiple "
     "physical groups for a single elementary entity)"},
+  { F|O, "IgnorePeriodicity" , opt_mesh_ignore_periodicity , 0. ,
+    "Ignore alignement of periodic boundaries when reading the mesh "
+    "(used by ParaView plugin)"},
 #if defined(HAVE_BLOSSOM)
   { F|O, "RecombinationAlgorithm" , opt_mesh_algo_recombine , 1 ,
 #else
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 8b0ac7c3c7..f46a3b78c1 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -6547,6 +6547,14 @@ double opt_mesh_preserve_numbering_msh2(OPT_ARGS_NUM)
   return CTX::instance()->mesh.preserveNumberingMsh2;
 }
 
+double opt_mesh_ignore_periodicity(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET)
+    CTX::instance()->mesh.ignorePeriodicity = (int) val;
+  return CTX::instance()->mesh.ignorePeriodicity;
+}
+
+
 double opt_solver_listen(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET)
diff --git a/Common/Options.h b/Common/Options.h
index f0555d2db9..e4c9568d86 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -541,6 +541,7 @@ double opt_mesh_partition_metis_edge_matching(OPT_ARGS_NUM);
 double opt_mesh_partition_metis_refine_algorithm(OPT_ARGS_NUM);
 double opt_mesh_clip(OPT_ARGS_NUM);
 double opt_mesh_ignore_part_bound(OPT_ARGS_NUM);
+double opt_mesh_ignore_periodicity(OPT_ARGS_NUM);
 double opt_mesh_preserve_numbering_msh2(OPT_ARGS_NUM);
 double opt_solver_listen(OPT_ARGS_NUM);
 double opt_solver_timeout(OPT_ARGS_NUM);
diff --git a/Geo/GModelIO_MSH2.cpp b/Geo/GModelIO_MSH2.cpp
index 304fc3cdb8..2ed71d51eb 100644
--- a/Geo/GModelIO_MSH2.cpp
+++ b/Geo/GModelIO_MSH2.cpp
@@ -719,7 +719,7 @@ int GModel::_readMSH2(const std::string &name)
 
   fclose(fp);
 
-  alignPeriodicBoundaries();
+  if(!CTX::instance()->mesh.ignorePeriodicity) alignPeriodicBoundaries();
 
   return postpro ? 2 : 1;
 }
diff --git a/doc/texinfo/opt_mesh.texi b/doc/texinfo/opt_mesh.texi
index 0ba66946b0..0174e07b41 100644
--- a/doc/texinfo/opt_mesh.texi
+++ b/doc/texinfo/opt_mesh.texi
@@ -524,6 +524,11 @@ Preserve element numbering in MSH2 format (will break meshes with multiple physi
 Default value: @code{0}@*
 Saved in: @code{General.OptionsFileName}
 
+@item Mesh.IgnorePeriodicity
+Ignore alignement of periodic boundaries when reading the mesh (used by ParaView plugin)@*
+Default value: @code{0}@*
+Saved in: @code{General.OptionsFileName}
+
 @item Mesh.RecombinationAlgorithm
 Mesh recombination algorithm (0=standard, 1=blossom)@*
 Default value: @code{1}@*
-- 
GitLab