From 39f9d1e46d0417d7c0db35ddd2d2c61efb34e16e Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Thu, 19 Jul 2018 19:03:44 +0200
Subject: [PATCH] Get node_id_per_cell_vector using connectivity object

Tried to get values from a specialized access function according to the type of
items but does not always compile depending on the placement of the called
function.
If the template function call is operated into the connectivity class,
everything works like a charm, but using it outside leads to weird compilation
issue. Is it a compiler issue?
---
 src/mesh/Connectivity1D.hpp        |  8 +++++++-
 src/mesh/Connectivity2D.hpp        |  6 ++++++
 src/mesh/Connectivity3D.hpp        |  6 ++++++
 src/mesh/MeshData.hpp              |  6 +++---
 src/mesh/TypeOfItem.hpp            | 11 +++++++++++
 src/scheme/AcousticSolver.hpp      |  4 ++--
 src/scheme/SubItemValuePerItem.hpp | 15 +++++----------
 7 files changed, 40 insertions(+), 16 deletions(-)
 create mode 100644 src/mesh/TypeOfItem.hpp

diff --git a/src/mesh/Connectivity1D.hpp b/src/mesh/Connectivity1D.hpp
index cc05b3f8e..51ca51a76 100644
--- a/src/mesh/Connectivity1D.hpp
+++ b/src/mesh/Connectivity1D.hpp
@@ -7,6 +7,7 @@
 #include <TinyVector.hpp>
 #include <ConnectivityUtils.hpp>
 
+#include <TypeOfItem.hpp>
 #include <RefId.hpp>
 #include <RefNodeList.hpp>
 
@@ -26,7 +27,12 @@ public:
   // a local node in a cell
   ConnectivityMatrix m_node_id_per_cell_matrix;
 
-private:
+  ConnectivityMatrix subItemIdPerItemMatrix() const
+  {
+    return m_node_id_per_cell_matrix;
+  }
+
+ private:
   std::vector<RefNodeList> m_ref_node_list;
 
   Kokkos::View<double*> m_inv_cell_nb_nodes;
diff --git a/src/mesh/Connectivity2D.hpp b/src/mesh/Connectivity2D.hpp
index 2714379f5..b7f2412ff 100644
--- a/src/mesh/Connectivity2D.hpp
+++ b/src/mesh/Connectivity2D.hpp
@@ -10,6 +10,7 @@
 #include <map>
 #include <algorithm>
 
+#include <TypeOfItem.hpp>
 #include <RefId.hpp>
 #include <RefNodeList.hpp>
 #include <RefFaceList.hpp>
@@ -33,6 +34,11 @@ class Connectivity2D
   // a local node in a cell
   ConnectivityMatrix m_node_id_per_cell_matrix;
 
+  inline ConnectivityMatrix subItemIdPerItemMatrix() const
+  {
+    return m_node_id_per_cell_matrix;
+  }
+
  private:
   std::vector<RefFaceList> m_ref_face_list;
   std::vector<RefNodeList> m_ref_node_list;
diff --git a/src/mesh/Connectivity3D.hpp b/src/mesh/Connectivity3D.hpp
index e57d9234a..0eb1c6318 100644
--- a/src/mesh/Connectivity3D.hpp
+++ b/src/mesh/Connectivity3D.hpp
@@ -12,6 +12,7 @@
 #include <algorithm>
 
 #include <RefId.hpp>
+#include <TypeOfItem.hpp>
 #include <RefNodeList.hpp>
 #include <RefFaceList.hpp>
 
@@ -41,6 +42,11 @@ public:
   // a local node in a cell
   ConnectivityMatrix m_node_id_per_cell_matrix;
 
+  inline ConnectivityMatrix subItemIdPerItemMatrix() const
+  {
+    return m_node_id_per_cell_matrix;
+  }
+
 private:
   std::vector<RefFaceList> m_ref_face_list;
   std::vector<RefNodeList> m_ref_node_list;
diff --git a/src/mesh/MeshData.hpp b/src/mesh/MeshData.hpp
index c8cef0b7a..09278a77f 100644
--- a/src/mesh/MeshData.hpp
+++ b/src/mesh/MeshData.hpp
@@ -203,9 +203,9 @@ class MeshData
 
   MeshData(const MeshType& mesh)
       : m_mesh(mesh),
