From 2a97982cf69b31d76d57cbdac204b7fc77d04087 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Wed, 1 Aug 2018 15:10:15 +0200
Subject: [PATCH] Define NodeValuePerFace

Also removed SubItemValuePerItem::SubViewConst to conform to Kokkos policy
One should allow constructions as SubItemValuePerItem<IT0, IT2, const DT>
following Kokkos
---
 src/mesh/Connectivity.hpp         | 30 +++++++++++++++++
 src/mesh/ConnectivityComputer.hpp |  6 ++--
 src/mesh/SubItemValuePerItem.hpp  | 55 ++++++++-----------------------
 3 files changed, 47 insertions(+), 44 deletions(-)

diff --git a/src/mesh/Connectivity.hpp b/src/mesh/Connectivity.hpp
index b02da8ac7..62710a761 100644
--- a/src/mesh/Connectivity.hpp
+++ b/src/mesh/Connectivity.hpp
@@ -403,6 +403,14 @@ Connectivity<3>::itemToItemMatrix<TypeOfItem::face,
 {
   return m_face_to_cell_matrix;
 }
+template <>
+template <>
+inline const ConnectivityMatrix&
+Connectivity<3>::itemToItemMatrix<TypeOfItem::face,
+                                  TypeOfItem::node>() const
+{
+  return m_face_to_node_matrix;
+}
 
 template <>
 template <>
@@ -443,6 +451,15 @@ Connectivity<2>::itemToItemMatrix<TypeOfItem::face,
   return m_face_to_cell_matrix;
 }
 
+template <>
+template <>
+inline const ConnectivityMatrix&
+Connectivity<2>::itemToItemMatrix<TypeOfItem::face,
+                                  TypeOfItem::node>() const
+{
+  return m_face_to_node_matrix;
+}
+
 template <>
 template <>
 inline const ConnectivityMatrix&
@@ -483,6 +500,16 @@ Connectivity<1>::itemToItemMatrix<TypeOfItem::face,
   return m_face_to_cell_matrix;
 }
 
+template <>
+template <>
+inline const ConnectivityMatrix&
+Connectivity<1>::itemToItemMatrix<TypeOfItem::face,
+                                  TypeOfItem::node>() const
+{
+#warning in 1d, faces and node are the same
+  return m_face_to_node_matrix;
+}
+
 template <>
 template <>
 inline const ConnectivityMatrix&
@@ -519,6 +546,9 @@ itemToItemMatrix(const TypeOfItem& item_type_0,
         case TypeOfItem::cell: {
           return itemToItemMatrix<TypeOfItem::face, TypeOfItem::cell>();
         }
+        case TypeOfItem::node: {
+          return itemToItemMatrix<TypeOfItem::face, TypeOfItem::node>();
+        }
         default: {
           std::cerr << __FILE__ << ":" << __LINE__ << ": NIY " << int(item_type_1) << "\n";
           std::exit(1);
diff --git a/src/mesh/ConnectivityComputer.hpp b/src/mesh/ConnectivityComputer.hpp
index d10a5652c..f8e2e31bb 100644
--- a/src/mesh/ConnectivityComputer.hpp
+++ b/src/mesh/ConnectivityComputer.hpp
@@ -13,9 +13,9 @@ struct ConnectivityComputer
                                          const ConnectivityMatrix& child_item_to_items_matrix,
                                          CellValuePerNode<unsigned short>&  child_item_number_in_item_matrix) const;
 
-    void computeLocalChildItemNumberInItem(const ConnectivityMatrix& item_to_child_items_matrix,
-                                           const ConnectivityMatrix& child_item_to_items_matrix,
-                                           NodeValuePerCell<unsigned short>&  child_item_number_in_item_matrix) const;
+  void computeLocalChildItemNumberInItem(const ConnectivityMatrix& item_to_child_items_matrix,
+                                         const ConnectivityMatrix& child_item_to_items_matrix,
+                                         NodeValuePerCell<unsigned short>&  child_item_number_in_item_matrix) const;
 
   void computeLocalChildItemNumberInItem(const ConnectivityMatrix& item_to_child_items_matrix,
                                          const ConnectivityMatrix& child_item_to_items_matrix,
diff --git a/src/mesh/SubItemValuePerItem.hpp b/src/mesh/SubItemValuePerItem.hpp
index 3f0c9951e..a8016d0a5 100644
--- a/src/mesh/SubItemValuePerItem.hpp
+++ b/src/mesh/SubItemValuePerItem.hpp
@@ -61,42 +61,6 @@ class SubItemValuePerItem
     }
   };
 
