DDC 0.12.0
Loading...
Searching...
No Matches
discrete_domain.hpp
1// Copyright (C) The DDC development team, see COPYRIGHT.md file
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <cstddef>
8#include <iterator>
9#include <tuple>
10#include <type_traits>
11#include <utility>
12
13#include <Kokkos_Assert.hpp>
14#include <Kokkos_Macros.hpp>
15
16#include "detail/type_seq.hpp"
17
20
21namespace ddc {
22
23template <class DDim>
25
26template <class... DDims>
27class DiscreteDomain;
28
29template <class T>
30struct is_discrete_domain : std::false_type
31{
32};
33
34template <class... Tags>
35struct is_discrete_domain<DiscreteDomain<Tags...>> : std::true_type
36{
37};
38
39template <class T>
40inline constexpr bool is_discrete_domain_v = is_discrete_domain<T>::value;
41
42namespace concepts {
43
44template <class T>
45concept discrete_domain = is_discrete_domain_v<T>;
46
47}
48
49namespace detail {
50
51template <class... Tags>
52struct ToTypeSeq<DiscreteDomain<Tags...>>
53{
54 using type = TypeSeq<Tags...>;
55};
56
57template <class T, class U>
58struct RebindDomain;
59
60template <class... DDims, class... ODDims>
61struct RebindDomain<DiscreteDomain<DDims...>, detail::TypeSeq<ODDims...>>
62{
63 using type = DiscreteDomain<ODDims...>;
64};
65
66} // namespace detail
67
68template <class... DDims>
70{
71 template <class...>
72 friend class DiscreteDomain;
73
74 static_assert(
75 type_seq_is_unique_v<detail::TypeSeq<DDims...>>,
76 "The dimensions of a DiscreteDomain must be unique");
77
78public:
79 using discrete_element_type = DiscreteElement<DDims...>;
80
81 using discrete_vector_type = DiscreteVector<DDims...>;
82
83private:
84 DiscreteElement<DDims...> m_element_begin;
85
86 DiscreteElement<DDims...> m_element_end;
87
88public:
89 static KOKKOS_FUNCTION constexpr std::size_t rank()
90 {
91 return sizeof...(DDims);
92 }
93
94 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain() = default;
95
96 /// Construct a DiscreteDomain by copies and merge of domains
97 template <concepts::discrete_domain... DDoms>
98 KOKKOS_FUNCTION constexpr explicit DiscreteDomain(DDoms const&... domains)
99 : m_element_begin(domains.front()...)
100 , m_element_end((domains.front() + domains.extents())...)
101 {
102 }
103
104 /** Construct a DiscreteDomain starting from element_begin with size points.
105 * @param element_begin the lower bound in each direction
106 * @param size the number of points in each direction
107 */
108 KOKKOS_FUNCTION constexpr DiscreteDomain(
109 discrete_element_type const& element_begin,
110 discrete_vector_type const& size)
111 : m_element_begin(element_begin)
112 , m_element_end(element_begin + size)
113 {
114 }
115
116 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain const& x) = default;
117
118 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain&& x) = default;
119
120 KOKKOS_DEFAULTED_FUNCTION ~DiscreteDomain() = default;
121
122 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain& operator=(DiscreteDomain const& x) = default;
123
124 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain& operator=(DiscreteDomain&& x) = default;
125
126 template <class... ODims>
127 KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain<ODims...> const& other) const
128 {
129 if (empty() && other.empty()) {
130 return true;
131 }
132 return m_element_begin == other.m_element_begin && m_element_end == other.m_element_end;
133 }
134
135#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
136 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
137 template <class... ODims>
138 KOKKOS_FUNCTION constexpr bool operator!=(DiscreteDomain<ODims...> const& other) const
139 {
140 return !(*this == other);
141 }
142#endif
143
144 KOKKOS_FUNCTION constexpr std::size_t size() const
145 {
146 return (1UL * ... * extent<DDims>().value());
147 }
148
149 KOKKOS_FUNCTION constexpr discrete_vector_type extents() const noexcept
150 {
151 return m_element_end - m_element_begin;
152 }
153
154 template <class QueryDDim>
155 KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDim> extent() const noexcept
156 {
157 return DiscreteElement<QueryDDim>(m_element_end)
158 - DiscreteElement<QueryDDim>(m_element_begin);
159 }
160
161 KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
162 {
163 return m_element_begin;
164 }
165
166 KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
167 {
168 return discrete_element_type((DiscreteElement<DDims>(m_element_end) - 1)...);
169 }
170
171 KOKKOS_FUNCTION constexpr DiscreteDomain take_first(discrete_vector_type n) const
172 {
173 return DiscreteDomain(front(), n);
174 }
175
176 KOKKOS_FUNCTION constexpr DiscreteDomain take_last(discrete_vector_type n) const
177 {
178 return DiscreteDomain(front() + (extents() - n), n);
179 }
180
181 KOKKOS_FUNCTION constexpr DiscreteDomain remove_first(discrete_vector_type n) const
182 {
183 return DiscreteDomain(front() + n, extents() - n);
184 }
185
186 KOKKOS_FUNCTION constexpr DiscreteDomain remove_last(discrete_vector_type n) const
187 {
188 return DiscreteDomain(front(), extents() - n);
189 }
190
191 KOKKOS_FUNCTION constexpr DiscreteDomain remove(
192 discrete_vector_type n1,
193 discrete_vector_type n2) const
194 {
195 return DiscreteDomain(front() + n1, extents() - n1 - n2);
196 }
197
198 KOKKOS_FUNCTION constexpr DiscreteElement<DDims...> operator()(
199 DiscreteVector<DDims...> const& dvect) const noexcept
200 {
201 return m_element_begin + dvect;
202 }
203
204 template <class... ODDims>
205 KOKKOS_FUNCTION constexpr auto restrict_with(DiscreteDomain<ODDims...> const& odomain) const
206 {
207 KOKKOS_ASSERT(
208 ((DiscreteElement<ODDims>(m_element_begin)
209 <= DiscreteElement<ODDims>(odomain.m_element_begin))
210 && ...))
211 KOKKOS_ASSERT(
212 ((DiscreteElement<ODDims>(m_element_end)
213 >= DiscreteElement<ODDims>(odomain.m_element_end))
214 && ...))
215 DiscreteVector<DDims...> const myextents = extents();
216 DiscreteVector<ODDims...> const oextents = odomain.extents();
217 return DiscreteDomain(
218 DiscreteElement<DDims...>((select_or<DDims>(
219 odomain.m_element_begin,
220 DiscreteElement<DDims>(m_element_begin)))...),
221 DiscreteVector<DDims...>(
222 (select_or<DDims>(oextents, DiscreteVector<DDims>(myextents)))...));
223 }
224
225 template <class... DElems>
226 KOKKOS_FUNCTION bool contains(DElems const&... delems) const noexcept
227 {
228 static_assert(
229 sizeof...(DDims) == (0 + ... + DElems::size()),
230 "Invalid number of dimensions");
231 static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements");
232 DiscreteElement<DDims...> const delem(delems...);
233 for (std::size_t i = 0; i < rank(); ++i) {
234 if ((detail::array(delem)[i] < detail::array(m_element_begin)[i])
235 || (detail::array(delem)[i] >= detail::array(m_element_end)[i])) {
236 return false;
237 }
238 }
239 return true;
240 }
241
242 template <class... DElems>
243 KOKKOS_FUNCTION DiscreteVector<DDims...> distance_from_front(
244 DElems const&... delems) const noexcept
245 {
246 static_assert(
247 sizeof...(DDims) == (0 + ... + DElems::size()),
248 "Invalid number of dimensions");
249 static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements");
250 return DiscreteVector<DDims...>(
251 (DiscreteElement<DDims>(take<DDims>(delems...))
252 - DiscreteElement<DDims>(m_element_begin))...);
253 }
254
255 KOKKOS_FUNCTION constexpr bool empty() const noexcept
256 {
257 return size() == 0;
258 }
259
260 KOKKOS_FUNCTION constexpr explicit operator bool()
261 {
262 return !empty();
263 }
264
265 KOKKOS_FUNCTION auto begin() const
266 requires(sizeof...(DDims) == 1)
267 {
268 return DiscreteDomainIterator<std::tuple_element_t<0, std::tuple<DDims...>>>(front());
269 }
270
271 KOKKOS_FUNCTION auto end() const
272 requires(sizeof...(DDims) == 1)
273 {
274 return DiscreteDomainIterator<std::tuple_element_t<0, std::tuple<DDims...>>>(m_element_end);
275 }
276
277 KOKKOS_FUNCTION auto cbegin() const
278 requires(sizeof...(DDims) == 1)
279 {
280 return DiscreteDomainIterator<std::tuple_element_t<0, std::tuple<DDims...>>>(front());
281 }
282
283 KOKKOS_FUNCTION auto cend() const
284 requires(sizeof...(DDims) == 1)
285 {
286 return DiscreteDomainIterator<std::tuple_element_t<0, std::tuple<DDims...>>>(m_element_end);
287 }
288
289 KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
290 requires(sizeof...(DDims) == 1)
291 {
292 return begin()[n];
293 }
294
295 KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
296 requires(sizeof...(DDims) == 1)
297 {
298 return begin()[n];
299 }
300};
301
302template <>
303class DiscreteDomain<>
304{
305 template <class...>
306 friend class DiscreteDomain;
307
308public:
309 using discrete_element_type = DiscreteElement<>;
310
311 using discrete_vector_type = DiscreteVector<>;
312
313 static KOKKOS_FUNCTION constexpr std::size_t rank()
314 {
315 return 0;
316 }
317
318 KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteDomain() = default;
319
320 /// Construct a DiscreteDomain by copies and merge of domains
321 template <class... DDoms>
322 KOKKOS_FUNCTION constexpr explicit DiscreteDomain(DDoms const&... /*domains*/)
323 requires(is_discrete_domain_v<DDoms> && ...)
324 {
325 }
326
327 /** Construct a DiscreteDomain starting from element_begin with size points.
328 * @param element_begin the lower bound in each direction
329 * @param size the number of points in each direction
330 */
331 KOKKOS_FUNCTION constexpr DiscreteDomain(
332 [[maybe_unused]] discrete_element_type const& element_begin,
333 [[maybe_unused]] discrete_vector_type const& size)
334 {
335 // Parameters `element_begin` and `size` are always unused, but needed for Doxygen
336 }
337
338 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain const& x) = default;
339
340 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain&& x) = default;
341
342 KOKKOS_DEFAULTED_FUNCTION ~DiscreteDomain() = default;
343
344 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain& operator=(DiscreteDomain const& x) = default;
345
346 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain& operator=(DiscreteDomain&& x) = default;
347
348 KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain const& /*other*/) const
349 {
350 return true;
351 }
352
353#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
354 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
355 KOKKOS_FUNCTION constexpr bool operator!=(DiscreteDomain const& other) const
356 {
357 return !(*this == other);
358 }
359#endif
360
361 static KOKKOS_FUNCTION constexpr std::size_t size()
362 {
363 return 1;
364 }
365
366 static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
367 {
368 return {};
369 }
370
371 static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
372 {
373 return {};
374 }
375
376 static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
377 {
378 return {};
379 }
380
381 KOKKOS_FUNCTION constexpr DiscreteDomain take_first(discrete_vector_type /*n*/) const
382 {
383 return *this;
384 }
385
386 KOKKOS_FUNCTION constexpr DiscreteDomain take_last(discrete_vector_type /*n*/) const
387 {
388 return *this;
389 }
390
391 KOKKOS_FUNCTION constexpr DiscreteDomain remove_first(discrete_vector_type /*n*/) const
392 {
393 return *this;
394 }
395
396 KOKKOS_FUNCTION constexpr DiscreteDomain remove_last(discrete_vector_type /*n*/) const
397 {
398 return *this;
399 }
400
401 KOKKOS_FUNCTION constexpr DiscreteDomain remove(
402 discrete_vector_type /*n1*/,
403 discrete_vector_type /*n2*/) const
404 {
405 return *this;
406 }
407
408 KOKKOS_FUNCTION constexpr DiscreteElement<> operator()(
409 DiscreteVector<> const& /*dvect*/) const noexcept
410 {
411 return {};
412 }
413
414 template <class... ODims>
415 KOKKOS_FUNCTION constexpr DiscreteDomain restrict_with(
416 DiscreteDomain<ODims...> const& /*odomain*/) const
417 {
418 return *this;
419 }
420
421 static KOKKOS_FUNCTION bool contains() noexcept
422 {
423 return true;
424 }
425
426 static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
427 {
428 return true;
429 }
430
431 static KOKKOS_FUNCTION DiscreteVector<> distance_from_front() noexcept
432 {
433 return {};
434 }
435
436 static KOKKOS_FUNCTION DiscreteVector<> distance_from_front(DiscreteElement<>) noexcept
437 {
438 return {};
439 }
440
441 static KOKKOS_FUNCTION constexpr bool empty() noexcept
442 {
443 return false;
444 }
445
446 KOKKOS_FUNCTION constexpr explicit operator bool()
447 {
448 return true;
449 }
450};
451
452template <class... QueryDDims, class... DDims>
453KOKKOS_FUNCTION constexpr DiscreteDomain<QueryDDims...> select(
454 DiscreteDomain<DDims...> const& domain)
455{
456 return DiscreteDomain<QueryDDims...>(domain);
457}
458
459namespace detail {
460
461template <class T>
462struct ConvertTypeSeqToDiscreteDomain;
463
464template <class... DDims>
465struct ConvertTypeSeqToDiscreteDomain<detail::TypeSeq<DDims...>>
466{
467 using type = DiscreteDomain<DDims...>;
468};
469
470template <class T>
471using convert_type_seq_to_discrete_domain_t = typename ConvertTypeSeqToDiscreteDomain<T>::type;
472
473} // namespace detail
474
475// Computes the cartesian product of DiscreteDomain types
476// Example usage : "using DDom = cartesian_prod_t<DDom1,DDom2,DDom3>;"
477template <typename... DDoms>
478struct cartesian_prod;
479
480template <typename... DDims1, typename... DDims2, typename... DDomsTail>
481struct cartesian_prod<DiscreteDomain<DDims1...>, DiscreteDomain<DDims2...>, DDomsTail...>
482{
483 using type = typename cartesian_prod<DiscreteDomain<DDims1..., DDims2...>, DDomsTail...>::type;
484};
485
486template <typename... DDims>
487struct cartesian_prod<DiscreteDomain<DDims...>>
488{
489 using type = DiscreteDomain<DDims...>;
490};
491
492template <>
493struct cartesian_prod<>
494{
495 using type = ddc::DiscreteDomain<>;
496};
497
498template <typename... DDoms>
499using cartesian_prod_t = typename cartesian_prod<DDoms...>::type;
500
501// Computes the subtraction DDom_a - DDom_b in the sense of linear spaces(retained dimensions are those in DDom_a which are not in DDom_b)
502template <class... DDimsA, class... DDimsB>
503KOKKOS_FUNCTION constexpr auto remove_dims_of(
504 DiscreteDomain<DDimsA...> const& DDom_a,
505 DiscreteDomain<DDimsB...> const& /*DDom_b*/) noexcept
506{
507 using TagSeqA = detail::TypeSeq<DDimsA...>;
508 using TagSeqB = detail::TypeSeq<DDimsB...>;
509
510 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
511 return detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(DDom_a);
512}
513
514//! Remove the dimensions DDimsB from DDom_a
515//! @param[in] DDom_a The discrete domain on which to remove dimensions
516//! @return The discrete domain without DDimsB dimensions
517template <class... DDimsB, class... DDimsA>
518KOKKOS_FUNCTION constexpr auto remove_dims_of(DiscreteDomain<DDimsA...> const& DDom_a) noexcept
519{
520 using TagSeqA = detail::TypeSeq<DDimsA...>;
521 using TagSeqB = detail::TypeSeq<DDimsB...>;
522
523 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
524 return detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(DDom_a);
525}
526
527// Remove dimensions from a domain type
528template <typename DDom, typename... DDims>
529using remove_dims_of_t = decltype(remove_dims_of<DDims...>(std::declval<DDom>()));
530
531namespace detail {
532
533// Checks if dimension of DDom_a is DDim1. If not, returns restriction to DDim2 of DDom_b. May not be useful in its own, it helps for replace_dim_of
534template <typename DDim1, typename DDim2, typename DDimA, typename... DDimsB>
535KOKKOS_FUNCTION constexpr std::conditional_t<
536 std::is_same_v<DDimA, DDim1>,
537 ddc::DiscreteDomain<DDim2>,
538 ddc::DiscreteDomain<DDimA>>
539replace_dim_of_1d(
540 [[maybe_unused]] DiscreteDomain<DDimA> const& DDom_a,
541 [[maybe_unused]] DiscreteDomain<DDimsB...> const& DDom_b) noexcept
542{
543 if constexpr (std::is_same_v<DDimA, DDim1>) {
544 return ddc::DiscreteDomain<DDim2>(DDom_b);
545 } else {
546 return DDom_a;
547 }
548}
549
550} // namespace detail
551
552// Replace in DDom_a the dimension Dim1 by the dimension Dim2 of DDom_b
553template <typename DDim1, typename DDim2, typename... DDimsA, typename... DDimsB>
554KOKKOS_FUNCTION constexpr auto replace_dim_of(
555 DiscreteDomain<DDimsA...> const& DDom_a,
556 [[maybe_unused]] DiscreteDomain<DDimsB...> const& DDom_b) noexcept
557{
558 // TODO : static_asserts
559 using TagSeqA = detail::TypeSeq<DDimsA...>;
560 using TagSeqB = detail::TypeSeq<DDim1>;
561 using TagSeqC = detail::TypeSeq<DDim2>;
562
563 using type_seq_r = ddc::type_seq_replace_t<TagSeqA, TagSeqB, TagSeqC>;
564 return ddc::detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(
565 detail::replace_dim_of_1d<
566 DDim1,
567 DDim2,
568 DDimsA,
569 DDimsB...>(ddc::DiscreteDomain<DDimsA>(DDom_a), DDom_b)...);
570}
571
572// Replace dimensions from a domain type
573template <typename DDom, typename DDim1, typename DDim2>
574using replace_dim_of_t = decltype(replace_dim_of<DDim1, DDim2>(
575 std::declval<DDom>(),
576 std::declval<typename detail::RebindDomain<DDom, detail::TypeSeq<DDim2>>::type>()));
577
578
579template <class... QueryDDims, class... DDims>
580KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDims...> extents(
581 DiscreteDomain<DDims...> const& domain) noexcept
582{
583 return DiscreteVector<QueryDDims...>(DiscreteDomain<QueryDDims>(domain).size()...);
584}
585
586template <class... QueryDDims, class... DDims>
587KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> front(
588 DiscreteDomain<DDims...> const& domain) noexcept
589{
590 return DiscreteElement<QueryDDims...>(DiscreteDomain<QueryDDims>(domain).front()...);
591}
592
593template <class... QueryDDims, class... DDims>
594KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> back(
595 DiscreteDomain<DDims...> const& domain) noexcept
596{
597 return DiscreteElement<QueryDDims...>(DiscreteDomain<QueryDDims>(domain).back()...);
598}
599
600template <class DDim>
602{
603private:
604 DiscreteElement<DDim> m_value = DiscreteElement<DDim>();
605
606public:
607 using iterator_category = std::random_access_iterator_tag;
608
609 using value_type = DiscreteElement<DDim>;
610
611 using difference_type = std::ptrdiff_t;
612
613 KOKKOS_DEFAULTED_FUNCTION DiscreteDomainIterator() = default;
614
615 KOKKOS_FUNCTION constexpr explicit DiscreteDomainIterator(DiscreteElement<DDim> value)
616 : m_value(value)
617 {
618 }
619
620 KOKKOS_FUNCTION constexpr DiscreteElement<DDim> operator*() const noexcept
621 {
622 return m_value;
623 }
624
625 KOKKOS_FUNCTION constexpr DiscreteDomainIterator& operator++()
626 {
627 ++m_value;
628 return *this;
629 }
630
631 KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator++(int)
632 {
633 auto tmp = *this;
634 ++*this;
635 return tmp;
636 }
637
638 KOKKOS_FUNCTION constexpr DiscreteDomainIterator& operator--()
639 {
640 --m_value;
641 return *this;
642 }
643
644 KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator--(int)
645 {
646 auto tmp = *this;
647 --*this;
648 return tmp;
649 }
650
651 KOKKOS_FUNCTION constexpr DiscreteDomainIterator& operator+=(difference_type n)
652 {
653 if (n >= static_cast<difference_type>(0)) {
654 m_value += static_cast<DiscreteElementType>(n);
655 } else {
656 m_value -= static_cast<DiscreteElementType>(-n);
657 }
658 return *this;
659 }
660
661 KOKKOS_FUNCTION constexpr DiscreteDomainIterator& operator-=(difference_type n)
662 {
663 if (n >= static_cast<difference_type>(0)) {
664 m_value -= static_cast<DiscreteElementType>(n);
665 } else {
666 m_value += static_cast<DiscreteElementType>(-n);
667 }
668 return *this;
669 }
670
671 KOKKOS_FUNCTION constexpr DiscreteElement<DDim> operator[](difference_type n) const
672 {
673 return m_value + n;
674 }
675
676 friend KOKKOS_FUNCTION constexpr bool operator==(
677 DiscreteDomainIterator const& xx,
678 DiscreteDomainIterator const& yy)
679 {
680 return xx.m_value == yy.m_value;
681 }
682
683#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
684 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
685 friend KOKKOS_FUNCTION constexpr bool operator!=(
688 {
689 return xx.m_value != yy.m_value;
690 }
691#endif
692
693 friend KOKKOS_FUNCTION constexpr bool operator<(
694 DiscreteDomainIterator const& xx,
695 DiscreteDomainIterator const& yy)
696 {
697 return xx.m_value < yy.m_value;
698 }
699
700 friend KOKKOS_FUNCTION constexpr bool operator>(
701 DiscreteDomainIterator const& xx,
702 DiscreteDomainIterator const& yy)
703 {
704 return yy < xx;
705 }
706
707 friend KOKKOS_FUNCTION constexpr bool operator<=(
708 DiscreteDomainIterator const& xx,
709 DiscreteDomainIterator const& yy)
710 {
711 return !(yy < xx);
712 }
713
714 friend KOKKOS_FUNCTION constexpr bool operator>=(
715 DiscreteDomainIterator const& xx,
716 DiscreteDomainIterator const& yy)
717 {
718 return !(xx < yy);
719 }
720
721 friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator+(
723 difference_type n)
724 {
725 return i += n;
726 }
727
728 friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator+(
729 difference_type n,
731 {
732 return i += n;
733 }
734
735 friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator-(
737 difference_type n)
738 {
739 return i -= n;
740 }
741
742 friend KOKKOS_FUNCTION constexpr difference_type operator-(
743 DiscreteDomainIterator const& xx,
744 DiscreteDomainIterator const& yy)
745 {
746 return (yy.m_value > xx.m_value) ? (-static_cast<difference_type>(yy.m_value - xx.m_value))
747 : (xx.m_value - yy.m_value);
748 }
749};
750
751} // namespace ddc
friend class ChunkSpan
KOKKOS_FUNCTION constexpr ChunkCommon(ElementType *ptr, SupportType const &domain)
Constructs a new ChunkCommon from scratch.
KOKKOS_FUNCTION constexpr bool is_strided() const noexcept
KOKKOS_DEFAULTED_FUNCTION ~ChunkCommon() noexcept=default
KOKKOS_FUNCTION constexpr ElementType * data_handle() const
Access to the underlying allocation pointer.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon()=default
Empty ChunkCommon.
allocation_mdspan_type m_allocation_mdspan
The raw view of the data.
KOKKOS_FUNCTION constexpr SupportType domain() const noexcept
Provide access to the domain on which this chunk is defined.
static KOKKOS_FUNCTION constexpr bool is_always_strided() noexcept
KOKKOS_FUNCTION constexpr allocation_mdspan_type allocation_mdspan() const
Provide a modifiable view of the data.
KOKKOS_FUNCTION constexpr ChunkCommon(allocation_mdspan_type allocation_mdspan, SupportType const &domain) noexcept
Constructs a new ChunkCommon from scratch.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon(ChunkCommon const &other)=default
Constructs a new ChunkCommon by copy, yields a new view to the same data.
static KOKKOS_FUNCTION constexpr bool is_always_unique() noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain< QueryDDims... > domain() const noexcept
Provide access to the domain on which this chunk is defined.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon & operator=(ChunkCommon const &other)=default
Copy-assigns a new value to this ChunkCommon, yields a new view to the same data.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon(ChunkCommon &&other) noexcept=default
Constructs a new ChunkCommon by move.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon & operator=(ChunkCommon &&other) noexcept=default
Move-assigns a new value to this ChunkCommon.
KOKKOS_FUNCTION constexpr size_type extent() const noexcept
KOKKOS_FUNCTION constexpr size_type stride() const
KOKKOS_FUNCTION constexpr bool is_exhaustive() const noexcept
KOKKOS_FUNCTION constexpr mapping_type mapping() const noexcept
static KOKKOS_FUNCTION constexpr int rank() noexcept
KOKKOS_FUNCTION constexpr bool is_unique() const noexcept
KOKKOS_FUNCTION constexpr accessor_type accessor() const
KOKKOS_FUNCTION constexpr SupportType::discrete_vector_type extents() const noexcept
KOKKOS_FUNCTION constexpr size_type size() const noexcept
SupportType m_domain
The mesh on which this chunk is defined.
static KOKKOS_FUNCTION constexpr int rank_dynamic() noexcept
static KOKKOS_FUNCTION constexpr size_type static_extent(std::size_t r) noexcept
static KOKKOS_FUNCTION constexpr bool is_always_exhaustive() noexcept
auto operator[](DiscreteElement< QueryDDims... > const &slice_spec) const
Slice out some dimensions.
Definition chunk.hpp:154
char const * label() const
Returns the label of the Chunk.
Definition chunk.hpp:249
const_allocation_mdspan_type allocation_mdspan() const
Provide a mdspan on the memory allocation.
Definition chunk.hpp:273
ElementType const * data_handle() const
Access to the underlying allocation pointer.
Definition chunk.hpp:257
auto allocation_kokkos_view()
Provide an unmanaged Kokkos::View on the memory allocation.
Definition chunk.hpp:289
auto operator[](DiscreteDomain< QueryDDims... > const &odomain)
Slice out some dimensions.
Definition chunk.hpp:176
auto allocation_kokkos_view() const
Provide an unmanaged Kokkos::View on the memory allocation.
Definition chunk.hpp:305
Chunk(SupportType const &domain, Allocator allocator=Allocator())
Construct a Chunk on a domain with uninitialized values.
Definition chunk.hpp:104
Chunk & operator=(Chunk const &other)=delete
Deleted: use deepcopy instead.
allocation_mdspan_type allocation_mdspan()
Provide a mdspan on the memory allocation.
Definition chunk.hpp:281
ElementType * data_handle()
Access to the underlying allocation pointer.
Definition chunk.hpp:265
view_type span_cview() const
Definition chunk.hpp:318
Chunk(Chunk const &other)=delete
Deleted: use deepcopy instead.
~Chunk() noexcept
Definition chunk.hpp:124
Chunk(std::string const &label, SupportType const &domain, Allocator allocator=Allocator())
Construct a labeled Chunk on a domain with uninitialized values.
Definition chunk.hpp:93
element_type & operator()(DElems const &... delems) noexcept
Element access using a list of DiscreteElement.
Definition chunk.hpp:219
Chunk()=default
Empty Chunk.
Chunk & operator=(Chunk &&other) noexcept
Move-assigns a new value to this field.
Definition chunk.hpp:138
Chunk(Chunk &&other) noexcept
Constructs a new Chunk by move.
Definition chunk.hpp:115
friend class Chunk
Definition chunk.hpp:81
span_type span_view()
Definition chunk.hpp:328
view_type span_view() const
Definition chunk.hpp:323
auto operator[](DiscreteDomain< QueryDDims... > const &odomain) const
Slice out some dimensions.
Definition chunk.hpp:168
element_type const & operator()(DElems const &... delems) const noexcept
Element access using a list of DiscreteElement.
Definition chunk.hpp:187
auto operator[](DiscreteElement< QueryDDims... > const &slice_spec)
Slice out some dimensions.
Definition chunk.hpp:161
static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
KOKKOS_DEFAULTED_FUNCTION ~DiscreteDomain()=default
KOKKOS_FUNCTION constexpr DiscreteDomain(discrete_element_type const &element_begin, discrete_vector_type const &size)
Construct a DiscreteDomain starting from element_begin with size points.
KOKKOS_FUNCTION constexpr DiscreteDomain(DDoms const &...)
Construct a DiscreteDomain by copies and merge of domains.
KOKKOS_FUNCTION constexpr DiscreteDomain take_last(discrete_vector_type) const
KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain const &) const
KOKKOS_FUNCTION constexpr DiscreteDomain remove(discrete_vector_type, discrete_vector_type) const
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_FUNCTION constexpr DiscreteDomain remove_last(discrete_vector_type) const
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain const &x)=default
static KOKKOS_FUNCTION bool contains() noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteDomain()=default
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr operator bool()
static KOKKOS_FUNCTION constexpr std::size_t size()
static KOKKOS_FUNCTION constexpr bool empty() noexcept
static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
static KOKKOS_FUNCTION DiscreteVector distance_from_front(DiscreteElement<>) noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain remove_first(discrete_vector_type) const
static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr DiscreteDomain take_first(discrete_vector_type) const
KOKKOS_FUNCTION constexpr DiscreteDomain restrict_with(DiscreteDomain< ODims... > const &) const
KOKKOS_FUNCTION constexpr DiscreteElement operator()(DiscreteVector<> const &) const noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain &&x)=default
static KOKKOS_FUNCTION DiscreteVector distance_from_front() noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain const &x)=default
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr DiscreteDomain remove_last(discrete_vector_type n) const
KOKKOS_FUNCTION bool contains(DElems const &... delems) const noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain take_last(discrete_vector_type n) const
KOKKOS_FUNCTION constexpr DiscreteDomain(DDoms const &... domains)
Construct a DiscreteDomain by copies and merge of domains.
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
KOKKOS_FUNCTION constexpr DiscreteDomain remove(discrete_vector_type n1, discrete_vector_type n2) const
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
KOKKOS_FUNCTION constexpr auto restrict_with(DiscreteDomain< ODDims... > const &odomain) const
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_FUNCTION constexpr bool empty() const noexcept
KOKKOS_FUNCTION constexpr std::size_t size() const
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr discrete_vector_type extents() const noexcept
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDim > extent() const noexcept
KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr DiscreteDomain remove_first(discrete_vector_type n) const
KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain< ODims... > const &other) const
KOKKOS_FUNCTION constexpr DiscreteDomain take_first(discrete_vector_type n) const
KOKKOS_DEFAULTED_FUNCTION ~DiscreteDomain()=default
KOKKOS_FUNCTION DiscreteVector< DDims... > distance_from_front(DElems const &... delems) const noexcept
KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr DiscreteElement< DDims... > operator()(DiscreteVector< DDims... > const &dvect) const noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain()=default
KOKKOS_FUNCTION constexpr operator bool()
KOKKOS_FUNCTION constexpr DiscreteDomain(discrete_element_type const &element_begin, discrete_vector_type const &size)
Construct a DiscreteDomain starting from element_begin with size points.
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement()=default
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteVector()=default
The top-level namespace of DDC.
constexpr bool is_borrowed_chunk_v
KOKKOS_FUNCTION auto get_domain(ChunkType const &chunk) noexcept
Access the domain (or subdomain) of a view.
constexpr bool enable_chunk< Chunk< ElementType, SupportType, Allocator > >
Definition chunk.hpp:28
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > back(DiscreteDomain< DDims... > const &domain) noexcept
constexpr bool enable_borrowed_chunk
constexpr bool enable_chunk
constexpr bool is_chunk_v
KOKKOS_FUNCTION constexpr auto remove_dims_of(DiscreteDomain< DDimsA... > const &DDom_a, DiscreteDomain< DDimsB... > const &) noexcept
KOKKOS_FUNCTION constexpr auto remove_dims_of(DiscreteDomain< DDimsA... > const &DDom_a) noexcept
Remove the dimensions DDimsB from DDom_a.
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > front(DiscreteDomain< DDims... > const &domain) noexcept
constexpr bool is_writable_chunk_v
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDims... > extents(DiscreteDomain< DDims... > const &domain) noexcept
Chunk(SupportType const &, Allocator) -> Chunk< typename Allocator::value_type, SupportType, Allocator >
KOKKOS_FUNCTION constexpr auto replace_dim_of(DiscreteDomain< DDimsA... > const &DDom_a, DiscreteDomain< DDimsB... > const &DDom_b) noexcept
Chunk(std::string const &, SupportType const &, Allocator) -> Chunk< typename Allocator::value_type, SupportType, Allocator >
constexpr bool is_discrete_domain_v
KOKKOS_FUNCTION constexpr DiscreteDomain< QueryDDims... > select(DiscreteDomain< DDims... > const &domain)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator--(int)
friend KOKKOS_FUNCTION constexpr bool operator<=(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
KOKKOS_FUNCTION constexpr DiscreteElement< DDim > operator*() const noexcept
friend KOKKOS_FUNCTION constexpr bool operator>=(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
KOKKOS_DEFAULTED_FUNCTION DiscreteDomainIterator()=default
KOKKOS_FUNCTION constexpr DiscreteElement< DDim > operator[](difference_type n) const
KOKKOS_FUNCTION constexpr DiscreteDomainIterator & operator--()
KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator++(int)
friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator-(DiscreteDomainIterator i, difference_type n)
friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator+(DiscreteDomainIterator i, difference_type n)
friend KOKKOS_FUNCTION constexpr bool operator>(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
friend KOKKOS_FUNCTION constexpr bool operator!=(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
friend KOKKOS_FUNCTION constexpr bool operator<(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator & operator+=(difference_type n)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator & operator++()
friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator+(difference_type n, DiscreteDomainIterator i)
friend KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator(DiscreteElement< DDim > value)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator & operator-=(difference_type n)
friend KOKKOS_FUNCTION constexpr difference_type operator-(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)