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& tuple,
80 DiscreteElementType
const& default_value)
noexcept
82 return tuple.
template uid_or<QueryTag>(default_value);
85template <
class... QueryTags,
class... Tags>
87 DiscreteElement<Tags...>
const& arr)
noexcept
89 return DiscreteElement<QueryTags...>(arr);
92template <
class... QueryTags,
class... Tags>
94 DiscreteElement<Tags...>&& arr)
noexcept
96 return DiscreteElement<QueryTags...>(std::move(arr));
105 is_discrete_element_v<HeadDElem> && (is_discrete_element_v<TailDElems> && ...),
108KOKKOS_FUNCTION constexpr auto const&
take(HeadDElem
const& head, TailDElems
const&... tail)
110 DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
111 if constexpr (type_seq_contains_v<detail::TypeSeq<QueryTag>, to_type_seq_t<HeadDElem>>) {
113 (!type_seq_contains_v<detail::TypeSeq<QueryTag>, to_type_seq_t<TailDElems>> && ...),
114 "ERROR: tag redundant");
117 static_assert(
sizeof...(TailDElems) > 0,
"ERROR: tag not found");
118 return take<QueryTag>(tail...);
126template <
class... Tags>
127KOKKOS_FUNCTION
constexpr std::array<DiscreteElementType,
sizeof...(Tags)>& array(
128 DiscreteElement<Tags...>& v)
noexcept
134template <
class... Tags>
135KOKKOS_FUNCTION
constexpr std::array<DiscreteElementType,
sizeof...(Tags)>
const& array(
136 DiscreteElement<Tags...>
const& v)
noexcept
144
145
146
147template <
class... Tags>
150 using tags_seq = detail::TypeSeq<Tags...>;
152 friend KOKKOS_FUNCTION
constexpr std::array<DiscreteElementType,
sizeof...(Tags)>& detail::
153 array<Tags...>(DiscreteElement<Tags...>& v)
noexcept;
155 friend KOKKOS_FUNCTION
constexpr std::array<DiscreteElementType,
sizeof...(Tags)>
const&
156 detail::array<Tags...>(DiscreteElement<Tags...>
const& v)
noexcept;
159 std::array<DiscreteElementType,
sizeof...(Tags)> m_values;
162 using value_type = DiscreteElementType;
166 return sizeof...(Tags);
172 KOKKOS_DEFAULTED_FUNCTION
constexpr DiscreteElement(DiscreteElement
const&) =
default;
174 KOKKOS_DEFAULTED_FUNCTION
constexpr DiscreteElement(DiscreteElement&&) =
default;
176 template <
class... DElems,
class = std::enable_if_t<(is_discrete_element_v<DElems> && ...)>>
178 : m_values {take<Tags>(delems...).
template uid<Tags>()...}
184 class = std::enable_if_t<(!is_discrete_element_v<Params> && ...)>,
185 class = std::enable_if_t<(std::is_integral_v<Params> && ...)>,
186 class = std::enable_if_t<
sizeof...(Params) ==
sizeof...(Tags)>>
188 : m_values {
static_cast<value_type>(params)...}
194 KOKKOS_DEFAULTED_FUNCTION DiscreteElement&
operator=(DiscreteElement
const& other) =
default;
196 KOKKOS_DEFAULTED_FUNCTION DiscreteElement&
operator=(DiscreteElement&& other) =
default;
198 template <
class QueryTag>
201 DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
202 if constexpr (in_tags_v<QueryTag, tags_seq>) {
203 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
205 return default_value;
210 template <
class QueryTag>
213 static_assert(in_tags_v<QueryTag, tags_seq>,
"requested Tag absent from DiscreteElement");
214 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
217 template <
class QueryTag>
220 static_assert(in_tags_v<QueryTag, tags_seq>,
"requested Tag absent from DiscreteElement");
221 return m_values[type_seq_rank_v<QueryTag, tags_seq>];
224 template <std::size_t N =
sizeof...(Tags)>
230 template <std::size_t N =
sizeof...(Tags)>
231 KOKKOS_FUNCTION constexpr std::enable_if_t<N == 1, value_type
const&>
uid()
const noexcept
236 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
243 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
246 DiscreteElement
const tmp = *
this;
251 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
258 template <std::size_t N =
sizeof...(Tags),
class = std::enable_if_t<N == 1>>
261 DiscreteElement
const tmp = *
this;
266 template <
class... OTags>
269 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
270 ((m_values[type_seq_rank_v<OTags, tags_seq>] += rhs.
template get<OTags>()), ...);
276 std::size_t N =
sizeof...(Tags),
277 class = std::enable_if_t<N == 1>,
278 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
285 template <
class... OTags>
288 static_assert(((type_seq_contains_v<detail::TypeSeq<OTags>, tags_seq>) && ...));
289 ((m_values[type_seq_rank_v<OTags, tags_seq>] -= rhs.
template get<OTags>()), ...);
295 std::size_t N =
sizeof...(Tags),
296 class = std::enable_if_t<N == 1>,
297 class = std::enable_if_t<std::is_integral_v<IntegralType>>>
305inline std::ostream& operator<<(std::ostream& out, DiscreteElement<>
const&)
311template <
class Head,
class... Tags>
312std::ostream& operator<<(std::ostream& out, DiscreteElement<Head, Tags...>
const& arr)
315 out << uid<Head>(arr);
316 ((out <<
", " << uid<Tags>(arr)), ...);
322template <
class... Tags,
class... OTags>
324 DiscreteElement<Tags...>
const& lhs,
325 DiscreteElement<OTags...>
const& rhs)
noexcept
327 return ((lhs.
template uid<Tags>() == rhs.
template uid<Tags>()) && ...);
330#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
343 DiscreteElement<Tag>
const& lhs,
344 DiscreteElement<Tag>
const& rhs)
346 return lhs.uid() < rhs.uid();
351 DiscreteElement<Tag>
const& lhs,
352 DiscreteElement<Tag>
const& rhs)
354 return lhs.uid() <= rhs.uid();
359 DiscreteElement<Tag>
const& lhs,
360 DiscreteElement<Tag>
const& rhs)
362 return lhs.uid() > rhs.uid();
367 DiscreteElement<Tag>
const& lhs,
368 DiscreteElement<Tag>
const& rhs)
370 return lhs.uid() >= rhs.uid();
375template <
class... Tags,
class... OTags>
377 DiscreteElement<Tags...>
const& lhs,
380 using detail::TypeSeq;
381 static_assert(((type_seq_contains_v<TypeSeq<OTags>, TypeSeq<Tags...>>) && ...));
382 DiscreteElement<Tags...> result(lhs);
390 class = std::enable_if_t<std::is_integral_v<IntegralType>>,
391 class = std::enable_if_t<!is_discrete_vector_v<IntegralType>>>
393 DiscreteElement<Tag>
const& lhs,
394 IntegralType
const& rhs)
396 return DiscreteElement<Tag>(uid<Tag>(lhs) + rhs);
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 return DiscreteElement<Tag>(uid<Tag>(lhs) - rhs);
425template <
class... Tags,
class... OTags>
427 DiscreteElement<Tags...>
const& lhs,
428 DiscreteElement<OTags...>
const& rhs)
430 static_assert(type_seq_same_v<detail::TypeSeq<Tags...>, detail::TypeSeq<OTags...>>);
431 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 value_type const & uid_or(value_type const &default_value) const &
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 DiscreteElementType const & uid_or(DiscreteElement< Tags... > const &tuple, DiscreteElementType const &default_value) noexcept
KOKKOS_FUNCTION constexpr bool operator==(DiscreteElement< Tags... > const &lhs, DiscreteElement< OTags... > const &rhs) noexcept
KOKKOS_FUNCTION constexpr DiscreteElement< QueryTags... > select(DiscreteElement< Tags... > &&arr) 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 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