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

Add tests for SubItemValuePerItem

parent fe1b47d9
No related branches found
No related tags found
1 merge request!84Add SubArray class
......@@ -55,7 +55,8 @@ class SubItemValuePerItem
public:
template <typename IndexType>
PUGS_INLINE const DataType& operator[](IndexType i) const noexcept(NO_ASSERT)
PUGS_INLINE const 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);
......@@ -63,7 +64,8 @@ class SubItemValuePerItem
}
template <typename IndexType>
PUGS_FORCEINLINE DataType& operator[](IndexType i) noexcept(NO_ASSERT)
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);
......@@ -91,6 +93,15 @@ class SubItemValuePerItem
}
};
friend PUGS_INLINE SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityPtr>
copy(SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& source)
{
SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityPtr> image(*source.m_connectivity_ptr);
image.m_values = copy(source.m_values);
return image;
}
PUGS_INLINE
bool
isBuilt() const noexcept
......@@ -109,18 +120,11 @@ class SubItemValuePerItem
return m_values[m_host_row_map(size_t{item_id}) + i];
}
PUGS_INLINE
size_t
numberOfValues() const noexcept(NO_ASSERT)
{
Assert(this->isBuilt());
return m_values.size();
}
// Following Kokkos logic, these classes are view and const view does allow
// changes in data
template <typename ArrayIndexType>
DataType& operator[](const ArrayIndexType& i) const noexcept(NO_ASSERT)
DataType&
operator[](const ArrayIndexType& i) const noexcept(NO_ASSERT)
{
static_assert(std::is_integral_v<ArrayIndexType>, "index must be an integral type");
Assert(this->isBuilt());
......@@ -128,13 +132,21 @@ class SubItemValuePerItem
return m_values[i];
}
PUGS_INLINE
size_t
numberOfValues() const noexcept(NO_ASSERT)
{
Assert(this->isBuilt());
return m_values.size();
}
PUGS_INLINE
size_t
numberOfItems() const noexcept(NO_ASSERT)
{
Assert(this->isBuilt());
Assert(m_host_row_map.extent(0) != 0);
return m_host_row_map.extent(0);
Assert(m_host_row_map.extent(0) > 0);
return m_host_row_map.extent(0) - 1;
}
template <typename IndexType>
......@@ -143,7 +155,7 @@ class SubItemValuePerItem
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
Assert(this->isBuilt());
Assert(item_id < m_host_row_map.extent(0));
Assert(item_id < this->numberOfItems());
return m_host_row_map(size_t{item_id} + 1) - m_host_row_map(size_t{item_id});
}
......@@ -153,7 +165,7 @@ class SubItemValuePerItem
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
Assert(this->isBuilt());
Assert(item_id < m_host_row_map.extent(0));
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);
......@@ -167,7 +179,7 @@ class SubItemValuePerItem
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
Assert(this->isBuilt());
Assert(item_id < m_host_row_map.extent(0));
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);
......
......@@ -102,6 +102,7 @@ add_executable (mpi_unit_tests
test_Partitioner.cpp
test_ItemValue.cpp
test_ItemValueUtils.cpp
test_SubItemValuePerItem.cpp
)
add_library(test_Pugs_MeshDataBase
......
This diff is collapsed.
edge_values_per_faceedge_values_per_faceedge_values_per_faceedge_values_per_faceedge_values_per_face
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment