14#include <similie/misc/are_all_same.hpp>
15#include <similie/misc/binomial_coefficient.hpp>
16#include <similie/misc/filled_struct.hpp>
17#include <similie/misc/specialization.hpp>
27 class LayoutStridedPolicy = Kokkos::LayoutRight,
28 class MemorySpace = Kokkos::HostSpace>
31template <
class SimplexType,
class LayoutStr
idedPolicy,
class MemorySpace>
37 std::size_t m_index = 0;
50 std::size_t index) noexcept
58 return (*m_chain)[m_index];
109 return m_index == other.m_index;
114 return !(*
this == other);
119 return m_index < other.m_index;
123template <
class SimplexType,
class LayoutStr
idedPolicy,
class MemorySpace>
132 = 1UL << ddc::type_seq_size_v<ddc::to_type_seq_t<discrete_vector_type>>;
139 static constexpr bool s_is_local =
true;
140 static constexpr std::size_t s_k = simplex_type::dimension();
143 std::size_t m_size = 0;
155 std::size_t
size = 0) noexcept
162 template <misc::Specialization<Kokkos::View> AllocationType>
164 AllocationType
const&,
170 template <misc::NotSpecialization<ddc::DiscreteVector>... T>
173 T... simplex) noexcept
175 , m_size(
sizeof...(T))
177 static_assert(
sizeof...(T) <=
MAX_SIZE);
179 ((m_vects[i++] = simplex), ...);
180 assert(
check() == 0 &&
"there are duplicate simplices in the chain");
181 if constexpr (
sizeof...(T) > 1) {
183 &&
"LocalChain must contain simplices with same origin (if not, use Chain)");
185 assert((!simplex.negative() && ...)
186 &&
"negative simplices are not supported in LocalChain");
194 AllocationType
const&,
196 Rest... simplices) noexcept
197 :
LocalChain(first_simplex.discrete_element(), first_simplex, simplices...)
201 template <misc::Specialization<ddc::DiscreteVector>... T>
202 requires(
sizeof...(T) >= 1)
205 , m_size(
sizeof...(T))
207 static_assert(
sizeof...(T) <=
MAX_SIZE);
210 assert(
check() == 0 &&
"there are duplicate simplices in the chain");
216 requires(
sizeof...(T) >= 1)
218 AllocationType
const&,
225 static KOKKOS_FUNCTION
constexpr bool is_local() noexcept
230 static KOKKOS_FUNCTION
constexpr std::size_t
dimension() noexcept
250 KOKKOS_FUNCTION
constexpr std::size_t
size() const noexcept
265 KOKKOS_FUNCTION
constexpr void resize(std::size_t
size)
noexcept
271 KOKKOS_FUNCTION
constexpr int check() const noexcept
273 for (
auto i =
begin(); i + 1 <
end(); ++i) {
274 for (
auto j = i + 1; j <
end(); ++j) {
343 m_vects[m_size++] = simplex;
350 std::size_t
const old_size = m_size;
351 for (
auto i = simplices_to_add.
begin(); i < simplices_to_add.
end(); ++i) {
352 m_vects[old_size + Kokkos::Experimental::distance(simplices_to_add.
begin(), i)] = *i;
354 m_size += simplices_to_add.
size();
361 local_chain += simplex;
368 local_chain += simplices_to_add;
376 }
else if (t == -1) {
377 for (std::size_t i = 0; i < m_size; ++i) {
378 m_vects[i] = -m_vects[i];
381 assert(
false &&
"chain must be multiplied by 1 or -1");
396 if (m_size != simplices.m_size) {
399 auto simplex =
begin();
400 auto other_simplex = simplices.
begin();
401 for (; simplex <
end(); ++simplex, ++other_simplex) {
402 if (*simplex != *other_simplex) {
412template <std::
size_t K, misc::Specialization<ddc::DiscreteDomain> Dom>
415template <std::size_t K,
class... Tag>
416struct TangentBasis<K, ddc::DiscreteDomain<Tag...>>
418 template <
class MemorySpace = Kokkos::HostSpace,
class Elem>
419 KOKKOS_FUNCTION
static constexpr auto run(Elem elem)
421 using chain_type =
LocalChain<
Simplex<K, Tag...>, Kokkos::LayoutRight, MemorySpace>;
422 std::array<std::ptrdiff_t,
sizeof...(Tag)> permutation
423 = {0 * ddc::type_seq_rank_v<Tag, ddc::detail::TypeSeq<Tag...>>...};
424 for (
auto i = permutation.begin(); i < permutation.begin() + K; ++i) {
427 chain_type basis {
typename chain_type::discrete_element_type(elem)};
429 typename chain_type::discrete_vector_type vect;
430 ddc::detail::array(vect) = permutation;
432 }
while (std::prev_permutation(permutation.begin(), permutation.end()));
441 misc::Specialization<ddc::DiscreteDomain> Dom,
442 misc::Specialization<ddc::DiscreteElement> Elem>
445 return detail::TangentBasis<K, Dom>::template run<Kokkos::HostSpace>(elem);
448template <std::
size_t K, misc::Specialization<ddc::DiscreteDomain> Dom,
class ExecSpace>
452 return detail::TangentBasis<K, Dom>::template run<typename ExecSpace::memory_space>(
456template <misc::Specialization<LocalChain> ChainType>
457std::ostream&
operator<<(std::ostream& out, ChainType
const& chain)
460 for (
auto const& simplex : chain) {
461 out <<
" -> " << simplex <<
"\n";
467template <misc::Specialization<Kokkos::View> AllocationType,
class SimplexType,
class... T>
469 std::remove_cvref_t<SimplexType>,
470 typename AllocationType::array_layout,
471 typename AllocationType::memory_space>;
KOKKOS_FUNCTION constexpr LocalChainIterator operator-(difference_type n) const noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr LocalChainIterator()=default
KOKKOS_FUNCTION constexpr bool operator==(LocalChainIterator const &other) const noexcept
KOKKOS_FUNCTION constexpr LocalChainIterator & operator--() noexcept
KOKKOS_FUNCTION constexpr reference operator*() const noexcept
std::ptrdiff_t difference_type
KOKKOS_FUNCTION constexpr difference_type operator-(LocalChainIterator const &other) const noexcept
value_type const & reference
KOKKOS_FUNCTION constexpr bool operator!=(LocalChainIterator const &other) const noexcept
KOKKOS_FUNCTION constexpr LocalChainIterator & operator++() noexcept
KOKKOS_FUNCTION constexpr bool operator<(LocalChainIterator const &other) const noexcept
KOKKOS_FUNCTION constexpr LocalChainIterator operator++(int) noexcept
KOKKOS_FUNCTION constexpr LocalChainIterator operator+(difference_type n) const noexcept
KOKKOS_FUNCTION constexpr LocalChainIterator(chain_type const *chain, std::size_t index) noexcept
KOKKOS_FUNCTION constexpr LocalChainIterator & operator+=(difference_type n) noexcept
KOKKOS_FUNCTION constexpr pointer operator->() const noexcept
value_type const * pointer
std::random_access_iterator_tag iterator_category
KOKKOS_FUNCTION constexpr LocalChain operator+(simplex_type const &simplex) const
static KOKKOS_FUNCTION constexpr std::size_t dimension() noexcept
KOKKOS_FUNCTION constexpr discrete_element_type origin() const noexcept
KOKKOS_FUNCTION constexpr LocalChain & operator+=(std::size_t n)
KOKKOS_FUNCTION constexpr LocalChain operator+(LocalChain const &simplices_to_add) const
KOKKOS_FUNCTION constexpr iterator_type begin() noexcept
KOKKOS_FUNCTION constexpr const_iterator_type end() const noexcept
KOKKOS_DEFAULTED_FUNCTION LocalChain & operator=(LocalChain const &)=default
KOKKOS_FUNCTION constexpr std::size_t size() const noexcept
KOKKOS_FUNCTION constexpr int check() const noexcept
static KOKKOS_FUNCTION constexpr bool is_local() noexcept
LocalChainIterator< SimplexType, LayoutStridedPolicy, MemorySpace > iterator_type
KOKKOS_FUNCTION constexpr LocalChain(AllocationType const &, discrete_element_type origin, T... vect) noexcept
KOKKOS_DEFAULTED_FUNCTION LocalChain & operator=(LocalChain &&)=default
typename simplex_type::discrete_vector_type discrete_vector_type
iterator_type const_iterator_type
KOKKOS_DEFAULTED_FUNCTION constexpr LocalChain()=default
KOKKOS_DEFAULTED_FUNCTION constexpr LocalChain(LocalChain const &)=default
KOKKOS_FUNCTION constexpr LocalChain(discrete_element_type origin, std::size_t size=0) noexcept
KOKKOS_FUNCTION constexpr LocalChain & operator+=(LocalChain const &simplices_to_add)
KOKKOS_FUNCTION constexpr const_iterator_type cbegin() const noexcept
KOKKOS_FUNCTION constexpr simplex_type const & operator[](std::size_t i) const noexcept
KOKKOS_FUNCTION constexpr auto operator*(T t) const
KOKKOS_FUNCTION constexpr iterator_type end() noexcept
KOKKOS_FUNCTION constexpr bool operator==(LocalChain const &simplices) const
KOKKOS_FUNCTION constexpr LocalChain(AllocationType const &, discrete_element_type origin)
KOKKOS_DEFAULTED_FUNCTION constexpr ~LocalChain()=default
static constexpr std::size_t MAX_SIZE
typename simplex_type::discrete_element_type discrete_element_type
KOKKOS_DEFAULTED_FUNCTION constexpr LocalChain(LocalChain &&)=default
KOKKOS_FUNCTION constexpr LocalChain & operator+=(discrete_vector_type const &vect)
KOKKOS_FUNCTION constexpr LocalChain(discrete_element_type origin, T... vect) noexcept
KOKKOS_FUNCTION constexpr LocalChain & operator+=(simplex_type const &simplex)
KOKKOS_FUNCTION constexpr LocalChain(AllocationType const &, First first_simplex, Rest... simplices) noexcept
KOKKOS_FUNCTION constexpr LocalChain(discrete_element_type origin, T... simplex) noexcept
KOKKOS_FUNCTION constexpr void resize(std::size_t size) noexcept
KOKKOS_FUNCTION constexpr storage_type & allocation() noexcept
KOKKOS_FUNCTION constexpr const_iterator_type begin() const noexcept
KOKKOS_FUNCTION constexpr LocalChain & operator++()
std::array< simplex_type, MAX_SIZE > storage_type
KOKKOS_FUNCTION constexpr std::size_t allocation_size() const noexcept
KOKKOS_FUNCTION constexpr LocalChain & operator*=(T t)
KOKKOS_FUNCTION constexpr const_iterator_type cend() const noexcept
static KOKKOS_FUNCTION constexpr bool negative()
KOKKOS_FUNCTION constexpr storage_type const & allocation() const noexcept
std::ostream & operator<<(std::ostream &out, ChainType const &chain)
Simplex(ddc::DiscreteElement< Tag... >, ddc::DiscreteVector< T... >) -> Simplex< sizeof...(T), Tag... >
KOKKOS_FUNCTION constexpr auto tangent_basis(Elem elem)
LocalChain(AllocationType, SimplexType, T...) -> LocalChain< std::remove_cvref_t< SimplexType >, typename AllocationType::array_layout, typename AllocationType::memory_space >
constexpr bool are_all_equal(Head head, Tail... tail)
constexpr T filled_struct(ElementType const n=0)
The top-level namespace of SimiLie.