-        m_Cjr(mesh.connectivity().m_node_id_per_cell_matrix),
-        m_ljr(mesh.connectivity().m_node_id_per_cell_matrix),
-        m_njr(mesh.connectivity().m_node_id_per_cell_matrix),
+        m_Cjr(mesh.connectivity()),
+        m_ljr(mesh.connectivity()),
+        m_njr(mesh.connectivity()),
         m_xj("xj", mesh.numberOfCells()),
         m_Vj("Vj", mesh.numberOfCells())
   {
diff --git a/src/mesh/TypeOfItem.hpp b/src/mesh/TypeOfItem.hpp
new file mode 100644
index 000000000..4b1b7d6a0
--- /dev/null
+++ b/src/mesh/TypeOfItem.hpp
@@ -0,0 +1,11 @@
+#ifndef TYPE_OF_ITEM_HPP
+#define TYPE_OF_ITEM_HPP
+
+enum class TypeOfItem {
+  node = 0,
+  edge = 1,
+  face = 2,
+  cell = 3
+};
+
+#endif // TYPE_OF_ITEM_HPP
diff --git a/src/scheme/AcousticSolver.hpp b/src/scheme/AcousticSolver.hpp
index f23dce1c6..6f1b9256a 100644
--- a/src/scheme/AcousticSolver.hpp
+++ b/src/scheme/AcousticSolver.hpp
@@ -255,10 +255,10 @@ class AcousticSolver
         m_connectivity(m_mesh.connectivity()),
         m_boundary_condition_list(bc_list),
         m_br("br", m_mesh.numberOfNodes()),
-        m_Ajr(m_connectivity.m_node_id_per_cell_matrix),
+        m_Ajr(m_connectivity),
         m_Ar("Ar", m_mesh.numberOfNodes()),
         m_inv_Ar("inv_Ar", m_mesh.numberOfNodes()),
-        m_Fjr(m_connectivity.m_node_id_per_cell_matrix),
+        m_Fjr(m_connectivity),
         m_ur("ur", m_mesh.numberOfNodes()),
         m_rhocj("rho_c", m_mesh.numberOfCells()),
         m_Vj_over_cj("Vj_over_cj", m_mesh.numberOfCells())
diff --git a/src/scheme/SubItemValuePerItem.hpp b/src/scheme/SubItemValuePerItem.hpp
index f185b519a..225001939 100644
--- a/src/scheme/SubItemValuePerItem.hpp
+++ b/src/scheme/SubItemValuePerItem.hpp
@@ -2,18 +2,12 @@
 #define SUBITEM_VALUE_PER_ITEM_HPP
 
 #include <Kokkos_StaticCrsGraph.hpp>
+#include <TypeOfItem.hpp>
 
 #warning should not stand in the scheme directory
 
 typedef Kokkos::StaticCrsGraph<unsigned int, Kokkos::HostSpace> ConnectivityMatrix;
 
-enum class TypeOfItem {
-  node,
-  edge,
-  face,
-  cell
-};
-
 template <typename DataType,
           TypeOfItem SubItemType,
           TypeOfItem ItemType>
@@ -166,8 +160,10 @@ class SubItemValuePerItem
   }
 
   SubItemValuePerItem() = default;
-  SubItemValuePerItem(const ConnectivityMatrix& subitem_id_per_item_matrix)
-      : m_subitem_id_per_item_matrix(subitem_id_per_item_matrix),
+
+  template <typename ConnectivityType>
+  SubItemValuePerItem(const ConnectivityType& connectivity)
+      : m_subitem_id_per_item_matrix(connectivity.subItemIdPerItemMatrix()),
         m_values("values", m_subitem_id_per_item_matrix.entries.extent(0))
   {
     ;
@@ -176,7 +172,6 @@ class SubItemValuePerItem
   ~SubItemValuePerItem() = default;
 };
 
-
 template <typename DataType>
 using NodeValuePerCell = SubItemValuePerItem<DataType, TypeOfItem::node, TypeOfItem::cell>;
 
-- 
GitLab