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