8#include <similie/misc/are_all_same.hpp>
9#include <similie/misc/binomial_coefficient.hpp>
10#include <similie/misc/filled_struct.hpp>
11#include <similie/misc/specialization.hpp>
23 class LayoutStridedPolicy1,
24 class LayoutStridedPolicy2,
26Kokkos::View<typename SimplexType::discrete_vector_type*, MemorySpace> extract_vects(
27 Kokkos::View<typename SimplexType::discrete_vector_type*, LayoutStridedPolicy1, MemorySpace>
29 Kokkos::View<SimplexType*, LayoutStridedPolicy2, MemorySpace> simplices)
31 for (
auto i = Kokkos::Experimental::begin(simplices); i < Kokkos::Experimental::end(simplices);
33 vects(i) = i->discrete_vector();
44 class LayoutStridedPolicy = Kokkos::LayoutRight,
45 class MemorySpace = Kokkos::HostSpace>
52 using simplices_type = Kokkos::View<SimplexType*, LayoutStridedPolicy, memory_space>;
55 using vects_type = Kokkos::View<discrete_vector_type*, LayoutStridedPolicy, memory_space>;
57 using iterator_type = Kokkos::Experimental::Impl::RandomAccessIterator<vects_type>;
60 static constexpr bool s_is_local =
true;
61 static constexpr std::size_t s_k = simplex_type::dimension();
67 KOKKOS_DEFAULTED_FUNCTION
constexpr LocalChain() =
default;
75 template <misc::NotSpecialization<ddc::DiscreteVector>... T>
78 , m_size(
sizeof...(T))
83 assert(
check() == 0 &&
"there are duplicate simplices in the chain");
84 if constexpr (
sizeof...(T) > 1) {
86 &&
"LocalChain must contain simplices with same origin (if not, use Chain)");
88 assert((!simplex.negative() && ...)
89 &&
"negative simplices are not supported in LocalChain");
95 std::size_t
size) noexcept
99 detail::extract_vects(m_vects, simplices)
100 assert(
check() == 0 &&
"there are duplicate simplices in the chain");
101#if not defined NDEBUG
102 Kokkos::View<discrete_element_type*, memory_space> elems(simplices.size());
103 for (
auto i = Kokkos::Experimental::begin(simplices);
104 i < Kokkos::Experimental::end(simplices);
106 elems[Kokkos::Experimental::distance(Kokkos::Experimental::begin(simplices), i)]
107 = i->discrete_element();
110 &&
"LocalChain must contain simplices with same origin (if not, use Chain)");
120 for (
auto i = Kokkos::Experimental::begin(simplices);
121 i < Kokkos::Experimental::end(simplices);
123 flag &= !i->negative();
125 assert(flag &&
"LocalChain must contain simplices with same origin (if not, use Chain)");
129 template <misc::Specialization<ddc::DiscreteVector>... T>
130 requires(
sizeof...(T) >= 1)
133 , m_size(
sizeof...(T))
137 assert(
check() == 0 &&
"there are duplicate simplices in the chain");
144 assert(
check() == 0 &&
"there are duplicate simplices in the chain");
153 static KOKKOS_FUNCTION
constexpr bool is_local() noexcept
158 static KOKKOS_FUNCTION
constexpr std::size_t
dimension() noexcept
168 KOKKOS_FUNCTION std::size_t
size() noexcept
173 KOKKOS_FUNCTION std::size_t
size() const noexcept
180 return m_vects.size();
185 return m_vects.size();
195 Kokkos::resize(m_vects,
size());
200 Kokkos::resize(m_vects,
size);
219 return Kokkos::Experimental::begin(m_vects);
224 return Kokkos::Experimental::begin(m_vects);
227 KOKKOS_FUNCTION
auto end()
229 return Kokkos::Experimental::begin(m_vects) +
size();
232 KOKKOS_FUNCTION
auto end()
const
234 return Kokkos::Experimental::begin(m_vects) +
size();
239 return Kokkos::Experimental::begin(m_vects);
242 KOKKOS_FUNCTION
auto cend()
const
244 return Kokkos::Experimental::begin(m_vects) +
size();
276 m_vects(m_size) = vect;
284 m_vects(m_size) = simplex.discrete_vector();
292 for (
auto i = vects_to_add.begin(); i < vects_to_add.end(); ++i) {
293 m_vects(m_size + Kokkos::Experimental::distance(vects_to_add.begin(), i)) = *i;
295 m_size += vects_to_add.size();
302 for (
auto i = simplices_to_add.
begin(); i < simplices_to_add.
end(); ++i) {
303 m_vects(m_size + Kokkos::Experimental::distance(simplices_to_add.
begin(), i)) = *i;
305 m_size += simplices_to_add.
size();
312 local_chain += simplex;
319 local_chain += simplices_to_add;
331 }
else if (t == -1) {
332 assert(
false &&
"negative simplices are unsupported in LocalChain");
334 assert(
false &&
"chain must be multiplied by 1 or -1");
349 for (
auto i = simplices.
begin(); i < simplices.
end(); ++i) {
350 if (*i != m_vects(Kokkos::Experimental::distance(simplices.
begin(), i))) {
358template <
class Head, misc::NotSpecialization<ddc::DiscreteVector>... Tail>
360 ddc::type_seq_element_t<0, ddc::detail::TypeSeq<Tail...>>,
361 typename Head::array_layout,
362 typename Head::memory_space>;
364template <
class Head, misc::Specialization<ddc::DiscreteVector>... Tail>
369 ddc::DiscreteElement,
370 ddc::to_type_seq_t<typename Head::value_type>>(),
371 ddc::type_seq_element_t<0, ddc::detail::TypeSeq<Tail...>>())),
372 typename Head::array_layout,
373 typename Head::memory_space>;
377template <std::
size_t K, misc::Specialization<ddc::DiscreteDomain> Dom>
380template <std::size_t K,
class... Tag>
381struct TangentBasis<K, ddc::DiscreteDomain<Tag...>>
383 template <
class ExecSpace>
384 static auto constexpr run(ExecSpace
const& exec_space)
386 std::array<std::ptrdiff_t,
sizeof...(Tag)> permutation
387 = {0 * ddc::type_seq_rank_v<Tag, ddc::detail::TypeSeq<Tag...>>...};
388 for (
auto i = permutation.begin(); i < permutation.begin() + K; ++i) {
391 Kokkos::View<ddc::DiscreteVector<Tag...>*, Kokkos::HostSpace>
395 basis_host(i) = ddc::DiscreteVector<Tag...>();
396 ddc::detail::array(basis_host(i++)) = permutation;
397 }
while (std::prev_permutation(permutation.begin(), permutation.end()));
398 Kokkos::View<ddc::DiscreteVector<Tag...>*,
typename ExecSpace::memory_space> basis
399 = create_mirror_view_and_copy(exec_space, basis_host);
404 typename ExecSpace::memory_space>(basis, basis.size());
410template <std::
size_t K, misc::Specialization<ddc::DiscreteDomain> Dom,
class ExecSpace>
413 return detail::TangentBasis<K, Dom>::run(exec_space);
416template <misc::Specialization<LocalChain> ChainType>
417std::ostream&
operator<<(std::ostream& out, ChainType
const& chain)
420 for (
typename ChainType::discrete_vector_type
const& vect : chain) {
421 out <<
" -> " << vect <<
"\n";
KOKKOS_FUNCTION constexpr LocalChain(vects_type allocation, std::size_t size) noexcept
static KOKKOS_FUNCTION constexpr std::size_t dimension() noexcept
KOKKOS_FUNCTION int check()
KOKKOS_FUNCTION std::size_t allocation_size() const noexcept
KOKKOS_FUNCTION LocalChain & operator*=(T t)
LocalChain operator-()=delete
KOKKOS_FUNCTION LocalChain & operator++()
KOKKOS_FUNCTION auto operator*(T t)
KOKKOS_FUNCTION LocalChain operator+(LocalChain simplices_to_add)
Kokkos::View< discrete_vector_type *, LayoutStridedPolicy, memory_space > vects_type
static KOKKOS_FUNCTION constexpr bool is_local() noexcept
KOKKOS_FUNCTION constexpr LocalChain(vects_type allocation, T... simplex) noexcept
KOKKOS_FUNCTION constexpr LocalChain(vects_type allocation, T... vect) noexcept
Kokkos::View< SimplexType *, LayoutStridedPolicy, memory_space > simplices_type
KOKKOS_FUNCTION std::size_t allocation_size() noexcept
KOKKOS_DEFAULTED_FUNCTION LocalChain & operator=(LocalChain &&other)=default
void resize(std::size_t size)
typename simplex_type::discrete_vector_type discrete_vector_type
KOKKOS_FUNCTION LocalChain & operator+=(const LocalChain &simplices_to_add)
KOKKOS_FUNCTION auto cend() const
KOKKOS_FUNCTION auto cbegin() const
KOKKOS_FUNCTION auto begin()
KOKKOS_DEFAULTED_FUNCTION constexpr LocalChain()=default
KOKKOS_DEFAULTED_FUNCTION ~LocalChain()=default
KOKKOS_DEFAULTED_FUNCTION constexpr LocalChain(LocalChain const &)=default
KOKKOS_FUNCTION constexpr LocalChain(vects_type allocation, simplices_type simplices, std::size_t size) noexcept
KOKKOS_FUNCTION auto end() const
KOKKOS_FUNCTION simplex_type operator[](std::size_t i) noexcept
KOKKOS_FUNCTION std::size_t size() const noexcept
KOKKOS_DEFAULTED_FUNCTION LocalChain & operator=(LocalChain const &other)=default
typename simplex_type::discrete_element_type discrete_element_type
KOKKOS_FUNCTION LocalChain & operator+=(const vects_type &vects_to_add)
KOKKOS_DEFAULTED_FUNCTION constexpr LocalChain(LocalChain &&)=default
KOKKOS_FUNCTION LocalChain operator+(simplex_type simplex)
KOKKOS_FUNCTION simplices_type & allocation() noexcept
LocalChain operator-(LocalChain)=delete
KOKKOS_FUNCTION LocalChain & operator+=(const std::size_t n)
KOKKOS_FUNCTION LocalChain & operator+=(const discrete_vector_type &vect)
KOKKOS_FUNCTION simplex_type const operator[](std::size_t i) const noexcept
KOKKOS_FUNCTION std::size_t size() noexcept
KOKKOS_FUNCTION auto begin() const
static KOKKOS_FUNCTION constexpr bool negative()
KOKKOS_FUNCTION bool operator==(LocalChain simplices)
Kokkos::Experimental::Impl::RandomAccessIterator< vects_type > iterator_type
KOKKOS_FUNCTION LocalChain & operator+=(const simplex_type &simplex)
KOKKOS_FUNCTION auto end()
std::ostream & operator<<(std::ostream &out, ChainType const &chain)
constexpr auto tangent_basis(ExecSpace const &exec_space)
Simplex(ddc::DiscreteElement< Tag... >, ddc::DiscreteVector< T... >) -> Simplex< sizeof...(T), Tag... >
LocalChain(Head, Tail...) -> LocalChain< ddc::type_seq_element_t< 0, ddc::detail::TypeSeq< Tail... > >, typename Head::array_layout, typename Head::memory_space >
constexpr bool are_all_equal(Head head, Tail... tail)
constexpr T filled_struct(ElementType const n=0)
constexpr std::size_t binomial_coefficient(std::size_t n, std::size_t k) noexcept
typename detail::ConvertTypeSeqTo< T, Seq >::type convert_type_seq_to_t
The top-level namespace of SimiLie.