-  class SubViewConst
-  {
-   private:
-    KOKKOS_RESTRICT const DataType* const m_sub_values;
-    const size_t m_size;
-   public:
-    KOKKOS_FORCEINLINE_FUNCTION
-    const DataType& operator[](const size_t& i) const
-    {
-      Assert(i<m_size);
-      return m_sub_values[i];
-    }
-
-    KOKKOS_INLINE_FUNCTION
-    const size_t& size() const
-    {
-      return m_size;
-    }
-
-    SubViewConst(const SubViewConst&) = delete;
-
-    KOKKOS_INLINE_FUNCTION
-    SubViewConst(SubViewConst&&) = default;
-
-    KOKKOS_INLINE_FUNCTION
-    SubViewConst(const Kokkos::View<DataType*>& values,
-                 const size_t& begin,
-                 const size_t& end)
-        : m_sub_values(&(values[begin])),
-          m_size(end-begin)
-    {
-      Assert(begin<=end);
-      Assert(end<=values.extent(0));
-    }
-  };
-
   SubItemValuePerItem& operator=(const SubItemValuePerItem&) = default;
 
   KOKKOS_FORCEINLINE_FUNCTION
@@ -105,8 +69,10 @@ class SubItemValuePerItem
     return m_values[m_host_row_map(j)+r];
   }
 
+  // Following Kokkos logic, these classes are view and const view does allow
+  // changes in data
   KOKKOS_FORCEINLINE_FUNCTION
-  const DataType& operator()(const size_t& j, const size_t& r) const
+  DataType& operator()(const size_t& j, const size_t& r) const
   {
     return m_values[m_host_row_map(j)+r];
   }
@@ -123,8 +89,10 @@ class SubItemValuePerItem
     return m_values[i];
   }
 
+  // Following Kokkos logic, these classes are view and const view does allow
+  // changes in data
   KOKKOS_FORCEINLINE_FUNCTION
-  const DataType& operator[](const size_t & i) const
+  DataType& operator[](const size_t & i) const
   {
     return m_values[i];
   }
@@ -132,7 +100,7 @@ class SubItemValuePerItem
   KOKKOS_INLINE_FUNCTION
   size_t numberOfItems() const
   {
-    Assert(m_host_row_map.extent(0) != 0>0);
+    Assert(m_host_row_map.extent(0) != 0);
     return m_host_row_map.extent(0);
   }
 
@@ -150,12 +118,14 @@ class SubItemValuePerItem
     return SubView(m_values, cell_begin, cell_end);
   }
 
+  // Following Kokkos logic, these classes are view and const view does allow
+  // changes in data
   KOKKOS_INLINE_FUNCTION
-  SubViewConst itemValues(const size_t& i_cell) const
+  SubView itemValues(const size_t& i_cell) const
   {
     const auto& cell_begin = m_host_row_map(i_cell);
     const auto& cell_end = m_host_row_map(i_cell+1);
-    return SubViewConst(m_values, cell_begin, cell_end);
+    return SubView(m_values, cell_begin, cell_end);
   }
 
   SubItemValuePerItem() = default;
@@ -174,6 +144,9 @@ class SubItemValuePerItem
 template <typename DataType>
 using NodeValuePerCell = SubItemValuePerItem<DataType, TypeOfItem::node, TypeOfItem::cell>;
 
+template <typename DataType>
+using NodeValuePerFace = SubItemValuePerItem<DataType, TypeOfItem::node, TypeOfItem::face>;
+
 template <typename DataType>
 using FaceValuePerCell = SubItemValuePerItem<DataType, TypeOfItem::face, TypeOfItem::cell>;
 
-- 
GitLab