From 1520b375fdf727f7ccdb19878bfc1b62d6603d48 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Wed, 18 Jul 2018 12:00:37 +0200
Subject: [PATCH] Get ride of max subitem per item constants

- m_max_nb_node_per_cell
- m_max_nb_face_per_cell
- m_max_nb_node_per_face

Data structures tend to be more unstructured
---
 src/mesh/Connectivity1D.hpp    |  8 -------
 src/mesh/Connectivity2D.hpp    | 44 ++++++++++++++--------------------
 src/mesh/Connectivity3D.hpp    | 28 +---------------------
 src/mesh/ConnectivityUtils.hpp |  8 -------
 src/mesh/MeshData.hpp          |  3 ++-
 5 files changed, 21 insertions(+), 70 deletions(-)

diff --git a/src/mesh/Connectivity1D.hpp b/src/mesh/Connectivity1D.hpp
index 9b9e11842..cc05b3f8e 100644
--- a/src/mesh/Connectivity1D.hpp
+++ b/src/mesh/Connectivity1D.hpp
@@ -31,8 +31,6 @@ private:
 
   Kokkos::View<double*> m_inv_cell_nb_nodes;
 
-  size_t m_max_nb_node_per_cell;
-
   std::vector<std::vector<unsigned int>>
   _buildConnectivity(const size_t& number_of_cells)
   {
@@ -70,11 +68,6 @@ public:
     return m_cell_to_node_matrix.numRows();
   }
 
-  const size_t& maxNbNodePerCell() const
-  {
-    return m_max_nb_node_per_cell;
-  }
-
   const Kokkos::View<const double*> invCellNbNodes() const
   {
     return m_inv_cell_nb_nodes;
@@ -122,7 +115,6 @@ public:
 
     ConnectivityUtils utils;
     utils.computeNodeCellConnectivity(m_cell_to_node_matrix,
-                                      m_max_nb_node_per_cell,
                                       m_node_to_cell_matrix,
                                       m_node_to_cell_local_node_matrix);
   }
diff --git a/src/mesh/Connectivity2D.hpp b/src/mesh/Connectivity2D.hpp
index 99d313fd1..2714379f5 100644
--- a/src/mesh/Connectivity2D.hpp
+++ b/src/mesh/Connectivity2D.hpp
@@ -42,8 +42,6 @@ class Connectivity2D
   Kokkos::View<unsigned short**> m_face_cell_local_face;
   Kokkos::View<unsigned short**> m_face_node_local_face;
 
-  size_t  m_max_nb_node_per_cell;
-
   struct Face
   {
     const unsigned int m_node0_id;
@@ -125,20 +123,20 @@ class Connectivity2D
           = Kokkos::create_staticcrsgraph<ConnectivityMatrix>("face_to_cell_matrix", face_to_cell_vector);
     }
 
-    Kokkos::View<unsigned short**> face_cell_local_face("face_cell_local_face",
-                                                        face_cells_map.size(), m_max_nb_node_per_cell);
-    {
-      int l=0;
-      for (const auto& face_cells_vector : face_cells_map) {
-        const auto& cells_vector = face_cells_vector.second;
-        for (unsigned short lj=0; lj<cells_vector.size(); ++lj) {
-          unsigned short cell_local_face = cells_vector[lj].second;
-          face_cell_local_face(l,lj) = cell_local_face;
-        }
-        ++l;
-      }
-    }
-    m_face_cell_local_face = face_cell_local_face;
+    // Kokkos::View<unsigned short**> face_cell_local_face("face_cell_local_face",
+    //                                                     face_cells_map.size(), m_max_nb_node_per_cell);
+    // {
+    //   int l=0;
+    //   for (const auto& face_cells_vector : face_cells_map) {
+    //     const auto& cells_vector = face_cells_vector.second;
+    //     for (unsigned short lj=0; lj<cells_vector.size(); ++lj) {
+    //       unsigned short cell_local_face = cells_vector[lj].second;
+    //       face_cell_local_face(l,lj) = cell_local_face;
+    //     }
+    //     ++l;
+    //   }
+    // }
+    // m_face_cell_local_face = face_cell_local_face;
   }
 
  public:
@@ -190,20 +188,15 @@ class Connectivity2D
     return m_cell_to_node_matrix.numRows();
   }
 
-  const size_t& maxNbNodePerCell() const
-  {
-    return m_max_nb_node_per_cell;
-  }
-
   const Kokkos::View<const double*> invCellNbNodes() const
   {
     return m_inv_cell_nb_nodes;
   }
 
-  const Kokkos::View<const unsigned short**> faceCellLocalFace() const
-  {
-    return m_face_cell_local_face;
-  }
+  // const Kokkos::View<const unsigned short**> faceCellLocalFace() const
+  // {
+  //   return m_face_cell_local_face;
+  // }
 
   unsigned int getFaceNumber(const unsigned int node0_id,
                              const unsigned int node1_id) const
@@ -260,7 +253,6 @@ class Connectivity2D
 
     ConnectivityUtils utils;
     utils.computeNodeCellConnectivity(m_cell_to_node_matrix,
-                                      m_max_nb_node_per_cell,
                                       m_node_to_cell_matrix,
                                       m_node_to_cell_local_node_matrix);
 
