Skip to content
Snippets Groups Projects
Commit d3adc9e5 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Simplify implementation and add a new access operators[](ItemId)

The new operator behaves exactly as the
SubItemValuePerItem::itemArray(ItemId) and
SubItemArrayPerItem::itemTable(ItemId) functions

This convenient change is mainly made in the goal of simplifying
item-to-item matrices used in connectivity
parent 72392790
No related branches found
No related tags found
1 merge request!133Simplify access functions to the number of items
......@@ -90,8 +90,14 @@ class SubItemArrayPerItem
return m_values[m_host_row_map(size_t{item_id}) + i];
}
// Following Kokkos logic, these classes are view and const view does allow
// changes in data
template <ItemType item_t>
Table<DataType>
operator[](const ItemIdT<item_t>& item_id) const noexcept(NO_ASSERT)
{
static_assert(item_t == item_type, "invalid ItemId type");
return this->itemTable(item_id);
}
template <typename ArrayIndexType>
Array<DataType>
operator[](const ArrayIndexType& i) const noexcept(NO_ASSERT)
......@@ -144,20 +150,6 @@ class SubItemArrayPerItem
m_values.fill(data);
}
template <typename IndexType>
PUGS_INLINE Table<DataType>
itemTable(IndexType item_id) noexcept(NO_ASSERT)
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
Assert(this->isBuilt());
Assert(item_id < this->numberOfItems());
const auto& item_begin = m_host_row_map(size_t{item_id});
const auto& item_end = m_host_row_map(size_t{item_id} + 1);
return subTable(m_values, item_begin, item_end - item_begin, 0, this->sizeOfArrays());
}
// Following Kokkos logic, these classes are view and const view does allow
// changes in data
template <typename IndexType>
PUGS_INLINE Table<DataType>
itemTable(IndexType item_id) const noexcept(NO_ASSERT)
......
......@@ -88,8 +88,14 @@ class SubItemValuePerItem
return m_values[m_host_row_map(size_t{item_id}) + i];
}
// Following Kokkos logic, these classes are view and const view does allow
// changes in data
template <ItemType item_t>
Array<DataType>
operator[](const ItemIdT<item_t>& item_id) const noexcept(NO_ASSERT)
{
static_assert(item_t == item_type, "invalid ItemId type");
return this->itemArray(item_id);
}
template <typename ArrayIndexType>
DataType&
operator[](const ArrayIndexType& i) const noexcept(NO_ASSERT)
......@@ -137,21 +143,7 @@ class SubItemValuePerItem
template <typename IndexType>
PUGS_INLINE Array<DataType>
itemArray(IndexType item_id) noexcept(NO_ASSERT)
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
Assert(this->isBuilt());
Assert(item_id < this->numberOfItems());
const auto& item_begin = m_host_row_map(size_t{item_id});
const auto& item_end = m_host_row_map(size_t{item_id} + 1);
return subArray(m_values, item_begin, item_end - item_begin);
}
// Following Kokkos logic, these classes are view and const view does allow
// changes in data
template <typename IndexType>
PUGS_INLINE Array<DataType>
itemArray(IndexType item_id) const noexcept(NO_ASSERT)
itemArray(const IndexType& item_id) const noexcept(NO_ASSERT)
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
Assert(this->isBuilt());
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment