From 144452739926f4eff30ffb95ece2369645d27baa Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Thu, 2 Aug 2018 10:42:32 +0200 Subject: [PATCH] Use m_item_to_item_matrix instead of m_node_to_cell_matrix --- src/mesh/Connectivity.hpp | 39 ++++++++++++++++++++++++++--------- src/mesh/MeshNodeBoundary.hpp | 10 +++++---- src/mesh/TypeOfItem.hpp | 6 +++--- src/scheme/AcousticSolver.hpp | 8 +++++-- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/mesh/Connectivity.hpp b/src/mesh/Connectivity.hpp index 931482a5f..99845abc1 100644 --- a/src/mesh/Connectivity.hpp +++ b/src/mesh/Connectivity.hpp @@ -231,11 +231,18 @@ class Connectivity final static constexpr size_t dimension = Dimension; public: + KOKKOS_INLINE_FUNCTION ConnectivityMatrix cellToNodeMatrix() const { return m_item_to_item_matrix[itemId(TypeOfItem::cell)][itemId(TypeOfItem::node)]; } + KOKKOS_INLINE_FUNCTION + ConnectivityMatrix nodeToCellMatrix() const + { + return m_item_to_item_matrix[itemId(TypeOfItem::node)][itemId(TypeOfItem::cell)]; + } + NodeValuePerCell<unsigned short> m_cell_to_node_local_cell; ConnectivityMatrix m_cell_to_face_matrix; @@ -245,18 +252,17 @@ class Connectivity final CellValuePerFace<unsigned short> m_face_to_cell_local_face; ConnectivityMatrix m_face_to_node_matrix; - ConnectivityMatrix m_node_to_cell_matrix; CellValuePerNode<unsigned short> m_node_to_cell_local_node; template <TypeOfItem SubItemType, TypeOfItem ItemType> const ConnectivityMatrix& itemToItemMatrix() const = delete; + KOKKOS_INLINE_FUNCTION const ConnectivityMatrix& itemToItemMatrix(const TypeOfItem& item_type_0, const TypeOfItem& item_type_1) const final; private: - ConnectivityMatrix m_item_to_item_matrix[Dimension+1][Dimension+1]; ConnectivityComputer m_connectivity_computer; @@ -309,7 +315,9 @@ private: KOKKOS_INLINE_FUNCTION size_t numberOfNodes() const { - return m_node_to_cell_matrix.numRows(); + const auto& node_to_cell_matrix + = m_item_to_item_matrix[itemId(TypeOfItem::node)][itemId(TypeOfItem::cell)]; + return node_to_cell_matrix.numRows(); } KOKKOS_INLINE_FUNCTION @@ -362,18 +370,21 @@ private: m_inv_cell_nb_nodes = inv_cell_nb_nodes; } + auto& node_to_cell_matrix + = m_item_to_item_matrix[itemId(TypeOfItem::node)][itemId(TypeOfItem::cell)]; + m_connectivity_computer.computeInverseConnectivityMatrix(cell_to_node_matrix, - m_node_to_cell_matrix); + node_to_cell_matrix); m_node_to_cell_local_node = CellValuePerNode<unsigned short>(*this); m_connectivity_computer.computeLocalChildItemNumberInItem(cell_to_node_matrix, - m_node_to_cell_matrix, + node_to_cell_matrix, m_node_to_cell_local_node); m_cell_to_node_local_cell = NodeValuePerCell<unsigned short>(*this); - m_connectivity_computer.computeLocalChildItemNumberInItem(m_node_to_cell_matrix, + m_connectivity_computer.computeLocalChildItemNumberInItem(node_to_cell_matrix, cell_to_node_matrix, m_cell_to_node_local_cell); if constexpr (Dimension>1) { @@ -434,7 +445,10 @@ inline const ConnectivityMatrix& Connectivity<3>::itemToItemMatrix<TypeOfItem::node, TypeOfItem::cell>() const { - return m_node_to_cell_matrix; + const auto& node_to_cell_matrix + = m_item_to_item_matrix[itemId(TypeOfItem::node)][itemId(TypeOfItem::cell)]; + + return node_to_cell_matrix; } @@ -485,7 +499,10 @@ inline const ConnectivityMatrix& Connectivity<2>::itemToItemMatrix<TypeOfItem::node, TypeOfItem::cell>() const { - return m_node_to_cell_matrix; + const auto& node_to_cell_matrix + = m_item_to_item_matrix[itemId(TypeOfItem::node)][itemId(TypeOfItem::cell)]; + + return node_to_cell_matrix; } using Connectivity1D = Connectivity<1>; @@ -538,8 +555,10 @@ inline const ConnectivityMatrix& Connectivity<1>::itemToItemMatrix<TypeOfItem::node, TypeOfItem::cell>() const { -#warning in 1d, faces and node are the same - return m_node_to_cell_matrix; + const auto& node_to_cell_matrix + = m_item_to_item_matrix[itemId(TypeOfItem::node)][itemId(TypeOfItem::cell)]; + + return node_to_cell_matrix; } template <size_t Dimension> diff --git a/src/mesh/MeshNodeBoundary.hpp b/src/mesh/MeshNodeBoundary.hpp index a2b70d07c..37821696b 100644 --- a/src/mesh/MeshNodeBoundary.hpp +++ b/src/mesh/MeshNodeBoundary.hpp @@ -307,9 +307,9 @@ _getOutgoingNormal(const MeshType& mesh) const Kokkos::View<const R*>& xr = mesh.xr(); const auto& cell_to_node_matrix = mesh.connectivity().cellToNodeMatrix(); - + const auto& node_to_cell_matrix = mesh.connectivity().nodeToCellMatrix(); const size_t r0 = m_node_list[0]; - const size_t j0 = mesh.connectivity().m_node_to_cell_matrix.rowConst(r0)(0); + const size_t j0 = node_to_cell_matrix.rowConst(r0)(0); const auto& j0_nodes = cell_to_node_matrix.rowConst(j0); double max_height = 0; for (size_t r=0; r<j0_nodes.length; ++r) { @@ -338,9 +338,10 @@ _getOutgoingNormal(const MeshType& mesh) const Kokkos::View<const R2*>& xr = mesh.xr(); const auto& cell_to_node_matrix = mesh.connectivity().cellToNodeMatrix(); + const auto& node_to_cell_matrix = mesh.connectivity().nodeToCellMatrix(); const size_t r0 = m_node_list[0]; - const size_t j0 = mesh.connectivity().m_node_to_cell_matrix.rowConst(r0)(0); + const size_t j0 = node_to_cell_matrix.rowConst(r0)(0); const auto& j0_nodes = cell_to_node_matrix.rowConst(j0); double max_height = 0; for (size_t r=0; r<j0_nodes.length; ++r) { @@ -369,9 +370,10 @@ _getOutgoingNormal(const MeshType& mesh) const Kokkos::View<const R3*>& xr = mesh.xr(); const auto& cell_to_node_matrix = mesh.connectivity().cellToNodeMatrix(); + const auto& node_to_cell_matrix = mesh.connectivity().nodeToCellMatrix(); const size_t r0 = m_node_list[0]; - const size_t j0 = mesh.connectivity().m_node_to_cell_matrix.rowConst(r0)(0); + const size_t j0 = node_to_cell_matrix.rowConst(r0)(0); const auto& j0_nodes = cell_to_node_matrix.rowConst(j0); double max_height = 0; for (size_t r=0; r<j0_nodes.length; ++r) { diff --git a/src/mesh/TypeOfItem.hpp b/src/mesh/TypeOfItem.hpp index ccf4ef4f8..10ff8c168 100644 --- a/src/mesh/TypeOfItem.hpp +++ b/src/mesh/TypeOfItem.hpp @@ -16,7 +16,7 @@ struct ItemId {}; template <> struct ItemId<1> { - static constexpr size_t itemId(const TypeOfItem& item_type) { + inline static constexpr size_t itemId(const TypeOfItem& item_type) { switch(item_type) { case TypeOfItem::cell: { return 0; @@ -34,7 +34,7 @@ struct ItemId<1> template <> struct ItemId<2> { - static constexpr size_t itemId(const TypeOfItem& item_type) { + inline static constexpr size_t itemId(const TypeOfItem& item_type) { switch(item_type) { case TypeOfItem::cell: { return 0; @@ -54,7 +54,7 @@ struct ItemId<2> template <> struct ItemId<3> { - static constexpr size_t itemId(const TypeOfItem& item_type) { + inline static constexpr size_t itemId(const TypeOfItem& item_type) { switch(item_type) { case TypeOfItem::cell: { return 0; diff --git a/src/scheme/AcousticSolver.hpp b/src/scheme/AcousticSolver.hpp index 2ad5c7203..24953e541 100644 --- a/src/scheme/AcousticSolver.hpp +++ b/src/scheme/AcousticSolver.hpp @@ -98,9 +98,11 @@ class AcousticSolver KOKKOS_INLINE_FUNCTION const Kokkos::View<const Rdd*> computeAr(const NodeValuePerCell<Rdd>& Ajr) { + const auto& node_to_cell_matrix = m_connectivity.nodeToCellMatrix(); + Kokkos::parallel_for(m_mesh.numberOfNodes(), KOKKOS_LAMBDA(const int& r) { Rdd sum = zero; - const auto& node_to_cell = m_connectivity.m_node_to_cell_matrix.rowConst(r); + const auto& node_to_cell = node_to_cell_matrix.rowConst(r); const auto& node_to_cell_local_node = m_connectivity.m_node_to_cell_local_node.itemValues(r); for (size_t j=0; j<node_to_cell.length; ++j) { const unsigned int J = node_to_cell(j); @@ -119,10 +121,12 @@ class AcousticSolver const NodeValuePerCell<Rd>& Cjr, const Kokkos::View<const Rd*>& uj, const Kokkos::View<const double*>& pj) { + const auto& node_to_cell_matrix = m_connectivity.nodeToCellMatrix(); + Kokkos::parallel_for(m_mesh.numberOfNodes(), KOKKOS_LAMBDA(const int& r) { Rd& br = m_br(r); br = zero; - const auto& node_to_cell = m_connectivity.m_node_to_cell_matrix.rowConst(r); + const auto& node_to_cell = node_to_cell_matrix.rowConst(r); const auto& node_to_cell_local_node = m_connectivity.m_node_to_cell_local_node.itemValues(r); for (size_t j=0; j<node_to_cell.length; ++j) { const unsigned int J = node_to_cell(j); -- GitLab