8#include <similie/misc/are_all_same.hpp>
9#include <similie/misc/portable_stl.hpp>
10#include <similie/misc/specialization.hpp>
12#include <Kokkos_StdAlgorithms.hpp>
23 class LayoutStridedPolicy = Kokkos::LayoutRight,
24 class MemorySpace = Kokkos::HostSpace>
31 using simplices_type = Kokkos::View<SimplexType*, LayoutStridedPolicy, memory_space>;
35 using iterator_type = Kokkos::Experimental::Impl::RandomAccessIterator<simplices_type>;
38 static constexpr bool s_is_local =
false;
39 static constexpr std::size_t s_k = simplex_type::dimension();
45 KOKKOS_DEFAULTED_FUNCTION
constexpr Chain() =
default;
47 KOKKOS_DEFAULTED_FUNCTION
constexpr Chain(
Chain const&) =
default;
49 KOKKOS_DEFAULTED_FUNCTION
constexpr Chain(
Chain&&) =
default;
52 requires(!std::is_convertible_v<T, std::size_t> && ...)
55 , m_size(sizeof...(T))
58 ((m_simplices(i++) = simplex), ...);
59 assert(
check() == 0 &&
"there are duplicate simplices in the chain");
66 assert(
check() == 0 &&
"there are duplicate simplices in the chain");
69 KOKKOS_DEFAULTED_FUNCTION
~Chain() =
default;
75 static KOKKOS_FUNCTION
constexpr bool is_local() noexcept
80 static KOKKOS_FUNCTION
constexpr std::size_t
dimension() noexcept
90 KOKKOS_FUNCTION std::size_t
size() noexcept
95 KOKKOS_FUNCTION std::size_t
size() const noexcept
102 return m_simplices.size();
107 return m_simplices.size();
112 Kokkos::resize(m_simplices,
size());
117 Kokkos::resize(m_simplices,
size);
122 for (
auto i =
begin(); i <
end() - 1; ++i) {
123 for (
auto j = i + 1; j <
end(); ++j) {
136 while (i < stop - 1) {
138 for (
auto j = i + 1; k == i && j < stop; ++j) {
144 misc::detail::shift_left(k, stop, 1);
145 misc::detail::shift_left(i, stop, 1);
152 assert(
check() == 0 &&
"there are duplicate simplices in the chain");
157 return Kokkos::Experimental::begin(m_simplices);
162 return Kokkos::Experimental::begin(m_simplices);
165 KOKKOS_FUNCTION
auto end()
167 return Kokkos::Experimental::begin(m_simplices) +
size();
170 KOKKOS_FUNCTION
auto end()
const
172 return Kokkos::Experimental::begin(m_simplices) +
size();
177 return Kokkos::Experimental::begin(m_simplices);
180 KOKKOS_FUNCTION
auto cend()
const
182 return Kokkos::Experimental::begin(m_simplices) +
size();
188 return m_simplices(i);
194 return m_simplices(i);
214 m_simplices(m_size) = simplex;
222 for (
auto i = simplices_to_add.
begin(); i < simplices_to_add.
end(); ++i) {
223 m_simplices(m_size + Kokkos::Experimental::distance(simplices_to_add.
begin(), i)) = *i;
225 m_size += simplices_to_add.
size();
239 chain += simplices_to_add;
245 for (
auto i = Kokkos::Experimental::begin(m_simplices);
246 i < Kokkos::Experimental::begin(m_simplices) +
size();
270 }
else if (t == -1) {
273 assert(
false &&
"chain must be multiplied by 1 or -1");
288 for (
auto i = simplices.
begin(); i < simplices.
end(); ++i) {
289 if (*i != m_simplices(Kokkos::Experimental::distance(simplices.
begin(), i))) {
297template <
class Head,
class... Tail>
299 typename Head::value_type,
300 typename Head::array_layout,
301 typename Head::memory_space>;
303template <misc::Specialization<Chain> ChainType>
304std::ostream&
operator<<(std::ostream& out, ChainType
const& chain)
307 for (
typename ChainType::simplex_type
const& simplex : chain) {
308 out <<
" " << simplex <<
"\n";
void resize(std::size_t size)
KOKKOS_FUNCTION Chain & revert()
KOKKOS_DEFAULTED_FUNCTION constexpr Chain(Chain const &)=default
KOKKOS_FUNCTION std::size_t allocation_size() const noexcept
KOKKOS_FUNCTION auto cend() const
typename simplex_type::discrete_element_type discrete_element_type
KOKKOS_FUNCTION std::size_t allocation_size() noexcept
KOKKOS_FUNCTION bool operator==(Chain simplices)
KOKKOS_FUNCTION Chain operator+(simplex_type simplex)
static KOKKOS_FUNCTION constexpr std::size_t dimension() noexcept
KOKKOS_FUNCTION Chain & operator++()
KOKKOS_FUNCTION int check()
KOKKOS_FUNCTION Chain & operator+=(const simplex_type &simplex)
KOKKOS_FUNCTION constexpr Chain(simplices_type allocation, std::size_t size) noexcept
KOKKOS_FUNCTION auto operator-(T t)
KOKKOS_FUNCTION void optimize()
KOKKOS_FUNCTION Chain & operator+=(const Chain &simplices_to_add)
KOKKOS_FUNCTION simplex_type const & operator[](std::size_t i) const noexcept
KOKKOS_FUNCTION Chain operator+(Chain simplices_to_add)
KOKKOS_FUNCTION Chain & operator*=(T t)
KOKKOS_DEFAULTED_FUNCTION constexpr Chain()=default
KOKKOS_FUNCTION Chain & operator+=(const std::size_t n)
KOKKOS_FUNCTION simplex_type & operator[](std::size_t i) noexcept
KOKKOS_FUNCTION auto operator*(T t)
KOKKOS_FUNCTION auto cbegin() const
KOKKOS_FUNCTION auto begin() const
Kokkos::View< SimplexType *, LayoutStridedPolicy, memory_space > simplices_type
KOKKOS_DEFAULTED_FUNCTION Chain & operator=(Chain const &other)=default
KOKKOS_FUNCTION auto end()
static KOKKOS_FUNCTION constexpr bool is_local() noexcept
KOKKOS_FUNCTION auto end() const
typename simplex_type::discrete_vector_type discrete_vector_type
KOKKOS_DEFAULTED_FUNCTION ~Chain()=default
Kokkos::Experimental::Impl::RandomAccessIterator< simplices_type > iterator_type
KOKKOS_DEFAULTED_FUNCTION Chain & operator=(Chain &&other)=default
KOKKOS_FUNCTION std::size_t size() const noexcept
KOKKOS_FUNCTION std::size_t size() noexcept
KOKKOS_FUNCTION auto begin()
KOKKOS_FUNCTION Chain operator-()
KOKKOS_FUNCTION simplices_type & allocation() noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr Chain(Chain &&)=default
std::ostream & operator<<(std::ostream &out, ChainType const &chain)
Chain(Head, Tail...) -> Chain< typename Head::value_type, typename Head::array_layout, typename Head::memory_space >
The top-level namespace of SimiLie.