From 2e7efc95c4ac2025a2a889ad18b4d54361627e95 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Tue, 17 Jul 2018 18:49:47 +0200 Subject: [PATCH] Add NodeByCellData::SubViewConst --- src/scheme/NodeByCellData.hpp | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/scheme/NodeByCellData.hpp b/src/scheme/NodeByCellData.hpp index 3ce0710d4..52f9b02cf 100644 --- a/src/scheme/NodeByCellData.hpp +++ b/src/scheme/NodeByCellData.hpp @@ -58,6 +58,42 @@ class NodeByCellData } }; + class SubViewConst + { + private: + KOKKOS_RESTRICT const DataType* const m_sub_values; + const size_t m_size; + public: + KOKKOS_INLINE_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)); + } + }; + KOKKOS_INLINE_FUNCTION DataType& operator()(const size_t& j, const size_t& r) { @@ -108,6 +144,14 @@ class NodeByCellData return SubView(m_values, cell_begin, cell_end); } + KOKKOS_INLINE_FUNCTION + SubViewConst cellValues(const size_t& i_cell) const + { + const ConnectivityMatrix::size_type& cell_begin = m_node_id_per_cell_matrix.row_map[i_cell]; + const ConnectivityMatrix::size_type& cell_end = m_node_id_per_cell_matrix.row_map[i_cell+1]; + return SubViewConst(m_values, cell_begin, cell_end); + } + NodeByCellData(const ConnectivityMatrix& node_id_per_cell_matrix) : m_node_id_per_cell_matrix(node_id_per_cell_matrix), m_values("values", m_node_id_per_cell_matrix.entries.extent(0)) -- GitLab