From 5ba73bfb533b2d226c98622f895711fd38f56697 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Mon, 11 Feb 2019 17:55:07 +0100
Subject: [PATCH] Add {item}IsOwned mechanism

This is based on ItemValue<const bool>, a refinement could be to build this
information on demand.
---
 src/mesh/Connectivity.cpp | 30 ++++++++++++++++++++++++++++++
 src/mesh/Connectivity.hpp | 24 +++++++++++++++++++++++-
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/src/mesh/Connectivity.cpp b/src/mesh/Connectivity.cpp
index 71f1d1c2d..b5ff6b825 100644
--- a/src/mesh/Connectivity.cpp
+++ b/src/mesh/Connectivity.cpp
@@ -1,6 +1,8 @@
 #include <Connectivity.hpp>
 #include <map>
 
+#include <Messenger.hpp>
+
 
 template<size_t Dimension>
 Connectivity<Dimension>::
@@ -66,12 +68,30 @@ Connectivity(const ConnectivityDescriptor& descriptor)
     m_cell_owner = cell_owner;
   }
 
+  {
+    const int rank = parallel::rank();
+    CellValue<bool> cell_is_owned(*this);
+    parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j) {
+        cell_is_owned[j] = (m_cell_owner[j] == rank);
+      });
+    m_cell_is_owned = cell_is_owned;
+  }
+
   {
     NodeValue<int> node_owner(*this);
     node_owner = convert_to_array(descriptor.node_owner_vector);
     m_node_owner = node_owner;
   }
 
+  {
+    const int rank = parallel::rank();
+    NodeValue<bool> node_is_owned(*this);
+    parallel_for(this->numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) {
+        node_is_owned[r] = (m_node_owner[r] == rank);
+      });
+    m_node_is_owned = node_is_owned;
+  }
+
   if constexpr (Dimension>1) {
     auto& face_to_node_matrix
         = m_item_to_item_matrix[itemTId(ItemType::face)][itemTId(ItemType::node)];
@@ -103,6 +123,16 @@ Connectivity(const ConnectivityDescriptor& descriptor)
       m_face_owner = face_owner;
     }
 
+    {
+      const int rank = parallel::rank();
+      FaceValue<bool> face_is_owned(*this);
+      parallel_for(this->numberOfFaces(), PASTIS_LAMBDA(const FaceId& l) {
+          face_is_owned[l] = (m_face_owner[l] == rank);
+        });
+      m_face_is_owned = face_is_owned;
+    }
+
+
     m_ref_face_list = descriptor.refFaceList();
   }
 }
diff --git a/src/mesh/Connectivity.hpp b/src/mesh/Connectivity.hpp
index fea77ee29..335689a34 100644
--- a/src/mesh/Connectivity.hpp
+++ b/src/mesh/Connectivity.hpp
@@ -104,9 +104,13 @@ class Connectivity final
   NodeValue<const int> m_node_number;
 
   CellValue<const int> m_cell_owner;
+  CellValue<const bool> m_cell_is_owned;
+
   FaceValue<const int> m_face_owner;
-#warning Missing EdgeValue<const int> m_edge_owner;
+  FaceValue<const bool> m_face_is_owned;
+#warning Missing EdgeValue<const int> m_edge_owner and m_edge_is_owned;
   NodeValue<const int> m_node_owner;
+  NodeValue<const bool> m_node_is_owned;
 
   FaceValuePerCell<const bool> m_cell_face_is_reversed;
 
@@ -215,6 +219,24 @@ class Connectivity final
     return m_node_owner;
   }
 
+  PASTIS_INLINE
+  const CellValue<const bool>& cellIsOwned() const
+  {
+    return m_cell_is_owned;
+  }
+
+  PASTIS_INLINE
+  const FaceValue<const bool>& faceIsOwned() const
+  {
+    return m_face_is_owned;
+  }
+
+  PASTIS_INLINE
+  const NodeValue<const bool>& nodeIsOwned() const
+  {
+    return m_node_is_owned;
+  }
+
   PASTIS_INLINE
   const bool& isConnectivityMatrixBuilt(const ItemType& item_type_0,
                                         const ItemType& item_type_1) const
-- 
GitLab