Skip to content
Snippets Groups Projects

Add Table class and use it in ItemArray

1 file
+ 12
53
Compare changes
  • Side-by-side
  • Inline
+ 12
53
@@ -50,55 +50,6 @@ class SubItemValuePerItem
public:
using ToShared = SubItemValuePerItem<DataType, ItemOfItem, ConnectivitySharedPtr>;
class SubView
{
public:
using data_type = DataType;
private:
PUGS_RESTRICT DataType* const m_sub_values;
const size_t m_size;
public:
template <typename IndexType>
PUGS_FORCEINLINE DataType&
operator[](IndexType i) const noexcept(NO_ASSERT)
{
static_assert(std::is_integral_v<IndexType>, "SubView is indexed by integral values");
Assert(i < m_size);
return m_sub_values[i];
}
template <typename IndexType>
PUGS_FORCEINLINE DataType&
operator[](IndexType i) noexcept(NO_ASSERT)
{
static_assert(std::is_integral_v<IndexType>, "SubView is indexed by integral values");
Assert(i < m_size);
return m_sub_values[i];
}
PUGS_INLINE
size_t
size() const noexcept
{
return m_size;
}
SubView(const SubView&) = delete;
SubView(SubView&&) noexcept = delete;
PUGS_INLINE
SubView(const Array<DataType>& values, size_t begin, size_t end) noexcept(NO_ASSERT)
: m_sub_values(&(values[begin])), m_size(end - begin)
{
Assert(begin <= end);
Assert(end <= values.size());
}
~SubView() = default;
};
friend PUGS_INLINE SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityPtr>
copy(SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& source)
{
@@ -178,8 +129,16 @@ class SubItemValuePerItem
return m_host_row_map(size_t{item_id} + 1) - m_host_row_map(size_t{item_id});
}
PUGS_INLINE
void
fill(const DataType& data) const noexcept
{
static_assert(not std::is_const_v<DataType>, "Cannot modify ItemValue of const");
m_values.fill(data);
}
template <typename IndexType>
PUGS_INLINE SubView
PUGS_INLINE Array<DataType>
itemValues(IndexType item_id) noexcept(NO_ASSERT)
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
@@ -187,13 +146,13 @@ class SubItemValuePerItem
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 SubView(m_values, item_begin, item_end);
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 SubView
PUGS_INLINE Array<DataType>
itemValues(IndexType item_id) const noexcept(NO_ASSERT)
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
@@ -201,7 +160,7 @@ class SubItemValuePerItem
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 SubView(m_values, item_begin, item_end);
return subArray(m_values, item_begin, item_end - item_begin);
}
template <typename DataType2, typename ConnectivityPtr2>
Loading