From 731b46e0c9d0ccb59d8078f6ba4c0566397f1123 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Mon, 11 Feb 2019 10:34:17 +0100
Subject: [PATCH] Fix parallel normal calculation in 1D

---
 src/mesh/MeshNodeBoundary.hpp | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/mesh/MeshNodeBoundary.hpp b/src/mesh/MeshNodeBoundary.hpp
index 45173f020..dbb3f6fec 100644
--- a/src/mesh/MeshNodeBoundary.hpp
+++ b/src/mesh/MeshNodeBoundary.hpp
@@ -374,23 +374,36 @@ _getOutgoingNormal(const MeshType& mesh)
 
   const R normal = this->_getNormal(mesh);
 
-  const NodeValue<const R>& xr = mesh.xr();
-  const auto& cell_to_node_matrix
-      = mesh.connectivity().cellToNodeMatrix();
+  double max_height = 0;
 
-  const auto& node_to_cell_matrix
-      = mesh.connectivity().nodeToCellMatrix();
+  if (m_node_list.size()>0) {
+    const NodeValue<const R>& xr = mesh.xr();
+    const auto& cell_to_node_matrix
+        = mesh.connectivity().cellToNodeMatrix();
 
-  const NodeId r0 = m_node_list[0];
-  const CellId j0 = node_to_cell_matrix[r0][0];
-  const auto& j0_nodes = cell_to_node_matrix[j0];
-  double max_height = 0;
-  for (size_t r=0; r<j0_nodes.size(); ++r) {
-    const double height = (xr[j0_nodes[r]]-xr[r0], normal);
+    const auto& node_to_cell_matrix
+        = mesh.connectivity().nodeToCellMatrix();
+
+    const NodeId r0 = m_node_list[0];
+    const CellId j0 = node_to_cell_matrix[r0][0];
+    const auto& j0_nodes = cell_to_node_matrix[j0];
+
+    for (size_t r=0; r<j0_nodes.size(); ++r) {
+      const double height = (xr[j0_nodes[r]]-xr[r0], normal);
+      if (std::abs(height) > std::abs(max_height)) {
+        max_height = height;
+      }
+    }
+  }
+
+  Array<double> max_height_array = parallel::allGather(max_height);
+  for (size_t i=0; i<max_height_array.size(); ++i) {
+    const double height = max_height_array[i];
     if (std::abs(height) > std::abs(max_height)) {
       max_height = height;
     }
   }
+
   if (max_height > 0) {
     return -normal;
   } else {
-- 
GitLab