DDC 0.16.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
19#include "type_seq.hpp"
20
21namespace ddc {
22
23template <concepts::discrete_dimension DDim>
25
26template <concepts::discrete_dimension... 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 = ddc::TypeSeq<Tags...>;
55};
56
57template <class... DDims, class... ODDims>
58struct Rebind<DiscreteDomain<DDims...>, ddc::TypeSeq<ODDims...>>
59{
60 using type = DiscreteDomain<ODDims...>;
61};
62
63} // namespace detail
64
65template <concepts::discrete_dimension... DDims>
67{
68 template <concepts::discrete_dimension...>
69 friend class DiscreteDomain;
70
71 static_assert(
72 type_seq_is_unique_v<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 <concepts::discrete_dimension... ODDims>
124 KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain<ODDims...> 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 <concepts::discrete_dimension... ODDims>
135 KOKKOS_FUNCTION constexpr bool operator!=(DiscreteDomain<ODDims...> 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 <concepts::discrete_dimension 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 <concepts::discrete_dimension... 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 <concepts::discrete_dimension...>
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 <concepts::discrete_dimension... ODDims>
412 KOKKOS_FUNCTION constexpr DiscreteDomain restrict_with(
413 DiscreteDomain<ODDims...> 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 <concepts::discrete_dimension... QueryDDims, concepts::discrete_dimension... 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 <ddc::concepts::discrete_dimension... DDims>
464struct ConvertTypeSeqToDiscreteDomain<ddc::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 <concepts::discrete_dimension... DDimsA, concepts::discrete_dimension... 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 = TypeSeq<DDimsA...>;
481 using TagSeqB = 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 <concepts::discrete_dimension... DDimsB, concepts::discrete_dimension... DDimsA>
491KOKKOS_FUNCTION constexpr auto remove_dims_of(DiscreteDomain<DDimsA...> const& DDom_a) noexcept
492{
493 using TagSeqA = TypeSeq<DDimsA...>;
494 using TagSeqB = 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//! Type alias for the discrete domain obtained by removing dimensions DDims from DDom.
501//! @tparam DDom The discrete domain type from which to remove dimensions.
502//! @tparam DDims The discrete dimensions to remove.
503//! @return The discrete domain type without the DDims dimensions.
504template <typename DDom, concepts::discrete_dimension... DDims>
505using remove_dims_of_t = decltype(remove_dims_of<DDims...>(std::declval<DDom>()));
506
507namespace detail {
508
509// 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
510template <
511 ddc::concepts::discrete_dimension DDim1,
512 ddc::concepts::discrete_dimension DDim2,
513 ddc::concepts::discrete_dimension DDimA,
514 ddc::concepts::discrete_dimension... DDimsB>
515KOKKOS_FUNCTION constexpr std::conditional_t<
516 std::is_same_v<DDimA, DDim1>,
517 ddc::DiscreteDomain<DDim2>,
518 ddc::DiscreteDomain<DDimA>>
519replace_dim_of_1d(
520 [[maybe_unused]] DiscreteDomain<DDimA> const& DDom_a,
521 [[maybe_unused]] DiscreteDomain<DDimsB...> const& DDom_b) noexcept
522{
523 if constexpr (std::is_same_v<DDimA, DDim1>) {
524 return ddc::DiscreteDomain<DDim2>(DDom_b);
525 } else {
526 return DDom_a;
527 }
528}
529
530} // namespace detail
531
532// Replace in DDom_a the dimension Dim1 by the dimension Dim2 of DDom_b
533template <
534 concepts::discrete_dimension DDim1,
535 concepts::discrete_dimension DDim2,
536 concepts::discrete_dimension... DDimsA,
537 concepts::discrete_dimension... DDimsB>
538KOKKOS_FUNCTION constexpr auto replace_dim_of(
539 DiscreteDomain<DDimsA...> const& DDom_a,
540 [[maybe_unused]] DiscreteDomain<DDimsB...> const& DDom_b) noexcept
541{
542 // TODO : static_asserts
543 using TagSeqA = TypeSeq<DDimsA...>;
544 using TagSeqB = TypeSeq<DDim1>;
545 using TagSeqC = TypeSeq<DDim2>;
546
547 using type_seq_r = ddc::type_seq_replace_t<TagSeqA, TagSeqB, TagSeqC>;
548 return ddc::detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(
549 detail::replace_dim_of_1d<
550 DDim1,
551 DDim2,
552 DDimsA,
553 DDimsB...>(ddc::DiscreteDomain<DDimsA>(DDom_a), DDom_b)...);
554}
555
556// Replace dimensions from a domain type
557template <typename DDom, concepts::discrete_dimension DDim1, concepts::discrete_dimension DDim2>
558using replace_dim_of_t = decltype(replace_dim_of<DDim1, DDim2>(
559 std::declval<DDom>(),
560 std::declval<typename detail::Rebind<DDom, TypeSeq<DDim2>>::type>()));
561
562
563template <concepts::discrete_dimension... QueryDDims, concepts::discrete_dimension... DDims>
564KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDims...> extents(
565 DiscreteDomain<DDims...> const& domain) noexcept
566{
567 return DiscreteVector<QueryDDims...>(DiscreteDomain<QueryDDims>(domain).size()...);
568}
569
570template <concepts::discrete_dimension... QueryDDims, concepts::discrete_dimension... DDims>
571KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> front(
572 DiscreteDomain<DDims...> const& domain) noexcept
573{
574 return DiscreteElement<QueryDDims...>(DiscreteDomain<QueryDDims>(domain).front()...);
575}
576
577template <concepts::discrete_dimension... QueryDDims, concepts::discrete_dimension... DDims>
578KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> back(
579 DiscreteDomain<DDims...> const& domain) noexcept
580{
581 return DiscreteElement<QueryDDims...>(DiscreteDomain<QueryDDims>(domain).back()...);
582}
583
584template <concepts::discrete_dimension DDim>
586{
587private:
588 DiscreteElement<DDim> m_value = DiscreteElement<DDim>();
589
590public:
591 using iterator_category = std::random_access_iterator_tag;
592
593 using value_type = DiscreteElement<DDim>;
594
595 using difference_type = std::ptrdiff_t;
596
597 KOKKOS_DEFAULTED_FUNCTION DiscreteDomainIterator() = default;
598
599 KOKKOS_FUNCTION constexpr explicit DiscreteDomainIterator(DiscreteElement<DDim> value)
600 : m_value(value)
601 {
602 }
603
604 KOKKOS_FUNCTION constexpr DiscreteElement<DDim> operator*() const noexcept
605 {
606 return m_value;
607 }
608
609 KOKKOS_FUNCTION constexpr DiscreteDomainIterator& operator++()
610 {
611 ++m_value;
612 return *this;
613 }
614
615 KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator++(int)
616 {
617 auto tmp = *this;
618 ++*this;
619 return tmp;
620 }
621
622 KOKKOS_FUNCTION constexpr DiscreteDomainIterator& operator--()
623 {
624 --m_value;
625 return *this;
626 }
627
628 KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator--(int)
629 {
630 auto tmp = *this;
631 --*this;
632 return tmp;
633 }
634
635 KOKKOS_FUNCTION constexpr DiscreteDomainIterator& operator+=(difference_type n)
636 {
637 if (n >= static_cast<difference_type>(0)) {
638 m_value += static_cast<DiscreteElementType>(n);
639 } else {
640 m_value -= static_cast<DiscreteElementType>(-n);
641 }
642 return *this;
643 }
644
645 KOKKOS_FUNCTION constexpr DiscreteDomainIterator& operator-=(difference_type n)
646 {
647 if (n >= static_cast<difference_type>(0)) {
648 m_value -= static_cast<DiscreteElementType>(n);
649 } else {
650 m_value += static_cast<DiscreteElementType>(-n);
651 }
652 return *this;
653 }
654
655 KOKKOS_FUNCTION constexpr DiscreteElement<DDim> operator[](difference_type n) const
656 {
657 return m_value + n;
658 }
659
660 friend KOKKOS_FUNCTION constexpr bool operator==(
661 DiscreteDomainIterator const& xx,
662 DiscreteDomainIterator const& yy)
663 {
664 return xx.m_value == yy.m_value;
665 }
666
667#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
668 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
669 friend KOKKOS_FUNCTION constexpr bool operator!=(
672 {
673 return xx.m_value != yy.m_value;
674 }
675#endif
676
677 friend KOKKOS_FUNCTION constexpr bool operator<(
678 DiscreteDomainIterator const& xx,
679 DiscreteDomainIterator const& yy)
680 {
681 return xx.m_value < yy.m_value;
682 }
683
684 friend KOKKOS_FUNCTION constexpr bool operator>(
685 DiscreteDomainIterator const& xx,
686 DiscreteDomainIterator const& yy)
687 {
688 return yy < xx;
689 }
690
691 friend KOKKOS_FUNCTION constexpr bool operator<=(
692 DiscreteDomainIterator const& xx,
693 DiscreteDomainIterator const& yy)
694 {
695 return !(yy < xx);
696 }
697
698 friend KOKKOS_FUNCTION constexpr bool operator>=(
699 DiscreteDomainIterator const& xx,
700 DiscreteDomainIterator const& yy)
701 {
702 return !(xx < yy);
703 }
704
705 friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator+(
707 difference_type n)
708 {
709 return i += n;
710 }
711
712 friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator+(
713 difference_type n,
715 {
716 return i += n;
717 }
718
719 friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator-(
721 difference_type n)
722 {
723 return i -= n;
724 }
725
726 friend KOKKOS_FUNCTION constexpr difference_type operator-(
727 DiscreteDomainIterator const& xx,
728 DiscreteDomainIterator const& yy)
729 {
730 return (yy.m_value > xx.m_value) ? (-static_cast<difference_type>(yy.m_value - xx.m_value))
731 : (xx.m_value - yy.m_value);
732 }
733};
734
735} // 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:170
auto operator[](DiscreteVector< QueryDDims... > const &slice_spec) const
Slice out some dimensions.
Definition chunk.hpp:156
char const * label() const
Returns the label of the Chunk.
Definition chunk.hpp:265
const_allocation_mdspan_type allocation_mdspan() const
Provide a mdspan on the memory allocation.
Definition chunk.hpp:289
ElementType const * data_handle() const
Access to the underlying allocation pointer.
Definition chunk.hpp:273
auto allocation_kokkos_view()
Provide an unmanaged Kokkos::View on the memory allocation.
Definition chunk.hpp:305
auto operator[](DiscreteDomain< QueryDDims... > const &odomain)
Slice out some dimensions.
Definition chunk.hpp:192
auto allocation_kokkos_view() const
Provide an unmanaged Kokkos::View on the memory allocation.
Definition chunk.hpp:321
Chunk(SupportType const &domain, Allocator allocator=Allocator())
Construct a Chunk on a domain with uninitialized values.
Definition chunk.hpp:106
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:297
ElementType * data_handle()
Access to the underlying allocation pointer.
Definition chunk.hpp:281
view_type span_cview() const
Definition chunk.hpp:334
Chunk(Chunk const &other)=delete
Deleted: use deepcopy instead.
~Chunk() noexcept
Definition chunk.hpp:126
Chunk(std::string const &label, SupportType const &domain, Allocator allocator=Allocator())
Construct a labeled Chunk on a domain with uninitialized values.
Definition chunk.hpp:95
element_type & operator()(DElems const &... delems) noexcept
Element access using a list of DiscreteElement.
Definition chunk.hpp:235
Chunk()=default
Empty Chunk.
Chunk & operator=(Chunk &&other) noexcept
Move-assigns a new value to this field.
Definition chunk.hpp:140
Chunk(Chunk &&other) noexcept
Constructs a new Chunk by move.
Definition chunk.hpp:117
friend class Chunk
Definition chunk.hpp:83
span_type span_view()
Definition chunk.hpp:344
view_type span_view() const
Definition chunk.hpp:339
auto operator[](DiscreteDomain< QueryDDims... > const &odomain) const
Slice out some dimensions.
Definition chunk.hpp:184
element_type const & operator()(DElems const &... delems) const noexcept
Element access using a list of DiscreteElement.
Definition chunk.hpp:203
auto operator[](DiscreteVector< QueryDDims... > const &slice_spec)
Slice out some dimensions.
Definition chunk.hpp:163
auto operator[](DiscreteElement< QueryDDims... > const &slice_spec)
Slice out some dimensions.
Definition chunk.hpp:177
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
KOKKOS_FUNCTION constexpr DiscreteDomain restrict_with(DiscreteDomain< ODDims... > const &) const
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 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 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_FUNCTION constexpr bool operator==(DiscreteDomain< ODDims... > const &other) const
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
#define DDC_BUILD_DEPRECATED_CODE
Definition config.hpp:7
#define DDC_BUILD_DOUBLE_PRECISION
Definition config.hpp:15
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:30
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)
A compile-time sequence of types.
Definition type_seq.hpp:30
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)