diff --git a/src/mesh/Connectivity3D.hpp b/src/mesh/Connectivity3D.hpp
index 9e6afd7b2..e57d9234a 100644
--- a/src/mesh/Connectivity3D.hpp
+++ b/src/mesh/Connectivity3D.hpp
@@ -35,6 +35,7 @@ public:
   ConnectivityMatrixShort m_node_to_cell_local_node_matrix;
 
   // Stores numbering of nodes of each cell.
+  // gives an id to each node of each cell. (j,r) -> id
   //
   // This is different from m_cell_to_node_matrix which return the global id of
   // a local node in a cell
@@ -49,10 +50,6 @@ private:
   Kokkos::View<const unsigned short*> m_node_nb_faces;
   Kokkos::View<const unsigned int**> m_node_faces;
 
-  size_t m_max_nb_node_per_cell;
-  size_t m_max_nb_face_per_cell;
-  size_t m_max_nb_node_per_face;
-
   class Face
   {
    public:
@@ -255,8 +252,6 @@ private:
         }
       }
     }
-    std::cerr << __FILE__ << ':' << __LINE__ << ':'
-              << rang::fg::red << " m_max_nb_node_per_face forced to 4" << rang::fg::reset << '\n';
 
     {
       std::vector<std::vector<unsigned int>> face_to_node_vector(face_cells_map.size());
@@ -270,7 +265,6 @@ private:
           = Kokkos::create_staticcrsgraph<ConnectivityMatrix>("face_to_node_matrix", face_to_node_vector);
     }
 
-    m_max_nb_node_per_face = 4;
     {
       int l=0;
       for (const auto& face_cells_vector : face_cells_map) {
@@ -335,10 +329,6 @@ private:
           = Kokkos::create_staticcrsgraph<ConnectivityMatrix>("cell_to_face_matrix", cell_to_face_vector);
     }
 
-    std::cerr << __FILE__ << ':' << __LINE__ << ':'
-              << rang::fg::red << " m_max_nb_face_per_cell forced to 6" << rang::fg::reset << '\n';
-    m_max_nb_face_per_cell = 6;
-
     {
       std::vector<std::vector<unsigned short>> cell_to_face_is_reversed_vector(this->numberOfCells());
       for (size_t j=0; j<cell_to_face_is_reversed_vector.size(); ++j) {
@@ -435,21 +425,6 @@ private:
     return m_cell_to_node_matrix.numRows();
   }
 
-  const size_t& maxNbFacePerCell() const
-  {
-    return m_max_nb_face_per_cell;
-  }
-
-  const size_t& maxNbNodePerCell() const
-  {
-    return m_max_nb_node_per_cell;
-  }
-
-  const size_t& maxNbNodePerFace() const
-  {
-    return m_max_nb_node_per_face;
-  }
-
   const Kokkos::View<const double*> invCellNbNodes() const
   {
     return m_inv_cell_nb_nodes;
@@ -503,7 +478,6 @@ private:
 
     ConnectivityUtils utils;
     utils.computeNodeCellConnectivity(m_cell_to_node_matrix,
-                                      m_max_nb_node_per_cell,
                                       m_node_to_cell_matrix,
                                       m_node_to_cell_local_node_matrix);
 
diff --git a/src/mesh/ConnectivityUtils.hpp b/src/mesh/ConnectivityUtils.hpp
index f99e2b176..d6e4b7527 100644
--- a/src/mesh/ConnectivityUtils.hpp
+++ b/src/mesh/ConnectivityUtils.hpp
@@ -13,19 +13,11 @@ class ConnectivityUtils
 {
  public:
   void computeNodeCellConnectivity(const ConnectivityMatrix& cell_to_node_matrix,
-                                   size_t& max_nb_node_per_cell,
                                    ConnectivityMatrix& node_to_cell_matrix,
                                    ConnectivityMatrixShort& node_to_cell_local_node_matrix)
   {
     std::map<unsigned int, std::vector<unsigned int>> node_cells_map;
     const size_t& number_of_cells = cell_to_node_matrix.numRows();
-    using namespace Kokkos::Experimental;
-    Kokkos::parallel_reduce(number_of_cells, KOKKOS_LAMBDA(const int& j, size_t& nb_max) {
-        const auto& cell_nodes = cell_to_node_matrix.rowConst(j);
-
-        const size_t n = cell_nodes.length;
-        if (n > nb_max) nb_max = n;
-      }, Kokkos::Max<size_t>(max_nb_node_per_cell));
 
     for (unsigned int j=0; j<number_of_cells; ++j) {
       const auto& cell_nodes = cell_to_node_matrix.rowConst(j);
diff --git a/src/mesh/MeshData.hpp b/src/mesh/MeshData.hpp
index 5e0aa268f..6b600e4aa 100644
--- a/src/mesh/MeshData.hpp
+++ b/src/mesh/MeshData.hpp
@@ -101,7 +101,8 @@ private:
     } else if (dimension ==3) {
       const Kokkos::View<const Rd*> xr = m_mesh.xr();
 
-      Kokkos::View<Rd**> Nlr("Nlr", m_mesh.connectivity().numberOfFaces(), m_mesh.connectivity().maxNbNodePerFace());
+#warning Rewrite using better data structures and remove this explicit 4
+      Kokkos::View<Rd**> Nlr("Nlr", m_mesh.connectivity().numberOfFaces(), 4);
 
       Kokkos::parallel_for(m_mesh.numberOfFaces(), KOKKOS_LAMBDA(const int& l) {
           const auto& face_nodes = m_mesh.connectivity().m_face_to_node_matrix.rowConst(l);
-- 
GitLab