13#include <Kokkos_Macros.hpp>
15#include "ddc/detail/macros.hpp"
16#include "ddc/detail/type_seq.hpp"
17#include "ddc/discrete_vector.hpp"
29template <
class... Tags>
40template <
class... Tags>
41struct ToTypeSeq<DiscreteElement<Tags...>>
43 using type = TypeSeq<Tags...>;
49
50using DiscreteElementType = std::size_t;
53KOKKOS_FUNCTION constexpr DiscreteElementType
const&
uid(DiscreteElement<Tag>
const& tuple)
noexcept
59KOKKOS_FUNCTION constexpr DiscreteElementType&
uid(DiscreteElement<Tag>& tuple)
noexcept
64template <
class QueryTag,
class... Tags>
66 DiscreteElement<Tags...>
const& tuple)
noexcept
68 return tuple.
template uid<QueryTag>();
71template <
class QueryTag,
class... Tags>
72KOKKOS_FUNCTION constexpr DiscreteElementType&
uid(DiscreteElement<Tags...>& tuple)
noexcept
74 return tuple.
template uid<QueryTag>();
77template <
class QueryTag,
class... Tags>
79 DiscreteElement<Tags...>
const& arr,
80 DiscreteElement<QueryTag>
const& default_value)
noexcept
82 if constexpr (in_tags_v<QueryTag, detail::TypeSeq<Tags...>>) {
83 return DiscreteElement<QueryTag>(arr);
89template <
class... QueryTags,
class... Tags>
91 DiscreteElement<Tags...>
const& arr)
noexcept
93 return DiscreteElement<QueryTags...>(arr);
96template <
class... QueryTags,
class... Tags>
98 DiscreteElement<Tags...>&& arr)
noexcept
100 return DiscreteElement<QueryTags...>(std::move(arr));
109 is_discrete_element_v<HeadDElem> && (is_discrete_element_v<TailDElems> && ...),
112KOKKOS_FUNCTION constexpr auto const&
take(HeadDElem
const& head, TailDElems
const&... tail)
114 DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
115 if constexpr (type_seq_contains_v<detail::TypeSeq<QueryTag>, to_type_seq_t<HeadDElem>>) {
117 (!type_seq_contains_v<detail::TypeSeq<QueryTag>, to_type_seq_t<TailDElems>> && ...),
118 "ERROR: tag redundant");
121 static_assert(
sizeof...(TailDElems) > 0,
"ERROR: tag not found");
122 return take<QueryTag>(tail...);
130template <
class... Tags>
131KOKKOS_FUNCTION
constexpr std::array<DiscreteElementType,
sizeof...(Tags)>& array(
132 DiscreteElement<Tags...>& v)
noexcept
138template <
class... Tags>
139KOKKOS_FUNCTION
constexpr std::array<DiscreteElementType,
sizeof...(Tags)>
const& array(
140 DiscreteElement<Tags...>
const& v)
noexcept
150 return DiscreteElement<DDim>(0);
154
155
156
157template <
class... Tags>
160 using tags_seq = detail::TypeSeq<Tags...>;
162 friend KOKKOS_FUNCTION
constexpr std::array<DiscreteElementType,
sizeof...(Tags)>& detail::
163 array<Tags...>(DiscreteElement<Tags...>& v)
noexcept;
165 friend KOKKOS_FUNCTION
constexpr std::array<DiscreteElementType,
sizeof...(Tags)>
const&
166 detail::array<Tags...>(DiscreteElement<Tags...>
const& v)
noexcept;
169 std::array<DiscreteElementType,
sizeof...(Tags)> m_values;
172 using value_type = DiscreteElementType;
176 return sizeof...(Tags);
182 KOKKOS_DEFAULTED_FUNCTION
constexpr DiscreteElement(DiscreteElement
const&) =
default;
184 KOKKOS_DEFAULTED_FUNCTION
constexpr DiscreteElement(DiscreteElement&&) =
default;
186 template <
class... DElems,
class = std::enable_if_t<(is_discrete_element_v<DElems> && ...)>>
188 : m_values {take<Tags>(delems...).
template uid<Tags>()...}
194 class = std::enable_if_t<(!is_discrete_element_v<Params> && ...)>,
195 class = std::enable_if_t<(std::is_convertible_v<Params, DiscreteElementType> && ...)>,
196 class = std::enable_if_t<
sizeof...(Params) ==
sizeof...(Tags)>>
198 : m_values {
static_cast<DiscreteElementType>(params)...}
204 KOKKOS_DEFAULTED_FUNCTION DiscreteElement&
operator=(DiscreteElement
const& other) =
default;
206 KOKKOS_DEFAULTED_FUNCTION DiscreteElement&
operator=(DiscreteElement&& other) =
default;
208 template <
class QueryTag>
211 static_assert(in_tags_v<QueryTag, tags_seq>,
"requested Tag absent from DiscreteElement");
212 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
215 template <
class QueryTag>
218 static_assert(in_tags_v<QueryTag, tags_seq>,
"requested Tag absent from DiscreteElement");
219 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
222 template <std::size_t N =
sizeof...(Tags)>
228 template <std::size_t N =
sizeof...(Tags)>
229 KOKKOS_FUNCTION constexpr std::enable_if_t<N == 1, value_type
const&>
uid()
const noexcept
234 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
241 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
244 DiscreteElement
const tmp = *
this;
249 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
256 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
259 DiscreteElement
const tmp = *
this;
264 template <
class... OTags>
267 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
268 ((m_values[type_seq_rank_v<OTags, tags_seq>] += rhs.
template get<OTags>()), ...);
274 std::size_t N =
sizeof...(Tags),
275 class = std::enable_if_t<N == 1>,
276 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
283 template <
class... OTags>
286 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
287 ((m_values[type_seq_rank_v<OTags, tags_seq>] -= rhs.
template get<OTags>()), ...);
293 std::size_t N =
sizeof...(Tags),
294 class = std::enable_if_t<N == 1>,
295 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
303inline std::ostream& operator<<(std::ostream& out, DiscreteElement<>
const&)
309template <
class Head,
class... Tags>
310std::ostream& operator<<(std::ostream& out, DiscreteElement<Head, Tags...>
const& arr)
313 out << uid<Head>(arr);
314 ((out <<
", " << uid<Tags>(arr)), ...);
320template <
class... Tags,
class... OTags>
322 DiscreteElement<Tags...>
const& lhs,
323 DiscreteElement<OTags...>
const& rhs)
noexcept
325 return ((lhs.
template uid<Tags>() == rhs.
template uid<Tags>()) && ...);
328#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
341 DiscreteElement<Tag>
const& lhs,
342 DiscreteElement<Tag>
const& rhs)
344 return lhs.uid() < rhs.uid();
349 DiscreteElement<Tag>
const& lhs,
350 DiscreteElement<Tag>
const& rhs)
352 return lhs.uid() <= rhs.uid();
357 DiscreteElement<Tag>
const& lhs,
358 DiscreteElement<Tag>
const& rhs)
360 return lhs.uid() > rhs.uid();
365 DiscreteElement<Tag>
const& lhs,
366 DiscreteElement<Tag>
const& rhs)
368 return lhs.uid() >= rhs.uid();
373template <
class... Tags,
class... OTags>
375 DiscreteElement<Tags...>
const& lhs,
378 using detail::TypeSeq;
379 static_assert(((type_seq_contains_v<TypeSeq<OTags>, TypeSeq<Tags...>>) && ...));
380 DiscreteElement<Tags...> result(lhs);
388 class = std::enable_if_t<std::is_integral_v<IntegralType>>,
389 class = std::enable_if_t<!is_discrete_vector_v<IntegralType>>>
391 DiscreteElement<Tag>
const& lhs,
392 IntegralType
const& rhs)
394 DiscreteElement<Tag> result(lhs);
399template <
class... Tags,
class... OTags>
401 DiscreteElement<Tags...>
const& lhs,
404 using detail::TypeSeq;
405 static_assert(((type_seq_contains_v<TypeSeq<OTags>, TypeSeq<Tags...>>) && ...));
406 DiscreteElement<Tags...> result(lhs);
414 class = std::enable_if_t<std::is_integral_v<IntegralType>>,
415 class = std::enable_if_t<!is_discrete_vector_v<IntegralType>>>
417 DiscreteElement<Tag>
const& lhs,
418 IntegralType
const& rhs)
420 DiscreteElement<Tag> result(lhs);
427template <
class... Tags,
class... OTags>
429 DiscreteElement<Tags...>
const& lhs,
430 DiscreteElement<OTags...>
const& rhs)
432 static_assert(type_seq_same_v<detail::TypeSeq<Tags...>, detail::TypeSeq<OTags...>>);
433 return DiscreteVector<Tags...>((uid<Tags>(lhs) - uid<Tags>(rhs))...);
KOKKOS_FUNCTION constexpr DiscreteElement & operator+=(DiscreteVector< OTags... > const &rhs)
KOKKOS_FUNCTION constexpr value_type const & uid() const noexcept
KOKKOS_FUNCTION constexpr value_type & uid() noexcept
KOKKOS_DEFAULTED_FUNCTION ~DiscreteElement()=default
KOKKOS_FUNCTION constexpr DiscreteElement & operator++()
KOKKOS_FUNCTION constexpr DiscreteElement & operator-=(IntegralType const &rhs)
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement(DiscreteElement const &)=default
KOKKOS_FUNCTION constexpr DiscreteElement(DElems const &... delems) noexcept
KOKKOS_FUNCTION constexpr DiscreteElement & operator-=(DiscreteVector< OTags... > const &rhs)
KOKKOS_FUNCTION constexpr DiscreteElement operator++(int)
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement()=default
KOKKOS_FUNCTION constexpr DiscreteElement & operator--()
KOKKOS_DEFAULTED_FUNCTION DiscreteElement & operator=(DiscreteElement const &other)=default
KOKKOS_FUNCTION constexpr DiscreteElement operator--(int)
KOKKOS_FUNCTION constexpr std::enable_if_t< N==1, value_type & > uid() noexcept
static KOKKOS_FUNCTION constexpr std::size_t size() noexcept
KOKKOS_FUNCTION constexpr std::enable_if_t< N==1, value_type const & > uid() const noexcept
KOKKOS_FUNCTION constexpr DiscreteElement & operator+=(IntegralType const &rhs)
KOKKOS_DEFAULTED_FUNCTION DiscreteElement & operator=(DiscreteElement &&other)=default
KOKKOS_FUNCTION constexpr DiscreteElement(Params const &... params) noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement(DiscreteElement &&)=default
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
The top-level namespace of DDC.
KOKKOS_FUNCTION constexpr bool operator<(DiscreteElement< Tag > const &lhs, DiscreteElement< Tag > const &rhs)
KOKKOS_FUNCTION constexpr bool operator==(DiscreteElement< Tags... > const &lhs, DiscreteElement< OTags... > const &rhs) noexcept
KOKKOS_FUNCTION constexpr DiscreteElement< QueryTags... > select(DiscreteElement< Tags... > &&arr) noexcept
constexpr DiscreteElement< DDim > create_reference_discrete_element() noexcept
KOKKOS_FUNCTION constexpr DiscreteElement< QueryTags... > select(DiscreteElement< Tags... > const &arr) noexcept
KOKKOS_FUNCTION constexpr auto const & take(HeadDElem const &head, TailDElems const &... tail)
Returns a reference towards the DiscreteElement that contains the QueryTag.
KOKKOS_FUNCTION constexpr DiscreteElement< Tag > operator-(DiscreteElement< Tag > const &lhs, IntegralType const &rhs)
KOKKOS_FUNCTION constexpr DiscreteVector< Tags... > operator-(DiscreteElement< Tags... > const &lhs, DiscreteElement< OTags... > const &rhs)
binary operator: -
KOKKOS_FUNCTION constexpr DiscreteElement< QueryTag > select_or(DiscreteElement< Tags... > const &arr, DiscreteElement< QueryTag > const &default_value) noexcept
KOKKOS_FUNCTION constexpr DiscreteElementType const & uid(DiscreteElement< Tag > const &tuple) noexcept
KOKKOS_FUNCTION constexpr DiscreteElement< Tags... > operator+(DiscreteElement< Tags... > const &lhs, DiscreteVector< OTags... > const &rhs)
right external binary operators: +, -
constexpr bool is_discrete_element_v
KOKKOS_FUNCTION constexpr bool operator>=(DiscreteElement< Tag > const &lhs, DiscreteElement< Tag > const &rhs)
KOKKOS_FUNCTION constexpr bool operator<=(DiscreteElement< Tag > const &lhs, DiscreteElement< Tag > const &rhs)
KOKKOS_FUNCTION constexpr DiscreteElementType & uid(DiscreteElement< Tags... > &tuple) noexcept
KOKKOS_FUNCTION constexpr bool operator>(DiscreteElement< Tag > const &lhs, DiscreteElement< Tag > const &rhs)
KOKKOS_FUNCTION constexpr DiscreteElement< Tag > operator+(DiscreteElement< Tag > const &lhs, IntegralType const &rhs)
KOKKOS_FUNCTION constexpr DiscreteElementType & uid(DiscreteElement< Tag > &tuple) noexcept
KOKKOS_FUNCTION constexpr DiscreteElement< Tags... > operator-(DiscreteElement< Tags... > const &lhs, DiscreteVector< OTags... > const &rhs)
KOKKOS_FUNCTION constexpr DiscreteElementType const & uid(DiscreteElement< Tags... > const &tuple) noexcept